Prevent possible rocksdb-corruption by running benchmark-storage (#11040)

* Prevent possible rocksdb-corruption by running benchmark-storage

Also adds a `sanitize_key` function to strip path-prefixes from the db-keys (for databases that
use prefixed keys such as rocksdb)

fixes #10998

* Fix @cheme 's annotations.

* Update utils/frame/benchmarking-cli/src/storage/write.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Make logic match the name of bool flag `invert_inserts`

* Remove unused lifetime

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
Falco Hirschenberger
2022-03-16 17:05:34 +01:00
committed by GitHub
parent 800cc1d4be
commit 7a54efd1f2
4 changed files with 46 additions and 35 deletions
+3 -5
View File
@@ -107,7 +107,8 @@ pub type DbState<B> =
sp_state_machine::TrieBackend<Arc<dyn sp_state_machine::Storage<HashFor<B>>>, HashFor<B>>;
/// Length of a [`DbHash`].
pub const DB_HASH_LEN: usize = 32;
const DB_HASH_LEN: usize = 32;
/// Hash type that this backend uses for the database.
pub type DbHash = sp_core::H256;
@@ -1351,10 +1352,7 @@ impl<Block: BlockT> Backend<Block> {
let mut removal: u64 = 0;
let mut bytes_removal: u64 = 0;
for (mut key, (val, rc)) in operation.db_updates.drain() {
if !self.storage.prefix_keys {
// Strip prefix
key.drain(0..key.len() - DB_HASH_LEN);
};
self.storage.db.sanitize_key(&mut key);
if rc > 0 {
ops += 1;
bytes += key.len() as u64 + val.len() as u64;
+4
View File
@@ -112,4 +112,8 @@ impl<H: Clone + AsRef<[u8]>> Database<H> for DbAdapter {
fn supports_ref_counting(&self) -> bool {
true
}
fn sanitize_key(&self, key: &mut Vec<u8>) {
let _prefix = key.drain(0..key.len() - crate::DB_HASH_LEN);
}
}