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

Code before:
            self.may_split_keys = splitable;
        }

        // If the region is truly splitable,
        // may_skip_split_check should be false
        if matches!(splitable, Some(true)) {
            self.may_skip_split_check = false;
        }
    }

    pub fn on_ingest_sst_result(&mut self, size: u64, keys: u64) {
        self.approximate_size = Some(self.approximate_size.unwrap_or_default() + size);
        self.approximate_keys = Some(self.approximate_keys.unwrap_or_default() + keys);

        // The ingested file may be overlapped with the data in engine, so we need to
        // check it again to get the accurate value.
        self.may_skip_split_check = false;
    }
}

bitflags! {
    /// A bitmap contains some useful flags to represent different reason for pending remove.
    pub struct PendingRemoveReason: u8 {
        const MERGE   = 0b0000_0001;
        const DESTROY = 0b0000_0010;
    }
}

impl PendingRemoveReason {
    pub fn is_destroy(&self) -> bool {
        *self == Self::DESTROY
    }
}

#[derive(Getters, MutGetters)]
pub struct Peer<EK, ER>
where
    EK: KvEngine,
    ER: RaftEngine,
{
    /// The ID of the Region which this Peer belongs to.
    region_id: u64,
    // TODO: remove it once panic!() support slog fields.
    /// Peer_tag, "[region <region_id>] <peer_id>"
    pub tag: String,
    /// The Peer meta information.
    pub peer: metapb::Peer,

    /// The Raft state machine of this Peer.
    pub raft_group: RawNode<PeerStorage<EK, ER>>,
    /// The online configurable Raft configurations

Review comment (suggestion):
Nit, you can use enum if you do not need bitwise operations, `FlagA | FlagB`.

enum → one-of-many, exclusive choice.

bitflags → many-at-once, combinable options.

Code after:
            self.may_split_keys = splitable;
        }

        // If the region is truly splitable,
        // may_skip_split_check should be false
        if matches!(splitable, Some(true)) {
            self.may_skip_split_check = false;
        }
    }

    pub fn on_ingest_sst_result(&mut self, size: u64, keys: u64) {
        self.approximate_size = Some(self.approximate_size.unwrap_or_default() + size);
        self.approximate_keys = Some(self.approximate_keys.unwrap_or_default() + keys);

        // The ingested file may be overlapped with the data in engine, so we need to
        // check it again to get the accurate value.
        self.may_skip_split_check = false;
    }
}

/// A enum contains some useful state to represent different reason for
/// pending remove.
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PendingRemoveReason {
    NotRemoved = 0,
    Merge,
    Destroy,
}

#[derive(Getters, MutGetters)]
pub struct Peer<EK, ER>
where
    EK: KvEngine,
    ER: RaftEngine,
{
    /// The ID of the Region which this Peer belongs to.
    region_id: u64,
    // TODO: remove it once panic!() support slog fields.
    /// Peer_tag, "[region <region_id>] <peer_id>"
    pub tag: String,
    /// The Peer meta information.
    pub peer: metapb::Peer,

    /// The Raft state machine of this Peer.
    pub raft_group: RawNode<PeerStorage<EK, ER>>,
    /// The online configurable Raft configurations
    raft_max_inflight_msgs: usize,
    /// The cache of meta information for Region's other Peers.
    peer_cache: RefCell<HashMap<u64, metapb::Peer>>,
    /// Record the last instant of each peer's heartbeat response.