Ejemplo n.º 1
0
func parseMigrateDB(c *client, arg []byte) (uint64, error) {
	db, err := ledis.StrUint64(arg, nil)
	if err != nil {
		return 0, err
	} else if db >= uint64(c.app.cfg.Databases) {
		return 0, fmt.Errorf("invalid db index %d, must < %d", db, c.app.cfg.Databases)
	}
	return db, nil
}
Ejemplo n.º 2
0
func syncCommand(c *client) error {
	args := c.args
	if len(args) != 1 {
		return ErrCmdParams
	}

	var logId uint64
	var err error

	if logId, err = ledis.StrUint64(args[0], nil); err != nil {
		return ErrCmdParams
	}

	lastLogID := logId - 1

	stat, err := c.app.ldb.ReplicationStat()
	if err != nil {
		return err
	}

	if lastLogID > stat.LastID {
		return fmt.Errorf("invalid sync logid %d > %d + 1", logId, stat.LastID)
	}

	c.lastLogID.Set(lastLogID)

	if lastLogID == stat.LastID {
		c.app.slaveAck(c)
	}

	c.syncBuf.Reset()

	c.syncBuf.Write(dummyBuf)

	if _, _, err := c.app.ldb.ReadLogsToTimeout(logId, &c.syncBuf, 1, c.app.quit); err != nil {
		return err
	} else {
		buf := c.syncBuf.Bytes()

		stat, err = c.app.ldb.ReplicationStat()
		if err != nil {
			return err
		}

		binary.BigEndian.PutUint64(buf, stat.LastID)

		c.resp.writeBulk(buf)
	}

	return nil
}