Skip to content

Commit

Permalink
chore: remove unused write operations (insert, delete, batch_delete) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
carneiro-cw authored Oct 14, 2024
1 parent e9b8d66 commit 903d9cd
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 77 deletions.
13 changes: 0 additions & 13 deletions src/eth/storage/rocks/rocks_batch_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,6 @@ impl BufferedBatchWriter {
Ok(())
}

pub fn delete<K, V>(&mut self, cf_ref: &RocksCfRef<K, V>, key: K) -> anyhow::Result<()>
where
K: Serialize + for<'de> Deserialize<'de> + Debug + std::hash::Hash + Eq,
V: Serialize + for<'de> Deserialize<'de> + Debug + Clone,
{
self.len += 1;
cf_ref.prepare_batch_deletion([key], &mut self.batch)?;
if self.len >= self.capacity {
self.flush(cf_ref.db())?;
}
Ok(())
}

pub fn flush(&mut self, db: &DB) -> anyhow::Result<()> {
if self.len == 0 {
return Ok(());
Expand Down
64 changes: 0 additions & 64 deletions src/eth/storage/rocks/rocks_cf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,37 +152,6 @@ where
.collect()
}

/// Insert pair (key, value) to the Column Family.
pub fn insert(&self, key: K, value: V) -> Result<()> {
self.insert_impl(key, value)
.with_context(|| format!("when trying to insert value in CF: '{}'", self.column_family))
}

#[inline]
fn insert_impl(&self, key: K, value: V) -> Result<()> {
let cf = self.handle();

let serialized_key = self.serialize_key_with_context(&key)?;
let serialized_value = self.serialize_value_with_context(&value)?;

self.db.put_cf(&cf, serialized_key, serialized_value).map_err(Into::into)
}

/// Deletes an entry from the database by key
#[allow(dead_code)]
pub fn delete(&self, key: &K) -> Result<()> {
self.delete_impl(key)
.with_context(|| format!("when trying to delete value from CF: '{}'", self.column_family))
}

#[inline]
fn delete_impl(&self, key: &K) -> Result<()> {
let serialized_key = self.serialize_key_with_context(key)?;
let cf = self.handle();

self.db.delete_cf(&cf, serialized_key).map_err(Into::into)
}

pub fn apply_batch_with_context(&self, batch: WriteBatch) -> Result<()> {
self.db
.write(batch)
Expand Down Expand Up @@ -213,39 +182,6 @@ where
Ok(())
}

pub fn prepare_batch_deletion<I>(&self, deletions: I, batch: &mut WriteBatch) -> Result<()>
where
I: IntoIterator<Item = K>,
{
let cf = self.handle();

for key in deletions {
let serialized_key = self
.serialize_key_with_context(&key)
.with_context(|| format!("failed to prepare batch delete for CF: '{}'", self.column_family))?;
// add the delete operation to the batch
batch.delete_cf(&cf, serialized_key);
}
Ok(())
}

// Custom method that combines entry and or_insert_with from a HashMap
pub fn get_or_insert_with<F>(&self, key: K, default: F) -> Result<V>
where
F: FnOnce() -> V,
{
let value = self.get(&key)?;

Ok(match value {
Some(value) => value,
None => {
let new_value = default();
self.insert(key, new_value.clone())?;
new_value
}
})
}

#[allow(dead_code)]
pub fn iter_start(&self) -> RocksCfIter<K, V> {
let cf = self.handle();
Expand Down

0 comments on commit 903d9cd

Please sign in to comment.