From 85d73358ccec1f20fe4bb558482c59c6bc4f28ea Mon Sep 17 00:00:00 2001 From: congqixia Date: Mon, 13 Sep 2021 16:50:57 +0800 Subject: [PATCH] Remove ctx from LongTermChecker (#7792) Signed-off-by: Congqi Xia --- internal/datacoord/server.go | 1 + internal/datacoord/util.go | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/internal/datacoord/server.go b/internal/datacoord/server.go index 40d1909ecb..473d5920c7 100644 --- a/internal/datacoord/server.go +++ b/internal/datacoord/server.go @@ -354,6 +354,7 @@ func (s *Server) startDataNodeTtLoop(ctx context.Context) { if enableTtChecker { checker = NewLongTermChecker(ctx, ttCheckerName, ttMaxInterval, ttCheckerWarnMsg) checker.Start() + defer checker.Stop() } for { select { diff --git a/internal/datacoord/util.go b/internal/datacoord/util.go index 2afaf6d771..a7b5bb9d4c 100644 --- a/internal/datacoord/util.go +++ b/internal/datacoord/util.go @@ -64,7 +64,7 @@ func VerifyResponse(response interface{}, err error) error { type LongTermChecker struct { d time.Duration t *time.Ticker - ctx context.Context + ch chan struct{} warn string name string } @@ -73,9 +73,9 @@ type LongTermChecker struct { func NewLongTermChecker(ctx context.Context, name string, d time.Duration, warn string) *LongTermChecker { c := &LongTermChecker{ name: name, - ctx: ctx, d: d, warn: warn, + ch: make(chan struct{}), } return c } @@ -86,7 +86,7 @@ func (c *LongTermChecker) Start() { go func() { for { select { - case <-c.ctx.Done(): + case <-c.ch: log.Warn(fmt.Sprintf("long term checker [%s] shutdown", c.name)) return case <-c.t.C: @@ -100,3 +100,9 @@ func (c *LongTermChecker) Start() { func (c *LongTermChecker) Check() { c.t.Reset(c.d) } + +// Stop stop the checker +func (c *LongTermChecker) Stop() { + c.t.Stop() + close(c.ch) +}