Skip to content

Commit

Permalink
Use time ticker
Browse files Browse the repository at this point in the history
Signed-off-by: JmPotato <ghzpotato@gmail.com>
  • Loading branch information
JmPotato committed Jul 7, 2023
1 parent 90f2e8b commit 31a1f03
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/keyspace/tso_keyspace_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,7 @@ func (m *GroupManager) MergeAllIntoDefaultKeyspaceGroup() error {
}
// Wait for the merge to finish.
ctx, cancel := context.WithTimeout(m.ctx, time.Minute)
ticker := time.NewTicker(time.Second)
checkLoop:
for {
select {
Expand All @@ -1060,8 +1061,9 @@ func (m *GroupManager) MergeAllIntoDefaultKeyspaceGroup() error {
zap.Int("batch-size", len(groupsToMerge)),
zap.Int("merged-group-num", mergedGroupNum))
cancel()
ticker.Stop()
return nil
case <-time.After(time.Second):
case <-ticker.C:
kg, err := m.GetKeyspaceGroupByID(utils.DefaultKeyspaceGroupID)
if err != nil {
log.Error("failed to check the default keyspace group merge state",
Expand All @@ -1070,6 +1072,7 @@ func (m *GroupManager) MergeAllIntoDefaultKeyspaceGroup() error {
zap.Int("merged-group-num", mergedGroupNum),
zap.Error(err))
cancel()
ticker.Stop()
return err
}
if !kg.IsMergeTarget() {
Expand All @@ -1078,6 +1081,7 @@ func (m *GroupManager) MergeAllIntoDefaultKeyspaceGroup() error {
}
}
cancel()
ticker.Stop()
mergedGroupNum += len(groupsToMerge)
groupsToMerge = groupsToMerge[:0]
}
Expand Down

0 comments on commit 31a1f03

Please sign in to comment.