From 642a6e0820810cc3baf5f89c6863a27e32ad040e Mon Sep 17 00:00:00 2001 From: Benjamin Wang Date: Wed, 27 Sep 2023 17:53:22 +0100 Subject: [PATCH] Do not update RaftCluster.members and RaftCluster.removed if the v3store is ahead of the current replayed WAL entry index Signed-off-by: Benjamin Wang --- server/etcdserver/api/membership/cluster.go | 81 +++++++++++++-------- 1 file changed, 50 insertions(+), 31 deletions(-) diff --git a/server/etcdserver/api/membership/cluster.go b/server/etcdserver/api/membership/cluster.go index fe657fb86900..57e3d2358385 100644 --- a/server/etcdserver/api/membership/cluster.go +++ b/server/etcdserver/api/membership/cluster.go @@ -395,19 +395,27 @@ func (c *RaftCluster) AddMember(m *Member, shouldApplyV3 ShouldApplyV3) { } if c.be != nil && shouldApplyV3 { c.be.MustSaveMemberToBackend(m) - } - c.members[m.ID] = m - c.updateMembershipMetric(m.ID, true) + c.members[m.ID] = m + c.updateMembershipMetric(m.ID, true) - c.lg.Info( - "added member", - zap.String("cluster-id", c.cid.String()), - zap.String("local-member-id", c.localID.String()), - zap.String("added-peer-id", m.ID.String()), - zap.Strings("added-peer-peer-urls", m.PeerURLs), - zap.Bool("added-peer-is-learner", m.IsLearner), - ) + c.lg.Info( + "added member", + zap.String("cluster-id", c.cid.String()), + zap.String("local-member-id", c.localID.String()), + zap.String("added-peer-id", m.ID.String()), + zap.Strings("added-peer-peer-urls", m.PeerURLs), + zap.Bool("added-peer-is-learner", m.IsLearner), + ) + } else { + c.lg.Info( + "ignore already added member", + zap.String("cluster-id", c.cid.String()), + zap.String("local-member-id", c.localID.String()), + zap.String("added-peer-id", m.ID.String()), + zap.Strings("added-peer-peer-urls", m.PeerURLs), + zap.Bool("added-peer-is-learner", m.IsLearner)) + } } // RemoveMember removes a member from the store. @@ -420,25 +428,32 @@ func (c *RaftCluster) RemoveMember(id types.ID, shouldApplyV3 ShouldApplyV3) { } if c.be != nil && shouldApplyV3 { c.be.MustDeleteMemberFromBackend(id) - } - m, ok := c.members[id] - delete(c.members, id) - c.removed[id] = true - c.updateMembershipMetric(id, false) - - if ok { - c.lg.Info( - "removed member", - zap.String("cluster-id", c.cid.String()), - zap.String("local-member-id", c.localID.String()), - zap.String("removed-remote-peer-id", id.String()), - zap.Strings("removed-remote-peer-urls", m.PeerURLs), - zap.Bool("removed-remote-peer-is-learner", m.IsLearner), - ) + m, ok := c.members[id] + delete(c.members, id) + c.removed[id] = true + c.updateMembershipMetric(id, false) + + if ok { + c.lg.Info( + "removed member", + zap.String("cluster-id", c.cid.String()), + zap.String("local-member-id", c.localID.String()), + zap.String("removed-remote-peer-id", id.String()), + zap.Strings("removed-remote-peer-urls", m.PeerURLs), + zap.Bool("removed-remote-peer-is-learner", m.IsLearner), + ) + } else { + c.lg.Warn( + "skipped removing already removed member", + zap.String("cluster-id", c.cid.String()), + zap.String("local-member-id", c.localID.String()), + zap.String("removed-remote-peer-id", id.String()), + ) + } } else { - c.lg.Warn( - "skipped removing already removed member", + c.lg.Info( + "ignore already removed member", zap.String("cluster-id", c.cid.String()), zap.String("local-member-id", c.localID.String()), zap.String("removed-remote-peer-id", id.String()), @@ -484,8 +499,10 @@ func (c *RaftCluster) PromoteMember(id types.ID, shouldApplyV3 ShouldApplyV3) { c.Lock() defer c.Unlock() - c.members[id].RaftAttributes.IsLearner = false - c.updateMembershipMetric(id, true) + if _, ok := c.members[id]; ok { + c.members[id].RaftAttributes.IsLearner = false + c.updateMembershipMetric(id, true) + } if c.v2store != nil { mustUpdateMemberInStore(c.lg, c.v2store, c.members[id]) } @@ -504,7 +521,9 @@ func (c *RaftCluster) UpdateRaftAttributes(id types.ID, raftAttr RaftAttributes, c.Lock() defer c.Unlock() - c.members[id].RaftAttributes = raftAttr + if _, ok := c.members[id]; ok { + c.members[id].RaftAttributes = raftAttr + } if c.v2store != nil { mustUpdateMemberInStore(c.lg, c.v2store, c.members[id]) }