From 497c9420668e2a94f341f0c1d360d01058f99393 Mon Sep 17 00:00:00 2001 From: JmPotato Date: Tue, 22 Aug 2023 14:02:04 +0800 Subject: [PATCH] mcs/tso: add log to show the progress of group cleaning up (#6971) ref tikv/pd#6589 Add log to show the progress of group cleaning up. Signed-off-by: JmPotato --- pkg/tso/keyspace_group_manager.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pkg/tso/keyspace_group_manager.go b/pkg/tso/keyspace_group_manager.go index b4f513eaa60..9ba3afb2a1f 100644 --- a/pkg/tso/keyspace_group_manager.go +++ b/pkg/tso/keyspace_group_manager.go @@ -137,6 +137,13 @@ func (s *state) getDeletedGroups() []uint32 { return groups } +// getDeletedGroupNum returns the number of the deleted keyspace groups. +func (s *state) getDeletedGroupNum() int { + s.RLock() + defer s.RUnlock() + return len(s.deletedGroups) +} + func (s *state) checkTSOSplit( targetGroupID uint32, ) (splitTargetAM, splitSourceAM *AllocatorManager, err error) { @@ -1391,6 +1398,11 @@ func (kgm *KeyspaceGroupManager) deletedGroupCleaner() { defer ticker.Stop() log.Info("deleted group cleaner is started", zap.Duration("patrol-interval", patrolInterval)) + var ( + empty = true + lastDeletedGroupID uint32 + lastDeletedGroupNum int + ) for { select { case <-kgm.ctx.Done(): @@ -1403,6 +1415,7 @@ func (kgm *KeyspaceGroupManager) deletedGroupCleaner() { if groupID == mcsutils.DefaultKeyspaceGroupID { continue } + empty = false // Make sure the allocator and group meta are not in use anymore. am, _ := kgm.getKeyspaceGroupMeta(groupID) if am != nil { @@ -1428,6 +1441,18 @@ func (kgm *KeyspaceGroupManager) deletedGroupCleaner() { kgm.Lock() delete(kgm.deletedGroups, groupID) kgm.Unlock() + lastDeletedGroupID = groupID + lastDeletedGroupNum += 1 + } + // This log would be helpful to check if the deleted groups are all gone. + if !empty && kgm.getDeletedGroupNum() == 0 { + log.Info("all the deleted keyspace groups have been cleaned up", + zap.Uint32("last-deleted-group-id", lastDeletedGroupID), + zap.Int("last-deleted-group-num", lastDeletedGroupNum)) + // Reset the state to make sure the log won't be printed again + // until we have new deleted groups. + empty = true + lastDeletedGroupNum = 0 } } }