diff --git a/config.go b/config.go index d3c12dd..c350561 100644 --- a/config.go +++ b/config.go @@ -11,9 +11,10 @@ import ( ) type ConfigServer struct { - ServerID uint64 `yaml:"serverid"` - Host string `yaml:"host"` - Port int `yaml:"port"` + ServerID uint64 `yaml:"serverid"` + Host string `yaml:"host"` + Port int `yaml:"port"` + Cluster []string `yaml:"cluster"` } func (cfg *ConfigServer) Address() string { diff --git a/etc/etc_a.yaml b/etc/etc_a.yaml index cbf1282..2dc1785 100644 --- a/etc/etc_a.yaml +++ b/etc/etc_a.yaml @@ -1,3 +1,4 @@ serverid: 1 host: "localhost" port: 5050 +cluster: [ "localhost:5050","localhost:5051","localhost:5052" ] diff --git a/etc/etc_b.yaml b/etc/etc_b.yaml index ba66ec4..9464b57 100644 --- a/etc/etc_b.yaml +++ b/etc/etc_b.yaml @@ -1,3 +1,4 @@ serverid: 2 host: "localhost" port: 5051 +cluster: [ "localhost:5050","localhost:5051","localhost:5052" ] diff --git a/etc/etc_c.yaml b/etc/etc_c.yaml index f481929..708d551 100644 --- a/etc/etc_c.yaml +++ b/etc/etc_c.yaml @@ -1,3 +1,4 @@ serverid: 3 host: "localhost" port: 5052 +cluster: [ "localhost:5050","localhost:5051","localhost:5052" ] diff --git a/main.go b/main.go index 4b6f523..eb6e59d 100644 --- a/main.go +++ b/main.go @@ -41,12 +41,6 @@ var DequeueHandler = triggered.RegisterExecute(func(params *triggered.Params[boo }) -var addresses []string = []string{ - "localhost:5500", - "localhost:5501", - "localhost:5502", -} - func StartNode(cfg *ConfigServer) { replicaID := cfg.ServerID @@ -72,7 +66,7 @@ func StartNode(cfg *ConfigServer) { // leave the initialMembers to be empty. we still populate the initialMembers // here for simplicity. - for idx, v := range addresses { + for idx, v := range cfg.Cluster { // key is the ReplicaID, ReplicaID is not allowed to be 0 // value is the raft address initialMembers[uint64(idx+1)] = v @@ -140,7 +134,7 @@ func StartNode(cfg *ConfigServer) { // 设置共享的参数 DequeueHandler.WithShared(nh) - if err := nh.StartReplica(initialMembers, false, NewSMQueue, rc); err != nil { + if err := nh.StartReplica(initialMembers, true, NewSMQueue, rc); err != nil { fmt.Fprintf(os.Stderr, "failed to add cluster, %v\n", err) os.Exit(1) }