From b9632e7cebbaf5d76882890d55e8653f9b30d2e0 Mon Sep 17 00:00:00 2001 From: Yu Yang Date: Tue, 20 Aug 2024 14:17:59 +0800 Subject: [PATCH] don't call GetNode in checkNodeStatus (#644) --- engine/factory/factory.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/engine/factory/factory.go b/engine/factory/factory.go index d2fb1a40..8bda0b1c 100644 --- a/engine/factory/factory.go +++ b/engine/factory/factory.go @@ -151,13 +151,14 @@ func (e *EngineCache) checkNodeStatus(ctx context.Context) { ch := e.stor.NodeStatusStream(ctx) for ns := range ch { - // GetNode will call GetEngine, so GetNode updates the engine cache automatically - if _, err := e.stor.GetNode(ctx, ns.Nodename); err != nil { - if errors.Is(err, types.ErrInvaildCount) { - logger.Infof(ctx, "remove metrics for invalid node %s", ns.Nodename) - metrics.Client.RemoveInvalidNodes(ns.Nodename) - } - logger.Warnf(ctx, "failed to get node %s: %s", ns.Nodename, err) + // don't need to add new entry to engine cache for alive node here, + // because NodeStatusStream calls GetNode, and GetNode will call GetEngine, + // so NodeStatusStream will update the engine cache for alive node automatically. + if errors.Is(ns.Error, types.ErrInvaildCount) { + // ns.Error is the error returned by GetNode which is called by NodeStatusStream + // so here is a good place to update metrics cache + logger.Infof(ctx, "remove metrics for invalid node %s", ns.Nodename) + metrics.Client.RemoveInvalidNodes(ns.Nodename) } if !ns.Alive {