1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use std::time::Duration;
use exocore_protos::core::NodeStoreConfig;
/// Configuration for `Store`.
#[derive(Clone, Copy)]
pub struct StoreConfig {
/// Size of the channel of queries to be executed.
pub query_channel_size: usize,
/// Maximum number fo queries to execute in parallel.
pub query_parallelism: usize,
/// Size of the result channel of each watched query.
pub handle_watch_query_channel_size: usize,
/// Maximum number of events from chain engine to batch together if more are
/// available.
pub chain_events_batch_size: usize,
/// Timeout for mutations that were awaiting for entities to be returned.
pub mutation_tracker_timeout: Duration,
/// How often the garbage collection process will run.
///
/// Since garbage collection doesn't happen on the whole index, but only on
/// entities that got flagged during search, it is better to run more
/// often than less. `GarbageCollectorConfig::queue_size` can be tweaked
/// to control rate of collection.
pub garbage_collect_interval: Duration,
/// Specifies the interval at which new blocks in the chain get indexed.
/// New blocks may not necessarily get immediately indexed if they don't
/// fall in the interval of `chain_index_min_depth` and
/// `chain_index_depth_leeway`.
///
/// Indexation can also be prevented if user queries were recently executed
/// (see `chain_index_deferred_query_secs`)
///
/// If '0' is specified, deferred indexation is disabled and blocks are
/// indexed when the chain layer emits events.
pub chain_index_deferred_interval: Option<Duration>,
/// Specifies the minimum interval to wait before indexing chain blocks
/// after receiving a user query. It prevents potential slow downs caused
/// by chain indexation if a user query get executed frequently.
pub chain_index_deferred_query_interval: Duration,
/// Specifies the maximum interval for which indexation may be blocked by
/// incoming user queries.
pub chain_index_deferred_max_interval: Duration,
}
impl Default for StoreConfig {
fn default() -> Self {
StoreConfig {
query_channel_size: 1000,
query_parallelism: 4,
handle_watch_query_channel_size: 100,
chain_events_batch_size: 50,
mutation_tracker_timeout: Duration::from_secs(5),
garbage_collect_interval: Duration::from_secs(13),
chain_index_deferred_interval: Some(Duration::from_secs(5)),
chain_index_deferred_query_interval: Duration::from_secs(15),
chain_index_deferred_max_interval: Duration::from_secs(5 * 60),
}
}
}
impl From<NodeStoreConfig> for StoreConfig {
fn from(proto: NodeStoreConfig) -> Self {
let mut config = StoreConfig::default();
if let Some(v) = proto.query_parallelism {
config.query_parallelism = v as usize;
}
if let Some(index) = &proto.index {
if let Some(gc) = &index.garbage_collector {
if let Some(v) = gc.run_interval_secs {
config.garbage_collect_interval = Duration::from_secs(v as u64);
}
}
if let Some(secs) = index.chain_index_deferred_interval_secs {
config.chain_index_deferred_interval = Some(Duration::from_secs(secs));
}
if let Some(secs) = index.chain_index_deferred_query_secs {
config.chain_index_deferred_query_interval = Duration::from_secs(secs);
}
if let Some(secs) = index.chain_index_deferred_max_secs {
config.chain_index_deferred_max_interval = Duration::from_secs(secs);
}
}
config
}
}