Skip to main content

tuwunel_database/map/
options.rs

1use std::sync::Arc;
2
3use rocksdb::{ReadOptions, ReadTier, WriteOptions};
4
5use crate::Engine;
6
7/// Builds iterator options restricted to block-cache reads.
8///
9/// The probe neither fills cache nor falls through to storage.
10#[inline]
11pub(crate) fn cache_iter_options_default(engine: &Arc<Engine>) -> ReadOptions {
12	let mut options = iter_options_default(engine);
13	options.set_read_tier(ReadTier::BlockCache);
14	options.fill_cache(false);
15	options
16}
17
18/// Builds the default options for a map iterator.
19///
20/// Iterator cleanup may purge obsolete files in the background.
21#[inline]
22pub(crate) fn iter_options_default(engine: &Arc<Engine>) -> ReadOptions {
23	let mut options = read_options_default(engine);
24	options.set_background_purge_on_iterator_cleanup(true);
25	options
26}
27
28/// Builds the options for a whole-column integrity walk.
29///
30/// Checksums are verified whatever the engine setting, and the walk leaves the
31/// block cache as it found it.
32#[inline]
33pub(crate) fn scan_options_default(engine: &Arc<Engine>) -> ReadOptions {
34	let mut options = iter_options_default(engine);
35
36	options.set_verify_checksums(true);
37	options.fill_cache(false);
38	options
39}
40
41/// Builds point-read options restricted to block cache.
42///
43/// The read neither fills cache nor falls through to storage.
44#[inline]
45pub(crate) fn cache_read_options_default(engine: &Arc<Engine>) -> ReadOptions {
46	let mut options = read_options_default(engine);
47	options.set_read_tier(ReadTier::BlockCache);
48	options.fill_cache(false);
49	options
50}
51
52/// Builds the base options shared by map reads and iterators.
53///
54/// Total-order seek is enabled. Checksum verification follows the engine
55/// setting.
56#[inline]
57pub(crate) fn read_options_default(engine: &Arc<Engine>) -> ReadOptions {
58	let mut options = ReadOptions::default();
59	options.set_total_order_seek(true);
60
61	if !engine.checksums {
62		options.set_verify_checksums(false);
63	}
64
65	options
66}
67
68/// Builds the default options for a map write.
69///
70/// The current engine configuration requires no map-specific overrides.
71#[inline]
72pub(crate) fn write_options_default(_engine: &Arc<Engine>) -> WriteOptions {
73	WriteOptions::default()
74}