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};
6use std::sync::Arc;
7
8/// Value log configuration
9pub struct Config<C: Compressor + Clone> {
10 /// Target size of vLog segments
11 pub(crate) segment_size_bytes: u64,
12
13 /// Blob cache to use
14 pub(crate) blob_cache: Arc<BlobCache>,
15
16 /// Compression to use
17 pub(crate) compression: C,
18}
19
20impl<C: Compressor + Clone + Default> Default for Config<C> {
21 fn default() -> Self {
22 Self {
23 segment_size_bytes: /* 256 MiB */ 256 * 1_024 * 1_024,
24 blob_cache: Arc::new(BlobCache::with_capacity_bytes(
25 /* 16 MiB */ 16 * 1_024 * 1_024,
26 )),
27 compression: C::default(),
28 }
29 }
30}
31
32impl<C: Compressor + Clone> Config<C> {
33 /// Sets the compression & decompression scheme.
34 #[must_use]
35 pub fn compression(mut self, compressor: C) -> Self {
36 self.compression = compressor;
37 self
38 }
39
40 /// Sets the blob cache.
41 ///
42 /// You can create a global [`BlobCache`] and share it between multiple
43 /// value logs to cap global cache memory usage.
44 ///
45 /// Defaults to a blob cache with 16 MiB of capacity *per value log*.
46 #[must_use]
47 pub fn blob_cache(mut self, blob_cache: Arc<BlobCache>) -> Self {
48 self.blob_cache = blob_cache;
49 self
50 }
51
52 /// Sets the maximum size of value log segments.
53 ///
54 /// This heavily influences space amplification, as
55 /// space reclamation works on a per-segment basis.
56 ///
57 /// Like `blob_file_size` in `RocksDB`.
58 ///
59 /// Default = 256 MiB
60 #[must_use]
61 pub fn segment_size_bytes(mut self, bytes: u64) -> Self {
62 self.segment_size_bytes = bytes;
63 self
64 }
65}