Skip to main content

surrealdb_core/
options.rs

1use std::time::Duration;
2
3/// Configuration for the engine behaviour
4///
5/// The defaults are optimal so please only modify these if you know
6/// deliberately why you are modifying them.
7#[derive(Clone, Copy, Debug)]
8pub struct EngineOptions {
9	/// Interval for refreshing node membership information
10	pub node_membership_refresh_interval: Duration,
11	/// Interval for checking node membership status
12	pub node_membership_check_interval: Duration,
13	/// Interval for cleaning up inactive nodes from the cluster
14	pub node_membership_cleanup_interval: Duration,
15	/// Interval for garbage collecting expired changefeed data
16	pub changefeed_gc_interval: Duration,
17	/// Interval for running the index compaction process
18	///
19	/// The index compaction thread runs at this interval to process indexes
20	/// that have been marked for compaction. Compaction helps optimize index
21	/// performance, particularly for full-text indexes, by consolidating
22	/// changes and removing unnecessary data.
23	///
24	/// Default: 5 seconds
25	pub index_compaction_interval: Duration,
26	/// Interval for processing queued async events.
27	///
28	/// Default: 5 seconds
29	pub event_processing_interval: Duration,
30}
31
32impl Default for EngineOptions {
33	fn default() -> Self {
34		Self {
35			node_membership_refresh_interval: Duration::from_secs(3),
36			node_membership_check_interval: Duration::from_secs(15),
37			node_membership_cleanup_interval: Duration::from_secs(300),
38			changefeed_gc_interval: Duration::from_secs(30),
39			index_compaction_interval: Duration::from_secs(5),
40			event_processing_interval: Duration::from_secs(5),
41		}
42	}
43}
44
45impl EngineOptions {
46	pub fn with_node_membership_refresh_interval(mut self, interval: Duration) -> Self {
47		self.node_membership_refresh_interval = interval;
48		self
49	}
50	pub fn with_node_membership_check_interval(mut self, interval: Duration) -> Self {
51		self.node_membership_check_interval = interval;
52		self
53	}
54	pub fn with_node_membership_cleanup_interval(mut self, interval: Duration) -> Self {
55		self.node_membership_cleanup_interval = interval;
56		self
57	}
58	pub fn with_changefeed_gc_interval(mut self, interval: Duration) -> Self {
59		self.changefeed_gc_interval = interval;
60		self
61	}
62
63	pub fn with_index_compaction_interval(mut self, interval: Duration) -> Self {
64		self.index_compaction_interval = interval;
65		self
66	}
67
68	pub fn with_event_processing_interval(mut self, interval: Duration) -> Self {
69		self.event_processing_interval = interval;
70		self
71	}
72}