Slight improvements to RocksDB range scans (#4478)

This commit is contained in:
Tobie Morgan Hitchcock 2024-08-08 10:54:03 +01:00 committed by GitHub
parent 85c30e8eeb
commit 82349eb557
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -404,25 +404,23 @@ impl super::api::Transaction for Transaction {
// Set the ReadOptions with the snapshot // Set the ReadOptions with the snapshot
let mut ro = ReadOptions::default(); let mut ro = ReadOptions::default();
ro.set_snapshot(&inner.snapshot()); ro.set_snapshot(&inner.snapshot());
ro.set_async_io(true);
ro.fill_cache(true);
// Create the iterator // Create the iterator
let mut iter = inner.raw_iterator_opt(ro); let mut iter = inner.raw_iterator_opt(ro);
// Seek to the start key // Seek to the start key
iter.seek(&rng.start); iter.seek(&rng.start);
// Scan the keys in the iterator
while iter.valid() {
// Check the scan limit // Check the scan limit
if res.len() < limit as usize { while res.len() < limit as usize {
// Get the key and value
let k = iter.key();
// Check the key and value // Check the key and value
if let Some(k) = k { if let Some(k) = iter.key() {
// Check the range validity
if k >= beg && k < end { if k >= beg && k < end {
res.push(k.to_vec()); res.push(k.to_vec());
iter.next(); iter.next();
continue; continue;
} }
} }
}
// Exit // Exit
break; break;
} }
@ -455,25 +453,23 @@ impl super::api::Transaction for Transaction {
// Set the ReadOptions with the snapshot // Set the ReadOptions with the snapshot
let mut ro = ReadOptions::default(); let mut ro = ReadOptions::default();
ro.set_snapshot(&inner.snapshot()); ro.set_snapshot(&inner.snapshot());
ro.set_async_io(true);
ro.fill_cache(true);
// Create the iterator // Create the iterator
let mut iter = inner.raw_iterator_opt(ro); let mut iter = inner.raw_iterator_opt(ro);
// Seek to the start key // Seek to the start key
iter.seek(&rng.start); iter.seek(&rng.start);
// Scan the keys in the iterator
while iter.valid() {
// Check the scan limit // Check the scan limit
if res.len() < limit as usize { while res.len() < limit as usize {
// Get the key and value
let (k, v) = (iter.key(), iter.value());
// Check the key and value // Check the key and value
if let (Some(k), Some(v)) = (k, v) { if let Some((k, v)) = iter.item() {
// Check the range validity
if k >= beg && k < end { if k >= beg && k < end {
res.push((k.to_vec(), v.to_vec())); res.push((k.to_vec(), v.to_vec()));
iter.next(); iter.next();
continue; continue;
} }
} }
}
// Exit // Exit
break; break;
} }