Skip to content

Commit fa09be9

Browse files
authored
Merge pull request #108 from fjall-rs/2.5.0
2.5.0
2 parents 80a7b99 + 4e92845 commit fa09be9

File tree

18 files changed

+132
-93
lines changed

18 files changed

+132
-93
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "fjall"
33
description = "LSM-based key-value storage engine"
44
license = "MIT OR Apache-2.0"
5-
version = "2.4.4"
5+
version = "2.5.0"
66
edition = "2021"
77
rust-version = "1.74.0"
88
readme = "README.md"
@@ -28,7 +28,7 @@ bytes = ["lsm-tree/bytes"]
2828

2929
[dependencies]
3030
byteorder = "1.5.0"
31-
lsm-tree = { version = "2.4.0", default-features = false }
31+
lsm-tree = { version = "2.5.0", default-features = false }
3232
log = "0.4.21"
3333
std-semaphore = "0.1.0"
3434
tempfile = "3.10.1"

examples/permuterm/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fn main() -> Result<()> {
8080

8181
for word in WORDS {
8282
for term in permuterm(word) {
83-
db.insert(format!("{term}#{word}"), word).unwrap();
83+
db.insert(format!("{term}#{word}"), *word).unwrap();
8484
}
8585
}
8686

examples/tx-blob-cas/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl Cas {
125125
let rc = self.decrement_ref_count(&mut tx, &prev_content_hash)?;
126126
if rc == 0 {
127127
// No more references
128-
tx.remove(&self.blobs, &prev_content_hash);
128+
tx.remove(&self.blobs, prev_content_hash);
129129
}
130130
}
131131

@@ -156,7 +156,7 @@ impl Cas {
156156
let rc = self.decrement_ref_count(&mut tx, &content_hash)?;
157157
if rc == 0 {
158158
// No more references
159-
tx.remove(&self.blobs, &content_hash);
159+
tx.remove(&self.blobs, content_hash);
160160
}
161161

162162
tx.commit()?;

examples/tx-mpmc-queue/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,12 @@ fn main() -> fjall::Result<()> {
6363
// Something like SingleDelete https://github.com/facebook/rocksdb/wiki/Single-Delete
6464
// would be good for this type of workload
6565
if let Some((key, _)) = tx.first_key_value(&tasks)? {
66-
tx.remove(&tasks, &key);
66+
let task_id = std::str::from_utf8(&key).unwrap().to_owned();
67+
68+
tx.remove(&tasks, key);
6769

6870
tx.commit()?;
6971

70-
let task_id = std::str::from_utf8(&key).unwrap();
7172
println!("consumer {idx} completed task {task_id}");
7273

7374
counter.fetch_add(1, Relaxed);

examples/tx-partition-move/src/main.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ fn main() -> fjall::Result<()> {
3333
// Something like SingleDelete https://github.com/facebook/rocksdb/wiki/Single-Delete
3434
// would be good for this type of workload
3535
if let Some((key, value)) = tx.first_key_value(&src)? {
36-
tx.remove(&src, &key);
37-
tx.insert(&dst, &key, &value);
36+
let task_id = std::str::from_utf8(&key).unwrap().to_owned();
37+
38+
tx.remove(&src, key.clone());
39+
tx.insert(&dst, key, value);
3840

3941
tx.commit()?;
4042

41-
let task_id = std::str::from_utf8(&key).unwrap();
4243
println!("consumer {idx} moved {task_id}");
4344

4445
let ms = rng.gen_range(10..100);

examples/tx-ssi-mpmc-queue/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,14 @@ fn main() -> fjall::Result<()> {
6565
// Something like SingleDelete https://github.com/facebook/rocksdb/wiki/Single-Delete
6666
// would be good for this type of workload
6767
if let Some((key, _)) = tx.first_key_value(&tasks)? {
68-
tx.remove(&tasks, &key);
68+
let task_id = std::str::from_utf8(&key).unwrap().to_owned();
69+
70+
tx.remove(&tasks, key);
6971

7072
if tx.commit()?.is_ok() {
7173
counter.fetch_add(1, Relaxed);
7274
}
7375

74-
let task_id = std::str::from_utf8(&key).unwrap();
7576
println!("consumer {idx} completed task {task_id}");
7677

7778
let ms = rng.gen_range(50..200);

examples/tx-ssi-partition-move/src/main.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ fn main() -> fjall::Result<()> {
3333
// Something like SingleDelete https://github.com/facebook/rocksdb/wiki/Single-Delete
3434
// would be good for this type of workload
3535
if let Some((key, value)) = tx.first_key_value(&src)? {
36-
tx.remove(&src, &key);
37-
tx.insert(&dst, &key, &value);
36+
let task_id = std::str::from_utf8(&key).unwrap().to_owned();
37+
38+
tx.remove(&src, key.clone());
39+
tx.insert(&dst, key, value);
3840

3941
tx.commit()?.ok();
4042

41-
let task_id = std::str::from_utf8(&key).unwrap();
4243
println!("consumer {idx} moved {task_id}");
4344

4445
let ms = rng.gen_range(10..100);

src/batch/mod.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub mod item;
66

77
use crate::{Keyspace, PartitionHandle, PersistMode};
88
use item::Item;
9-
use lsm_tree::{AbstractTree, ValueType};
9+
use lsm_tree::{AbstractTree, UserKey, UserValue, ValueType};
1010
use std::{collections::HashSet, sync::Arc};
1111

1212
/// Partition key (a.k.a. column family, locality group)
@@ -52,28 +52,20 @@ impl Batch {
5252
}
5353

5454
/// Inserts a key-value pair into the batch
55-
pub fn insert<K: AsRef<[u8]>, V: AsRef<[u8]>>(
55+
pub fn insert<K: Into<UserKey>, V: Into<UserValue>>(
5656
&mut self,
5757
p: &PartitionHandle,
5858
key: K,
5959
value: V,
6060
) {
61-
self.data.push(Item::new(
62-
p.name.clone(),
63-
key.as_ref(),
64-
value.as_ref(),
65-
ValueType::Value,
66-
));
61+
self.data
62+
.push(Item::new(p.name.clone(), key, value, ValueType::Value));
6763
}
6864

6965
/// Adds a tombstone marker for a key
70-
pub fn remove<K: AsRef<[u8]>>(&mut self, p: &PartitionHandle, key: K) {
71-
self.data.push(Item::new(
72-
p.name.clone(),
73-
key.as_ref(),
74-
vec![],
75-
ValueType::Tombstone,
76-
));
66+
pub fn remove<K: Into<UserKey>>(&mut self, p: &PartitionHandle, key: K) {
67+
self.data
68+
.push(Item::new(p.name.clone(), key, vec![], ValueType::Tombstone));
7769
}
7870

7971
/// Commits the batch to the [`Keyspace`] atomically

src/compaction/worker.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
use super::manager::CompactionManager;
66
use crate::snapshot_tracker::SnapshotTracker;
77
use lsm_tree::AbstractTree;
8+
use std::sync::atomic::AtomicUsize;
89

910
/// Runs a single run of compaction.
10-
pub fn run(compaction_manager: &CompactionManager, snapshot_tracker: &SnapshotTracker) {
11+
pub fn run(
12+
compaction_manager: &CompactionManager,
13+
snapshot_tracker: &SnapshotTracker,
14+
compaction_counter: &AtomicUsize,
15+
) {
1116
let Some(item) = compaction_manager.pop() else {
1217
return;
1318
};
@@ -21,10 +26,12 @@ pub fn run(compaction_manager: &CompactionManager, snapshot_tracker: &SnapshotTr
2126

2227
// TODO: loop if there's more work to do
2328

29+
compaction_counter.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
2430
if let Err(e) = item
2531
.tree
2632
.compact(strategy.inner(), snapshot_tracker.get_seqno_safe_to_gc())
2733
{
2834
log::error!("Compaction failed: {e:?}");
2935
};
36+
compaction_counter.fetch_sub(1, std::sync::atomic::Ordering::Relaxed);
3037
}

src/flush/worker.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ pub fn run(
152152
flush_manager.dequeue_tasks(partition.name.clone(), created_segments.len());
153153

154154
write_buffer_manager.free(memtables_size);
155-
compaction_manager.notify(partition);
155+
156+
for _ in 0..parallelism {
157+
compaction_manager.notify(partition.clone());
158+
}
156159
}
157160
}
158161
Err(e) => {

0 commit comments

Comments
 (0)