Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

release/v2.2007 - fix(maxVersion): Use choosekey instead of KeyToList (#1532) #1533

Merged
merged 1 commit into from
Sep 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 5 additions & 26 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -1831,36 +1831,15 @@ func (db *DB) MaxVersion() (uint64, error) {
stream = db.NewStream()
}

stream.KeyToList = func(key []byte, itr *Iterator) (*pb.KVList, error) {
maxVs := uint64(0)
for ; itr.Valid(); itr.Next() {
item := itr.Item()
if item.IsDeletedOrExpired() {
break
}
if !bytes.Equal(key, item.Key()) {
// Break out on the first encounter with another key.
break
}

if item.Version() > maxVs {
maxVs = item.Version()
}
if db.opt.NumVersionsToKeep == 1 {
break
}

if item.DiscardEarlierVersions() {
break
}
}
stream.ChooseKey = func(item *Item) bool {
mu.Lock()
if maxVs > maxVersion {
maxVersion = maxVs
if item.Version() > maxVersion {
maxVersion = item.Version()
}
mu.Unlock()
return nil, nil
return false
}
stream.KeyToList = nil
stream.Send = nil
if err := stream.Orchestrate(context.Background()); err != nil {
return 0, err
Expand Down