dedicated trait for stats
MODIFY
light_node/src/main.rs
light_node/src/main.rs
@@ -35,7 +35,6 @@ use storage::persistent::{
};
use storage::ActionFileStorage;
use storage::ContextActionStorage;
-use storage::KeyValueStoreBackend;
use storage::{
check_database_compatibility, context::TezedgeContext, persistent::DBError,
resolve_storage_init_chain_data, BlockStorage, StorageInitInfo,

MODIFY
storage/src/backend/btree_map.rs
storage/src/backend/btree_map.rs
@@ -5,9 +5,7 @@ use std::collections::{btree_map::Entry, BTreeMap};
use crate::merkle_storage::{ContextValue, EntryHash};
use crate::persistent::database::RocksDBStats;
-use crate::storage_backend::{
- StorageBackend as KVStoreTrait, StorageBackendError as KVStoreError,
-};
+use crate::storage_backend::{StorageBackend as KVStoreTrait, StorageBackendError as KVStoreError};
/// In Memory Key Value Store implemented with [BTreeMap](std::collections::BTreeMap)
#[derive(Debug)]

MODIFY
storage/src/backend/rocksdb_backend.rs
storage/src/backend/rocksdb_backend.rs
// SPDX-License-Identifier: MIT
use crate::merkle_storage::{ContextValue, EntryHash};
+use crate::persistent::database::GetInMemStats;
use crate::persistent::database::RocksDBStats;
use crate::storage_backend::{StorageBackend, StorageBackendError};
use rocksdb::{WriteOptions, DB};
@@ -102,8 +103,7 @@ impl StorageBackend for RocksDBBackend {
let v = self
.inner
.get_cf(cf, &key.as_ref()[..])
- .map_err(StorageBackendError::from)?
- .map(|value| value);
+ .map_err(StorageBackendError::from)?;
Ok(v)
}
@@ -112,14 +112,8 @@ impl StorageBackend for RocksDBBackend {
}
fn get_mem_use_stats(&self) -> Result<RocksDBStats, StorageBackendError> {
- // TODO - fix compilation problem
- //let r = self.inner.get_mem_use_stats();
- Ok(RocksDBStats {
- mem_table_total: 0,
- mem_table_unflushed: 0,
- mem_table_readers_total: 0,
- cache_total: 0,
- })
-
+ self.inner
+ .get_stats()
+ .map_err(|_| StorageBackendError::BackendError)
}
}

MODIFY
storage/src/persistent/database.rs
storage/src/persistent/database.rs
@@ -123,6 +123,22 @@ pub trait KeyValueStoreWithSchema<S: KeyValueSchema> {
fn get_mem_use_stats(&self) -> Result<RocksDBStats, DBError>;
}
+pub trait GetInMemStats {
+ fn get_stats(&self) -> Result<RocksDBStats, DBError>;
+}
+
+impl GetInMemStats for DB {
+ fn get_stats(&self) -> Result<RocksDBStats, DBError> {
+ let memory_usage_stats = rocksdb::perf::get_memory_usage_stats(Some(&[&self]), None)?;
+ Ok(RocksDBStats {
+ mem_table_total: memory_usage_stats.mem_table_total,
+ mem_table_unflushed: memory_usage_stats.mem_table_unflushed,
+ mem_table_readers_total: memory_usage_stats.mem_table_readers_total,
+ cache_total: memory_usage_stats.cache_total,
+ })
+ }
+}
+
impl<S: KeyValueSchema> KeyValueStoreWithSchema<S> for DB {
fn put(&self, key: &S::Key, value: &S::Value) -> Result<(), DBError> {
let key = key.encode()?;

dedicated trait for stats