Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Redb implementation and add CI checks #6856

Merged
merged 6 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ lint-fix:

# Also run the lints on the optimized-only tests
lint-full:
RUSTFLAGS="-C debug-assertions=no $(RUSTFLAGS)" $(MAKE) lint
TEST_FEATURES="beacon-node-leveldb,beacon-node-redb,${TEST_FEATURES}" RUSTFLAGS="-C debug-assertions=no $(RUSTFLAGS)" $(MAKE) lint

# Runs the makefile in the `ef_tests` repo.
#
Expand Down
33 changes: 19 additions & 14 deletions beacon_node/store/src/database/redb_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,12 @@ impl<E: EthSpec> Redb<E> {
let table_definition: TableDefinition<'_, &[u8], &[u8]> =
TableDefinition::new(column.into());

let iter = {
let result = (|| {
let open_db = self.db.read();
let read_txn = open_db.begin_read()?;
let table = read_txn.open_table(table_definition)?;
table.range(from..)?.map(move |res| {
let range = table.range(from..)?;
Ok(range.map(move |res| {
let (key, _) = res?;
metrics::inc_counter_vec(&metrics::DISK_DB_KEY_READ_COUNT, &[column.into()]);
metrics::inc_counter_vec_by(
Expand All @@ -228,10 +229,13 @@ impl<E: EthSpec> Redb<E> {
key.value().len() as u64,
);
K::from_bytes(key.value())
})
};
}))
})();

Box::new(iter)
match result {
Ok(iter) => Box::new(iter),
Err(err) => Box::new(std::iter::once(Err(err))),
}
}

/// Iterate through all keys and values in a particular column.
Expand All @@ -243,15 +247,13 @@ impl<E: EthSpec> Redb<E> {
let table_definition: TableDefinition<'_, &[u8], &[u8]> =
TableDefinition::new(column.into());

let prefix = from.to_vec();

let iter = {
let result = (|| {
let open_db = self.db.read();
let read_txn = open_db.begin_read()?;
let table = read_txn.open_table(table_definition)?;
let range = table.range(from..)?;

table
.range(from..)?
Ok(range
.take_while(move |res| match res.as_ref() {
Ok((_, _)) => true,
Err(_) => false,
Expand All @@ -265,14 +267,17 @@ impl<E: EthSpec> Redb<E> {
value.value().len() as u64,
);
Ok((K::from_bytes(key.value())?, value.value().to_vec()))
})
};
}))
})();

Ok(Box::new(iter))
match result {
Ok(iter) => Box::new(iter),
Err(err) => Box::new(std::iter::once(Err(err))),
}
}

pub fn iter_column<K: Key>(&self, column: DBColumn) -> ColumnIter<K> {
self.iter_column_from(column, &vec![0; column.key_size()], |_, _| true)
self.iter_column_from(column, &vec![0; column.key_size()])
}

pub fn delete_batch(&self, col: DBColumn, ops: HashSet<&[u8]>) -> Result<(), Error> {
Expand Down
1 change: 1 addition & 0 deletions beacon_node/store/src/forwards_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
return None;
}
self.inner
.as_mut()
.next()?
.and_then(|(slot_bytes, root_bytes)| {
let slot = slot_bytes
Expand Down
6 changes: 3 additions & 3 deletions beacon_node/store/src/hot_cold_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use crate::metadata::{
};
use crate::state_cache::{PutStateOutcome, StateCache};
use crate::{
get_data_column_key, metrics, parse_data_column_key, BlobSidecarListFromRoot, DBColumn,
DatabaseBlock, Error, ItemStore, KeyValueStore, KeyValueStoreOp, StoreItem, StoreOp,
get_data_column_key, metrics, parse_data_column_key, BlobSidecarListFromRoot, ColumnKeyIter,
DBColumn, DatabaseBlock, Error, ItemStore, KeyValueStore, KeyValueStoreOp, StoreItem, StoreOp,
};
use itertools::{process_results, Itertools};
use lru::LruCache;
Expand Down Expand Up @@ -405,7 +405,7 @@ impl<E: EthSpec> HotColdDB<E, BeaconNodeBackend<E>, BeaconNodeBackend<E>> {
}

/// Return an iterator over the state roots of all temporary states.
pub fn iter_temporary_state_roots(&self) -> impl Iterator<Item = Result<Hash256, Error>> + '_ {
pub fn iter_temporary_state_roots(&self) -> ColumnKeyIter<Hash256> {
self.hot_db
.iter_column_keys::<Hash256>(DBColumn::BeaconStateTemporary)
}
Expand Down