fix heartbeat timeout inner 1371 (cherry pick) (#3369)

This commit is contained in:
ylinzhu
2022-08-19 09:47:32 +08:00
committed by GitHub
parent e047959014
commit 1625c339ff

View File

@@ -48,6 +48,8 @@ public abstract class PhysicalDbInstance {
private final LongAdder writeCount = new LongAdder();
private final AtomicBoolean isInitial = new AtomicBoolean(false);
private AtomicBoolean initHeartbeat = new AtomicBoolean(false);
// connection pool
private ConnectionPool connectionPool;
@@ -340,15 +342,19 @@ public abstract class PhysicalDbInstance {
}
heartbeat.start();
heartbeat.setScheduledFuture(Scheduler.getInstance().getScheduledExecutor().scheduleAtFixedRate(() -> {
if (DbleServer.getInstance().getConfig().isFullyConfigured()) {
if (TimeUtil.currentTimeMillis() < heartbeatRecoveryTime) {
return;
}
if (initHeartbeat.compareAndSet(false, true)) {
heartbeat.setScheduledFuture(Scheduler.getInstance().getScheduledExecutor().scheduleAtFixedRate(() -> {
if (DbleServer.getInstance().getConfig().isFullyConfigured()) {
if (TimeUtil.currentTimeMillis() < heartbeatRecoveryTime) {
return;
}
heartbeat.heartbeat();
}
}, 0L, config.getPoolConfig().getHeartbeatPeriodMillis(), MILLISECONDS));
heartbeat.heartbeat();
}
}, 0L, config.getPoolConfig().getHeartbeatPeriodMillis(), MILLISECONDS));
} else {
LOGGER.warn("init dbInstance[{}] heartbeat, but it has been initialized, skip initialization.", heartbeat.getSource().getName());
}
}
public void start(String reason) {
@@ -361,6 +367,9 @@ public abstract class PhysicalDbInstance {
public void stop(String reason, boolean closeFront) {
heartbeat.stop(reason);
if (!heartbeat.isStop()) {
initHeartbeat.set(false);
}
if (dbGroupConfig.getRwSplitMode() != RW_SPLIT_OFF || dbGroup.getWriteDbInstance() == this) {
LOGGER.info("stop connection pool of physical db instance[{}], due to {}", name, reason);
connectionPool.stop(reason, closeFront);