Skip to content

Commit

Permalink
add parent shard deletion in task
Browse files Browse the repository at this point in the history
  • Loading branch information
Trisfald committed Oct 1, 2024
1 parent 306c502 commit b9f11d4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
27 changes: 6 additions & 21 deletions chain/chain/src/flat_storage_resharder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ impl FlatStorageResharder {
// TODO(Trisfald): implement child catch up
todo!()
}
FlatStorageReshardingStatus::ToBeDeleted => {
// Parent shard's content has been previously copied to the children.
// Nothing else to do.
}
}
Ok(())
}
Expand Down Expand Up @@ -501,11 +497,8 @@ fn split_shard_task_postprocessing(resharder: FlatStorageResharderInner, success
let mut store_update = flat_store.store_update();
if success {
// Split shard completed successfully.
// Parent flat storage can be later deleted.
store_update.set_flat_storage_status(
parent_shard,
FlatStorageStatus::Resharding(FlatStorageReshardingStatus::ToBeDeleted),
);
// Parent flat storage can be deleted.
store_update.remove_flat_storage(parent_shard);
// TODO(trisfald): trigger parent delete
// Children must perform catchup.
for child_shard in [left_child_shard, right_child_shard] {
Expand All @@ -526,9 +519,7 @@ fn split_shard_task_postprocessing(resharder: FlatStorageResharderInner, success
);
// Remove children shards leftovers.
for child_shard in [left_child_shard, right_child_shard] {
store_update.remove_all_deltas(child_shard);
store_update.remove_all(child_shard);
store_update.remove_status(child_shard);
store_update.remove_flat_storage(child_shard);
}
}
store_update.commit().unwrap();
Expand Down Expand Up @@ -743,11 +734,7 @@ mod tests {

assert!(resharder.resharding_event().is_some());
assert!(resharder
.start_resharding_from_new_shard_layout(
&new_shard_layout,
&scheduler,
controller.clone()
)
.start_resharding_from_new_shard_layout(&new_shard_layout, &scheduler, controller)
.is_err());
}

Expand Down Expand Up @@ -894,10 +881,8 @@ mod tests {

// Check final status of children and parent flat storages.
let parent = ShardUId { version: 3, shard_id: 1 };
assert_eq!(
flat_store.get_flat_storage_status(parent),
Ok(FlatStorageStatus::Resharding(FlatStorageReshardingStatus::ToBeDeleted))
);
assert_eq!(flat_store.get_flat_storage_status(parent), Ok(FlatStorageStatus::Empty));
assert_eq!(flat_store.iter(parent).count(), 0);
let last_hash = chain.head().unwrap().last_block_hash;
assert_eq!(
flat_store.get_flat_storage_status(left_child),
Expand Down
6 changes: 6 additions & 0 deletions core/store/src/adapter/flat_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ impl<'a> FlatStoreUpdateAdapter<'a> {
self.remove_range_by_shard_uid(shard_uid, DBCol::FlatStateDeltaMetadata);
}

pub fn remove_flat_storage(&mut self, shard_uid: ShardUId) {
self.remove_all_deltas(shard_uid);
self.remove_all(shard_uid);
self.remove_status(shard_uid);
}

// helper
fn remove_range_by_shard_uid(&mut self, shard_uid: ShardUId, col: DBCol) {
let key_from = shard_uid.to_bytes();
Expand Down
3 changes: 0 additions & 3 deletions core/store/src/flat/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ impl Into<i64> for &FlatStorageStatus {
FlatStorageReshardingStatus::SplittingParent(_) => 20,
FlatStorageReshardingStatus::CreatingChild => 21,
FlatStorageReshardingStatus::CatchingUp(_) => 22,
FlatStorageReshardingStatus::ToBeDeleted => 23,
},
}
}
Expand Down Expand Up @@ -150,8 +149,6 @@ pub enum FlatStorageReshardingStatus {
/// We apply deltas from disk until the head reaches final head.
/// Includes block hash of flat storage head.
CatchingUp(CryptoHash),
/// The shard does no longer exist and its content should be deleted.
ToBeDeleted,
}

/// Current step of fetching state to fill flat storage.
Expand Down

0 comments on commit b9f11d4

Please sign in to comment.