Slight improvements to RocksDB range scans (#4478)
This commit is contained in:
parent
85c30e8eeb
commit
82349eb557
1 changed files with 22 additions and 26 deletions
|
@ -404,23 +404,21 @@ impl super::api::Transaction for Transaction {
|
|||
// Set the ReadOptions with the snapshot
|
||||
let mut ro = ReadOptions::default();
|
||||
ro.set_snapshot(&inner.snapshot());
|
||||
ro.set_async_io(true);
|
||||
ro.fill_cache(true);
|
||||
// Create the iterator
|
||||
let mut iter = inner.raw_iterator_opt(ro);
|
||||
// Seek to the start key
|
||||
iter.seek(&rng.start);
|
||||
// Scan the keys in the iterator
|
||||
while iter.valid() {
|
||||
// Check the scan limit
|
||||
if res.len() < limit as usize {
|
||||
// Get the key and value
|
||||
let k = iter.key();
|
||||
// Check the key and value
|
||||
if let Some(k) = k {
|
||||
if k >= beg && k < end {
|
||||
res.push(k.to_vec());
|
||||
iter.next();
|
||||
continue;
|
||||
}
|
||||
// Check the scan limit
|
||||
while res.len() < limit as usize {
|
||||
// Check the key and value
|
||||
if let Some(k) = iter.key() {
|
||||
// Check the range validity
|
||||
if k >= beg && k < end {
|
||||
res.push(k.to_vec());
|
||||
iter.next();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Exit
|
||||
|
@ -455,23 +453,21 @@ impl super::api::Transaction for Transaction {
|
|||
// Set the ReadOptions with the snapshot
|
||||
let mut ro = ReadOptions::default();
|
||||
ro.set_snapshot(&inner.snapshot());
|
||||
ro.set_async_io(true);
|
||||
ro.fill_cache(true);
|
||||
// Create the iterator
|
||||
let mut iter = inner.raw_iterator_opt(ro);
|
||||
// Seek to the start key
|
||||
iter.seek(&rng.start);
|
||||
// Scan the keys in the iterator
|
||||
while iter.valid() {
|
||||
// Check the scan limit
|
||||
if res.len() < limit as usize {
|
||||
// Get the key and value
|
||||
let (k, v) = (iter.key(), iter.value());
|
||||
// Check the key and value
|
||||
if let (Some(k), Some(v)) = (k, v) {
|
||||
if k >= beg && k < end {
|
||||
res.push((k.to_vec(), v.to_vec()));
|
||||
iter.next();
|
||||
continue;
|
||||
}
|
||||
// Check the scan limit
|
||||
while res.len() < limit as usize {
|
||||
// Check the key and value
|
||||
if let Some((k, v)) = iter.item() {
|
||||
// Check the range validity
|
||||
if k >= beg && k < end {
|
||||
res.push((k.to_vec(), v.to_vec()));
|
||||
iter.next();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Exit
|
||||
|
|
Loading…
Reference in a new issue