From 93c912e681905ffde66205bfaec687d76448be2f Mon Sep 17 00:00:00 2001 From: "cai.zhang" Date: Fri, 24 Sep 2021 20:37:56 +0800 Subject: [PATCH] Start once for IndexNode (#8170) Signed-off-by: cai.zhang --- internal/indexnode/indexnode.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/internal/indexnode/indexnode.go b/internal/indexnode/indexnode.go index 0fda444b06..ac770ae2b2 100644 --- a/internal/indexnode/indexnode.go +++ b/internal/indexnode/indexnode.go @@ -62,6 +62,8 @@ type IndexNode struct { sched *TaskScheduler + once sync.Once + kv kv.BaseKV session *sessionutil.Session liveCh <-chan bool @@ -161,20 +163,25 @@ func (i *IndexNode) Init() error { } func (i *IndexNode) Start() error { - i.sched.Start() + var startErr error = nil + i.once.Do(func() { + startErr = i.sched.Start() - //start liveness check - go i.session.LivenessCheck(i.loopCtx, i.liveCh, func() { - i.Stop() + //start liveness check + go i.session.LivenessCheck(i.loopCtx, i.liveCh, func() { + i.Stop() + }) + + i.UpdateStateCode(internalpb.StateCode_Healthy) + log.Debug("IndexNode", zap.Any("State", i.stateCode.Load())) }) - - i.UpdateStateCode(internalpb.StateCode_Healthy) - log.Debug("IndexNode", zap.Any("State", i.stateCode.Load())) // Start callbacks for _, cb := range i.startCallbacks { cb() } - return nil + + log.Debug("IndexNode start finished", zap.Error(startErr)) + return startErr } // Stop Close closes the server.