func (m *master) sync() error { var err error var syncID uint64 if syncID, err = m.nextSyncLogID(); err != nil { return err } if err := m.conn.Send("sync", syncID); err != nil { return err } m.state.Set(replConnectedState) m.syncBuf.Reset() if err = m.conn.ReceiveBulkTo(&m.syncBuf); err != nil { if strings.Contains(err.Error(), ledis.ErrLogMissed.Error()) { return m.fullSync() } else { return err } } m.state.Set(replConnectedState) buf := m.syncBuf.Bytes() if len(buf) < 8 { return fmt.Errorf("inavlid sync size %d", len(buf)) } m.app.info.Replication.MasterLastLogID.Set(num.BytesToUint64(buf)) var t bytes.Buffer m.app.info.dumpReplication(&t) buf = buf[8:] if len(buf) == 0 { return nil } if err = m.app.ldb.StoreLogsFromData(buf); err != nil { return err } return nil }
func (s *GoLevelDBStore) lastID() (uint64, error) { if s.last != InvalidLogID { return s.last, nil } it := s.db.NewIterator() defer it.Close() it.SeekToLast() if it.Valid() { s.last = num.BytesToUint64(it.RawKey()) } return s.last, nil }