Skip to content

Commit

Permalink
delete all dag block in sync dag store to protect the blocks not int … (
Browse files Browse the repository at this point in the history
#4165)

* delete all dag block in sync dag store to protect the blocks not int he blue fork

* add testing code
  • Loading branch information
jackzhhuang authored Aug 5, 2024
1 parent 9b4670a commit e0b569a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sync/src/store/sync_absent_ancestor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub trait AbsentDagBlockStoreReader {
pub trait AbsentDagBlockStoreWriter {
fn save_absent_block(&self, blocks: Vec<DagSyncBlock>) -> anyhow::Result<()>;
fn delete_absent_block(&self, number: BlockNumber, block_id: HashValue) -> anyhow::Result<()>;
fn delete_all_absent_block(&self) -> anyhow::Result<()>;
}

pub(crate) const SYNC_ABSENT_BLOCK_CF: &str = "sync-absent-block";
Expand Down Expand Up @@ -187,4 +188,10 @@ impl AbsentDagBlockStoreWriter for SyncAbsentBlockStore {
}
Ok(())
}

fn delete_all_absent_block(&self) -> anyhow::Result<()> {
self.cache_access
.delete_all(DirectDbWriter::new(&self.db))
.map_err(|e| format_err!("failed to delete all absent block: {:?}", e))
}
}
4 changes: 4 additions & 0 deletions sync/src/store/sync_dag_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,8 @@ impl SyncDagStore {
e
})
}

pub(crate) fn delete_all_dag_sync_block(&self) -> anyhow::Result<()> {
self.absent_dag_store.delete_all_absent_block()
}
}
8 changes: 8 additions & 0 deletions sync/src/store/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,13 @@ fn test_write_read_in_order() -> anyhow::Result<()> {

assert_eq!(expect_order, db_order);

let mut iter_to_see_empty = sync_dag_store.iter_at_first()?;
assert!(iter_to_see_empty.next().is_some());

sync_dag_store.delete_all_dag_sync_block()?;

iter_to_see_empty = sync_dag_store.iter_at_first()?;
assert!(iter_to_see_empty.next().is_none());

Ok(())
}
2 changes: 2 additions & 0 deletions sync/src/tasks/inner_sync_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ where
}
}
}
// clear the dag sync if fork happened
self.sync_dag_store.delete_all_dag_sync_block()?;

Ok(TaskGenerator::new(
block_sync_task,
Expand Down

0 comments on commit e0b569a

Please sign in to comment.