Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Clean flat state via range #9109

Merged
merged 8 commits into from
May 26, 2023
Merged

Conversation

jbajic
Copy link
Contributor

@jbajic jbajic commented May 25, 2023

Use range deletion in clean_state when removing values from FlatState column. Addresses #8332

@jbajic jbajic added C-housekeeping Category: Refactoring, cleanups, code quality A-storage Area: storage and databases labels May 25, 2023
@jbajic jbajic self-assigned this May 25, 2023
@jbajic jbajic marked this pull request as ready for review May 25, 2023 14:08
@jbajic jbajic requested a review from a team as a code owner May 25, 2023 14:08
@jbajic jbajic requested a review from nikurt May 25, 2023 14:08
@jbajic jbajic assigned pugachAG and unassigned pugachAG May 25, 2023
@jbajic jbajic requested a review from pugachAG May 25, 2023 15:10
Copy link
Contributor

@pugachAG pugachAG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall looks good, well done!

shard_uid: ShardUId,
shard_layout: ShardLayout,
) -> Result<(), StorageError> {
pub fn remove_flat_storage_for_shard(&self, shard_uid: ShardUId) -> Result<(), StorageError> {
let mut flat_storages = self.0.flat_storages.lock().expect(POISONED_LOCK_ERR);

match flat_storages.remove(&shard_uid) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let refactor this to avoid nasty None => {} case:

if let Some(flat_store) = flat_storages.remove(&shard_uid) {
...
}

@@ -307,24 +307,20 @@ impl FlatStorage {
// TODO (#7327): call it just after we stopped tracking a shard.
// TODO (#7327): remove FlatStateChanges. Consider custom serialization of keys to remove them by
// prefix.
// TODO (#7327): support range deletions which are much faster than naive deletions. For that, we
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also remove the following comments above, that is no longer relevant:

        // Removes all items belonging to the shard one by one.
        // Note that it does not work for resharding.
        // TODO (#7327): remove FlatStateChanges.

guard.shard_uid,
&[DBCol::FlatState],
);
let removed_items = guard.store.iter(DBCol::FlatState).count();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is potentially expensive operation and the result is only used for logging, let's drop that part

@@ -57,11 +57,16 @@ pub fn remove_delta(store_update: &mut StoreUpdate, shard_uid: ShardUId, block_h
store_update.delete(DBCol::FlatStateDeltaMetadata, &key);
}

pub fn remove_all_deltas(store_update: &mut StoreUpdate, shard_uid: ShardUId) {
pub fn remove_range_by_shard_uid(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is potentially dangerous public API since it accepts any DBCol while not all of those are prefixed by shard_uid.
I suggest to keep that as a private helper function and expose 2 public functions:

pub(crate) fn remove_all_flat_state_values(store_update: &mut StoreUpdate, shard_uid: ShardUId) -> Result<..> {
    remove_range_by_shard_uid(store_update, shard_uid, &DBCol::FlatState)
}
pub(crate) fn remove_all_deltas(store_update: &mut StoreUpdate, shard_uid: ShardUId) ...

also I suggest changing parameter cols: &[DBCol] to col: &DBCol and just calling it twice in remove_all_deltas for changes and metadata.

@jbajic jbajic requested a review from pugachAG May 26, 2023 08:02
@pugachAG pugachAG linked an issue May 26, 2023 that may be closed by this pull request
@near-bulldozer near-bulldozer bot merged commit 8e483e3 into master May 26, 2023
@near-bulldozer near-bulldozer bot deleted the clean-flat-state-via-range branch May 26, 2023 09:03
nikurt pushed a commit that referenced this pull request May 31, 2023
Use range deletion in `clean_state` when removing values from `FlatState` column. Addresses #8332
nikurt pushed a commit that referenced this pull request Jun 13, 2023
Use range deletion in `clean_state` when removing values from `FlatState` column. Addresses #8332
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-storage Area: storage and databases C-housekeeping Category: Refactoring, cleanups, code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Quick flat state removal for non-tracked shard
3 participants