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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//! mds の設定を定義しているcrate。

use std::ops::Range;
use std::time::Duration;

/// `frugalos_mds` の設定。
///
/// 以下の理由で現時点では module 毎に設定を struct で分けていない。
///
/// - ほとんどの設定が `Node` のためのものであること。
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FrugalosMdsConfig {
    /// コミットをタイムアウトさせるかどうかを決める閾値。
    ///
    /// この設定値の1単位は `node_polling_interval` である点に注意。
    #[serde(default = "default_commit_timeout_threshold")]
    pub commit_timeout_threshold: usize,

    /// proposal キューが長すぎる(リーダーが重い)と判断する基準となる閾値。
    ///
    /// この設定値の1単位は `node_polling_interval` である点に注意。
    #[serde(default = "default_large_proposal_queue_threshold")]
    pub large_proposal_queue_threshold: usize,

    /// リーダー選出待ちキューが長すぎると判断する基準となる閾値。
    #[serde(default = "default_large_leader_waiting_queue_threshold")]
    pub large_leader_waiting_queue_threshold: usize,

    /// リーダー選出待ちをあきらめるまでの閾値。
    ///
    /// この設定値の1単位は `node_polling_interval` である点に注意。
    #[serde(default = "default_leader_waiting_timeout_threshold")]
    pub leader_waiting_timeout_threshold: usize,

    /// true ならリーダー不在状況でログを出す。
    #[serde(default = "default_log_leader_absence")]
    pub log_leader_absence: bool,

    /// リーダー不在状況でログを出すまでの閾値。
    ///
    /// この設定値の1単位は `node_polling_interval` である点に注意。
    #[serde(default = "default_log_leader_absence_threshold")]
    pub log_leader_absence_threshold: usize,

    /// node がポーリングする間隔。
    #[serde(
        rename = "node_polling_interval_millis",
        default = "default_node_polling_interval",
        with = "frugalos_core::serde_ext::duration_millis"
    )]
    pub node_polling_interval: Duration,

    /// リーダが重い場合に再選出を行うかどうかを決める閾値。
    ///
    /// この設定値の1単位は `node_polling_interval` である点に注意。
    #[serde(default = "default_reelection_threshold")]
    pub reelection_threshold: usize,

    /// スナップショットを取る際の閾値の下限(この値を含む).
    #[serde(default = "default_snapshot_threshold_min")]
    pub snapshot_threshold_min: usize,

    /// スナップショットを取る際の閾値の上限(この値を含む).
    #[serde(default = "default_snapshot_threshold_max")]
    pub snapshot_threshold_max: usize,

    /// リーダー不在状況でオブジェクトが古くなりすぎているか否かを決める閾値の上限(この値を含む).
    ///
    /// この設定値の1単位は `node_polling_interval` である点に注意。
    #[serde(default = "default_staled_object_threshold")]
    pub staled_object_threshold: usize,
}

impl FrugalosMdsConfig {
    /// スナップショットを取る際の閾値を返す(両端の値を含む).
    ///
    /// `Node` のローカルログの長さが、この値を超えた場合に、スナップショットの取得が開始される.
    pub fn snapshot_threshold(&self) -> Range<usize> {
        Range {
            start: self.snapshot_threshold_min,
            end: self.snapshot_threshold_max,
        }
    }
}

impl Default for FrugalosMdsConfig {
    fn default() -> Self {
        Self {
            commit_timeout_threshold: default_commit_timeout_threshold(),
            large_proposal_queue_threshold: default_large_proposal_queue_threshold(),
            large_leader_waiting_queue_threshold: default_large_leader_waiting_queue_threshold(),
            leader_waiting_timeout_threshold: default_leader_waiting_timeout_threshold(),
            log_leader_absence: default_log_leader_absence(),
            log_leader_absence_threshold: default_log_leader_absence_threshold(),
            node_polling_interval: default_node_polling_interval(),
            reelection_threshold: default_reelection_threshold(),
            snapshot_threshold_min: default_snapshot_threshold_min(),
            snapshot_threshold_max: default_snapshot_threshold_max(),
            staled_object_threshold: default_staled_object_threshold(),
        }
    }
}

fn default_commit_timeout_threshold() -> usize {
    30
}

fn default_large_proposal_queue_threshold() -> usize {
    1024
}

fn default_large_leader_waiting_queue_threshold() -> usize {
    10000
}

fn default_leader_waiting_timeout_threshold() -> usize {
    10
}

fn default_log_leader_absence() -> bool {
    false
}

fn default_log_leader_absence_threshold() -> usize {
    600 // 5 minutes
}

fn default_node_polling_interval() -> Duration {
    Duration::from_millis(500)
}

fn default_reelection_threshold() -> usize {
    10
}

fn default_snapshot_threshold_min() -> usize {
    9_500
}

fn default_snapshot_threshold_max() -> usize {
    10_500
}

fn default_staled_object_threshold() -> usize {
    50
}