Repository: qdrant/qdrant
File: lib/collection/src/shards/replica_set/mod.rs (Rust)

Code before:
    // Active and sound
    #[default]
    Active,
    // Failed for some reason
    Dead,
    // The shard is partially loaded and is currently receiving data from other shards
    Partial,
    // Collection is being created
    Initializing,
    // A shard which receives data, but is not used for search
    // Useful for backup shards
    Listener,
    // Deprecated since Qdrant 1.9.0, used in Qdrant 1.7.0 and 1.8.0
    //
    // Snapshot shard transfer is in progress, updates aren't sent to the shard
    // Normally rejects updates. Since 1.8 it allows updates if force is true.
    PartialSnapshot,
    // Shard is undergoing recovery by an external node
    // Normally rejects updates, accepts updates if force is true
    Recovery,
    // Points are being migrated to this shard as part of resharding up
    Resharding,
    // Points are being migrated to this shard as part of resharding down
    ReshardingScaleDown,
    // Active for readers, Partial for writers
    ReadActive,
}

impl ReplicaState {
    /// Check if replica state is active
    pub fn is_active(self) -> bool {
        match self {
            ReplicaState::Active => true,
            ReplicaState::ReshardingScaleDown => true,

            ReplicaState::Dead
            | ReplicaState::Partial
            | ReplicaState::Initializing
            | ReplicaState::Listener
            | ReplicaState::PartialSnapshot
            | ReplicaState::Recovery
            | ReplicaState::Resharding
            | ReplicaState::ReadActive => false,
        }
    }

    /// Check whether the replica state is active or listener or resharding.
    pub fn is_active_or_listener_or_resharding(self) -> bool {
        match self {
            ReplicaState::Active
            | ReplicaState::Listener

Review comment (suggestion):
Nit: I might like the name `ActiveRead` a little bit better. As I consider it a sub variant of `Active`.

Code after:
            .collect()
    }

    pub fn active_or_resharding_peers(&self) -> impl Iterator<Item = PeerId> + '_ {
        self.peers.iter().filter_map(|(peer_id, state)| {
            matches!(
                state,
                ReplicaState::Active | ReplicaState::Resharding | ReplicaState::ReshardingScaleDown
            )
            .then_some(*peer_id)
        })
    }

    pub fn set_peers(&mut self, peers: HashMap<PeerId, ReplicaState>) {
        self.peers = peers;
    }
}

/// State of the single shard within a replica set.
#[derive(
    Debug, Deserialize, Serialize, JsonSchema, Default, PartialEq, Eq, Hash, Clone, Copy, Anonymize,
)]
pub enum ReplicaState {
    // Active and sound
    #[default]
    Active,
    // Failed for some reason
    Dead,
    // The shard is partially loaded and is currently receiving data from other shards
    Partial,
    // Collection is being created
    Initializing,
    // A shard which receives data, but is not used for search
    // Useful for backup shards
    Listener,
    // Deprecated since Qdrant 1.9.0, used in Qdrant 1.7.0 and 1.8.0
    //
    // Snapshot shard transfer is in progress, updates aren't sent to the shard
    // Normally rejects updates. Since 1.8 it allows updates if force is true.
    PartialSnapshot,
    // Shard is undergoing recovery by an external node
    // Normally rejects updates, accepts updates if force is true
    Recovery,
    // Points are being migrated to this shard as part of resharding up
    Resharding,
    // Points are being migrated to this shard as part of resharding down
    ReshardingScaleDown,
    // Active for readers, Partial for writers
    ActiveRead,
}