Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yzang2019 committed Apr 30, 2024
1 parent f685adf commit e9bfd77
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
8 changes: 6 additions & 2 deletions ss/pebbledb/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,13 @@ func newPebbleDBIterator(src *pebble.Iterator, prefix, mvccStart, mvccEnd []byte
}
}

// Make sure we do not return any tombstone value
// Make sure we skip to the next key if the current one is tombstone
if valTombstoned(itr.source.Value()) {
itr.valid = false
if reverse {
itr.nextReverse()
} else {
itr.nextForward()
}
}

return itr
Expand Down
13 changes: 7 additions & 6 deletions ss/test/storage_test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,31 +362,32 @@ func (s *StorageTestSuite) TestDatabaseIteratorDeletes() {
defer db.Close()

s.Require().NoError(DBApplyChangeset(db, 1, storeKey1, [][]byte{[]byte("key001")}, [][]byte{[]byte("value001")}))
s.Require().NoError(DBApplyChangeset(db, 1, storeKey1, [][]byte{[]byte("key002")}, [][]byte{[]byte("value002")}))
s.Require().NoError(DBApplyDeleteChangeset(db, 5, storeKey1, [][]byte{[]byte("key001")}))

itr, err := db.Iterator(storeKey1, 11, []byte("key001"), nil)
s.Require().NoError(err)

// there should be no valid key in the iterator
// there should be only one valid key in the iterator
var count = 0
for ; itr.Valid(); itr.Next() {
s.Require().Equal([]byte("key002"), itr.Key())
count++
}
s.Require().Equal(0, count)
s.Require().Equal(1, count)
s.Require().NoError(itr.Error())
itr.Close()

s.Require().NoError(DBApplyChangeset(db, 10, storeKey1, [][]byte{[]byte("key001")}, [][]byte{[]byte("value002")}))
s.Require().NoError(DBApplyChangeset(db, 10, storeKey1, [][]byte{[]byte("key001")}, [][]byte{[]byte("value001")}))
itr, err = db.Iterator(storeKey1, 11, []byte("key001"), nil)
s.Require().NoError(err)

// there should only be one valid key in the iterator
// there should be two valid keys in the iterator
count = 0
for ; itr.Valid(); itr.Next() {
s.Require().Equal([]byte("key001"), itr.Key())
count++
}
s.Require().Equal(1, count)
s.Require().Equal(2, count)
s.Require().NoError(itr.Error())
itr.Close()
}
Expand Down

0 comments on commit e9bfd77

Please sign in to comment.