Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Fix kill_prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
gavofyork committed May 20, 2022
1 parent 6f0cc2f commit e65b4ff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions primitives/io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1766,6 +1766,11 @@ mod tests {
assert!(storage::get(b":abdd").is_some());
assert!(storage::get(b":abcd").is_none());
assert!(storage::get(b":abc").is_none());

assert!(matches!(
storage::clear_prefix(b":abc", None),
KillStorageResult::AllRemoved(0)
));
});
}

Expand Down
16 changes: 16 additions & 0 deletions primitives/state-machine/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ where

self.mark_dirty();
let _overlay_count = self.overlay.clear_prefix(prefix);
//, Some(&self.overlay.changes)
let (all, count) = self.limit_remove_from_backend(None, Some(prefix), limit);
(all, count)
}
Expand All @@ -486,6 +487,7 @@ where

self.mark_dirty();
let _overlay_count = self.overlay.clear_child_prefix(child_info, prefix);
//, Some(&self.overlay.changes)
let (all, count) = self.limit_remove_from_backend(Some(child_info), Some(prefix), limit);
(all, count)
}
Expand Down Expand Up @@ -743,6 +745,13 @@ where
all_deleted = false;
return false
}
if let Some(None) = match child_info {
Some(child_info) => self.overlay.child_storage(child_info, key),
None => self.overlay.storage(key),
} {
// already deleted.
return true;
}
if let Some(num) = num_deleted.checked_add(1) {
num_deleted = num;
} else {
Expand All @@ -759,6 +768,13 @@ where
(all_deleted, num_deleted)
} else {
self.backend.apply_to_keys_while(child_info, prefix, |key| {
if let Some(None) = match child_info {
Some(child_info) => self.overlay.child_storage(child_info, key),
None => self.overlay.storage(key),
} {
// already deleted.
return true;
}
num_deleted = num_deleted.saturating_add(1);
if let Some(child_info) = child_info {
self.overlay.set_child_storage(child_info, key.to_vec(), None);
Expand Down

0 comments on commit e65b4ff

Please sign in to comment.