1use std::ffi::OsString;
2
3use clap::Parser;
4
5#[derive(Parser, Debug, Clone)]
6#[command(author, version, about, long_about = None)]
7pub struct Args {
9 #[clap(
10 short,
11 long,
12 help = "Unique node name, used to differentiate between nodes for \
13 distribution of load.",
14 default_value = "dbeel"
15 )]
16 pub name: String,
17
18 #[clap(
19 short,
20 long,
21 help = "The seed nodes for service discovery of all nodes.
22Expected format is <hostname/ip>:<port>.",
23 num_args = 0..,
24 )]
25 pub seed_nodes: Vec<String>,
26
27 #[clap(
28 short,
29 long,
30 help = "Listen hostname / ip.",
31 default_value = "127.0.0.1"
32 )]
33 pub ip: String,
34
35 #[clap(
36 short,
37 long,
38 help = "Server port base.
39Each shard has a different port calculated by <port_base> + \
40 <cpu_id>.
41This port is for listening on client requests.",
42 default_value = "10000"
43 )]
44 pub port: u16,
45
46 #[clap(
47 short,
48 long,
49 help = "Database files directory.",
50 default_value = "/tmp/dbeel"
51 )]
52 pub dir: String,
53
54 #[clap(
55 long,
56 help = "Default number of nodes (replicas) that hold a copy for a \
57specific key for tunable availability / consistency, when the replication \
58factor is not set in a create collection request.",
59 default_value = "1"
60 )]
61 pub default_replication_factor: u16,
62
63 #[clap(
64 long,
65 help = "Remote shard port base.
66This port is for listening for distributed messages from \
67 remote shards.",
68 default_value = "20000"
69 )]
70 pub remote_shard_port: u16,
71
72 #[clap(
73 long,
74 help = "Remote shard connect timeout in milliseconds.",
75 default_value = "5000"
76 )]
77 pub remote_shard_connect_timeout: u64,
78
79 #[clap(
80 long,
81 help = "Remote shard write request timeout in milliseconds.",
82 default_value = "15000"
83 )]
84 pub remote_shard_write_timeout: u64,
85
86 #[clap(
87 long,
88 help = "Remote shard read request timeout in milliseconds.",
89 default_value = "15000"
90 )]
91 pub remote_shard_read_timeout: u64,
92
93 #[clap(
94 long,
95 help = "Gossip UDP server port.
96This port is for listening for gossip messages from \
97 remote nodes.",
98 default_value = "30000"
99 )]
100 pub gossip_port: u16,
101
102 #[clap(long, help = "Gossip number of nodes fanout.", default_value = "3")]
103 pub gossip_fanout: usize,
104
105 #[clap(
106 long,
107 help = "Gossip max number of items an event is seen before \
108retransmitting the event again.",
109 default_value = "3"
110 )]
111 pub gossip_max_seen_count: u8,
112
113 #[clap(
114 long,
115 help = "The interval at which to ping a node, in milliseconds.",
116 default_value = "500"
117 )]
118 pub failure_detection_interval: u64,
119
120 #[clap(
121 short,
122 long,
123 help = "How much files to compact each time.",
124 default_value = "2"
125 )]
126 pub compaction_factor: usize,
127
128 #[clap(
129 long,
130 help = "Page cache size in bytes.",
131 default_value = "1073741824"
132 )]
133 pub page_cache_size: usize,
134
135 #[clap(
136 long,
137 help = "How much time (in microseconds) to delay the WAL sync.
1380 means no delay, sync on every write.
139Note that on many systems, the effective resolution of sleep delays is 10 \
140 milliseconds, so test your system before setting this value.",
141 default_value = "0"
142 )]
143 pub wal_sync_delay: u64,
144
145 #[clap(
146 long,
147 help = "Call fdatasync on the WAL file after each write.",
148 default_value = "false"
149 )]
150 pub wal_sync: bool,
151
152 #[clap(
153 long,
154 help = "The minimum size of an sstable (in bytes) to calculate and \
155 store its bloom filter.",
156 default_value = "1048576"
157 )]
158 pub sstable_bloom_min_size: u64,
159
160 #[clap(
161 long,
162 help = "Foreground tasks shares (0 - 1000).",
163 default_value = "1000"
164 )]
165 pub foreground_tasks_shares: u16,
166
167 #[clap(
168 long,
169 help = "Background tasks shares (0 - 1000).",
170 default_value = "250"
171 )]
172 pub background_tasks_shares: u16,
173}
174
175#[must_use]
176pub fn parse_args() -> Args {
177 Args::parse()
178}
179
180pub fn parse_args_from<I, T>(itr: I) -> Args
181where
182 I: IntoIterator<Item = T>,
183 T: Into<OsString> + Clone,
184{
185 Args::parse_from(itr)
186}