Skip to main content

Options

Struct Options 

Source
pub struct Options {
Show 22 fields pub sync_on_write: bool, pub concurrent_write: u8, pub gc_timeout: u64, pub checkpoint_nudge_ms: u64, pub data_garbage_ratio: u32, pub gc_eager: bool, pub blob_file_size: usize, pub blob_garbage_ratio: usize, pub blob_gc_ratio: usize, pub tmp_store: bool, pub log_root: PathBuf, pub lru_capacity: usize, pub stat_mask_cache_count: usize, pub data_handle_cache_capacity: usize, pub blob_handle_cache_capacity: usize, pub data_file_size: usize, pub wal_buffer_size: usize, pub max_ckpt_per_txn: usize, pub wal_file_size: u32, pub keep_stable_wal_file: bool, pub truncate_corrupted_wal: bool, pub observer: Arc<dyn Observer>, /* private fields */
}
Expand description

Configuration options for the Mace storage engine.

Fields§

§sync_on_write: bool

Force-sync data to disk for every wal/data write.

The default value is true (use fsync or else use fdatasync). Turning it off may result in data loss, while turning it on may reduce performance.

§concurrent_write: u8

Writer group count. Default is Self::CONCURRENT_WRITE and it must be in the range [1, 128]

Once set, it cannot be modified

§gc_timeout: u64

Garbage collection cycle interval (milliseconds).

§checkpoint_nudge_ms: u64

Proactive page-checkpoint trigger interval (milliseconds).

When a bucket has pending dirty pages but no foreground write reaches checkpoint thresholds, the evictor triggers checkpoint near this interval to prevent WAL checkpoint stalling.

Set to 0 to disable proactive triggering.

§data_garbage_ratio: u32

Perform compaction when the garbage ratio exceeds this value, in the range [0, 100]

§gc_eager: bool

If true, compact immediately when Self::data_garbage_ratio is reached.

§blob_file_size: usize

Size limit of a blob file. Default is Self::BLOB_FILE_SIZE

§blob_garbage_ratio: usize

Trigger blob GC when the garbage ratio exceeds this value, in the range [0, 100]

§blob_gc_ratio: usize

At each blob GC cycle, pick the lowest-utilization Self::blob_gc_ratio% of blob files as candidates.

§tmp_store: bool

Whether this is temporary storage.

If true, db_root will be removed on exit.

§log_root: PathBuf

Directory where log files are stored.

The default value is db_root/log.

§lru_capacity: usize

Shared logical-address cache capacity in bytes.

This cache keeps file-loaded blob values and auxiliary history/sibling pages. Resident tree pages and dirty pool pages are accounted elsewhere and are not inserted here. Trimming is best-effort and happens in small rounds, so short-term overshoot is possible.

Different subsystems may transiently hold refs to the same allocation.

§stat_mask_cache_count: usize

Bitmap-cache entry count for data and blob stats.

§data_handle_cache_capacity: usize

Maximum number of open data-file handles cached concurrently, used for loading data pages.

§blob_handle_cache_capacity: usize

Maximum number of open blob-file handles cached concurrently, used for loading blob pages.

§data_file_size: usize

Size limit of a data file. Minimum is Self::DATA_FILE_SIZE

§wal_buffer_size: usize

WAL ring buffer size. Must be greater than the page size and a power of two.

§max_ckpt_per_txn: usize

Number of checkpoints a transaction can span (i.e., transaction length limit).

If a transaction exceeds this limit, it is forcibly aborted.

§wal_file_size: u32

WAL file size limit that triggers switching to a new WAL file, up to 2GB.

§keep_stable_wal_file: bool

If true, remove unused stable WAL files (never used in recovery).

Default is false.

§truncate_corrupted_wal: bool

If true, corrupted WAL is truncated during recovery; otherwise recovery panics.

Default is true.

§observer: Arc<dyn Observer>

Observability callback. Default is no-op.

Implementations§

Source§

impl Options

Source

pub const CONCURRENT_WRITE: u8 = 16

Source

pub const MAX_CONCURRENT_WRITE: u8 = 128

Source

pub const DATA_FILE_SIZE: usize

Source

pub const BLOB_FILE_SIZE: usize

Source

pub const LRU_CAPACITY: usize

Source

pub const STAT_MASK_CACHE_CNT: usize = 16384

Source

pub const WAL_BUF_SZ: usize

Source

pub const WAL_FILE_SZ: usize

Source

pub fn new<P: AsRef<Path>>(db_root: P) -> Self

Creates a new Options instance with default values and the given database root.

