value_log/config.rs
1// Copyright (c) 2024-present, fjall-rs
2// This source code is licensed under both the Apache 2.0 and MIT License
3// (found in the LICENSE-* files in the repository)
4
5use crate::{blob_cache::BlobCache, compression::Compressor};
6
7/// Value log configuration
8pub struct Config<BC: BlobCache, C: Compressor + Clone> {
9 /// Target size of vLog segments
10 pub(crate) segment_size_bytes: u64,
11
12 /// Blob cache to use
13 pub(crate) blob_cache: BC,
14
15 /// Compression to use
16 pub(crate) compression: Option<C>,
17}
18
19impl<BC: BlobCache, C: Compressor + Clone + Default> Config<BC, C> {
20 /// Creates a new configuration builder.
21 pub fn new(blob_cache: BC) -> Self {
22 Self {
23 blob_cache,
24 compression: None,
25 segment_size_bytes: 128 * 1_024 * 1_024,
26 }
27 }
28
29 /// Sets the compression & decompression scheme.
30 #[must_use]
31 pub fn compression(mut self, compressor: Option<C>) -> Self {
32 self.compression = compressor;
33 self
34 }
35
36 /// Sets the blob cache.
37 ///
38 /// You can create a global [`BlobCache`] and share it between multiple
39 /// value logs to cap global cache memory usage.
40 #[must_use]
41 pub fn blob_cache(mut self, blob_cache: BC) -> Self {
42 self.blob_cache = blob_cache;
43 self
44 }
45
46 /// Sets the maximum size of value log segments.
47 ///
48 /// This heavily influences space amplification, as
49 /// space reclamation works on a per-segment basis.
50 ///
51 /// Like `blob_file_size` in `RocksDB`.
52 ///
53 /// Default = 256 MiB
54 #[must_use]
55 pub fn segment_size_bytes(mut self, bytes: u64) -> Self {
56 self.segment_size_bytes = bytes;
57 self
58 }
59}