Skip to content

Commit 46eed6a

Browse files
committed
enable the compress feature on Fjall
1 parent 7f213fd commit 46eed6a

File tree

3 files changed

+43
-21
lines changed

3 files changed

+43
-21
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ sha3 = "0.10"
2222

2323
threadpool = "1.8.1" # used in a background cleaner
2424

25-
fjall = "2.11.2"
25+
fjall = { version = "=3.0.0-rc.5", default-features = false }
2626
rocksdb = { version = "0.24.0", default-features = false, features = ["bindgen-runtime"] }
2727

2828
vsdb = { path = "wrappers", version = "7.0.0", default-features = false }

core/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "vsdb_core"
3-
version = "7.0.0"
3+
version = "7.0.1"
44
authors = ["[email protected]"]
55
edition = "2024"
66
description = "A std-collection-like database"
@@ -32,7 +32,7 @@ default = ["compress", "fjall_backend"]
3232
fjall_backend = ["fjall"]
3333
rocks_backend = ["rocksdb"]
3434

35-
compress = ["rocksdb?/zstd"]
35+
compress = ["rocksdb?/zstd", "fjall?/lz4"]
3636

3737
# [[bench]]
3838
# name = "basic"

core/src/common/engines/fjall_backend.rs

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ use crate::common::{
22
Engine, PREFIX_SIZE, Pre, PreBytes, RESERVED_ID_CNT, RawKey, RawValue,
33
vsdb_get_base_dir, vsdb_set_base_dir,
44
};
5-
use fjall::{Config, Keyspace, Partition, PartitionCreateOptions};
5+
use fjall::{
6+
CompressionType, Database, Keyspace, KeyspaceCreateOptions, PersistMode,
7+
config::CompressionPolicy,
8+
};
69
use parking_lot::Mutex;
710
use ruc::*;
811
use std::{
@@ -21,10 +24,32 @@ const SHARD_CNT: usize = 16;
2124
const META_KEY_MAX_KEYLEN: [u8; 1] = [u8::MAX];
2225
const META_KEY_PREFIX_ALLOCATOR: [u8; 1] = [u8::MIN];
2326

27+
fn keyspace_create_options() -> KeyspaceCreateOptions {
28+
let mut opts = KeyspaceCreateOptions::default();
29+
30+
#[cfg(feature = "compress")]
31+
{
32+
// When compress feature is enabled, use LZ4 compression for data blocks
33+
// L0 and L1 are uncompressed for performance, L2+ use LZ4
34+
opts = opts.data_block_compression_policy(CompressionPolicy::new([
35+
CompressionType::None,
36+
CompressionType::None,
37+
CompressionType::Lz4,
38+
]));
39+
}
40+
41+
#[cfg(not(feature = "compress"))]
42+
{
43+
opts = opts.data_block_compression_policy(CompressionPolicy::disabled());
44+
}
45+
46+
opts
47+
}
48+
2449
pub struct FjallEngine {
25-
meta: Partition,
26-
shards: Vec<Keyspace>,
27-
shards_parts: Vec<Vec<Partition>>,
50+
meta: Keyspace,
51+
shards: Vec<Database>,
52+
shards_parts: Vec<Vec<Keyspace>>,
2853
prefix_allocator: PreAllocator,
2954
max_keylen: AtomicUsize,
3055
}
@@ -36,7 +61,7 @@ impl FjallEngine {
3661
}
3762

3863
#[inline(always)]
39-
fn get_part(&self, prefix: PreBytes) -> &Partition {
64+
fn get_part(&self, prefix: PreBytes) -> &Keyspace {
4065
let shard_idx = self.get_shard_idx(prefix);
4166
let part_idx = self.area_idx(prefix);
4267
&self.shards_parts[shard_idx][part_idx]
@@ -70,25 +95,22 @@ impl Engine for FjallEngine {
7095

7196
for i in 0..SHARD_CNT {
7297
let dir = base_dir.join(format!("shard_{}", i));
73-
let ks = Config::new(dir).open().c(d!())?;
98+
let db = Database::builder(&dir).open().c(d!())?;
7499

75100
let mut parts = Vec::with_capacity(DATA_SET_NUM);
76101
for j in 0..DATA_SET_NUM {
77-
let p = ks
78-
.open_partition(
79-
&format!("part_{}", j),
80-
PartitionCreateOptions::default(),
81-
)
102+
let p = db
103+
.keyspace(&format!("part_{}", j), keyspace_create_options)
82104
.c(d!())?;
83105
parts.push(p);
84106
}
85-
shards.push(ks);
107+
shards.push(db);
86108
shards_parts.push(parts);
87109
}
88110

89-
// Use a dedicated partition in shard 0 for meta
111+
// Use a dedicated keyspace in shard 0 for meta
90112
let meta = shards[0]
91-
.open_partition("meta", PartitionCreateOptions::default())
113+
.keyspace("meta", keyspace_create_options)
92114
.c(d!())?;
93115

94116
let (prefix_allocator, initial_value) = PreAllocator::init();
@@ -142,16 +164,16 @@ impl Engine for FjallEngine {
142164
}
143165

144166
fn flush(&self) {
145-
for ks in &self.shards {
146-
ks.persist(fjall::PersistMode::SyncAll).unwrap();
167+
for db in &self.shards {
168+
db.persist(PersistMode::SyncAll).unwrap();
147169
}
148170
}
149171

150172
fn iter(&self, meta_prefix: PreBytes) -> FjallIter {
151173
let part = self.get_part(meta_prefix);
152174
let inner = part
153175
.prefix(meta_prefix)
154-
.map(|res| res.map(|(k, v)| (k.to_vec(), v.to_vec())));
176+
.map(|guard| guard.into_inner().map(|(k, v)| (k.to_vec(), v.to_vec())));
155177

156178
FjallIter {
157179
inner: Box::new(inner),
@@ -196,7 +218,7 @@ impl Engine for FjallEngine {
196218

197219
let inner = part
198220
.range((start, end))
199-
.map(|res| res.map(|(k, v)| (k.to_vec(), v.to_vec())));
221+
.map(|guard| guard.into_inner().map(|(k, v)| (k.to_vec(), v.to_vec())));
200222

201223
FjallIter {
202224
inner: Box::new(inner),

0 commit comments

Comments
 (0)