Skip to content

Commit 92e25a4

Browse files
committed
correct constructors
1 parent 65a7512 commit 92e25a4

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

grovedb/src/replication.rs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ struct SubtreeStateSyncInfo<'db> {
3131
num_processed_chunks: usize,
3232
}
3333

34+
impl SubtreeStateSyncInfo<'_> {
35+
// Function to create an instance of SubtreeStateSyncInfo with default values
36+
fn new() -> Self {
37+
let pending_chunks = BTreeSet::new();
38+
Self {
39+
restorer: None,
40+
pending_chunks,
41+
num_processed_chunks: 0,
42+
}
43+
}
44+
}
45+
3446
// Struct governing state sync
3547
pub struct MultiStateSyncInfo<'db> {
3648
// Map of current processing subtrees
@@ -42,6 +54,19 @@ pub struct MultiStateSyncInfo<'db> {
4254
version: u16,
4355
}
4456

57+
impl MultiStateSyncInfo<'_> {
58+
// Function to create an instance of MultiStateSyncInfo with default values
59+
pub fn new() -> Self {
60+
let processed_prefixes = BTreeSet::new();
61+
let current_prefixes = BTreeMap::default();
62+
Self {
63+
current_prefixes,
64+
processed_prefixes,
65+
version: CURRENT_STATE_SYNC_VERSION,
66+
}
67+
}
68+
}
69+
4570
// Struct containing information about current subtrees found in GroveDB
4671
pub struct SubtreesMetadata {
4772
// Map of Prefix (Path digest) -> (Actual path, Parent Subtree actual_value_hash, Parent
@@ -140,25 +165,6 @@ pub fn util_decode_vec_ops(chunk: Vec<u8>) -> Result<Vec<Op>, Error> {
140165

141166
#[cfg(feature = "full")]
142167
impl GroveDb {
143-
fn create_subtree_state_sync_info(&self) -> SubtreeStateSyncInfo {
144-
let pending_chunks = BTreeSet::new();
145-
SubtreeStateSyncInfo {
146-
restorer: None,
147-
pending_chunks,
148-
num_processed_chunks: 0,
149-
}
150-
}
151-
152-
pub fn create_multi_state_sync_info(&self) -> MultiStateSyncInfo {
153-
let processed_prefixes = BTreeSet::new();
154-
let current_prefixes = BTreeMap::default();
155-
MultiStateSyncInfo {
156-
current_prefixes,
157-
processed_prefixes,
158-
version: CURRENT_STATE_SYNC_VERSION,
159-
}
160-
}
161-
162168
// Returns the discovered subtrees found recursively along with their associated
163169
// metadata Params:
164170
// tx: Transaction. Function returns the data by opening merks at given tx.
@@ -383,7 +389,7 @@ impl GroveDb {
383389
replication::util_path_to_string(&[])
384390
);
385391

386-
let mut root_prefix_state_sync_info = self.create_subtree_state_sync_info();
392+
let mut root_prefix_state_sync_info = SubtreeStateSyncInfo::new();
387393
let root_prefix = [0u8; 32];
388394
if let Ok(merk) = self.open_merk_for_replication(SubtreePath::empty(), tx) {
389395
let restorer = Restorer::new(merk, app_hash, None);
@@ -588,7 +594,7 @@ impl GroveDb {
588594
replication::util_path_to_string(&prefix_metadata.0)
589595
);
590596

591-
let mut subtree_state_sync_info = self.create_subtree_state_sync_info();
597+
let mut subtree_state_sync_info = SubtreeStateSyncInfo::new();
592598
if let Ok(merk) = self.open_merk_for_replication(path.into(), tx) {
593599
let restorer =
594600
Restorer::new(merk, *s_elem_value_hash, Some(*s_actual_value_hash));

tutorials/src/bin/replication.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ fn main() {
101101
println!("{:?}", subtrees_metadata_source);
102102

103103
println!("\n######### db_checkpoint_0 -> db_destination state sync");
104-
let state_info = db_destination.create_multi_state_sync_info();
104+
let state_info = MultiStateSyncInfo::new();
105105
let tx = db_destination.start_transaction();
106106
sync_db_demo(&db_checkpoint_0, &db_destination, state_info, &tx).unwrap();
107107
db_destination.commit_transaction(tx).unwrap().expect("expected to commit transaction");

0 commit comments

Comments
 (0)