Repository: tikv/tikv
File: components/raftstore/src/store/peer.rs (Rust)

Code before:
    pub force_leader: Option<ForceLeaderState>,

    /// Record the instants of peers being added into the configuration.
    /// Remove them after they are not pending any more.
    pub peers_start_pending_time: Vec<(u64, Instant)>,
    /// A inaccurate cache about which peer is marked as down.
    down_peer_ids: Vec<u64>,
    /// the split check trigger
    pub split_check_trigger: SplitCheckTrigger,
    /// The count of deleted keys since last reset.
    delete_keys_hint: u64,

    /// The state for consistency check.
    pub consistency_state: ConsistencyState,

    /// The counter records pending snapshot requests.
    pub pending_request_snapshot_count: Arc<AtomicUsize>,
    /// The index of last scheduled committed raft log.
    pub last_applying_idx: u64,
    pub max_apply_unpersisted_log_limit: u64,
    enable_apply_unpersisted_log_state: bool,
    /// The minimum raft index after which apply unpersisted raft log can be
    /// enabled. We force disable apply unpersisted raft log in following 2
    /// situation:
    /// 1) Raft term changes. In this case, the min index is set to the current
    ///    last index. This is to let apply unpersisted log only happen within
    ///    the same term so it's easier to if any applied but not persisted logs
    ///    has changed in which case we should just panic to avoid data
    ///    inconsistency.
    /// 2) Propose PrepareMerge. In this case, the min index is set to that raft
    ///    log's index. This is to make online unsafe recovery easier when
    ///    region state is PrepareMerge.
    pub min_safe_index_for_unpersisted_apply: u64,
    /// The index of last compacted raft log. It is used for the next compact
    /// log task.
    pub last_compacted_idx: u64,
    /// Record the time of the last raft log compact, the witness should query
    /// the leader periodically whether `voter_replicated_index` is updated
    /// if CompactLog admin command isn't triggered for a while.
    pub last_compacted_time: Instant,
    /// When the peer is witness, and there is any voter lagging behind, the
    /// log truncation of the witness shouldn't be triggered even if it's
    /// force mode, and this item will be set to `true`, after all pending
    /// compact cmds have been handled, it will be set to `false`.
    pub has_pending_compact_cmd: bool,
    /// The index of the latest urgent proposal index.
    last_urgent_proposal_idx: u64,
    /// The index of the latest committed split command.
    last_committed_split_idx: u64,
    /// The index of last sent snapshot
    last_sent_snapshot_idx: u64,

Review comment (bug):
nit: is it necessary to add this member solely for triaging the trigger types of the `enable` and `disable` actions related to the "apply unpersisted log" feature?

If necessary, please add some annotations here.

Code after:
    pub force_leader: Option<ForceLeaderState>,

    /// Record the instants of peers being added into the configuration.
    /// Remove them after they are not pending any more.
    pub peers_start_pending_time: Vec<(u64, Instant)>,
    /// A inaccurate cache about which peer is marked as down.
    down_peer_ids: Vec<u64>,
    /// the split check trigger
    pub split_check_trigger: SplitCheckTrigger,
    /// The count of deleted keys since last reset.
    delete_keys_hint: u64,

    /// The state for consistency check.
    pub consistency_state: ConsistencyState,

    /// The counter records pending snapshot requests.
    pub pending_request_snapshot_count: Arc<AtomicUsize>,
    /// The index of last scheduled committed raft log.
    pub last_applying_idx: u64,
    pub max_apply_unpersisted_log_limit: u64,
    /// A flag used to track whether `max_apply_unpersisted_log_limit` is set
    /// to the Peer in raft-rs. We need this flag to handle the metrics
    /// `RAFT_ENABLE_UNPERSISTED_APPLY_GAUGE` correctly because raft-rs can
    /// reset `max_apply_unpersisted_log_limit` to 0 when it demotes from
    /// leader.
    enable_apply_unpersisted_log_state: bool,
    /// The minimum raft index after which apply unpersisted raft log can be
    /// enabled. We force disable apply unpersisted raft log in following 2
    /// situation:
    /// 1) Raft term changes. In this case, the min index is set to the current
    ///    last index. This is to let apply unpersisted log only happen within
    ///    the same term so it's easier to if any applied but not persisted logs
    ///    has changed in which case we should just panic to avoid data
    ///    inconsistency.
    /// 2) Propose PrepareMerge. In this case, the min index is set to that raft
    ///    log's index. This is to make online unsafe recovery easier when
    ///    region state is PrepareMerge.
    pub min_safe_index_for_unpersisted_apply: u64,
    /// The index of last compacted raft log. It is used for the next compact
    /// log task.
    pub last_compacted_idx: u64,
    /// Record the time of the last raft log compact, the witness should query
    /// the leader periodically whether `voter_replicated_index` is updated
    /// if CompactLog admin command isn't triggered for a while.
    pub last_compacted_time: Instant,
    /// When the peer is witness, and there is any voter lagging behind, the
    /// log truncation of the witness shouldn't be triggered even if it's
    /// force mode, and this item will be set to `true`, after all pending
    /// compact cmds have been handled, it will be set to `false`.
    pub has_pending_compact_cmd: bool,
    /// The index of the latest urgent proposal index.