mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-18 04:13:00 +00:00
Redb slasher backend impl (#4529)
* initial redb impl * redb impl * remove phantom data * fixed table definition * fighting the borrow checker * a rough draft that doesnt cause lifetime issues * refactoring * refactor * refactor * passing unit tests * refactor * refactor * refactor * commit * move everything to one database * remove panics, ready for a review * merge * a working redb impl * passing a ref of txn to cursor * this tries to create a second write transaction when initializing cursor. breaks everything * Use 2 lifetimes and subtyping Also fixes a bug in last_key caused by rev and next_back cancelling out * Move table into cursor * Merge remote-tracking branch 'origin/unstable' into redb-slasher-backend-impl * changes based on feedback * update lmdb * fix lifetime issues * moving everything from Cursor to Transaction * update * upgrade to redb 2.0 * Merge branch 'unstable' of https://github.com/sigp/lighthouse into redb-slasher-backend-impl * bring back cursor * Merge branch 'unstable' of https://github.com/sigp/lighthouse into redb-slasher-backend-impl * fix delete while * linting * linting * switch to lmdb * update redb to v2.1 * build fixes, remove unwrap or default * another build error * hopefully this is the last build error * fmt * cargo.toml * fix mdbx * Merge branch 'unstable' of https://github.com/sigp/lighthouse into redb-slasher-backend-impl * Remove a collect * Merge remote-tracking branch 'origin/unstable' into redb-slasher-backend-impl * Merge branch 'redb-slasher-backend-impl' of https://github.com/eserilev/lighthouse into redb-slasher-backend-impl * re-enable test * fix failing slasher test * Merge remote-tracking branch 'origin/unstable' into redb-slasher-backend-impl * Rename DB file to `slasher.redb`
This commit is contained in:
@@ -100,7 +100,7 @@ impl Environment {
|
||||
impl<'env> RwTransaction<'env> {
|
||||
pub fn get<K: AsRef<[u8]> + ?Sized>(
|
||||
&'env self,
|
||||
db: &Database<'env>,
|
||||
db: &'env Database,
|
||||
key: &K,
|
||||
) -> Result<Option<Cow<'env, [u8]>>, Error> {
|
||||
Ok(self.txn.get(db.db, key).optional()?.map(Cow::Borrowed))
|
||||
@@ -182,6 +182,29 @@ impl<'env> Cursor<'env> {
|
||||
.put(&key, &value, RwTransaction::write_flags())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn delete_while(
|
||||
&mut self,
|
||||
f: impl Fn(&[u8]) -> Result<bool, Error>,
|
||||
) -> Result<Vec<Cow<'_, [u8]>>, Error> {
|
||||
let mut result = vec![];
|
||||
|
||||
loop {
|
||||
let (key_bytes, value) = self.get_current()?.ok_or(Error::MissingKey)?;
|
||||
|
||||
if f(&key_bytes)? {
|
||||
result.push(value);
|
||||
self.delete_current()?;
|
||||
if self.next_key()?.is_none() {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
|
||||
/// Mix-in trait for loading values from LMDB that may or may not exist.
|
||||
|
||||
Reference in New Issue
Block a user