From 07f38a47638068805cff07af524d269fc4e73ac9 Mon Sep 17 00:00:00 2001 From: Pixy Yuan Date: Thu, 3 Jun 2021 09:35:01 +0800 Subject: [PATCH] [ISSUE #5927] Init health check status when loading snapshot of persistent instances. (#5928) --- .../core/v2/client/impl/IpPortBasedClient.java | 16 +++++++++------- .../naming/healthcheck/v2/HealthCheckTaskV2.java | 4 ++-- .../v2/processor/TcpHealthCheckProcessor.java | 4 ++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/v2/client/impl/IpPortBasedClient.java b/naming/src/main/java/com/alibaba/nacos/naming/core/v2/client/impl/IpPortBasedClient.java index fea723337..0bb73f264 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/v2/client/impl/IpPortBasedClient.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/v2/client/impl/IpPortBasedClient.java @@ -112,15 +112,17 @@ public class IpPortBasedClient extends AbstractClient { } private HealthCheckInstancePublishInfo parseToHealthCheckInstance(InstancePublishInfo instancePublishInfo) { + HealthCheckInstancePublishInfo result; if (instancePublishInfo instanceof HealthCheckInstancePublishInfo) { - return (HealthCheckInstancePublishInfo) instancePublishInfo; + result = (HealthCheckInstancePublishInfo) instancePublishInfo; + } else { + result = new HealthCheckInstancePublishInfo(); + result.setIp(instancePublishInfo.getIp()); + result.setPort(instancePublishInfo.getPort()); + result.setHealthy(instancePublishInfo.isHealthy()); + result.setCluster(instancePublishInfo.getCluster()); + result.setExtendDatum(instancePublishInfo.getExtendDatum()); } - HealthCheckInstancePublishInfo result = new HealthCheckInstancePublishInfo(); - result.setIp(instancePublishInfo.getIp()); - result.setPort(instancePublishInfo.getPort()); - result.setHealthy(instancePublishInfo.isHealthy()); - result.setCluster(instancePublishInfo.getCluster()); - result.setExtendDatum(instancePublishInfo.getExtendDatum()); if (!ephemeral) { result.initHealthCheck(); } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/v2/HealthCheckTaskV2.java b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/v2/HealthCheckTaskV2.java index 698ac3e96..a43251789 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/v2/HealthCheckTaskV2.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/v2/HealthCheckTaskV2.java @@ -98,12 +98,12 @@ public class HealthCheckTaskV2 extends AbstractExecuteTask implements NacosHealt ClusterMetadata metadata = getClusterMetadata(each, instancePublishInfo); ApplicationUtils.getBean(HealthCheckProcessorV2Delegate.class).process(this, each, metadata); if (Loggers.EVT_LOG.isDebugEnabled()) { - Loggers.EVT_LOG.debug("[HEALTH-CHECK] schedule health check task: {}", client.getClientId()); + Loggers.EVT_LOG.debug("[HEALTH-CHECK-V2] schedule health check task: {}", client.getClientId()); } } } } catch (Throwable e) { - Loggers.SRV_LOG.error("[HEALTH-CHECK] error while process health check for {}", client.getClientId(), e); + Loggers.SRV_LOG.error("[HEALTH-CHECK-V2] error while process health check for {}", client.getClientId(), e); } finally { if (!cancelled) { HealthCheckReactor.scheduleCheck(this); diff --git a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/v2/processor/TcpHealthCheckProcessor.java b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/v2/processor/TcpHealthCheckProcessor.java index e12f09ce9..36e39b083 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/v2/processor/TcpHealthCheckProcessor.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/v2/processor/TcpHealthCheckProcessor.java @@ -101,7 +101,7 @@ public class TcpHealthCheckProcessor implements HealthCheckProcessorV2, Runnable } // TODO handle marked(white list) logic like v1.x. if (!instance.tryStartCheck()) { - SRV_LOG.warn("tcp check started before last one finished, service: {} : {} : {}:{}", + SRV_LOG.warn("[HEALTH-CHECK-V2] tcp check started before last one finished, service: {} : {} : {}:{}", service.getGroupedServiceName(), instance.getCluster(), instance.getIp(), instance.getPort()); healthCheckCommon .reEvaluateCheckRT(task.getCheckRtNormalized() * 2, task, switchDomain.getTcpHealthParams()); @@ -151,7 +151,7 @@ public class TcpHealthCheckProcessor implements HealthCheckProcessorV2, Runnable GlobalExecutor.executeTcpSuperSense(new PostProcessor(key)); } } catch (Throwable e) { - SRV_LOG.error("[HEALTH-CHECK] error while processing NIO task", e); + SRV_LOG.error("[HEALTH-CHECK-V2] error while processing NIO task", e); } } }