Skip to content

Commit 2c6a6f7

Browse files
authored
Merge pull request #120 from fjall-rs/feat/new-cache-api
New cache API
2 parents 0f46ab0 + 5f67e87 commit 2c6a6f7

25 files changed

+343
-302
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ quick_cache = { version = "0.6.5", default-features = false, features = [] }
3737
rustc-hash = "2.0.0"
3838
self_cell = "1.0.4"
3939
tempfile = "3.12.0"
40-
value-log = { version = "1.7.3", default-features = false, features = [] }
40+
value-log = { version = "~1.8", default-features = false, features = [] }
4141
varint-rs = "2.2.0"
4242
xxhash-rust = { version = "0.8.12", features = ["xxh3"] }
4343

src/blob_tree/cache.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use crate::cache::Cache;
2+
use std::sync::Arc;
3+
use value_log::BlobCache;
4+
5+
#[derive(Clone)]
6+
pub struct MyBlobCache(pub(crate) Arc<Cache>);
7+
8+
impl BlobCache for MyBlobCache {
9+
fn get(
10+
&self,
11+
vlog_id: value_log::ValueLogId,
12+
vhandle: &value_log::ValueHandle,
13+
) -> Option<value_log::UserValue> {
14+
self.0.get_blob(vlog_id, vhandle)
15+
}
16+
17+
fn insert(
18+
&self,
19+
vlog_id: value_log::ValueLogId,
20+
vhandle: &value_log::ValueHandle,
21+
value: value_log::UserValue,
22+
) {
23+
self.0.insert_blob(vlog_id, vhandle, value);
24+
}
25+
}

src/blob_tree/mod.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// This source code is licensed under both the Apache 2.0 and MIT License
33
// (found in the LICENSE-* files in the repository)
44

5+
mod cache;
56
mod compression;
67
mod gc;
78
pub mod index;
@@ -16,6 +17,7 @@ use crate::{
1617
value::InternalValue,
1718
Config, KvPair, Memtable, Segment, SegmentId, SeqNo, Snapshot, UserKey, UserValue,
1819
};
20+
use cache::MyBlobCache;
1921
use compression::MyCompressor;
2022
use gc::{reader::GcReader, writer::GcWriter};
2123
use index::IndexTree;
@@ -27,7 +29,7 @@ use std::{
2729
use value::MaybeInlineValue;
2830
use value_log::ValueLog;
2931

30-
fn resolve_value_handle(vlog: &ValueLog<MyCompressor>, item: RangeItem) -> RangeItem {
32+
fn resolve_value_handle(vlog: &ValueLog<MyBlobCache, MyCompressor>, item: RangeItem) -> RangeItem {
3133
use MaybeInlineValue::{Indirect, Inline};
3234

3335
match item {
@@ -67,7 +69,7 @@ pub struct BlobTree {
6769

6870
/// Log-structured value-log that stores large values
6971
#[doc(hidden)]
70-
pub blobs: ValueLog<MyCompressor>,
72+
pub blobs: ValueLog<MyBlobCache, MyCompressor>,
7173

7274
// TODO: maybe replace this with a nonce system
7375
#[doc(hidden)]
@@ -79,10 +81,10 @@ impl BlobTree {
7981
let path = &config.path;
8082

8183
let vlog_path = path.join(BLOBS_FOLDER);
82-
let vlog_cfg = value_log::Config::<MyCompressor>::default()
83-
.blob_cache(config.blob_cache.clone())
84-
.segment_size_bytes(config.blob_file_target_size)
85-
.compression(MyCompressor(config.blob_compression));
84+
let vlog_cfg =
85+
value_log::Config::<MyBlobCache, MyCompressor>::new(MyBlobCache(config.cache.clone()))
86+
.segment_size_bytes(config.blob_file_target_size)
87+
.compression(MyCompressor(config.blob_compression));
8688

8789
let index: IndexTree = config.open()?.into();
8890

@@ -188,7 +190,7 @@ impl BlobTree {
188190

189191
pub fn apply_gc_strategy(
190192
&self,
191-
strategy: &impl value_log::GcStrategy<MyCompressor>,
193+
strategy: &impl value_log::GcStrategy<MyBlobCache, MyCompressor>,
192194
seqno: SeqNo,
193195
) -> crate::Result<u64> {
194196
// IMPORTANT: Write lock memtable to avoid read skew

src/block_cache.rs

-168
This file was deleted.

0 commit comments

Comments
 (0)