Remove ctx from LongTermChecker (#7792)

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
pull/7808/head
congqixia 2021-09-13 16:50:57 +08:00 committed by GitHub
parent a9a01e1bc9
commit 85d73358cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -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 {

View File

@ -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)
}