From 4ba7127ab1bf8fa045d623d0c6293a083f209ad7 Mon Sep 17 00:00:00 2001 From: chrislu Date: Sat, 26 Mar 2022 13:13:19 -0700 Subject: [PATCH] refactor --- weed/command/master.go | 7 ++++++- weed/server/raft_server.go | 8 ++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/weed/command/master.go b/weed/command/master.go index 9e45c5037..9792ce0ba 100644 --- a/weed/command/master.go +++ b/weed/command/master.go @@ -141,10 +141,15 @@ func startMaster(masterOption MasterOptions, masterWhiteList []string) { glog.Fatalf("Master startup error: %v", e) } + masterPeers := make(map[string]pb.ServerAddress) + for _, peer := range peers { + masterPeers[peer.String()] = peer + } + // start raftServer raftServerOption := &weed_server.RaftServerOption{ GrpcDialOption: security.LoadClientTLS(util.GetViper(), "grpc.master"), - Peers: peers, + Peers: masterPeers, ServerAddr: myMasterAddress, DataDir: util.ResolvePath(*masterOption.metaFolder), Topo: ms.Topo, diff --git a/weed/server/raft_server.go b/weed/server/raft_server.go index 5f27a3a0e..648e20505 100644 --- a/weed/server/raft_server.go +++ b/weed/server/raft_server.go @@ -19,7 +19,7 @@ import ( type RaftServerOption struct { GrpcDialOption grpc.DialOption - Peers []pb.ServerAddress + Peers map[string]pb.ServerAddress ServerAddr pb.ServerAddress DataDir string Topo *topology.Topology @@ -62,12 +62,8 @@ func (s StateMachine) Recovery(data []byte) error { } func NewRaftServer(option *RaftServerOption) (*RaftServer, error) { - peers := make(map[string]pb.ServerAddress) - for _, peer := range option.Peers { - peers[peer.String()] = peer - } s := &RaftServer{ - peers: peers, + peers: option.Peers, serverAddr: option.ServerAddr, dataDir: option.DataDir, topo: option.Topo,