common_wal/config/
raft_engine.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::time::Duration;
16
17use common_base::readable_size::ReadableSize;
18use serde::{Deserialize, Serialize};
19
20/// Configurations for raft-engine wal.
21#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
22#[serde(default)]
23pub struct RaftEngineConfig {
24    /// Wal directory
25    pub dir: Option<String>,
26    /// Wal file size in bytes
27    pub file_size: ReadableSize,
28    /// Wal purge threshold in bytes
29    pub purge_threshold: ReadableSize,
30    /// Purge interval in seconds
31    #[serde(with = "humantime_serde")]
32    pub purge_interval: Duration,
33    /// Read batch size
34    pub read_batch_size: usize,
35    /// Whether to sync log file after every write
36    pub sync_write: bool,
37    /// Whether to reuse logically truncated log files.
38    pub enable_log_recycle: bool,
39    /// Whether to pre-create log files on start up
40    pub prefill_log_files: bool,
41    /// Duration for fsyncing log files.
42    #[serde(with = "humantime_serde")]
43    pub sync_period: Option<Duration>,
44    /// Parallelism during log recovery.
45    pub recovery_parallelism: usize,
46}
47
48impl Default for RaftEngineConfig {
49    fn default() -> Self {
50        Self {
51            dir: None,
52            file_size: ReadableSize::mb(128),
53            purge_threshold: ReadableSize::gb(1),
54            purge_interval: Duration::from_secs(60),
55            read_batch_size: 128,
56            sync_write: false,
57            enable_log_recycle: true,
58            prefill_log_files: false,
59            sync_period: None,
60            recovery_parallelism: num_cpus::get(),
61        }
62    }
63}