Skip to content
Snippets Groups Projects
Commit 8056973b authored by Georgy Moshkin's avatar Georgy Moshkin :speech_balloon:
Browse files

refactor: use DMLOp for replication_factor

parent 3b3e8179
No related branches found
No related tags found
1 merge request!239Feat/cluster wide dml op
Pipeline #11992 passed
......@@ -11,6 +11,7 @@ use ::tarantool::tlua;
use ::tarantool::transaction::start_transaction;
use std::convert::TryFrom;
use std::time::{Duration, Instant};
use traft::storage::{RaftSpace, RaftStateKey};
use traft::ExpelRequest;
use clap::StructOpt as _;
......@@ -610,9 +611,15 @@ fn start_boot(args: &args::Run) {
lc.inc();
init_entries.push({
let ctx = traft::EntryContextNormal {
op: traft::Op::PersistReplicationFactor {
replication_factor: args.init_replication_factor,
},
op: traft::OpDML::insert(
RaftSpace::State,
&(
RaftStateKey::ReplicationFactor,
args.init_replication_factor,
),
)
.expect("cannot fail")
.into(),
lc,
};
let e = traft::Entry {
......
......@@ -87,11 +87,6 @@ pub enum Op {
PersistPeer {
peer: Peer,
},
#[serde(alias = "persist_replication_factor")]
PersistReplicationFactor {
replication_factor: u8,
},
/// Cluster-wide data modification operation.
/// Should be used to manipulate the cluster-wide configuration.
Dml(OpDML),
......@@ -107,9 +102,6 @@ impl std::fmt::Display for Op {
Self::PersistPeer { peer } => {
write!(f, "PersistPeer{}", peer)
}
Self::PersistReplicationFactor { replication_factor } => {
write!(f, "PersistReplicationFactor({replication_factor})")
}
Self::Dml(OpDML::Insert { space, tuple }) => {
write!(f, "Insert({space}, {})", DisplayAsJson(tuple))
}
......@@ -170,10 +162,6 @@ impl Op {
Storage::persist_peer(peer).unwrap();
Box::new(peer.clone())
}
Self::PersistReplicationFactor { replication_factor } => {
Storage::persist_replication_factor(*replication_factor).unwrap();
Box::new(())
}
Self::Dml(op) => Box::new(op.result()),
}
}
......
......@@ -45,6 +45,33 @@ const RAFT_GROUP: &str = RaftSpace::Group.as_str();
const RAFT_STATE: &str = RaftSpace::State.as_str();
const RAFT_LOG: &str = RaftSpace::Log.as_str();
////////////////////////////////////////////////////////////////////////////////
// RaftStateKey
////////////////////////////////////////////////////////////////////////////////
define_str_enum! {
/// An enumeration of builtin raft spaces
pub enum RaftStateKey {
ReplicationFactor = "replication_factor",
Commit = "commit",
Applied = "applied",
Term = "term",
Vote = "vote",
Gen = "gen",
Voters = "voters",
Learners = "learners",
VotersOutgoing = "voters_outgoing",
LearnersNext = "learners_next",
AutoLeave = "auto_leave",
}
FromStr::Err = UnknownRaftStateKey;
}
#[derive(Error, Debug)]
#[error("unknown raft state key {0}")]
pub struct UnknownRaftStateKey(pub String);
////////////////////////////////////////////////////////////////////////////////
// Error
////////////////////////////////////////////////////////////////////////////////
......@@ -271,11 +298,7 @@ impl Storage {
}
pub fn replication_factor() -> Result<Option<u8>, StorageError> {
Storage::raft_state("replication_factor")
}
pub fn persist_replication_factor(replication_factor: u8) -> Result<(), StorageError> {
Storage::persist_raft_state("replication_factor", replication_factor)
Storage::raft_state(RaftStateKey::ReplicationFactor.as_str())
}
pub fn persist_commit(commit: RaftIndex) -> Result<(), StorageError> {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment