Skip to content

Commit

Permalink
Use rocksdb read option total_order_seek in all place where we iterat…
Browse files Browse the repository at this point in the history
…e from a key to outside of a prefix.
  • Loading branch information
AurelienFT committed Oct 30, 2024
1 parent a3213af commit d07ce5c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ where
fn get(&self, key: &[u8], column: Self::Column) -> StorageResult<Option<Value>> {
let read_history = &self.read_db;
let height_key = height_key(key, &self.height);
let options = ReadOptions::default();
let mut options = ReadOptions::default();
// We need this option because our iterator will try to start in the `height_key` prefix section
// but if there is no data in this section, we expect the iterator to fetch data in an other prefix section.
// Without this option it's not guarantee that we fetch the correct next prefix section.
// Source : https://github.com/facebook/rocksdb/wiki/Prefix-Seek#how-to-ignore-prefix-bloom-filters-in-read
// and https://github.com/facebook/rocksdb/wiki/Prefix-Seek#general-prefix-seek-api
options.set_total_order_seek(true);
let nearest_modification = read_history
.iterator::<KeyAndValue>(
Column::HistoricalDuplicateColumn(column),
Expand Down
15 changes: 13 additions & 2 deletions crates/fuel-core/src/state/rocks_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,11 @@ where
{
let reverse_iterator = next_prefix(prefix.to_vec()).map(|next_prefix| {
let mut opts = self.read_options();
// We need this option because our iterator start in the `next_prefix` prefix section
// and continue in `prefix` section. Without this option the correct
// iteration between prefix section isn't guaranteed
// Source : https://github.com/facebook/rocksdb/wiki/Prefix-Seek#how-to-ignore-prefix-bloom-filters-in-read
// and https://github.com/facebook/rocksdb/wiki/Prefix-Seek#general-prefix-seek-api
opts.set_total_order_seek(true);
self.iterator::<T>(
column,
Expand Down Expand Up @@ -600,8 +605,14 @@ where
// start iterating in a certain direction from the start key
let iter_mode =
IteratorMode::From(start, convert_to_rocksdb_direction(direction));
self.iterator::<T>(column, self.read_options(), iter_mode)
.into_boxed()
let mut opts = self.read_options();
// We need this option because our iterator start in the `start` prefix section
// and continue in next sections. Without this option the correct
// iteration between prefix section isn't guaranteed
// Source : https://github.com/facebook/rocksdb/wiki/Prefix-Seek#how-to-ignore-prefix-bloom-filters-in-read
// and https://github.com/facebook/rocksdb/wiki/Prefix-Seek#general-prefix-seek-api
opts.set_total_order_seek(true);
self.iterator::<T>(column, opts, iter_mode).into_boxed()
}
(Some(prefix), Some(start)) => {
// TODO: Maybe we want to allow the `start` to be without a `prefix` in the future.
Expand Down

0 comments on commit d07ce5c

Please sign in to comment.