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

fix(governor): vshard_bootstrapped flag is set via raft log

parent 7956e029
No related branches found
No related tags found
1 merge request!299Feat/poor mans vshard
...@@ -1225,6 +1225,7 @@ fn raft_conf_change_loop(status: Rc<Cell<Status>>, storage: Storage) { ...@@ -1225,6 +1225,7 @@ fn raft_conf_change_loop(status: Rc<Cell<Status>>, storage: Storage) {
.any(|peer| peer.has_grades(CurrentGrade::Replicated, TargetGrade::Online)); .any(|peer| peer.has_grades(CurrentGrade::Replicated, TargetGrade::Online));
if need_sharding { if need_sharding {
let res = (|| -> Result<(), Error> { let res = (|| -> Result<(), Error> {
let vshard_bootstrapped = storage.state.vshard_bootstrapped()?;
// TODO: filter out Offline & Expelled peers // TODO: filter out Offline & Expelled peers
let reqs = peers.iter().map(|peer| { let reqs = peers.iter().map(|peer| {
( (
...@@ -1232,6 +1233,7 @@ fn raft_conf_change_loop(status: Rc<Cell<Status>>, storage: Storage) { ...@@ -1232,6 +1233,7 @@ fn raft_conf_change_loop(status: Rc<Cell<Status>>, storage: Storage) {
sharding::Request { sharding::Request {
leader_id, leader_id,
term, term,
bootstrap: !vshard_bootstrapped && peer.raft_id == leader_id,
..Default::default() ..Default::default()
}, },
) )
...@@ -1254,6 +1256,18 @@ fn raft_conf_change_loop(status: Rc<Cell<Status>>, storage: Storage) { ...@@ -1254,6 +1256,18 @@ fn raft_conf_change_loop(status: Rc<Cell<Status>>, storage: Storage) {
"instance_id" => &*peer_iid, "instance_id" => &*peer_iid,
); );
} }
if !vshard_bootstrapped {
node.propose_and_wait(
traft::OpDML::replace(
ClusterSpace::State,
&(StateKey::VshardBootstrapped, true),
)?,
// TODO: don't hard code the timeout
Duration::from_secs(3),
)??;
}
Ok(()) Ok(())
})(); })();
if let Err(e) = res { if let Err(e) = res {
......
use ::tarantool::{proc, tlua}; use ::tarantool::{proc, tlua};
use crate::traft::storage::StateKey;
use crate::traft::{error::Error, node, RaftId, RaftTerm}; use crate::traft::{error::Error, node, RaftId, RaftTerm};
#[proc(packed_args)] #[proc(packed_args)]
...@@ -33,15 +32,8 @@ fn proc_sharding(req: Request) -> Result<Response, Error> { ...@@ -33,15 +32,8 @@ fn proc_sharding(req: Request) -> Result<Response, Error> {
lua.exec_with("vshard.router.cfg(...)", &cfg) lua.exec_with("vshard.router.cfg(...)", &cfg)
.map_err(tlua::LuaError::from)?; .map_err(tlua::LuaError::from)?;
// TODO: governor should decide who does this, and propose a OpDML entry if req.bootstrap {
// afterwards
if !storage
.state
.get(StateKey::VshardBootstrapped)?
.unwrap_or(false)
{
lua.exec("vshard.router.bootstrap()")?; lua.exec("vshard.router.bootstrap()")?;
storage.state.put(StateKey::VshardBootstrapped, &true)?;
} }
Ok(Response {}) Ok(Response {})
...@@ -53,6 +45,7 @@ pub struct Request { ...@@ -53,6 +45,7 @@ pub struct Request {
pub leader_id: RaftId, pub leader_id: RaftId,
pub term: RaftTerm, pub term: RaftTerm,
pub weights: Option<cfg::ReplicasetWeights>, pub weights: Option<cfg::ReplicasetWeights>,
pub bootstrap: bool,
} }
impl ::tarantool::tuple::Encode for Request {} impl ::tarantool::tuple::Encode for Request {}
......
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