From 702b1cb8762283b000c8ff782c7dc658bd223b55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A3=D1=81=D1=82=D1=8E=D0=B6=D0=B0=D0=BD=D0=B8=D0=BD=20?= =?UTF-8?q?=D0=90=D0=BD=D1=82=D0=BE=D0=BD=20=D0=90=D0=BB=D0=B5=D0=BA=D1=81?= =?UTF-8?q?=D0=B0=D0=BD=D0=B4=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Sun, 4 Oct 2020 21:56:17 +0500 Subject: [PATCH] fix: remove deleted peers if resumeState = true --- weed/server/raft_server.go | 17 +++++++++++++++++ weed/server/raft_server_handlers.go | 14 +++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/weed/server/raft_server.go b/weed/server/raft_server.go index 7045437e8..66a6734e3 100644 --- a/weed/server/raft_server.go +++ b/weed/server/raft_server.go @@ -104,7 +104,24 @@ func NewRaftServer(grpcDialOption grpc.DialOption, peers []string, serverAddr, d if err := s.raftServer.AddPeer(peer, pb.ServerToGrpcAddress(peer)); err != nil { return nil, err } + } + // Remove deleted peers + if raftResumeState { + for existsPeerName, _ := range s.raftServer.Peers() { + exists := false + for _, peer := range s.peers { + if peer == existsPeerName { + exists = true + } + } + if !exists { + if err := s.raftServer.RemovePeer(existsPeerName); err != nil { + glog.V(0).Infoln(err) + return nil, err + } + } + } } s.GrpcServer = raft.NewGrpcServer(s.raftServer) diff --git a/weed/server/raft_server_handlers.go b/weed/server/raft_server_handlers.go index fd38cb977..252570eab 100644 --- a/weed/server/raft_server_handlers.go +++ b/weed/server/raft_server_handlers.go @@ -1,20 +1,24 @@ package weed_server import ( + "github.com/chrislusf/seaweedfs/weed/storage/needle" "net/http" ) type ClusterStatusResult struct { - IsLeader bool `json:"IsLeader,omitempty"` - Leader string `json:"Leader,omitempty"` - Peers []string `json:"Peers,omitempty"` + IsLeader bool `json:"IsLeader,omitempty"` + Leader string `json:"Leader,omitempty"` + Peers []string `json:"Peers,omitempty"` + MaxVolumeId needle.VolumeId `json:"MaxVolumeId,omitempty"` } func (s *RaftServer) StatusHandler(w http.ResponseWriter, r *http.Request) { ret := ClusterStatusResult{ - IsLeader: s.topo.IsLeader(), - Peers: s.Peers(), + IsLeader: s.topo.IsLeader(), + Peers: s.Peers(), + MaxVolumeId: s.topo.GetMaxVolumeId(), } + if leader, e := s.topo.Leader(); e == nil { ret.Leader = leader }