Skip to content

Commit ae3c21d

Browse files
committed
more refactoring
1 parent e5adf0d commit ae3c21d

File tree

2 files changed

+21
-24
lines changed

2 files changed

+21
-24
lines changed

grovedb/src/replication.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,11 @@ impl GroveDb {
203203
// "0" for right. TODO: Compact CHUNK_ID into bitset for size optimization
204204
// as a subtree can be big hence traversal instructions for the deepest chunks
205205
// tx: Transaction. Function returns the data by opening merks at given tx.
206-
// TODO: Make this tx optional: None -> Use latest data
207206
// Returns the Chunk proof operators for the requested chunk
208207
pub fn fetch_chunk<'db>(
209208
&'db self,
210209
global_chunk_id: &[u8],
211-
tx: &'db Transaction,
210+
tx: TransactionArg,
212211
) -> Result<Vec<Op>, Error> {
213212
let chunk_prefix_length: usize = 32;
214213
if global_chunk_id.len() < chunk_prefix_length {
@@ -223,7 +222,7 @@ impl GroveDb {
223222
array.copy_from_slice(chunk_prefix);
224223
let chunk_prefix_key: crate::SubtreePrefix = array;
225224

226-
let subtrees_metadata = self.get_subtrees_metadata(Some(tx))?;
225+
let subtrees_metadata = self.get_subtrees_metadata(tx)?;
227226

228227
match subtrees_metadata.data.get(&chunk_prefix_key) {
229228
Some(path_data) => {
@@ -232,7 +231,7 @@ impl GroveDb {
232231
let path: &[&[u8]] = &subtree_path;
233232

234233
let merk = self
235-
.open_transactional_merk_at_path(path.into(), tx, None)
234+
.open_non_transactional_merk_at_path(path.into(), None)
236235
.value?;
237236

238237
if merk.is_empty_tree().unwrap() {

tutorials/src/bin/replication.rs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,24 @@ fn main() {
7070
let db_destination = create_empty_db(path_destination.clone());
7171

7272
println!("\n######### root_hashes:");
73-
let root_hash_0 = db_source.root_hash(None).unwrap().unwrap();
74-
println!("root_hash_0: {:?}", hex::encode(root_hash_0));
73+
let root_hash_source = db_source.root_hash(None).unwrap().unwrap();
74+
println!("root_hash_source: {:?}", hex::encode(root_hash_source));
7575
let root_hash_checkpoint_0 = db_checkpoint_0.root_hash(None).unwrap().unwrap();
7676
println!("root_hash_checkpoint_0: {:?}", hex::encode(root_hash_checkpoint_0));
77-
let root_hash_copy = db_destination.root_hash(None).unwrap().unwrap();
78-
println!("root_hash_copy: {:?}", hex::encode(root_hash_copy));
77+
let root_hash_destination = db_destination.root_hash(None).unwrap().unwrap();
78+
println!("root_hash_destination: {:?}", hex::encode(root_hash_destination));
7979

80-
println!("\n######### source_subtree_metadata");
81-
let subtrees_metadata = db_source.get_subtrees_metadata(None).unwrap();
82-
println!("{:?}", subtrees_metadata);
80+
println!("\n######### source_subtree_metadata of db_source");
81+
let subtrees_metadata_source = db_source.get_subtrees_metadata(None).unwrap();
82+
println!("{:?}", subtrees_metadata_source);
8383

84-
println!("\n######### db_checkpoint_0 -> db_copy state sync");
84+
println!("\n######### db_checkpoint_0 -> db_destination state sync");
8585
let state_info = db_destination.create_state_sync_info();
86-
let source_tx = db_source.start_transaction();
87-
let target_tx = db_destination.start_transaction();
88-
sync_db_demo(&db_checkpoint_0, &db_destination, state_info, &source_tx, &target_tx).unwrap();
89-
db_destination.commit_transaction(target_tx).unwrap().expect("expected to commit transaction");
86+
let tx = db_destination.start_transaction();
87+
sync_db_demo(&db_checkpoint_0, &db_destination, state_info, &tx).unwrap();
88+
db_destination.commit_transaction(tx).unwrap().expect("expected to commit transaction");
9089

91-
println!("\n######### verify db_copy");
90+
println!("\n######### verify db_destination");
9291
let incorrect_hashes = db_destination.verify_grovedb(None).unwrap();
9392
if incorrect_hashes.len() > 0 {
9493
println!("DB verification failed!");
@@ -98,18 +97,18 @@ fn main() {
9897
}
9998

10099
println!("\n######### root_hashes:");
101-
let root_hash_0 = db_source.root_hash(None).unwrap().unwrap();
102-
println!("root_hash_0: {:?}", hex::encode(root_hash_0));
100+
let root_hash_source = db_source.root_hash(None).unwrap().unwrap();
101+
println!("root_hash_source: {:?}", hex::encode(root_hash_source));
103102
let root_hash_checkpoint_0 = db_checkpoint_0.root_hash(None).unwrap().unwrap();
104103
println!("root_hash_checkpoint_0: {:?}", hex::encode(root_hash_checkpoint_0));
105-
let root_hash_copy = db_destination.root_hash(None).unwrap().unwrap();
106-
println!("root_hash_copy: {:?}", hex::encode(root_hash_copy));
104+
let root_hash_destination = db_destination.root_hash(None).unwrap().unwrap();
105+
println!("root_hash_destination: {:?}", hex::encode(root_hash_destination));
107106

108107
let query_path = &[MAIN_ΚΕΥ, KEY_INT_0];
109108
let query_key = (20487u32).to_be_bytes().to_vec();
110109
println!("\n######## Query on db_checkpoint_0:");
111110
query_db(&db_checkpoint_0, query_path, query_key.clone());
112-
println!("\n######## Query on db_copy:");
111+
println!("\n######## Query on db_destination:");
113112
query_db(&db_destination, query_path, query_key.clone());
114113

115114
return;
@@ -224,7 +223,6 @@ fn sync_db_demo(
224223
source_db: &GroveDb,
225224
target_db: &GroveDb,
226225
state_sync_info: StateSyncInfo,
227-
source_tx: &Transaction,
228226
target_tx: &Transaction,
229227
) -> Result<(), grovedb::Error> {
230228
let app_hash = source_db.root_hash(None).value.unwrap();
@@ -235,7 +233,7 @@ fn sync_db_demo(
235233
chunk_queue.extend(chunk_ids);
236234

237235
while let Some(chunk_id) = chunk_queue.pop_front() {
238-
let ops = source_db.fetch_chunk(chunk_id.as_slice(), source_tx)?;
236+
let ops = source_db.fetch_chunk(chunk_id.as_slice(), None)?;
239237
let (more_chunks, new_state_sync_info) = target_db.apply_chunk(state_sync_info, (chunk_id.as_slice(), ops), target_tx)?;
240238
state_sync_info = new_state_sync_info;
241239
chunk_queue.extend(more_chunks);

0 commit comments

Comments
 (0)