From fac4102ab4864be4809e6da22a005fe21de76aa5 Mon Sep 17 00:00:00 2001 From: Geeta Gharpure Date: Tue, 25 Jul 2023 19:57:58 +0000 Subject: [PATCH] Update membership export logic Signed-off-by: Geeta Gharpure --- server/etcdserver/api/membership/cluster.go | 6 +++++- server/etcdserver/api/membership/storev2.go | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/server/etcdserver/api/membership/cluster.go b/server/etcdserver/api/membership/cluster.go index bd4213d7ab6b..c8f04c9dd016 100644 --- a/server/etcdserver/api/membership/cluster.go +++ b/server/etcdserver/api/membership/cluster.go @@ -858,6 +858,9 @@ func ValidateMaxLearnerConfig(maxLearners int, members []*Member, scaleUpLearner func (c *RaftCluster) Store(store v2store.Store) { c.Lock() defer c.Unlock() + + verifyNoMembersInStore(c.lg, store) + for _, m := range c.members { mustSaveMemberToStore(c.lg, store, m) if m.ClientURLs != nil { @@ -871,7 +874,8 @@ func (c *RaftCluster) Store(store v2store.Store) { ) } for id, _ := range c.removed { - mustDeleteMemberFromStore(c.lg, store, id) + //We do not need to delete the member since the store is empty. + mustAddToRemovedMembersInStore(c.lg, store, id) } if c.version != nil { mustSaveClusterVersionToStore(c.lg, store, c.version) diff --git a/server/etcdserver/api/membership/storev2.go b/server/etcdserver/api/membership/storev2.go index 9af5a8eb7e2c..faf38e2be7c7 100644 --- a/server/etcdserver/api/membership/storev2.go +++ b/server/etcdserver/api/membership/storev2.go @@ -78,6 +78,13 @@ func TrimMembershipFromV2Store(lg *zap.Logger, s v2store.Store) error { return nil } +func verifyNoMembersInStore(lg *zap.Logger, s v2store.Store) { + members, removed := membersFromStore(lg, s) + if len(members) != 0 || len(removed) != 0 { + lg.Panic("store has membership info") + } +} + func mustSaveMemberToStore(lg *zap.Logger, s v2store.Store, m *Member) { b, err := json.Marshal(m.RaftAttributes) if err != nil { @@ -94,13 +101,19 @@ func mustSaveMemberToStore(lg *zap.Logger, s v2store.Store, m *Member) { } func mustDeleteMemberFromStore(lg *zap.Logger, s v2store.Store, id types.ID) { - if _, err := s.Delete(MemberStoreKey(id), true, true); err != nil && !isKeyNotFound(err) { + if _, err := s.Delete(MemberStoreKey(id), true, true); err != nil { lg.Panic( "failed to delete member from store", zap.String("path", MemberStoreKey(id)), zap.Error(err), ) } + + mustAddToRemovedMembersInStore(lg, s, id) +} + +func mustAddToRemovedMembersInStore(lg *zap.Logger, s v2store.Store, id types.ID) { + if _, err := s.Create(RemovedMemberStoreKey(id), false, "", false, v2store.TTLOptionSet{ExpireTime: v2store.Permanent}); err != nil { lg.Panic( "failed to create removedMember",