Skip to content

Commit

Permalink
get storage context by subtree prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
ogabrielides committed Jun 6, 2024
1 parent ee76ebf commit 90ebcac
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
21 changes: 20 additions & 1 deletion storage/src/rocksdb_storage/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ use crate::{

const BLAKE_BLOCK_LEN: usize = 64;

pub(crate) type SubtreePrefix = [u8; blake3::OUT_LEN];
pub type SubtreePrefix = [u8; blake3::OUT_LEN];

fn blake_block_count(len: usize) -> usize {
if len == 0 {
Expand Down Expand Up @@ -472,6 +472,15 @@ impl<'db> Storage<'db> for RocksDbStorage {
.map(|prefix| PrefixedRocksDbStorageContext::new(&self.db, prefix, batch))
}

fn get_storage_context_by_subtree_prefix(
&'db self,
prefix: SubtreePrefix,
batch: Option<&'db StorageBatch>,
) -> CostContext<Self::BatchStorageContext>
{
PrefixedRocksDbStorageContext::new(&self.db, prefix, batch).wrap_with_cost(OperationCost::default())
}

fn get_transactional_storage_context<'b, B>(
&'db self,
path: SubtreePath<'b, B>,
Expand All @@ -486,6 +495,16 @@ impl<'db> Storage<'db> for RocksDbStorage {
})
}

fn get_transactional_storage_context_by_subtree_prefix(
&'db self,
prefix: SubtreePrefix,
batch: Option<&'db StorageBatch>,
transaction: &'db Self::Transaction,
) -> CostContext<Self::BatchTransactionalStorageContext>
{
PrefixedRocksDbTransactionContext::new(&self.db, transaction, prefix, batch).wrap_with_cost(OperationCost::default())
}

fn get_immediate_storage_context<'b, B>(
&'db self,
path: SubtreePath<'b, B>,
Expand Down
19 changes: 19 additions & 0 deletions storage/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ use grovedb_visualize::visualize_to_vec;

use crate::{worst_case_costs::WorstKeyLength, Error};

pub type SubtreePrefix = [u8; blake3::OUT_LEN];

/// Top-level storage_cost abstraction.
/// Should be able to hold storage_cost connection and to start transaction when
/// needed. All query operations will be exposed using [StorageContext].
Expand Down Expand Up @@ -89,6 +91,14 @@ pub trait Storage<'db> {
where
B: AsRef<[u8]> + 'b;

/// Make storage context for a subtree with prefix, keeping all write
/// operations inside a `batch` if provided.
fn get_storage_context_by_subtree_prefix(
&'db self,
prefix: SubtreePrefix,
batch: Option<&'db StorageBatch>,
) -> CostContext<Self::BatchStorageContext>;

/// Make context for a subtree on transactional data, keeping all write
/// operations inside a `batch` if provided.
fn get_transactional_storage_context<'b, B>(
Expand All @@ -100,6 +110,15 @@ pub trait Storage<'db> {
where
B: AsRef<[u8]> + 'b;

/// Make context for a subtree by prefix on transactional data, keeping all write
/// operations inside a `batch` if provided.
fn get_transactional_storage_context_by_subtree_prefix(
&'db self,
prefix: SubtreePrefix,
batch: Option<&'db StorageBatch>,
transaction: &'db Self::Transaction,
) -> CostContext<Self::BatchTransactionalStorageContext>;

/// Make context for a subtree on transactional data that will apply all
/// operations straight to the storage.
fn get_immediate_storage_context<'b, B>(
Expand Down

0 comments on commit 90ebcac

Please sign in to comment.