Skip to content

Commit

Permalink
mcs/tso: add log to show the progress of group cleaning up (#6971)
Browse files Browse the repository at this point in the history
ref #6589

Add log to show the progress of group cleaning up.

Signed-off-by: JmPotato <[email protected]>
  • Loading branch information
JmPotato authored Aug 22, 2023
1 parent 346e771 commit 497c942
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pkg/tso/keyspace_group_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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():
Expand All @@ -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 {
Expand All @@ -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
}
}
}

0 comments on commit 497c942

Please sign in to comment.