Skip to content

Commit

Permalink
support wg run
Browse files Browse the repository at this point in the history
  • Loading branch information
Yisaer committed Jan 18, 2023
1 parent 360249b commit 9685d30
Showing 1 changed file with 17 additions and 32 deletions.
49 changes: 17 additions & 32 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1341,10 +1341,8 @@ func (do *Domain) LoadPrivilegeLoop(sctx sessionctx.Context) error {
duration = 10 * time.Minute
}

do.wg.Add(1)
go func() {
do.wg.Run(func() {
defer func() {
do.wg.Done()
logutil.BgLogger().Info("loadPrivilegeInLoop exited.")
util.Recover(metrics.LabelDomain, "loadPrivilegeInLoop", nil, false)
}()
Expand Down Expand Up @@ -1374,7 +1372,7 @@ func (do *Domain) LoadPrivilegeLoop(sctx sessionctx.Context) error {
logutil.BgLogger().Error("load privilege failed", zap.Error(err))
}
}
}()
}, "loadPrivilegeInLoop")
return nil
}

Expand All @@ -1391,10 +1389,9 @@ func (do *Domain) LoadSysVarCacheLoop(ctx sessionctx.Context) error {
if do.etcdClient != nil {
watchCh = do.etcdClient.Watch(context.Background(), sysVarCacheKey)
}
do.wg.Add(1)
go func() {

do.wg.Run(func() {
defer func() {
do.wg.Done()
logutil.BgLogger().Info("LoadSysVarCacheLoop exited.")
util.Recover(metrics.LabelDomain, "LoadSysVarCacheLoop", nil, false)
}()
Expand Down Expand Up @@ -1437,7 +1434,7 @@ func (do *Domain) LoadSysVarCacheLoop(ctx sessionctx.Context) error {
logutil.BgLogger().Error("LoadSysVarCacheLoop failed", zap.Error(err))
}
}
}()
}, "LoadSysVarCacheLoop")
return nil
}

Expand All @@ -1450,11 +1447,9 @@ func (do *Domain) WatchTiFlashComputeNodeChange() error {
if do.etcdClient != nil {
watchCh = do.etcdClient.Watch(context.Background(), tiflashComputeNodeKey)
}
do.wg.Add(1)
duration := 10 * time.Second
go func() {
do.wg.Run(func() {
defer func() {
do.wg.Done()
logutil.BgLogger().Info("WatchTiFlashComputeNodeChange exit")
util.Recover(metrics.LabelDomain, "WatchTiFlashComputeNodeChange", nil, false)
}()
Expand Down Expand Up @@ -1495,7 +1490,7 @@ func (do *Domain) WatchTiFlashComputeNodeChange() error {
return
}
}
}()
}, "WatchTiFlashComputeNodeChange")
return nil
}

Expand Down Expand Up @@ -1530,10 +1525,8 @@ func (do *Domain) LoadBindInfoLoop(ctxForHandle sessionctx.Context, ctxForEvolve
}

func (do *Domain) globalBindHandleWorkerLoop(owner owner.Manager) {
do.wg.Add(1)
go func() {
do.wg.Run(func() {
defer func() {
do.wg.Done()
logutil.BgLogger().Info("globalBindHandleWorkerLoop exited.")
util.Recover(metrics.LabelDomain, "globalBindHandleWorkerLoop", nil, false)
}()
Expand Down Expand Up @@ -1570,14 +1563,12 @@ func (do *Domain) globalBindHandleWorkerLoop(owner owner.Manager) {
}
}
}
}()
}, "globalBindHandleWorkerLoop")
}

func (do *Domain) handleEvolvePlanTasksLoop(ctx sessionctx.Context, owner owner.Manager) {
do.wg.Add(1)
go func() {
do.wg.Run(func() {
defer func() {
do.wg.Done()
logutil.BgLogger().Info("handleEvolvePlanTasksLoop exited.")
util.Recover(metrics.LabelDomain, "handleEvolvePlanTasksLoop", nil, false)
}()
Expand All @@ -1595,7 +1586,7 @@ func (do *Domain) handleEvolvePlanTasksLoop(ctx sessionctx.Context, owner owner.
}
}
}
}()
}, "handleEvolvePlanTasksLoop")
}

// TelemetryReportLoop create a goroutine that reports usage data in a loop, it should be called only once
Expand All @@ -1607,10 +1598,8 @@ func (do *Domain) TelemetryReportLoop(ctx sessionctx.Context) {
logutil.BgLogger().Warn("Initial telemetry run failed", zap.Error(err))
}

do.wg.Add(1)
go func() {
do.wg.Run(func() {
defer func() {
do.wg.Done()
logutil.BgLogger().Info("TelemetryReportLoop exited.")
util.Recover(metrics.LabelDomain, "TelemetryReportLoop", nil, false)
}()
Expand All @@ -1631,16 +1620,14 @@ func (do *Domain) TelemetryReportLoop(ctx sessionctx.Context) {
}
}
}
}()
}, "TelemetryReportLoop")
}

// TelemetryRotateSubWindowLoop create a goroutine that rotates the telemetry window regularly.
func (do *Domain) TelemetryRotateSubWindowLoop(ctx sessionctx.Context) {
ctx.GetSessionVars().InRestrictedSQL = true
do.wg.Add(1)
go func() {
do.wg.Run(func() {
defer func() {
do.wg.Done()
logutil.BgLogger().Info("TelemetryRotateSubWindowLoop exited.")
util.Recover(metrics.LabelDomain, "TelemetryRotateSubWindowLoop", nil, false)
}()
Expand All @@ -1652,7 +1639,7 @@ func (do *Domain) TelemetryRotateSubWindowLoop(ctx sessionctx.Context) {
telemetry.RotateSubWindow()
}
}
}()
}, "TelemetryRotateSubWindowLoop")
}

// SetupPlanReplayerHandle setup plan replayer handle
Expand Down Expand Up @@ -2249,10 +2236,8 @@ func (do *Domain) LoadSigningCertLoop(signingCert, signingKey string) {
sessionstates.SetCertPath(signingCert)
sessionstates.SetKeyPath(signingKey)

do.wg.Add(1)
go func() {
do.wg.Run(func() {
defer func() {
do.wg.Done()
logutil.BgLogger().Debug("loadSigningCertLoop exited.")
util.Recover(metrics.LabelDomain, "LoadSigningCertLoop", nil, false)
}()
Expand All @@ -2264,7 +2249,7 @@ func (do *Domain) LoadSigningCertLoop(signingCert, signingKey string) {
return
}
}
}()
}, "loadSigningCertLoop")
}

// ServerID gets serverID.
Expand Down

0 comments on commit 9685d30

Please sign in to comment.