Skip to content

Commit

Permalink
Rkuris/streaming iterator from start (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkuris authored Nov 15, 2023
1 parent b33a9c1 commit 1989a96
Show file tree
Hide file tree
Showing 2 changed files with 354 additions and 6 deletions.
25 changes: 19 additions & 6 deletions firewood/src/db.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
// Copyright (C) 2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE.md for licensing terms.

use crate::shale::{
self,
compact::{CompactSpace, CompactSpaceHeader},
disk_address::DiskAddress,
CachedStore, Obj, ShaleError, ShaleStore, SpaceId, Storable, StoredView,
};
pub use crate::{
config::{DbConfig, DbRevConfig},
storage::{buffer::DiskBufferConfig, WalConfig},
Expand All @@ -23,8 +17,18 @@ use crate::{
},
v2::api::{self, HashKey, KeyType, Proof, ValueType},
};
use crate::{
merkle,
shale::{
self,
compact::{CompactSpace, CompactSpaceHeader},
disk_address::DiskAddress,
CachedStore, Obj, ShaleError, ShaleStore, SpaceId, Storable, StoredView,
},
};
use async_trait::async_trait;
use bytemuck::{cast_slice, AnyBitPattern};

use metered::metered;
use parking_lot::{Mutex, RwLock};
use std::{
Expand Down Expand Up @@ -312,6 +316,15 @@ impl<S: ShaleStore<Node> + Send + Sync> api::DbView for DbRev<S> {
}

impl<S: ShaleStore<Node> + Send + Sync> DbRev<S> {
pub fn stream<K: KeyType>(
&self,
start_key: Option<K>,
) -> Result<merkle::MerkleKeyValueStream<'_, S>, api::Error> {
self.merkle
.get_iter(start_key, self.header.kv_root)
.map_err(|e| api::Error::InternalError(e.into()))
}

fn flush_dirty(&mut self) -> Option<()> {
self.header.flush_dirty();
self.merkle.flush_dirty()?;
Expand Down
Loading

0 comments on commit 1989a96

Please sign in to comment.