Skip to content

Commit

Permalink
chore: remove unused methods (#4922)
Browse files Browse the repository at this point in the history
Delete some unused methods
  • Loading branch information
stringhandler authored Nov 16, 2022
1 parent 92d73e4 commit c84faa0
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 69 deletions.
20 changes: 0 additions & 20 deletions base_layer/core/src/chain_storage/lmdb_db/key_prefix_cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,6 @@ where V: DeserializeOwned
}
}

/// Returns the item on or before the given seek key, progressing backwards until the key prefix no longer matches
#[allow(dead_code)]
pub fn prev(&mut self) -> Result<Option<(Vec<u8>, V)>, ChainStorageError> {
if !self.has_seeked {
let prefix_key = self.prefix_key;
if let Some((k, val)) = self.seek_gte(prefix_key)? {
// seek_range_k returns the greater key, so we only want to return the current value that was seeked to
// if it exactly matches the prefix_key
if k == prefix_key {
return Ok(Some((k, val)));
}
}
}

match self.cursor.prev(&self.access).to_opt()? {
Some((k, v)) => Self::deserialize_if_matches(self.prefix_key, k, v),
None => Ok(None),
}
}

// This function could be used later in cases where multiple seeks are required.
#[cfg(test)]
pub fn reset_to(&mut self, prefix_key: &'a [u8]) {
Expand Down
49 changes: 0 additions & 49 deletions base_layer/core/src/chain_storage/lmdb_db/lmdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,52 +445,3 @@ pub fn lmdb_clear(txn: &WriteTransaction<'_>, db: &Database) -> Result<usize, Ch
}
Ok(num_deleted)
}

/// Used for migrations, you probably dont want to use this as it loops though the entire database.
#[allow(dead_code)]
pub(super) fn lmdb_map_inplace<F, V, R>(
txn: &WriteTransaction<'_>,
db: &Database,
f: F,
) -> Result<(), ChainStorageError>
where
F: Fn(V) -> Option<R>,
V: DeserializeOwned,
R: Serialize,
{
let mut access = txn.access();
let mut cursor = txn.cursor(db).map_err(|e| {
error!(target: LOG_TARGET, "Could not get read cursor from lmdb: {:?}", e);
ChainStorageError::AccessError(e.to_string())
})?;
let iter = CursorIter::new(
MaybeOwned::Borrowed(&mut cursor),
&access,
|c, a| c.first(a),
Cursor::next::<[u8], [u8]>,
)?;
let items = iter
.map(|r| r.map(|(k, v)| (k.to_vec(), v.to_vec())))
.collect::<Result<Vec<_>, _>>()?;

for (key, val) in items {
// let (key, val) = row?;
let val = deserialize::<V>(&val)?;
if let Some(ret) = f(val) {
let ret_bytes = serialize(&ret)?;
access.put(db, &key, &ret_bytes, put::Flags::empty()).map_err(|e| {
if let lmdb_zero::Error::Code(code) = &e {
if *code == lmdb_zero::error::MAP_FULL {
return ChainStorageError::DbResizeRequired;
}
}
error!(
target: LOG_TARGET,
"Could not replace value in lmdb transaction: {:?}", e
);
ChainStorageError::AccessError(e.to_string())
})?;
}
}
Ok(())
}

0 comments on commit c84faa0

Please sign in to comment.