Skip to content

Commit

Permalink
fix(pendingWrites): don't skip the pending entries with version=0 (#1721
Browse files Browse the repository at this point in the history
)

With the introduction of SinceTs, a bug was introduced #1653 that skips the pending entries.
The default value of SinceTs is zero. And for the transaction made at readTs 0, the pending entries have version set to 0. So they were also getting skipped.

(cherry picked from commit 3911787)
  • Loading branch information
NamanJain8 committed Jul 8, 2021
1 parent 439b568 commit e1f9dce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ func (it *Iterator) parseItem() bool {
// Skip any versions which are beyond the readTs.
version := y.ParseTs(key)
// Ignore everything that is above the readTs and below or at the sinceTs.
if version > it.readTs || version <= it.opt.SinceTs {
if version > it.readTs || (it.opt.SinceTs > 0 && version <= it.opt.SinceTs) {
mi.Next()
return false
}
Expand Down
18 changes: 18 additions & 0 deletions iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,24 @@ func TestIterateSinceTs(t *testing.T) {
})
}

func TestIterateSinceTsWithPendingWrites(t *testing.T) {
// The pending entries still have version=0. Even IteratorOptions.SinceTs is 0, the entries
// should be visible.
runBadgerTest(t, nil, func(t *testing.T, db *DB) {
txn := db.NewTransaction(true)
defer txn.Discard()
require.NoError(t, txn.Set([]byte("key1"), []byte("value1")))
require.NoError(t, txn.Set([]byte("key2"), []byte("value2")))
itr := txn.NewIterator(DefaultIteratorOptions)
defer itr.Close()
count := 0
for itr.Rewind(); itr.Valid(); itr.Next() {
count++
}
require.Equal(t, 2, count)
})
}

func TestIteratePrefix(t *testing.T) {
if !*manual {
t.Skip("Skipping test meant to be run manually.")
Expand Down

0 comments on commit e1f9dce

Please sign in to comment.