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
|
// 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
|
// Check the scan limit
|
||||||
while iter.valid() {
|
while res.len() < limit as usize {
|
||||||
// Check the scan limit
|
// Check the key and value
|
||||||
if res.len() < limit as usize {
|
if let Some(k) = iter.key() {
|
||||||
// Get the key and value
|
// Check the range validity
|
||||||
let k = iter.key();
|
if k >= beg && k < end {
|
||||||
// Check the key and value
|
res.push(k.to_vec());
|
||||||
if let Some(k) = k {
|
iter.next();
|
||||||
if k >= beg && k < end {
|
continue;
|
||||||
res.push(k.to_vec());
|
|
||||||
iter.next();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Exit
|
// Exit
|
||||||
|
@ -455,23 +453,21 @@ 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
|
// Check the scan limit
|
||||||
while iter.valid() {
|
while res.len() < limit as usize {
|
||||||
// Check the scan limit
|
// Check the key and value
|
||||||
if res.len() < limit as usize {
|
if let Some((k, v)) = iter.item() {
|
||||||
// Get the key and value
|
// Check the range validity
|
||||||
let (k, v) = (iter.key(), iter.value());
|
if k >= beg && k < end {
|
||||||
// Check the key and value
|
res.push((k.to_vec(), v.to_vec()));
|
||||||
if let (Some(k), Some(v)) = (k, v) {
|
iter.next();
|
||||||
if k >= beg && k < end {
|
continue;
|
||||||
res.push((k.to_vec(), v.to_vec()));
|
|
||||||
iter.next();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Exit
|
// Exit
|
||||||
|
|
Loading…
Reference in a new issue