Examples found in repository?
examples/observer.rs (line 13)
8fn main() -> Result<(), OpCode> {
9    let path = std::env::temp_dir().join(format!("mace_observer_{}", std::process::id()));
10    let _ = std::fs::remove_dir_all(&path);
11
12    let observer = Arc::new(InMemoryObserver::new(256));
13    let mut opt = Options::new(&path);
14    opt.observer = observer.clone();
15
16    let db = Mace::new(opt.validate()?)?;
17    let bucket = db.new_bucket("observe", BucketOptions::default())?;
18
19    let tx = bucket.begin()?;
20    tx.put("k1", "v1")?;
21
22    let r = tx.put("k1", "v2");
23    assert_eq!(r.err(), Some(OpCode::AbortTx));
24    drop(tx);
25
26    let tx = bucket.begin()?;
27    tx.put("k2", "v2")?;
28    tx.commit()?;
29
30    let snapshot = observer.snapshot();
31    print_snapshot(&snapshot);
32    Ok(())
33}
More examples
Hide additional examples
examples/demo.rs (line 6)
3fn main() -> Result<(), OpCode> {
4    let path = std::env::temp_dir().join("mace");
5    let _ = std::fs::remove_dir_all(&path);
6    let opt = Options::new(path).validate()?;
7    let db = Mace::new(opt)?;
8    let bucket = db.new_bucket("test", BucketOptions::default())?;
9
10    // start a read-write transaction
11    let kv = bucket.begin()?;
12    kv.put("foo", "bar")?;
13    kv.put("fool", "+1s")?;
14    kv.put("foolish", "elder")?;
15
16    // can't create two identical keys
17    let r = kv.put("foolish", "114514").err();
18    assert_eq!(r.unwrap(), OpCode::AbortTx);
19
20    // use `update` for exist key or use `upsert` when unsure
21    let r = kv.update("foolish", "114514");
22    assert!(r.is_ok());
23
24    let r = kv.get("foo")?;
25    assert_eq!(r.slice(), "bar".as_bytes());
26    kv.del("foolish")?;
27    kv.commit()?;
28
29    // rollback
30    let kv = bucket.begin()?;
31    kv.put("mo", "ha")?;
32    drop(kv);
33
34    // start a read-only transaction
35    let view = bucket.view()?;
36    let r = view.get("foo")?;
37    assert_eq!(r.slice(), "bar".as_bytes());
38    let r = view.get("mo");
39    assert_eq!(r.err().unwrap(), OpCode::NotFound);
40
41    // prefix scan
42    let r = view.get("foolish");
43    assert!(r.is_err() && r.err().unwrap() == OpCode::NotFound);
44    let iter = view.seek("foo");
45    assert_eq!(iter.count(), 2);
46
47    Ok(())
48}
Source

pub fn validate(self) -> Result<ParsedOptions, OpCode>

Validates the options and returns a ParsedOptions instance.

Examples found in repository?
examples/observer.rs (line 16)
8fn main() -> Result<(), OpCode> {
9    let path = std::env::temp_dir().join(format!("mace_observer_{}", std::process::id()));
10    let _ = std::fs::remove_dir_all(&path);
11
12    let observer = Arc::new(InMemoryObserver::new(256));
13    let mut opt = Options::new(&path);
14    opt.observer = observer.clone();
15
16    let db = Mace::new(opt.validate()?)?;
17    let bucket = db.new_bucket("observe", BucketOptions::default())?;
18
19    let tx = bucket.begin()?;
20    tx.put("k1", "v1")?;
21
22    let r = tx.put("k1", "v2");
23    assert_eq!(r.err(), Some(OpCode::AbortTx));
24    drop(tx);
25
26    let tx = bucket.begin()?;
27    tx.put("k2", "v2")?;
28    tx.commit()?;
29
30    let snapshot = observer.snapshot();
31    print_snapshot(&snapshot);
32    Ok(())
33}
More examples
Hide additional examples
examples/demo.rs (line 6)
3fn main() -> Result<(), OpCode> {
4    let path = std::env::temp_dir().join("mace");
5    let _ = std::fs::remove_dir_all(&path);
6    let opt = Options::new(path).validate()?;
7    let db = Mace::new(opt)?;
8    let bucket = db.new_bucket("test", BucketOptions::default())?;
9
10    // start a read-write transaction
11    let kv = bucket.begin()?;
12    kv.put("foo", "bar")?;
13    kv.put("fool", "+1s")?;
14    kv.put("foolish", "elder")?;
15
16    // can't create two identical keys
17    let r = kv.put("foolish", "114514").err();
18    assert_eq!(r.unwrap(), OpCode::AbortTx);
19
20    // use `update` for exist key or use `upsert` when unsure
21    let r = kv.update("foolish", "114514");
22    assert!(r.is_ok());
23
24    let r = kv.get("foo")?;
25    assert_eq!(r.slice(), "bar".as_bytes());
26    kv.del("foolish")?;
27    kv.commit()?;
28
29    // rollback
30    let kv = bucket.begin()?;
31    kv.put("mo", "ha")?;
32    drop(kv);
33
34    // start a read-only transaction
35    let view = bucket.view()?;
36    let r = view.get("foo")?;
37    assert_eq!(r.slice(), "bar".as_bytes());
38    let r = view.get("mo");
39    assert_eq!(r.err().unwrap(), OpCode::NotFound);
40
41    // prefix scan
42    let r = view.get("foolish");
43    assert!(r.is_err() && r.err().unwrap() == OpCode::NotFound);
44    let iter = view.seek("foo");
45    assert_eq!(iter.count(), 2);
46
47    Ok(())
48}
Source

pub fn create_dir(&self) -> Result<()>

Creates the directory structure for the database.

Source§

impl Options

Source

pub const SEP: &'static str = "_"

Source

pub const DATA_PREFIX: &'static str = "data"

Source

pub const BLOB_PREFIX: &'static str = "blob"

Source

pub const WAL_PREFIX: &'static str = "wal"

Source

pub const WAL_STABLE: &'static str = "stable-wal"

Source

pub const MANIFEST: &'static str = "manifest"

Source

pub fn data_root(&self) -> PathBuf

Source

pub fn data_file(&self, id: u64) -> PathBuf

Source

pub fn blob_file(&self, id: u64) -> PathBuf

Source

pub fn log_root(&self) -> PathBuf

Source

pub fn db_root(&self) -> PathBuf

Source

pub fn wal_file(&self, group_id: u8, seq: u64) -> PathBuf

Source

pub fn wal_backup(&self, group_id: u8, seq: u64) -> PathBuf

Source

pub fn manifest(&self) -> PathBuf

Trait Implementations§

Source§

impl Clone for Options

Source§

fn clone(&self) -> Options

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.