Skip to content

Commit

Permalink
Merge pull request #37 from hansieodendaal/sw_small_db_improvements
Browse files Browse the repository at this point in the history
feat: improve logging
  • Loading branch information
SWvheerden authored Nov 7, 2023
2 parents 8bc052b + 7f95a18 commit 5f5dd66
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions base_layer/core/src/chain_storage/lmdb_db/lmdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,35 @@ where
V: Serialize + Debug,
{
let val_buf = serialize(val)?;
trace!(target: LOG_TARGET, "LMDB: {} bytes inserted", val_buf.len());
match txn.access().put(db, key, &val_buf, put::NOOVERWRITE) {
Ok(_) => Ok(()),
Err(lmdb_zero::Error::Code(lmdb_zero::error::KEYEXIST)) => Err(ChainStorageError::KeyExists {
table_name,
key: to_hex(key.as_lmdb_bytes()),
}),
Err(lmdb_zero::Error::Code(lmdb_zero::error::MAP_FULL)) => Err(ChainStorageError::DbResizeRequired),
Err(e) => {
Ok(_) => {
trace!(
target: LOG_TARGET, "Inserted {} bytes with key '{}' into '{}'",
val_buf.len(), to_hex(key.as_lmdb_bytes()), table_name
);
Ok(())
},
err @ Err(lmdb_zero::Error::Code(lmdb_zero::error::KEYEXIST)) => {
error!(
target: LOG_TARGET,
"Could not insert value into lmdb {} ({}/{:?}): {:?}",
target: LOG_TARGET, "Could not insert {} bytes with key '{}' into '{}' ({:?})",
val_buf.len(), to_hex(key.as_lmdb_bytes()), table_name, err
);
Err(ChainStorageError::KeyExists {
table_name,
to_hex(key.as_lmdb_bytes()),
val,
e,
key: to_hex(key.as_lmdb_bytes()),
})
},
err @ Err(lmdb_zero::Error::Code(lmdb_zero::error::MAP_FULL)) => {
error!(
target: LOG_TARGET, "Could not insert {} bytes with key '{}' into '{}' ({:?})",
val_buf.len(), to_hex(key.as_lmdb_bytes()), table_name, err
);
Err(ChainStorageError::DbResizeRequired)
},
Err(e) => {
error!(
target: LOG_TARGET, "Could not insert {} bytes with key '{}' into '{}' ({:?})",
val_buf.len(), to_hex(key.as_lmdb_bytes()), table_name, e
);
Err(ChainStorageError::InsertError {
table: table_name,
Expand Down

0 comments on commit 5f5dd66

Please sign in to comment.