Skip to content

Commit

Permalink
Exposing more B+Tree functionality
Browse files Browse the repository at this point in the history
This largely enables external Roots to be written. As part of
khonsulabs/bonsaidb#250, I am moving the document map into the view
entries tree, which requires using two roots like the Versioned root.
The biggest limiting factor was a lot of unexported functionality and
types.

This set of changes also removes some of the &mut requirements for some
of the closures.

The last major change is adding the Value associated type to Root, which
allows a tree to use something other than ArcBytes on its public API
surface. The two built-in trees will continue to use ArcBytes, but the
ViewEntries tree in BonsaiDb will be using a custom type to prevent
extra deserialization.
  • Loading branch information
ecton committed May 15, 2022
1 parent 9507fe5 commit 480ffc8
Show file tree
Hide file tree
Showing 19 changed files with 701 additions and 478 deletions.
7 changes: 5 additions & 2 deletions benchmarks/benches/nebari-bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub trait BenchConfig: Display {

pub trait NebariBenchmark {
const BACKEND: &'static str;
type Root: Root + Default;
type Root: Root<Value = ArcBytes<'static>> + Default;
}

pub struct VersionedBenchmark;
Expand All @@ -120,7 +120,10 @@ use criterion::{
criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, BenchmarkId, Criterion,
Throughput,
};
use nebari::tree::{Root, Unversioned, Versioned};
use nebari::{
tree::{Root, Unversioned, Versioned},
ArcBytes,
};

fn all_benches(c: &mut Criterion) {
blobs::benches(c);
Expand Down
4 changes: 2 additions & 2 deletions fuzz/fuzz_targets/compare_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use libfuzzer_sys::fuzz_target;
use nebari::{
io::{fs::StdFile, FileManager},
tree::{
CompareSwap, KeyOperation, Modification, Operation, PersistenceMode, State, TreeFile,
Unversioned,
btree::KeyOperation, CompareSwap, Modification, Operation, PersistenceMode, State,
TreeFile, Unversioned,
},
ArcBytes, Context,
};
Expand Down
2 changes: 1 addition & 1 deletion nebari/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ parking_lot = "0.12.0"
tracing = { version = "0.1.30", optional = true }
num_cpus = "1.13.1"
backtrace = "0.3.64"
arc-bytes = "0.3.2"
arc-bytes = "0.3.5"

[dev-dependencies]
nanorand = "0.7.0"
Expand Down
9 changes: 5 additions & 4 deletions nebari/examples/embedded-indexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use byteorder::BigEndian;
use nanorand::{Pcg64, Rng};
use nebari::{
tree::{
EmbeddedIndex, Indexer, Reducer, Root, ScanEvaluation, Serializable, VersionedTreeRoot,
btree::{Indexer, Reducer},
EmbeddedIndex, Root, ScanEvaluation, Serializable, VersionedTreeRoot,
},
Error,
ArcBytes, Error,
};

fn main() -> Result<(), Error> {
Expand Down Expand Up @@ -55,15 +56,15 @@ fn main() -> Result<(), Error> {
#[derive(Clone, Debug)]
pub struct Zeroes(pub u32);

impl EmbeddedIndex for Zeroes {
impl EmbeddedIndex<ArcBytes<'static>> for Zeroes {
type Reduced = Self;
type Indexer = ZeroesIndexer;
}

#[derive(Default, Clone, Debug)]
pub struct ZeroesIndexer;

impl Indexer<Zeroes> for ZeroesIndexer {
impl Indexer<ArcBytes<'static>, Zeroes> for ZeroesIndexer {
fn index(
&self,
_key: &nebari::ArcBytes<'_>,
Expand Down
12 changes: 6 additions & 6 deletions nebari/examples/low-level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ fn main() -> Result<(), Error> {
..,
true,
false,
&mut |_key| ScanEvaluation::ReadData,
&mut |key, data| {
|_key| ScanEvaluation::ReadData,
|key, data| {
println!(
"Key {:?} contained {:?} at sequence {:?}. Previous sequence: {:?}",
key.key, data, key.sequence, key.last_sequence
Expand All @@ -61,7 +61,7 @@ fn main() -> Result<(), Error> {
Ok(())
}

fn tree_basics<Root: nebari::tree::Root, File: ManagedFile>(
fn tree_basics<Root: nebari::tree::Root<Value = ArcBytes<'static>>, File: ManagedFile>(
tree: &mut TreeFile<Root, File>,
) -> Result<(), Error> {
// Insert a few key-value pairs.
Expand All @@ -76,9 +76,9 @@ fn tree_basics<Root: nebari::tree::Root, File: ManagedFile>(
&(..),
true,
false,
&mut |_, _, _| ScanEvaluation::ReadData,
&mut |_key, _index| ScanEvaluation::ReadData,
&mut |key, _index, value| {
|_, _, _| ScanEvaluation::ReadData,
|_key, _index| ScanEvaluation::ReadData,
|key, _index, value| {
println!("Found key {:?} with value {:?}", key, value);
Ok(())
},
Expand Down
4 changes: 4 additions & 0 deletions nebari/src/chunk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@ impl ChunkCache {
}
}

/// A cached chunk of data that has possibly been decoded already.
#[derive(Clone)]
pub enum CacheEntry {
/// A buffer of bytes that has been cached.
ArcBytes(ArcBytes<'static>),
/// A previously decoded value that was stored using
/// [`ChunkCache::replace_with_decoded()`].
Decoded(Arc<dyn AnySendSync>),
}
4 changes: 2 additions & 2 deletions nebari/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ mod test_util;
pub use arc_bytes::ArcBytes;

pub use self::{
chunk_cache::ChunkCache,
chunk_cache::{CacheEntry, ChunkCache},
context::Context,
error::{Error, ErrorKind},
roots::{
AbortError, CompareAndSwapError, Config, ExecutingTransaction, LockedTransactionTree,
Roots, ThreadPool, TransactionTree, Tree, UnlockedTransactionTree,
},
vault::Vault,
vault::{AnyVault, Vault},
};
Loading

0 comments on commit 480ffc8

Please sign in to comment.