Skip to content

Commit

Permalink
Added missing methods for versioned trees
Browse files Browse the repository at this point in the history
These functions existed on TreeFile but hadn't been exposed to Roots.
  • Loading branch information
ecton committed May 12, 2022
1 parent bef5f14 commit 493a70e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `get_multiple_with_indexes()` multi-key value + index retrieval
- `get_range_indexes()` ranged index retrieval
- `get_range_with_indexes()` ranged value + index retrieval
- `Tree` and `TransactionTree` now both have `current_sequence_id()` and
`scan_sequences()` functions. These functions serve the same purpose as those
already existing on `TreeFile`.

## v0.5.3

Expand Down
36 changes: 32 additions & 4 deletions nebari/src/roots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,35 @@ where
Index: Clone + EmbeddedIndex + Debug + 'static,
{
/// Returns the latest sequence id.
#[must_use]
pub fn current_sequence_id(&self) -> SequenceId {
let state = self.tree.state.lock();
state.root.sequence
}

/// Scans the tree for keys that are contained within `range`. If `forwards`
/// is true, scanning starts at the lowest sort-order key and scans forward.
/// Otherwise, scanning starts at the highest sort-order key and scans
/// backwards. `key_evaluator` is invoked for each key as it is encountered.
/// For all [`ScanEvaluation::ReadData`] results returned, `callback` will be
/// invoked with the key and values. The callback may not be invoked in the
/// same order as the keys are scanned.
pub fn scan_sequences<CallerError, Range, KeyEvaluator, DataCallback>(
&mut self,
range: Range,
forwards: bool,
key_evaluator: &mut KeyEvaluator,
data_callback: &mut DataCallback,
) -> Result<(), AbortError<CallerError>>
where
Range: RangeBounds<SequenceId> + Debug + 'static,
KeyEvaluator: FnMut(KeySequence) -> ScanEvaluation,
DataCallback: FnMut(KeySequence, ArcBytes<'static>) -> Result<(), AbortError<CallerError>>,
CallerError: Display + Debug,
{
self.tree
.scan_sequences(range, forwards, true, key_evaluator, data_callback)
}
}

impl<Root: tree::Root, File: ManagedFile> TransactionTree<Root, File> {
Expand Down Expand Up @@ -1327,17 +1352,20 @@ impl<File: ManagedFile, Index> Tree<VersionedTreeRoot<Index>, File>
where
Index: EmbeddedIndex + Clone + Debug + 'static,
{
/// Returns the latest sequence id.
#[must_use]
pub fn current_sequence_id(&self) -> SequenceId {
let state = self.state.lock();
state.root.sequence
}

/// Scans the tree for keys that are contained within `range`. If `forwards`
/// is true, scanning starts at the lowest sort-order key and scans forward.
/// Otherwise, scanning starts at the highest sort-order key and scans
/// backwards. `key_evaluator` is invoked for each key as it is encountered.
/// For all [`ScanEvaluation::ReadData`] results returned, `callback` will be
/// invoked with the key and values. The callback may not be invoked in the
/// same order as the keys are scanned.
#[cfg_attr(
feature = "tracing",
tracing::instrument(skip(self, key_evaluator, data_callback))
)]
pub fn scan_sequences<CallerError, Range, KeyEvaluator, DataCallback>(
&mut self,
range: Range,
Expand Down

0 comments on commit 493a70e

Please sign in to comment.