Skip to content

Commit

Permalink
Fix bug in DBWALIterator that would return updates before the given s…
Browse files Browse the repository at this point in the history
…equence
  • Loading branch information
schmidek committed Nov 9, 2023
1 parent e59fc02 commit ba56ad7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/db_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ impl Iterator for DBWALIterator {

// if the initial sequence number is what was requested we skip it to
// only provide changes *after* it
if seq == self.start_seq_number {
while seq <= self.start_seq_number {
unsafe {
ffi::rocksdb_wal_iter_next(self.inner);
}
Expand Down
32 changes: 32 additions & 0 deletions tests/test_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,38 @@ fn test_get_updates_since_one_batch() {
assert_eq!(counts.deletes, 1);
}

#[test]
fn test_get_updates_since_batches() {
let path = DBPath::new("_rust_rocksdb_test_get_updates_since_one_batch");
let db = DB::open_default(&path).unwrap();
db.put(b"key2", b"value2").unwrap();

assert_eq!(db.latest_sequence_number(), 1);
let mut batch = WriteBatch::default();
batch.put(b"key1", b"value1");
batch.delete(b"key2");
db.write(batch).unwrap();
let seq2 = db.latest_sequence_number();
assert_eq!(seq2, 3);
let mut batch = WriteBatch::default();
batch.put(b"key3", b"value1");
batch.put(b"key4", b"value1");
db.write(batch).unwrap();
assert_eq!(db.latest_sequence_number(), 5);
let mut iter = db.get_updates_since(seq2).unwrap();
let mut counts = OperationCounts {
puts: 0,
deletes: 0,
};
// Verify we get the 2nd batch with 2 puts back and not the first
let (seq, batch) = iter.next().unwrap().unwrap();
assert_eq!(seq, 4);
batch.iterate(&mut counts);
assert!(iter.next().is_none());
assert_eq!(counts.puts, 2);
assert_eq!(counts.deletes, 0);
}

#[test]
fn test_get_updates_since_nothing() {
let path = DBPath::new("_rust_rocksdb_test_get_updates_since_nothing");
Expand Down

0 comments on commit ba56ad7

Please sign in to comment.