Skip to content

Commit

Permalink
store/boostrap: rename some functions
Browse files Browse the repository at this point in the history
Signed-off-by: Neil Shen <overvenus@gmail.com>
  • Loading branch information
overvenus committed Mar 10, 2019
1 parent 802c1ad commit 89613ac
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions components/test_raftstore/src/cluster.rs
Expand Up @@ -436,7 +436,7 @@ impl<T: Simulator> Cluster<T> {
}

for engines in self.engines.values() {
prepare_bootstrap(engines, &region)?;
prepare_bootstrap_cluster(engines, &region)?;
}

self.bootstrap_cluster(region);
Expand Down Expand Up @@ -467,7 +467,7 @@ impl<T: Simulator> Cluster<T> {
region.mut_region_epoch().set_conf_ver(INIT_EPOCH_CONF_VER);
region.mut_peers().push(new_peer(node_id, peer_id));

prepare_bootstrap(&self.engines[&node_id], &region).unwrap();
prepare_bootstrap_cluster(&self.engines[&node_id], &region).unwrap();
self.bootstrap_cluster(region);
region_id
}
Expand Down
16 changes: 8 additions & 8 deletions src/raftstore/store/bootstrap.rs
Expand Up @@ -60,10 +60,10 @@ pub fn bootstrap_store(engines: &Engines, cluster_id: u64, store_id: u64) -> Res
Ok(())
}

/// The first phase of bootstrap
/// The first phase of bootstrap cluster
///
/// Write the first region meta and prepare state.
pub fn prepare_bootstrap(engines: &Engines, region: &metapb::Region) -> Result<()> {
pub fn prepare_bootstrap_cluster(engines: &Engines, region: &metapb::Region) -> Result<()> {
let mut state = RegionLocalState::new();
state.set_region(region.clone());

Expand All @@ -82,8 +82,8 @@ pub fn prepare_bootstrap(engines: &Engines, region: &metapb::Region) -> Result<(
Ok(())
}

// Clear first region meta and prepare state.
pub fn clear_prepare_bootstrap(engines: &Engines, region_id: u64) -> Result<()> {
// Clear first region meta and prepare key.
pub fn clear_prepare_bootstrap_cluster(engines: &Engines, region_id: u64) -> Result<()> {
engines.raft.delete(&keys::raft_state_key(region_id))?;
engines.raft.sync_wal()?;

Expand All @@ -98,8 +98,8 @@ pub fn clear_prepare_bootstrap(engines: &Engines, region_id: u64) -> Result<()>
Ok(())
}

// Clear prepare state
pub fn clear_prepare_bootstrap_state(engines: &Engines) -> Result<()> {
// Clear prepare key
pub fn clear_prepare_bootstrap_key(engines: &Engines) -> Result<()> {
engines.kv.delete(keys::PREPARE_BOOTSTRAP_KEY)?;
engines.kv.sync_wal()?;
Ok(())
Expand Down Expand Up @@ -164,8 +164,8 @@ mod tests {
.unwrap()
.is_some());

assert!(clear_prepare_bootstrap_state(&engines).is_ok());
assert!(clear_prepare_bootstrap(&engines, 1).is_ok());
assert!(clear_prepare_bootstrap_key(&engines).is_ok());
assert!(clear_prepare_bootstrap_cluster(&engines, 1).is_ok());
assert!(is_range_empty(
&kv_engine,
CF_RAFT,
Expand Down
4 changes: 2 additions & 2 deletions src/raftstore/store/mod.rs
Expand Up @@ -30,8 +30,8 @@ mod snap;
mod worker;

pub use self::bootstrap::{
bootstrap_store, clear_prepare_bootstrap, clear_prepare_bootstrap_state, prepare_bootstrap,
INIT_EPOCH_CONF_VER, INIT_EPOCH_VER,
bootstrap_store, clear_prepare_bootstrap_cluster, clear_prepare_bootstrap_key,
prepare_bootstrap_cluster, INIT_EPOCH_CONF_VER, INIT_EPOCH_VER,
};
pub use self::config::Config;
pub use self::engine::{Iterable, Mutable, Peekable};
Expand Down
8 changes: 4 additions & 4 deletions src/server/node.rs
Expand Up @@ -231,7 +231,7 @@ where
region.mut_region_epoch().set_conf_ver(INIT_EPOCH_CONF_VER);
region.mut_peers().push(new_peer(store_id, peer_id));

store::prepare_bootstrap(engines, &region)?;
store::prepare_bootstrap_cluster(engines, &region)?;
Ok(region)
}

Expand Down Expand Up @@ -264,18 +264,18 @@ where
{
Ok(_) => {
fail_point!("node_after_bootstrap_cluster", |_| Ok(()));
store::clear_prepare_bootstrap_state(engines)?;
store::clear_prepare_bootstrap_key(engines)?;
info!("bootstrap cluster ok"; "cluster_id" => self.cluster_id);
return Ok(());
}
Err(PdError::ClusterBootstrapped(_)) => match self.pd_client.get_region(b"") {
Ok(region) => {
if region == first_region {
store::clear_prepare_bootstrap_state(engines)?;
store::clear_prepare_bootstrap_key(engines)?;
return Ok(());
} else {
error!("cluster is already bootstrapped"; "cluster_id" => self.cluster_id);
store::clear_prepare_bootstrap(engines, region_id)?;
store::clear_prepare_bootstrap_cluster(engines, region_id)?;
return Ok(());
}
}
Expand Down

0 comments on commit 89613ac

Please sign in to comment.