Skip to content

Commit

Permalink
code rabbit suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ogabrielides committed Dec 27, 2024
1 parent 0667774 commit 9cac8a8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
20 changes: 13 additions & 7 deletions grovedb/src/replication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ impl GroveDb {
MultiStateSyncSession::new(self.start_transaction(), app_hash)
}

pub fn commit_session(&self, session: Pin<Box<MultiStateSyncSession>>) {
// we do not care about the cost
let _ = self.commit_transaction(session.into_transaction());
pub fn commit_session(&self, session: Pin<Box<MultiStateSyncSession>>) -> Result<(), Error> {
match self.commit_transaction(session.into_transaction()).value {
Ok(_) => Ok(()),
Err(e) => {
// Log the error or handle it as needed
eprintln!("Failed to commit session: {:?}", e);
Err(e)
}
}
}

// Fetch a chunk by global chunk id (should be called by ABCI when
Expand Down Expand Up @@ -168,12 +174,12 @@ impl GroveDb {
/// should be called by ABCI when OfferSnapshot method is called.
/// Returns the first set of global chunk ids that can be fetched from
/// sources and a new sync session.
pub fn start_snapshot_syncing<'db>(
&'db self,
pub fn start_snapshot_syncing(
&self,
app_hash: CryptoHash,
version: u16,
grove_version: &GroveVersion,
) -> Result<Pin<Box<MultiStateSyncSession<'db>>>, Error> {
) -> Result<Pin<Box<MultiStateSyncSession>>, Error> {
check_grovedb_v0!(
"start_snapshot_syncing",
grove_version
Expand Down Expand Up @@ -211,7 +217,7 @@ impl GroveDb {
pub fn util_path_to_string(path: &[Vec<u8>]) -> Vec<String> {
let mut subtree_path_str: Vec<String> = vec![];
for subtree in path {
let string = std::str::from_utf8(&subtree).unwrap_or_else(|_| "<NON_UTF8_PATH>");
let string = std::str::from_utf8(subtree).unwrap_or("<NON_UTF8_PATH>");
subtree_path_str.push(string.to_string());
}
subtree_path_str
Expand Down
8 changes: 4 additions & 4 deletions grovedb/src/replication/state_sync_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl<'db> MultiStateSyncSession<'db> {
next_chunk_ids.push(util_create_global_chunk_id(
chunk_prefix,
subtree_state_sync.root_key.clone(),
subtree_state_sync.is_sum_tree.clone(),
subtree_state_sync.is_sum_tree,
local_chunk_id.clone(),
));
}
Expand Down Expand Up @@ -403,9 +403,9 @@ impl<'db> MultiStateSyncSession<'db> {
let next_chunks_ids = self.add_subtree_sync_info(
db,
path.into(),
elem_value_hash.clone(),
Some(actual_value_hash.clone()),
prefix.clone(),
*elem_value_hash,
Some(*actual_value_hash),
*prefix,
grove_version,
)?;

Expand Down
2 changes: 1 addition & 1 deletion tutorials/src/bin/replication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ fn sync_db_demo(
println!("num_chunks: {}", num_chunks);

if session.is_sync_completed() {
target_db.commit_session(session);
target_db.commit_session(session).expect("failed to commit session");
}
let elapsed = start_time.elapsed();
println!("state_synced in {:.2?}", elapsed);
Expand Down

0 comments on commit 9cac8a8

Please sign in to comment.