Skip to content

Commit

Permalink
fix : when the HealthCheck ScheduledThreadPoolExecutor error , the jo…
Browse files Browse the repository at this point in the history
…b will be shutdown
  • Loading branch information
zhaieryuan committed Aug 8, 2024
1 parent cf8f572 commit d89ba4e
Showing 1 changed file with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,24 @@ private void startHealthCheck(int intervalSeconds) {
DefaultThreadFactory threadFactory =
new DefaultThreadFactory(ThreadNameConst.HEALTH_CHECKER, true);
new ScheduledThreadPoolExecutor(1, threadFactory).scheduleWithFixedDelay(() -> {
cpuHealthChecker.updateHealthStatus();
memoryHealthChecker.updateHealthStatus();
node.getDiscoveryService()
.getLocalNodeStatusManager()
.updateHealthStatus(isHealthy());
long now = System.currentTimeMillis();
long previousUpdateTimestamp = lastUpdateTimestamp + intervalMillis;
lastUpdateTimestamp = now;
if (previousUpdateTimestamp > now) {
// There are a lof of modules heavily depending on the system time, e.g. logging,
// snowflake ID.
// So we log a warning message for troubleshooting if the time goes backwards.
LOGGER.warn("The system time goes backwards. The time drift is ({}) millis",
previousUpdateTimestamp - now);
try{
cpuHealthChecker.updateHealthStatus();
memoryHealthChecker.updateHealthStatus();
node.getDiscoveryService()
.getLocalNodeStatusManager()
.updateHealthStatus(isHealthy());
long now = System.currentTimeMillis();
long previousUpdateTimestamp = lastUpdateTimestamp + intervalMillis;
lastUpdateTimestamp = now;
if (previousUpdateTimestamp > now) {
// There are a lof of modules heavily depending on the system time, e.g. logging,
// snowflake ID.
// So we log a warning message for troubleshooting if the time goes backwards.
LOGGER.warn("The system time goes backwards. The time drift is ({}) millis",
previousUpdateTimestamp - now);
}
}catch (Exception e){
LOGGER.error("Failed to update the health status", e);
}
}, 0, intervalSeconds, TimeUnit.SECONDS);
}
Expand Down

0 comments on commit d89ba4e

Please sign in to comment.