Remove mem_info and references to parity-util-mem (#12795)

* Remove mem_info and some references to parity-util-mem

* [Draft] Finish removing references to `parity-util-mem`

* Upgrade dependencies

* Update scripts/ci/deny.toml

Co-authored-by: ordian <write@reusable.software>

* Fix Cargo.lock (remove unwanted dependency changes)

* Removed unused argument

* Run cargo fmt (didn't have pre-commit set up)

* Fix some CI errors

* Fix another CI error

* Remove unused dependency

Co-authored-by: ordian <write@reusable.software>
This commit is contained in:
Marcin S
2022-12-06 09:55:10 -05:00
committed by GitHub
parent 07117e7913
commit aa21e56744
46 changed files with 70 additions and 426 deletions
+11 -48
View File
@@ -49,10 +49,8 @@ mod test;
use codec::Codec;
use log::trace;
use noncanonical::NonCanonicalOverlay;
use parity_util_mem::{malloc_size, MallocSizeOf};
use parking_lot::RwLock;
use pruning::{HaveBlock, RefWindow};
use sc_client_api::{MemorySize, StateDbMemoryInfo};
use std::{
collections::{hash_map::Entry, HashMap},
fmt,
@@ -220,8 +218,6 @@ pub struct Constraints {
/// Maximum blocks. Defaults to 0 when unspecified, effectively keeping only non-canonical
/// states.
pub max_blocks: Option<u32>,
/// Maximum memory in the pruning overlay.
pub max_mem: Option<usize>,
}
/// Pruning mode.
@@ -238,7 +234,7 @@ pub enum PruningMode {
impl PruningMode {
/// Create a mode that keeps given number of blocks.
pub fn blocks_pruning(n: u32) -> PruningMode {
PruningMode::Constrained(Constraints { max_blocks: Some(n), max_mem: None })
PruningMode::Constrained(Constraints { max_blocks: Some(n) })
}
/// Is this an archive (either ArchiveAll or ArchiveCanonical) pruning mode?
@@ -276,7 +272,7 @@ impl Default for PruningMode {
impl Default for Constraints {
fn default() -> Self {
Self { max_blocks: Some(DEFAULT_MAX_BLOCK_CONSTRAINT), max_mem: None }
Self { max_blocks: Some(DEFAULT_MAX_BLOCK_CONSTRAINT) }
}
}
@@ -294,9 +290,7 @@ pub struct StateDbSync<BlockHash: Hash, Key: Hash, D: MetaDb> {
ref_counting: bool,
}
impl<BlockHash: Hash + MallocSizeOf, Key: Hash + MallocSizeOf, D: MetaDb>
StateDbSync<BlockHash, Key, D>
{
impl<BlockHash: Hash, Key: Hash, D: MetaDb> StateDbSync<BlockHash, Key, D> {
fn new(
mode: PruningMode,
ref_counting: bool,
@@ -306,8 +300,7 @@ impl<BlockHash: Hash + MallocSizeOf, Key: Hash + MallocSizeOf, D: MetaDb>
let non_canonical: NonCanonicalOverlay<BlockHash, Key> = NonCanonicalOverlay::new(&db)?;
let pruning: Option<RefWindow<BlockHash, Key, D>> = match mode {
PruningMode::Constrained(Constraints { max_mem: Some(_), .. }) => unimplemented!(),
PruningMode::Constrained(Constraints { max_blocks, .. }) =>
PruningMode::Constrained(Constraints { max_blocks }) =>
Some(RefWindow::new(db, max_blocks.unwrap_or(0), ref_counting)?),
PruningMode::ArchiveAll | PruningMode::ArchiveCanonical => None,
};
@@ -392,10 +385,6 @@ impl<BlockHash: Hash + MallocSizeOf, Key: Hash + MallocSizeOf, D: MetaDb>
break
}
if constraints.max_mem.map_or(false, |m| pruning.mem_used() > m) {
break
}
let pinned = &self.pinned;
match pruning.next_hash() {
// the block record is temporary unavailable, break and try next time
@@ -496,14 +485,6 @@ impl<BlockHash: Hash + MallocSizeOf, Key: Hash + MallocSizeOf, D: MetaDb>
}
db.get(key.as_ref()).map_err(Error::Db)
}
fn memory_info(&self) -> StateDbMemoryInfo {
StateDbMemoryInfo {
non_canonical: MemorySize::from_bytes(malloc_size(&self.non_canonical)),
pruning: self.pruning.as_ref().map(|p| MemorySize::from_bytes(malloc_size(&p))),
pinned: MemorySize::from_bytes(malloc_size(&self.pinned)),
}
}
}
/// State DB maintenance. See module description.
@@ -512,9 +493,7 @@ pub struct StateDb<BlockHash: Hash, Key: Hash, D: MetaDb> {
db: RwLock<StateDbSync<BlockHash, Key, D>>,
}
impl<BlockHash: Hash + MallocSizeOf, Key: Hash + MallocSizeOf, D: MetaDb>
StateDb<BlockHash, Key, D>
{
impl<BlockHash: Hash, Key: Hash, D: MetaDb> StateDb<BlockHash, Key, D> {
/// Create an instance of [`StateDb`].
pub fn open(
db: D,
@@ -637,11 +616,6 @@ impl<BlockHash: Hash + MallocSizeOf, Key: Hash + MallocSizeOf, D: MetaDb>
*state_db = StateDbSync::new(state_db.mode.clone(), state_db.ref_counting, db)?;
Ok(())
}
/// Returns the current memory statistics of this instance.
pub fn memory_info(&self) -> StateDbMemoryInfo {
self.db.read().memory_info()
}
}
/// The result return by `StateDb::is_pruned`
@@ -772,10 +746,8 @@ mod tests {
#[test]
fn block_record_unavailable() {
let (mut db, state_db) = make_test_db(PruningMode::Constrained(Constraints {
max_blocks: Some(1),
max_mem: None,
}));
let (mut db, state_db) =
make_test_db(PruningMode::Constrained(Constraints { max_blocks: Some(1) }));
// import 2 blocks
for i in &[5, 6] {
db.commit(
@@ -809,19 +781,13 @@ mod tests {
#[test]
fn prune_window_0() {
let (db, _) = make_test_db(PruningMode::Constrained(Constraints {
max_blocks: Some(0),
max_mem: None,
}));
let (db, _) = make_test_db(PruningMode::Constrained(Constraints { max_blocks: Some(0) }));
assert!(db.data_eq(&make_db(&[21, 3, 922, 94])));
}
#[test]
fn prune_window_1() {
let (db, sdb) = make_test_db(PruningMode::Constrained(Constraints {
max_blocks: Some(1),
max_mem: None,
}));
let (db, sdb) = make_test_db(PruningMode::Constrained(Constraints { max_blocks: Some(1) }));
assert_eq!(sdb.is_pruned(&H256::from_low_u64_be(0), 0), IsPruned::Pruned);
assert_eq!(sdb.is_pruned(&H256::from_low_u64_be(1), 1), IsPruned::Pruned);
assert_eq!(sdb.is_pruned(&H256::from_low_u64_be(21), 2), IsPruned::Pruned);
@@ -831,10 +797,7 @@ mod tests {
#[test]
fn prune_window_2() {
let (db, sdb) = make_test_db(PruningMode::Constrained(Constraints {
max_blocks: Some(2),
max_mem: None,
}));
let (db, sdb) = make_test_db(PruningMode::Constrained(Constraints { max_blocks: Some(2) }));
assert_eq!(sdb.is_pruned(&H256::from_low_u64_be(0), 0), IsPruned::Pruned);
assert_eq!(sdb.is_pruned(&H256::from_low_u64_be(1), 1), IsPruned::Pruned);
assert_eq!(sdb.is_pruned(&H256::from_low_u64_be(21), 2), IsPruned::NotPruned);
@@ -858,7 +821,7 @@ mod tests {
)
.unwrap(),
);
let new_mode = PruningMode::Constrained(Constraints { max_blocks: Some(2), max_mem: None });
let new_mode = PruningMode::Constrained(Constraints { max_blocks: Some(2) });
let state_db_open_result: Result<(_, StateDb<H256, H256, TestDb>), _> =
StateDb::open(db.clone(), Some(new_mode), false, false);
assert!(state_db_open_result.is_err());
@@ -30,7 +30,6 @@ pub(crate) const LAST_CANONICAL: &[u8] = b"last_canonical";
const MAX_BLOCKS_PER_LEVEL: u64 = 32;
/// See module documentation.
#[derive(parity_util_mem_derive::MallocSizeOf)]
pub struct NonCanonicalOverlay<BlockHash: Hash, Key: Hash> {
last_canonicalized: Option<(BlockHash, u64)>,
levels: VecDeque<OverlayLevel<BlockHash, Key>>,
@@ -41,7 +40,6 @@ pub struct NonCanonicalOverlay<BlockHash: Hash, Key: Hash> {
pinned_insertions: HashMap<BlockHash, (Vec<Key>, u32)>,
}
#[derive(parity_util_mem_derive::MallocSizeOf)]
#[cfg_attr(test, derive(PartialEq, Debug))]
struct OverlayLevel<BlockHash: Hash, Key: Hash> {
blocks: Vec<BlockOverlay<BlockHash, Key>>,
@@ -81,7 +79,6 @@ fn to_journal_key(block: u64, index: u64) -> Vec<u8> {
}
#[cfg_attr(test, derive(PartialEq, Debug))]
#[derive(parity_util_mem_derive::MallocSizeOf)]
struct BlockOverlay<BlockHash: Hash, Key: Hash> {
hash: BlockHash,
journal_index: u64,
+1 -8
View File
@@ -36,7 +36,6 @@ pub(crate) const LAST_PRUNED: &[u8] = b"last_pruned";
const PRUNING_JOURNAL: &[u8] = b"pruning_journal";
/// See module documentation.
#[derive(parity_util_mem_derive::MallocSizeOf)]
pub struct RefWindow<BlockHash: Hash, Key: Hash, D: MetaDb> {
/// A queue of blocks keep tracking keys that should be deleted for each block in the
/// pruning window.
@@ -50,7 +49,6 @@ pub struct RefWindow<BlockHash: Hash, Key: Hash, D: MetaDb> {
/// blocks in memory, and keep track of re-inserted keys to not delete them when pruning
/// - `DbBacked`, used when the backend database supports reference counting, only keep
/// a few number of blocks in memory and load more blocks on demand
#[derive(parity_util_mem_derive::MallocSizeOf)]
enum DeathRowQueue<BlockHash: Hash, Key: Hash, D: MetaDb> {
Mem {
/// A queue of keys that should be deleted for each block in the pruning window.
@@ -60,7 +58,6 @@ enum DeathRowQueue<BlockHash: Hash, Key: Hash, D: MetaDb> {
},
DbBacked {
// The backend database
#[ignore_malloc_size_of = "Shared data"]
db: D,
/// A queue of keys that should be deleted for each block in the pruning window.
/// Only caching the first few blocks of the pruning window, blocks inside are
@@ -251,7 +248,7 @@ fn load_death_row_from_db<BlockHash: Hash, Key: Hash, D: MetaDb>(
}
}
#[derive(Clone, Debug, PartialEq, Eq, parity_util_mem_derive::MallocSizeOf)]
#[derive(Clone, Debug, PartialEq, Eq)]
struct DeathRow<BlockHash: Hash, Key: Hash> {
hash: BlockHash,
deleted: HashSet<Key>,
@@ -345,10 +342,6 @@ impl<BlockHash: Hash, Key: Hash, D: MetaDb> RefWindow<BlockHash, Key, D> {
Ok(res)
}
pub fn mem_used(&self) -> usize {
0
}
fn is_empty(&self) -> bool {
self.window_size() == 0
}