Skip to content

Commit

Permalink
chore(logs): add logs back
Browse files Browse the repository at this point in the history
  • Loading branch information
0xLucqs committed Jan 10, 2024
1 parent 276ce14 commit 90c20a3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ derive_more = { version = "0.99.17", default-features = false, features = [
hashbrown = { version = "0.14.3", default-features = false, features = [
"ahash",
] }
log = "0.4.20"
parity-scale-codec = { version = "3.0.0", default-features = false, features = [
"derive",
] }
Expand Down
7 changes: 7 additions & 0 deletions ensure_no_std/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions src/databases/rocks_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::{
id::Id,
BonsaiStorageError,
};
use log::trace;

const TRIE_LOG_CF: &str = "trie_log";
const TRIE_CF: &str = "trie";
Expand Down Expand Up @@ -70,6 +71,7 @@ impl Default for RocksDBConfig {
impl<'db, ID: Id> RocksDB<'db, ID> {
/// Creates a new RocksDB wrapper from the given RocksDB database
pub fn new(db: &'db OptimisticTransactionDB, config: RocksDBConfig) -> Self {
trace!("RockDB database opened");
Self {
db,
config,
Expand Down Expand Up @@ -188,6 +190,7 @@ where
value: &[u8],
batch: Option<&mut Self::Batch>,
) -> Result<Option<Vec<u8>>, Self::DatabaseError> {
trace!("Inserting into RocksDB: {:?} {:?}", key, value);
let handle_cf = self.db.cf_handle(key.get_cf()).expect(CF_ERROR);
let old_value = self.db.get_cf(&handle_cf, key.as_slice())?;
if let Some(batch) = batch {
Expand All @@ -199,6 +202,7 @@ where
}

fn get(&self, key: &KeyType) -> Result<Option<Vec<u8>>, Self::DatabaseError> {
trace!("Getting from RocksDB: {:?}", key);
let handle = self.db.cf_handle(key.get_cf()).expect(CF_ERROR);
Ok(self.db.get_cf(&handle, key.as_slice())?)
}
Expand All @@ -207,6 +211,7 @@ where
&self,
prefix: &KeyType,
) -> Result<Vec<(Vec<u8>, Vec<u8>)>, Self::DatabaseError> {
trace!("Getting from RocksDB: {:?}", prefix);
let handle = self.db.cf_handle(prefix.get_cf()).expect(CF_ERROR);
let iter = self.db.iterator_cf(
&handle,
Expand All @@ -228,6 +233,7 @@ where
}

fn contains(&self, key: &KeyType) -> Result<bool, Self::DatabaseError> {
trace!("Checking if RocksDB contains: {:?}", key);
let handle = self.db.cf_handle(key.get_cf()).expect(CF_ERROR);
Ok(self
.db
Expand All @@ -240,6 +246,7 @@ where
key: &KeyType,
batch: Option<&mut Self::Batch>,
) -> Result<Option<Vec<u8>>, Self::DatabaseError> {
trace!("Removing from RocksDB: {:?}", key);
let handle = self.db.cf_handle(key.get_cf()).expect(CF_ERROR);
let old_value = self.db.get_cf(&handle, key.as_slice())?;
if let Some(batch) = batch {
Expand All @@ -251,6 +258,7 @@ where
}

fn remove_by_prefix(&mut self, prefix: &KeyType) -> Result<(), Self::DatabaseError> {
trace!("Getting from RocksDB: {:?}", prefix);
let handle = self.db.cf_handle(prefix.get_cf()).expect(CF_ERROR);
let iter = self.db.iterator_cf(
&handle,
Expand Down Expand Up @@ -324,6 +332,7 @@ impl<'db> BonsaiDatabase for RocksDBTransaction<'db> {
value: &[u8],
batch: Option<&mut Self::Batch>,
) -> Result<Option<Vec<u8>>, Self::DatabaseError> {
trace!("Inserting into RocksDB: {:?} {:?}", key, value);
let handle_cf = self.column_families.get(key.get_cf()).expect(CF_ERROR);
let old_value = self
.txn
Expand All @@ -337,6 +346,7 @@ impl<'db> BonsaiDatabase for RocksDBTransaction<'db> {
}

fn get(&self, key: &KeyType) -> Result<Option<Vec<u8>>, Self::DatabaseError> {
trace!("Getting from RocksDB: {:?}", key);
let handle = self.column_families.get(key.get_cf()).expect(CF_ERROR);
Ok(self
.txn
Expand All @@ -347,6 +357,7 @@ impl<'db> BonsaiDatabase for RocksDBTransaction<'db> {
&self,
prefix: &KeyType,
) -> Result<Vec<(Vec<u8>, Vec<u8>)>, Self::DatabaseError> {
trace!("Getting from RocksDB: {:?}", prefix);
let handle = self.column_families.get(prefix.get_cf()).expect(CF_ERROR);
let iter = self.txn.iterator_cf(
handle,
Expand All @@ -368,6 +379,7 @@ impl<'db> BonsaiDatabase for RocksDBTransaction<'db> {
}

fn contains(&self, key: &KeyType) -> Result<bool, Self::DatabaseError> {
trace!("Checking if RocksDB contains: {:?}", key);
let handle = self.column_families.get(key.get_cf()).expect(CF_ERROR);
Ok(self
.txn
Expand All @@ -380,6 +392,7 @@ impl<'db> BonsaiDatabase for RocksDBTransaction<'db> {
key: &KeyType,
batch: Option<&mut Self::Batch>,
) -> Result<Option<Vec<u8>>, Self::DatabaseError> {
trace!("Removing from RocksDB: {:?}", key);
let handle = self.column_families.get(key.get_cf()).expect(CF_ERROR);
let old_value = self
.txn
Expand All @@ -393,6 +406,7 @@ impl<'db> BonsaiDatabase for RocksDBTransaction<'db> {
}

fn remove_by_prefix(&mut self, prefix: &KeyType) -> Result<(), Self::DatabaseError> {
trace!("Getting from RocksDB: {:?}", prefix);
let mut batch = self.create_batch();
{
let handle = self.column_families.get(prefix.get_cf()).expect(CF_ERROR);
Expand Down Expand Up @@ -429,6 +443,7 @@ where
type DatabaseError = RocksDBError;

fn snapshot(&mut self, id: ID) {
trace!("Generating RocksDB transaction");
let snapshot = self.db.snapshot();
self.snapshots.insert(id, snapshot);
if let Some(max_number_snapshot) = self.config.max_saved_snapshots {
Expand All @@ -439,6 +454,7 @@ where
}

fn transaction(&self, id: ID) -> Option<Self::Transaction> {
trace!("Generating RocksDB transaction");
if let Some(snapshot) = self.snapshots.get(&id) {
let write_opts = WriteOptions::default();
let mut txn_opts = OptimisticTransactionOptions::default();
Expand Down
6 changes: 6 additions & 0 deletions src/key_value_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use alloc::collections::BTreeSet;
use alloc::format;
use alloc::string::ToString;
use alloc::vec::Vec;
use log::trace;

use crate::{
bonsai_database::{BonsaiDatabase, BonsaiPersistentDatabase, KeyType},
Expand Down Expand Up @@ -124,10 +125,12 @@ where
}

pub(crate) fn get(&self, key: &TrieKeyType) -> Result<Option<Vec<u8>>, BonsaiStorageError> {
trace!("Getting from KeyValueDB: {:?}", key);
Ok(self.db.get(&key.into())?)
}

pub(crate) fn contains(&self, key: &TrieKeyType) -> Result<bool, BonsaiStorageError> {
trace!("Contains from KeyValueDB: {:?}", key);
Ok(self.db.contains(&key.into())?)
}

Expand All @@ -137,6 +140,7 @@ where
value: &[u8],
batch: Option<&mut DB::Batch>,
) -> Result<(), BonsaiStorageError> {
trace!("Inserting into KeyValueDB: {:?} {:?}", key, value);
let old_value = self.db.insert(&key.into(), value, batch)?;
self.changes_store.current_changes.insert_in_place(
key.into(),
Expand All @@ -153,6 +157,7 @@ where
key: &TrieKeyType,
batch: Option<&mut DB::Batch>,
) -> Result<(), BonsaiStorageError> {
trace!("Removing from KeyValueDB: {:?}", key);
let old_value = self.db.remove(&key.into(), batch)?;
self.changes_store.current_changes.insert_in_place(
key.into(),
Expand All @@ -165,6 +170,7 @@ where
}

pub(crate) fn write_batch(&mut self, batch: DB::Batch) -> Result<(), BonsaiStorageError> {
trace!("Writing batch into KeyValueDB");
Ok(self.db.write_batch(batch)?)
}
}
Expand Down

0 comments on commit 90c20a3

Please sign in to comment.