Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix : when the HealthCheck ScheduledThreadPoolExecutor error , the job will be shutdown #1545

Closed
wants to merge 8 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class HealthCheckManager {
private final CpuHealthChecker cpuHealthChecker;
private final MemoryHealthChecker memoryHealthChecker;
private long lastUpdateTimestamp;
private static final long MILLISECONDS_IN_SECOND = 1000L;

public HealthCheckManager(@Lazy Node node, TurmsPropertiesManager propertiesManager) {
this.node = node;
Expand All @@ -70,26 +71,34 @@ public boolean isHealthy() {
}

private void startHealthCheck(int intervalSeconds) {
long intervalMillis = intervalSeconds * 1000L;
long intervalMillis = intervalSeconds * MILLISECONDS_IN_SECOND;
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());


this.checkAndUpdateTimestamp(System.currentTimeMillis(), intervalMillis);
}catch (Exception e){
LOGGER.error("Failed to update health status", e);
}
}, 0, intervalSeconds, TimeUnit.SECONDS);
}

private void checkAndUpdateTimestamp(long now, long intervalMillis) {
long previousUpdateTimestamp = lastUpdateTimestamp + intervalMillis;
lastUpdateTimestamp = now;
if (previousUpdateTimestamp > now) {
long timeDrift = previousUpdateTimestamp - now;
if (timeDrift > MILLISECONDS_IN_SECOND) { // 增加条件以减少不必要的日志
LOGGER.warn("The system time goes backwards. The time drift is ({}) millis", timeDrift);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ public class SimultaneousLoginProperties {
@GlobalProperty
@MutableProperty
private SimultaneousLoginStrategy strategy =
SimultaneousLoginStrategy.ALLOW_ONE_DEVICE_OF_EACH_DEVICE_TYPE_ONLINE;
SimultaneousLoginStrategy.ALLOW_ONE_DEVICE_FOR_ALL_DEVICE_TYPES_ONLINE;

@Description("The login conflict strategy is used for servers to know how to behave "
+ "if a device is logging in when there are conflicted and logged-in devices")
@GlobalProperty
@MutableProperty
private LoginConflictStrategy loginConflictStrategy =
LoginConflictStrategy.DISCONNECT_LOGGED_IN_DEVICES;
LoginConflictStrategy.DISCONNECT_LOGGING_IN_DEVICE;

@Description("Whether to allow the devices of DeviceType.UNKNOWN to login")
@GlobalProperty
Expand Down
Loading