Skip to content

Commit

Permalink
Added better suppport for working with indexes
Browse files Browse the repository at this point in the history
While working on khonsulabs/bonsaidb#225, I had to do major updates on
how documents are stored. In the new storage scheme, the key in Nebari
is the DocumentId, Revision::id is Nebari's SequenceId, and
Revision::hash is indexed and stored as an embedded index. This means
that retrieving a document needs access to the index to fully construct
the Document record -- hence these new APIs.

Refs: khonsulabs/bonsaidb#250
  • Loading branch information
sharonminer052 committed May 11, 2022
1 parent 410e550 commit 9f8f844
Show file tree
Hide file tree
Showing 10 changed files with 648 additions and 199 deletions.
27 changes: 26 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

This change also adds `&self` to the `index()` function's signature, allowing
the embedded indexer to have a configuration/state.

- `CompareSwap`'s function now takes an additional parameter:
`Option<&Root::Index>`. This parameter allows inspecting the currently stored
index during the swap function.
- `modify()` now returns a `Vec<ModificationResult<Root::Index>>`, which
contains a list of keys that were modified and their new indexes (if the key
still exists after the modification). Note that for a Versioned tree,
modifications will always produce new indexes as removed keys are still
stored.
- `set()` now returns `Root::Index`, which is the newly stored index for the
key.
- `replace()` now returns a `(Option<ArcBytes>, Root::Index)>`, which is the
previously stored value and the new index for this key.
- `remove()` now returns both the key and index.

### Fixed

- When using `Roots::delete_tree()` on a tree that had previously been opened,
Expand Down Expand Up @@ -72,6 +85,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`PersistenceMode::Flush` will only ensure all application-level caches are
flushed before confirming the write is successful.

### Added

- `TreeFile`, `Tree`, and `TransactionTree` now have additional methods that
allow fetching indexes or values and indexes:

- `get_index()` - single-key index retrieval
- `get_with_index()` - single-key value + index retrieval
- `get_multiple_indexes()` multi-key index retrieval
- `get_multiple_with_indexes()` multi-key value + index retrieval
- `get_range_indexes()` ranged index retrieval
- `get_range_with_indexes()` ranged value + index retrieval

## v0.5.3

### Fixed
Expand Down
16 changes: 9 additions & 7 deletions fuzz/fuzz_targets/compare_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ fuzz_target!(|batches: Vec<BTreeSet<u16>>| {
.iter()
.map(|key| ArcBytes::from(key.to_be_bytes()))
.collect(),
operation: Operation::CompareSwap(CompareSwap::new(&mut |key, current_value| {
if current_value.is_some() {
KeyOperation::Remove
} else {
KeyOperation::Set(key.to_owned())
}
})),
operation: Operation::CompareSwap(CompareSwap::new(
&mut |key, _index, current_value| {
if current_value.is_some() {
KeyOperation::Remove
} else {
KeyOperation::Set(key.to_owned())
}
},
)),
})
.unwrap();
for key in batch {
Expand Down
Loading

0 comments on commit 9f8f844

Please sign in to comment.