Skip to content

Commit

Permalink
add testing log and write batch with sync option
Browse files Browse the repository at this point in the history
  • Loading branch information
jackzhhuang committed Dec 16, 2024
1 parent c096925 commit 9286c33
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
20 changes: 10 additions & 10 deletions flexidag/src/blockdag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl BlockDAG {
}
};

info!("jacktest: start to commit via batch");
info!("start to commit via batch");

// Create a DB batch writer
let mut batch = WriteBatch::default();
Expand All @@ -231,7 +231,7 @@ impl BlockDAG {
self.storage.reachability_store.upgradable_read(),
);

info!("jacktest: start to add block into the ghostdata store");
info!("start to add block into the ghostdata store");
// Store ghostdata
process_key_already_error(self.storage.ghost_dag_store.insert_batch(
&mut batch,
Expand All @@ -240,7 +240,7 @@ impl BlockDAG {
))
.expect("failed to ghostdata in batch");
info!(
"jacktest: finish adding block into the ghostdata store, data: {:?}",
"finish adding block into the ghostdata store, data: {:?}",
ghostdata
);

Expand All @@ -251,14 +251,14 @@ impl BlockDAG {
header.number()
);

info!("jacktest: start to prepare mergeset into the reachability store");
info!("start to prepare mergeset into the reachability store");
let mut merge_set = ghostdata
.unordered_mergeset_without_selected_parent()
.filter(|hash| self.storage.reachability_store.read().has(*hash).unwrap())
.collect::<Vec<_>>()
.into_iter();
info!(
"jacktest: finish preparing mergeset into the reachability store, mergeset: {:?}",
"finish preparing mergeset into the reachability store, mergeset: {:?}",
merge_set
);
match inquirer::add_block(
Expand All @@ -281,7 +281,7 @@ impl BlockDAG {
}
},
}
info!("jacktest: finish adding block into reachability store and start to insert relations into the relations store, data: {:?}", parents);
info!("finish adding block into reachability store and start to insert relations into the relations store, data: {:?}", parents);

process_key_already_error(self.storage.relations_store.write().insert_batch(
&mut batch,
Expand All @@ -290,7 +290,7 @@ impl BlockDAG {
))
.expect("failed to insert relations in batch");

info!("jacktest: finish inserting relations into the relations store, start to insert header into the header store");
info!("finish inserting relations into the relations store, start to insert header into the header store");

// Store header store
process_key_already_error(self.storage.header_store.insert(
Expand All @@ -300,7 +300,7 @@ impl BlockDAG {
))
.expect("failed to insert header in batch");

info!("jacktest: finish inserting header into the header store, start to commit the stage");
info!("finish inserting header into the header store, start to commit the stage");

// the read lock will be updated to the write lock
// and then write the batch
Expand All @@ -309,13 +309,13 @@ impl BlockDAG {
.commit(&mut batch)
.expect("failed to write the stage reachability in batch");

info!("jacktest: finish committing the stage, start to write the batch");
info!("finish committing the stage, start to write the batch");

// write the data just one time
self.storage
.write_batch(batch)
.expect("failed to write dag data in batch");
info!("jacktest: finish writing the batch");
info!("finish writing the batch");
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion flexidag/src/consensusdb/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl FlexiDagStorage {
}

pub fn write_batch(&self, batch: WriteBatch) -> Result<(), StoreError> {
self.db.raw_write_batch(batch).map_err(|e| {
self.db.raw_write_batch_sync(batch).map_err(|e| {
StoreError::DBIoError(format!(
"failed to write in batch for dag data, error: {:?}",
e.to_string()
Expand Down
7 changes: 7 additions & 0 deletions storage/src/db_storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,4 +544,11 @@ impl RawDBStorage for DBStorage {
self.db.write(batch)?;
Ok(())
}

fn raw_write_batch_sync(&self, batch: DBWriteBatch) -> Result<()> {
let mut opt = WriteOptions::default();
opt.set_sync(true);
self.db.write_opt(batch, &opt)?;
Ok(())
}
}
1 change: 1 addition & 0 deletions storage/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub trait RawDBStorage: Send + Sync {
) -> Result<Option<DBPinnableSlice>>;

fn raw_write_batch(&self, batch: DBWriteBatch) -> Result<()>;
fn raw_write_batch_sync(&self, batch: DBWriteBatch) -> Result<()>;
}

///Storage instance type define
Expand Down

0 comments on commit 9286c33

Please sign in to comment.