Skip to content

Commit

Permalink
some renames
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhailOK committed Aug 11, 2020
1 parent 17c9508 commit 7d906c9
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions core/store/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,15 @@ impl Database for RocksDB {
fn get(&self, col: DBCol, key: &[u8]) -> Result<Option<Vec<u8>>, DBError> {
let read_options = rocksdb_read_options();
let result = self.db.get_cf_opt(unsafe { &*self.cfs[col as usize] }, key, &read_options)?;
Ok(RocksDB::empty_value_filtering(col, result))
Ok(RocksDB::empty_value_filtering_get(col, result))
}

fn iter<'a>(&'a self, col: DBCol) -> Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + 'a> {
let read_options = rocksdb_read_options();
unsafe {
let cf_handle = &*self.cfs[col as usize];
let iterator = self.db.iterator_cf_opt(cf_handle, read_options, IteratorMode::Start);
RocksDB::iter_empty_value_filtering(col, iterator)
RocksDB::empty_value_filtering_iter(col, iterator)
}
}

Expand All @@ -310,7 +310,7 @@ impl Database for RocksDB {
IteratorMode::From(key_prefix, Direction::Forward),
)
.take_while(move |(key, _value)| key.starts_with(key_prefix));
RocksDB::iter_empty_value_filtering(col, iterator)
RocksDB::empty_value_filtering_iter(col, iterator)
}
}

Expand Down Expand Up @@ -478,32 +478,37 @@ impl RocksDB {
let mut result = vec![];
if let Some(val) = existing_val {
// Error is only possible if decoding refcount fails (=value is between 1 and 3 bytes)
merge_refcounted_records(&mut result, val).unwrap();
merge_refcounted_records(&mut result, val)
.expect("Not a refcounted record in ColState");
}
for val in operands {
// Error is only possible if decoding refcount fails (=value is between 1 and 3 bytes)
merge_refcounted_records(&mut result, val).unwrap();
merge_refcounted_records(&mut result, val)
.expect("Not a refcounted record in ColState");
}
Some(result)
}

fn empty_value_filter(_level: u32, _key: &[u8], value: &[u8]) -> Decision {
/// Compaction filter for ColState
fn empty_value_compaction_filter(_level: u32, _key: &[u8], value: &[u8]) -> Decision {
if value.is_empty() {
Decision::Remove
} else {
Decision::Keep
}
}

fn empty_value_filtering(column: DBCol, value: Option<Vec<u8>>) -> Option<Vec<u8>> {
/// ColState get() treats empty value as no value
fn empty_value_filtering_get(column: DBCol, value: Option<Vec<u8>>) -> Option<Vec<u8>> {
if column == DBCol::ColState && Some(vec![]) == value {
None
} else {
value
}
}

fn iter_empty_value_filtering<'a, I>(
/// ColState iterator treats empty value as no value
fn empty_value_filtering_iter<'a, I>(
column: DBCol,
iterator: I,
) -> Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + 'a>
Expand Down

0 comments on commit 7d906c9

Please sign in to comment.