// New initializes a replication.LogReplicator using an already open kv.DB. func New(db kv.DB, prefix []byte) (replication.LogReplicator, error) { nextIndex := uint64(0) iter := db.NewIterator(kv.BytesPrefix(prefix)) if hasEntries := iter.Last(); hasEntries { nextIndex = binary.BigEndian.Uint64(iter.Key()[len(prefix):]) + 1 } iter.Release() if err := iter.Error(); err != nil { return nil, err } leaderHintSet := make(chan bool, 1) leaderHintSet <- true return &kvLog{ db: db, prefix: prefix, nextIndex: nextIndex, propose: make(chan replication.LogEntry, 100), leaderHintSet: leaderHintSet, waitCommitted: make(chan replication.LogEntry), stop: make(chan struct{}), stopped: make(chan struct{}), }, nil }