@@ -329,20 +329,18 @@ impl MetaNode {
329329 Ok ( ( ) )
330330 }
331331
332- /// Open or create a metasrv node.
333- /// Optionally boot a single node cluster.
332+ /// Open or create a meta node.
334333 /// 1. If `open` is `Some`, try to open an existent one.
335334 /// 2. If `create` is `Some`, try to create an one in non-voter mode.
336335 #[ tracing:: instrument( level = "debug" , skip_all) ]
337- pub async fn open_create_boot (
336+ pub async fn open_create (
338337 config : & RaftConfig ,
339338 open : Option < ( ) > ,
340339 create : Option < ( ) > ,
341- initialize_cluster : Option < Node > ,
342340 ) -> Result < Arc < MetaNode > , MetaStartupError > {
343341 info ! (
344- "open_create_boot, config: {:?}, open: {:?}, create: {:?}, initialize_cluster: {:?} " ,
345- config, open, create, initialize_cluster
342+ "open_create_boot, config: {:?}, open: {:?}, create: {:?}" ,
343+ config, open, create
346344 ) ;
347345
348346 let mut config = config. clone ( ) ;
@@ -371,10 +369,21 @@ impl MetaNode {
371369
372370 info ! ( "MetaNode started: {:?}" , config) ;
373371
374- // init_cluster with advertise_host other than listen_host
375- if mn. is_opened ( ) {
376- return Ok ( mn) ;
377- }
372+ Ok ( mn)
373+ }
374+
375+ /// Open or create a metasrv node.
376+ /// Optionally boot a single node cluster.
377+ /// 1. If `open` is `Some`, try to open an existent one.
378+ /// 2. If `create` is `Some`, try to create an one in non-voter mode.
379+ #[ tracing:: instrument( level = "debug" , skip_all) ]
380+ pub async fn open_create_boot (
381+ config : & RaftConfig ,
382+ open : Option < ( ) > ,
383+ create : Option < ( ) > ,
384+ initialize_cluster : Option < Node > ,
385+ ) -> Result < Arc < MetaNode > , MetaStartupError > {
386+ let mn = Self :: open_create ( config, open, create) . await ?;
378387
379388 if let Some ( node) = initialize_cluster {
380389 mn. init_cluster ( node) . await ?;
@@ -718,47 +727,43 @@ impl MetaNode {
718727 async fn do_start ( conf : & MetaConfig ) -> Result < Arc < MetaNode > , MetaStartupError > {
719728 let raft_conf = & conf. raft_config ;
720729
721- let initialize_cluster = if raft_conf. single {
722- Some ( conf. get_node ( ) )
723- } else {
724- None
725- } ;
726-
727730 if raft_conf. single {
728- let mn = MetaNode :: open_create_boot ( raft_conf, Some ( ( ) ) , Some ( ( ) ) , initialize_cluster )
729- . await ?;
731+ let mn = MetaNode :: open_create ( raft_conf, Some ( ( ) ) , Some ( ( ) ) ) . await ? ;
732+ mn . init_cluster ( conf . get_node ( ) ) . await ?;
730733 return Ok ( mn) ;
731734 }
732735
733736 if !raft_conf. join . is_empty ( ) {
734737 // Bring up a new node, join it into a cluster
735738
736- let mn = MetaNode :: open_create_boot ( raft_conf, Some ( ( ) ) , Some ( ( ) ) , initialize_cluster)
737- . await ?;
739+ let mn = MetaNode :: open_create ( raft_conf, Some ( ( ) ) , Some ( ( ) ) ) . await ?;
738740 return Ok ( mn) ;
739741 }
740742 // open mode
741743
742- let mn = MetaNode :: open_create_boot ( raft_conf, Some ( ( ) ) , None , initialize_cluster ) . await ?;
744+ let mn = MetaNode :: open_create ( raft_conf, Some ( ( ) ) , None ) . await ?;
743745 Ok ( mn)
744746 }
745747
746748 /// Boot up the first node to create a cluster.
747749 /// For every cluster this func should be called exactly once.
748750 #[ tracing:: instrument( level = "debug" , skip( config) , fields( config_id=config. raft_config. config_id. as_str( ) ) ) ]
749751 pub async fn boot ( config : & MetaConfig ) -> Result < Arc < MetaNode > , MetaStartupError > {
750- let mn =
751- Self :: open_create_boot ( & config. raft_config , None , Some ( ( ) ) , Some ( config. get_node ( ) ) )
752- . await ?;
753-
752+ let mn = Self :: open_create ( & config. raft_config , None , Some ( ( ) ) ) . await ?;
753+ mn. init_cluster ( config. get_node ( ) ) . await ?;
754754 Ok ( mn)
755755 }
756756
757- // Initialized a single node cluster by :
758- // - Initializing raft membership.
759- // - Adding current node into the meta data.
757+ /// Initialized a single node cluster if this node is just created :
758+ /// - Initializing raft membership.
759+ /// - Adding current node into the meta data.
760760 #[ tracing:: instrument( level = "debug" , skip( self ) ) ]
761761 pub async fn init_cluster ( & self , node : Node ) -> Result < ( ) , MetaStartupError > {
762+ if self . is_opened ( ) {
763+ info ! ( "It is opened, skip initializing cluster" ) ;
764+ return Ok ( ( ) ) ;
765+ }
766+
762767 let node_id = self . sto . id ;
763768
764769 let mut cluster_node_ids = BTreeSet :: new ( ) ;
0 commit comments