Skip to content

Commit 26722da

Browse files
committed
wip: improve traversal
1 parent 8e970c8 commit 26722da

File tree

19 files changed

+3680
-3129
lines changed

19 files changed

+3680
-3129
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ signet-storage = { version = "0.0.1", path = "./crates/storage" }
4242
signet-storage-types = { version = "0.0.1", path = "./crates/types" }
4343

4444
# External, in-house
45-
signet-libmdbx = "0.6.0"
45+
signet-libmdbx = { version = "0.7.0" }
4646

4747
signet-zenith = "0.16.0-rc.5"
4848

@@ -64,4 +64,5 @@ tempfile = "3.20.0"
6464
thiserror = "2.0.18"
6565
tokio = { version = "1.45.0", features = ["full"] }
6666
tokio-util = { version = "0.7", features = ["rt"] }
67+
itertools = "0.14"
6768
tracing = "0.1.44"

crates/hot-mdbx/src/cursor.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
use crate::{FixedSizeInfo, MdbxError};
44
use signet_hot::{
55
MAX_FIXED_VAL_SIZE, MAX_KEY_SIZE,
6-
model::{DualKeyTraverse, KvTraverse, KvTraverseMut, RawDualKeyValue, RawKeyValue, RawValue},
6+
model::{
7+
DualKeyTraverse, DualKeyTraverseMut, KvTraverse, KvTraverseMut, RawDualKeyValue,
8+
RawKeyValue, RawValue,
9+
},
710
};
811
use signet_libmdbx::{Ro, Rw, RwSync, TransactionKind, tx::WriteMarker};
912
use std::{
@@ -104,7 +107,7 @@ where
104107

105108
impl<K: TransactionKind + WriteMarker> KvTraverseMut<MdbxError> for Cursor<'_, K> {
106109
fn delete_current(&mut self) -> Result<(), MdbxError> {
107-
self.inner.del(Default::default()).map_err(MdbxError::Mdbx)
110+
self.inner.del().map_err(MdbxError::Mdbx)
108111
}
109112
}
110113

@@ -502,3 +505,24 @@ where
502505
}
503506
}
504507
}
508+
509+
impl<K: TransactionKind + WriteMarker> DualKeyTraverseMut<MdbxError> for Cursor<'_, K> {
510+
fn delete_current(&mut self) -> Result<(), MdbxError> {
511+
// For DUPSORT tables, del() deletes only the current duplicate
512+
self.inner.del().map_err(MdbxError::Mdbx)
513+
}
514+
515+
fn clear_k1(&mut self, key1: &[u8]) -> Result<(), MdbxError> {
516+
if !self.fsi.is_dupsort() {
517+
return Err(MdbxError::NotDupSort);
518+
}
519+
520+
// Position at the K1 - if it doesn't exist, nothing to delete
521+
if self.inner.set::<()>(key1)?.is_none() {
522+
return Ok(());
523+
}
524+
// Delete all K2 entries for this K1
525+
self.inner.del_all_dups()?;
526+
Ok(())
527+
}
528+
}

0 commit comments

Comments
 (0)