Select Git revision
replicaset.rs
replicaset.rs 5.22 KiB
use super::instance::InstanceId;
use crate::instance::Instance;
use ::tarantool::tlua;
use ::tarantool::tuple::Encode;
// TODO: this redundant boilerplate needs to be removed
crate::define_string_newtype! {
/// Unique id of a replicaset.
///
/// This is a new-type style wrapper around String,
/// to distinguish it from other strings.
pub struct ReplicasetId(pub String);
}
pub type Weight = f64;
////////////////////////////////////////////////////////////////////////////////
/// Replicaset info
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq)]
pub struct Replicaset {
/// Primary identifier.
pub replicaset_id: ReplicasetId,
/// UUID used to identify replicasets by tarantool's subsystems.
pub replicaset_uuid: String,
/// Instance id of the current replication leader.
pub current_master_id: InstanceId,
/// Id of instance which should become the replication leader.
pub target_master_id: InstanceId,
/// Name of the tier the replicaset belongs to.
pub tier: String,
/// Sharding weight of the replicaset.
///
/// Determines the portion of the tier's buckets which will be stored in
/// this replicaset.
pub weight: Weight,
/// Describes how the `weight` is chosen: either automatically by governor,
/// or manually by the user.
pub weight_origin: WeightOrigin,
/// Current state of the replicaset. This is set to `NotReady` when the
/// replicaset is not filled up to the tier's replication factor.
pub state: ReplicasetState,
}
impl Encode for Replicaset {}
impl Replicaset {
/// Index of field "replicaset_uuid" in the table _pico_replicaset format.
///
/// Index of first field is 0.
pub const FIELD_REPLICASET_UUID: u32 = 1;
/// Index of field "target_master_id" in the table _pico_replicaset format.
pub const FIELD_TARGET_MASTER_ID: u32 = 3;
#[inline]
pub fn with_one_instance(master: &Instance) -> Replicaset {
Replicaset {
replicaset_id: master.replicaset_id.clone(),
replicaset_uuid: master.replicaset_uuid.clone(),
current_master_id: master.instance_id.clone(),
target_master_id: master.instance_id.clone(),
weight: 0.,
weight_origin: WeightOrigin::Auto,
state: ReplicasetState::NotReady,