|
|
@@ -27,18 +27,16 @@ public class ClusterMasterHandler extends ChannelInboundHandlerAdapter {
|
|
|
ClusterMessage clusterMsg = (ClusterMessage) msg;
|
|
|
ClusterNode cluster = ctx.channel().attr(AbstractClusterConfig.CLUSTER_ATTRIBUTE_KEY).get();
|
|
|
if (cluster == null) {
|
|
|
- log.error("ClusterNodeId: {}, ClusterMasterHandler.channelRead: [{}], [FROM: clusterId: {}, master: {}, serverTime: {}], Not Found Channel Cluster Object. Will be closed.",
|
|
|
- this.clusterNode.getId(), ClusterUtils.getTcpAddress(ctx.channel()),
|
|
|
- clusterMsg.getClusterId(), clusterMsg.isMaster(), clusterMsg.getCurrentTimeMillis());
|
|
|
+ log.error("ClusterNodeId: {}, ClusterMasterHandler.channelRead: [FROM: clusterId: {}, master: {}, serverTime: {}], Not Found Channel Cluster Object. Will be closed.",
|
|
|
+ this.clusterConfig.getId(), clusterMsg.getClusterId(), clusterMsg.isMaster(), clusterMsg.getCurrentTimeMillis());
|
|
|
|
|
|
- closeChannel(this.clusterNode, ctx.channel());
|
|
|
+ closeChannel(this.clusterNode, null, ctx.channel());
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (this.clusterConfig.isLogging()) {
|
|
|
- log.info("ClusterNodeId: {}, ClusterMasterHandler.channelRead: [{}], [FROM: clusterId: {}, master: {}, serverTime: {}]",
|
|
|
- this.clusterNode.getId(), ClusterUtils.getTcpAddress(ctx.channel()),
|
|
|
- clusterMsg.getClusterId(), clusterMsg.isMaster(), clusterMsg.getCurrentTimeMillis());
|
|
|
+ log.info("ClusterNodeId: {}, ClusterMasterHandler.channelRead: fromClusterId: {}, master: {}, serverTime: {}]",
|
|
|
+ this.clusterConfig.getId(), clusterMsg.getClusterId(), clusterMsg.isMaster(), clusterMsg.getCurrentTimeMillis());
|
|
|
}
|
|
|
|
|
|
cluster.getElectionState().setLastRecvTime();
|
|
|
@@ -54,11 +52,13 @@ public class ClusterMasterHandler extends ChannelInboundHandlerAdapter {
|
|
|
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
|
|
ClusterNode cluster = ctx.channel().attr(AbstractClusterConfig.CLUSTER_ATTRIBUTE_KEY).get();
|
|
|
if (cluster == null) {
|
|
|
- log.error("ClusterNodeId: {}, ClusterMasterHandler.channelInactive: Unknown Cluster: {}.", this.clusterNode.getId(), ClusterUtils.getAddress(ctx.channel()));
|
|
|
+ log.error("ClusterNodeId: {}, ClusterMasterHandler.channelInactive: Unknown Cluster: [{}].",
|
|
|
+ this.clusterConfig.getId(), ClusterUtils.getAddress(ctx.channel()));
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- log.info("ClusterNodeId: {}, ClusterMasterHandler.channelInactive: fromClusterId: {}, [{}].", this.clusterNode.getId(), cluster.getId(), cluster.getIp());
|
|
|
+ log.warn("ClusterNodeId: {}, ClusterMasterHandler.channelInactive: fromClusterId: {}, [{}].",
|
|
|
+ this.clusterConfig.getId(), cluster.getId(), cluster.getIp());
|
|
|
|
|
|
cluster.getElectionState().disConnect();
|
|
|
|
|
|
@@ -66,7 +66,7 @@ public class ClusterMasterHandler extends ChannelInboundHandlerAdapter {
|
|
|
ctx.fireChannelInactive();
|
|
|
|
|
|
// 클러스터가 연결 종료되었음을 추상함수를 호출해서 알리도록함.
|
|
|
- this.masterService.onNotifyClusterNetworkState(cluster, true);
|
|
|
+ this.masterService.onNotifyClusterNetworkState(cluster, false);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -74,31 +74,38 @@ public class ClusterMasterHandler extends ChannelInboundHandlerAdapter {
|
|
|
if (e instanceof IdleStateEvent) {
|
|
|
ClusterNode cluster = ctx.channel().attr(AbstractClusterConfig.CLUSTER_ATTRIBUTE_KEY).get();
|
|
|
if (cluster == null) {
|
|
|
- log.error("ClusterNodeId: {}, ClusterMasterHandler.userEventTriggered: Unknown Cluster: {}.", this.clusterNode.getId(), ClusterUtils.getAddress(ctx.channel()));
|
|
|
+ log.error("ClusterNodeId: {}, ClusterMasterHandler.userEventTriggered: Unknown Cluster: [{}].",
|
|
|
+ this.clusterConfig.getId(), ClusterUtils.getAddress(ctx.channel()));
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
IdleStateEvent evt = (IdleStateEvent) e;
|
|
|
-
|
|
|
- if (this.clusterConfig.isLogging()) {
|
|
|
- log.info("ClusterNodeId: {}, ClusterMasterHandler.userEventTriggered: {}. {}", this.clusterNode.getId(), ClusterUtils.getAddress(ctx.channel()), evt);
|
|
|
- }
|
|
|
-
|
|
|
if (evt.state() == IdleState.READER_IDLE) {
|
|
|
+ log.info("ClusterNodeId: {}, ClusterMasterHandler.userEventTriggered: fromClusterNodeId: {}.",
|
|
|
+ this.clusterConfig.getId(), cluster.getId());
|
|
|
+
|
|
|
long recvTimeout = System.currentTimeMillis() - cluster.getElectionState().getLastRecvTime();
|
|
|
long heartbeatTimeout = this.clusterConfig.getSyncSeconds() * 1000L * 3;
|
|
|
if (recvTimeout > heartbeatTimeout) {
|
|
|
- log.warn("ClusterNodeId: {}, ClusterMasterHandler.userEventTriggered: {}. [{}, {}]. Heartbeat timeout, {}, {} ms. Will be closed.",
|
|
|
- this.clusterNode.getId(), ClusterUtils.getAddress(ctx.channel()), cluster.getLogKey(), cluster.getIp(), recvTimeout, heartbeatTimeout);
|
|
|
+ log.warn("ClusterNodeId: {}, ClusterMasterHandler.userEventTriggered: fromClusterNodeId: {} [{}], Heartbeat timeout, {}/{} ms. Will be closed.",
|
|
|
+ this.clusterConfig.getId(), cluster.getId(), cluster.getIp(), recvTimeout, heartbeatTimeout);
|
|
|
|
|
|
- closeChannel(this.clusterNode, ctx.channel());
|
|
|
+ closeChannel(this.clusterNode, cluster, ctx.channel());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
ctx.fireUserEventTriggered(e);
|
|
|
}
|
|
|
|
|
|
- public static void closeChannel(ClusterNode clusterNode, Channel channel) {
|
|
|
+ public static void closeChannel(ClusterNode clusterNode, ClusterNode fromClusterNode, Channel channel) {
|
|
|
+ if (fromClusterNode == null) {
|
|
|
+ log.warn("ClusterNodeId: {}, ClusterMasterHandler.closeChannel: Unknown Cluster: [{}].",
|
|
|
+ clusterNode.getId(), ClusterUtils.getAddress(channel));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ log.warn("ClusterNodeId: {}, ClusterMasterHandler.closeChannel: fromClusterNodeId: {} [{}].",
|
|
|
+ clusterNode.getId(), fromClusterNode.getId(), fromClusterNode.getIp());
|
|
|
+ }
|
|
|
try {
|
|
|
if (channel != null) {
|
|
|
channel.flush();
|