Skip to content

Commit

Permalink
Merge pull request MyCATApache#28 from Gao-Zhiwen/dev_cluster
Browse files Browse the repository at this point in the history
bugfix:3节点下第三个节点加入集群时空指针异常
  • Loading branch information
apachemycat authored Aug 23, 2017
2 parents d960b1d + ba9ba96 commit 68cfc33
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void onSocketRead(final AdminSession session) throws IOException {
session.curAdminCommand.handlerPkg(session, pkgType);
}
// 下一个报文解析
// session.readingBuffer.readIndex = session.curAdminPkgInf.startPos+session.curAdminPkgInf.length;
session.readingBuffer.readIndex = session.curAdminPkgInf.startPos+session.curAdminPkgInf.length;
}

// session.readingBuffer.writeIndex = bufferLimit;
Expand Down
4 changes: 4 additions & 0 deletions source/src/main/java/io/mycat/proxy/man/MyCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ public ClusterNode getMyNode() {
return myNode;
}

public void setMyLeader(ClusterNode myLeader) {
this.myLeader = myLeader;
}

public ClusterState getClusterState() {
return clusterState;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public void handlerPkg(AdminSession session, byte cmdType) throws IOException {
if (respPacket.getJoinState() == JoinCLusterNotifyPacket.JOIN_STATE_DENNIED) {
logger.warn("Leader denied my join cluster request ");
} else if (respPacket.getJoinState() == JoinCLusterNotifyPacket.JOIN_STATE_NEED_ACK) {
ClusterNode node = session.cluster().findNode(session.getNodeId());
session.cluster().setMyLeader(node);
session.cluster().setClusterState(ClusterState.Clustered);
JoinCLusterAckPacket ackPacket = new JoinCLusterAckPacket(session.cluster().getMyAliveNodes());
session.answerClientNow(ackPacket);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ public void handlerPkg(AdminSession session,byte cmdType) throws IOException {
NodeRegInfoPacket pkg = new NodeRegInfoPacket();
pkg.resolve(session.readingBuffer);
session.setNodeId(pkg.getNodeId());
session.cluster().onClusterNodeUp(pkg,session);
if (!pkg.isAnswer()) {// 连接到对端后收到对端发送的注册信息,此时应答自己的注册状态
pkg = new NodeRegInfoPacket(session.cluster().getMyNodeId(), session.cluster().getClusterState(),
session.cluster().getLastClusterStateTime(), session.cluster().getMyLeaderId(),
ProxyRuntime.INSTANCE.getStartTime());
pkg.setAnswer(true);
session.answerClientNow(pkg);
return;
}
session.cluster().onClusterNodeUp(pkg,session);
}

}
7 changes: 7 additions & 0 deletions source/src/main/resources/mycat3.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
bindip=0.0.0.0
bindport=8069
cluster.enabled=true
cluster.ip=127.0.0.1
cluster.port=9069
cluster.myid=leader-3
cluster.allnodes=leader-1:127.0.0.1:9066,leader-2:127.0.0.1:9068,leader-3:127.0.0.1:9069

0 comments on commit 68cfc33

Please sign in to comment.