Skip to content

Commit

Permalink
fix(maxVersion): Use choosekey instead of KeyToList (#1532) (#1533)
Browse files Browse the repository at this point in the history
(cherry picked from commit f07dcfc)
  • Loading branch information
Ibrahim Jarif authored Sep 21, 2020
1 parent 7c169e9 commit 6a6b506
Showing 1 changed file with 5 additions and 26 deletions.
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

0 comments on commit 6a6b506

Please # to comment.