Skip to content
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
28 changes: 25 additions & 3 deletions src/transaction/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,14 @@ impl Buffer {

// fetch from TiKV
// fetch more entries because some of them may be deleted.
let redundant_limit = limit
+ mutation_range
let deleted_count = u32::try_from(
mutation_range
.clone()
.filter(|(_, m)| matches!(m, BufferEntry::Del))
.count() as u32;
.count(),
)
.unwrap_or(u32::MAX);
let redundant_limit = limit.saturating_add(deleted_count);

let mut results = f(range, redundant_limit)
.await?
Expand Down Expand Up @@ -513,6 +516,25 @@ mod tests {
);
}

#[test]
fn scan_and_fetch_redundant_limit_does_not_overflow() {
let mut buffer = Buffer::new(false);
buffer.delete(b"key1".to_vec().into());

let range: BoundRange = (..).into();
let res =
block_on(
buffer.scan_and_fetch(range, u32::MAX, false, false, |_, redundant_limit| {
assert_eq!(redundant_limit, u32::MAX);
ready(Ok(Vec::<KvPair>::new()))
}),
)
.unwrap()
.collect::<Vec<_>>();

assert!(res.is_empty());
}

// Check that multiple writes to the same key combine in the correct way.
#[test]
fn state_machine() {
Expand Down