mirror of
https://gitee.com/BDWare/agent-backend
synced 2025-01-10 09:54:11 +00:00
fix: fix bugs in MasterWSAction.startContractMultiPoint
fix bugs in MasterWSAction.startContractMultiPoint to avoid the node starting a multi-point contract in a cluster without itself
This commit is contained in:
parent
b3ef7bbe7d
commit
d6979118fc
@ -26,10 +26,7 @@ import org.bdware.units.NetworkManager;
|
|||||||
import org.zz.gmhelper.SM2KeyPair;
|
import org.zz.gmhelper.SM2KeyPair;
|
||||||
import org.zz.gmhelper.SM2Util;
|
import org.zz.gmhelper.SM2Util;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -139,7 +136,7 @@ public class MasterWSAction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
List<String> nodeNames; // nodes' peerID
|
Set<String> nodeNames; // nodes' peerID
|
||||||
// if (contract.getType().equals(ContractExecType.SelfAdaptiveSharding)) {
|
// if (contract.getType().equals(ContractExecType.SelfAdaptiveSharding)) {
|
||||||
// if (ContractManager.instance.nodeCenterConn.listNodes().length < 3) {
|
// if (ContractManager.instance.nodeCenterConn.listNodes().length < 3) {
|
||||||
// rc.onResult(
|
// rc.onResult(
|
||||||
@ -160,16 +157,18 @@ public class MasterWSAction {
|
|||||||
nodeNames =
|
nodeNames =
|
||||||
Arrays.stream(nodeNamesStr)
|
Arrays.stream(nodeNamesStr)
|
||||||
.filter(x -> null != x && !x.isEmpty())
|
.filter(x -> null != x && !x.isEmpty())
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toSet());
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
SM2KeyPair keyPair = GlobalConf.instance.keyPair;
|
||||||
|
String masterNode = keyPair.getPublicKeyStr();
|
||||||
|
nodeNames.add(masterNode);
|
||||||
int nodeSize = nodeNames.size();
|
int nodeSize = nodeNames.size();
|
||||||
|
|
||||||
// 方式一向NodeCenter发,要求Slave节点主动连接到Master节点.
|
// 方式一向NodeCenter发,要求Slave节点主动连接到Master节点.
|
||||||
Map<String, Object> requestConnect = new HashMap<>();
|
Map<String, Object> requestConnect = new HashMap<>();
|
||||||
requestConnect.put("action", "requestConnectToMaster");
|
requestConnect.put("action", "requestConnectToMaster");
|
||||||
LOGGER.debug(multiPointContractInfo.masterNode);
|
LOGGER.debug(multiPointContractInfo.masterNode);
|
||||||
SM2KeyPair keyPair = GlobalConf.instance.keyPair;
|
|
||||||
String masterNode = keyPair.getPublicKeyStr();
|
|
||||||
requestConnect.put("master", masterNode); // 从哪个节点启动,哪个节点就是master
|
requestConnect.put("master", masterNode); // 从哪个节点启动,哪个节点就是master
|
||||||
requestConnect.put("members", nodeNames);
|
requestConnect.put("members", nodeNames);
|
||||||
if (contract.getType() == ContractExecType.Sharding) {
|
if (contract.getType() == ContractExecType.Sharding) {
|
||||||
@ -256,12 +255,12 @@ public class MasterWSAction {
|
|||||||
String startReq = JsonUtil.toJson(request);
|
String startReq = JsonUtil.toJson(request);
|
||||||
LOGGER.debug("start contract " + startReq);
|
LOGGER.debug("start contract " + startReq);
|
||||||
|
|
||||||
for (int i = 0; i < nodeSize; ++i) {
|
int i = 0;
|
||||||
String nodeID = nodeNames.get(i); // 根据i获得nodeID
|
for (String nodeID : nodeNames) {
|
||||||
// for (String nodeID : nodeNames) {
|
// for (String nodeID : nodeNames) {
|
||||||
// 设置字段
|
// 设置字段
|
||||||
if (multiPointContractInfo.type == ContractExecType.Sharding) {
|
if (multiPointContractInfo.type == ContractExecType.Sharding) {
|
||||||
contract.setShardingId(i);
|
contract.setShardingId(i++);
|
||||||
request.put("contractStr", JsonUtil.toJson(contract));
|
request.put("contractStr", JsonUtil.toJson(contract));
|
||||||
startReq = JsonUtil.toJson(request);
|
startReq = JsonUtil.toJson(request);
|
||||||
LOGGER.debug("start contract: " + startReq);
|
LOGGER.debug("start contract: " + startReq);
|
||||||
@ -292,7 +291,7 @@ public class MasterWSAction {
|
|||||||
LOGGER.info("success!");
|
LOGGER.info("success!");
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean waitForConnection(List<String> nodeNames) {
|
private boolean waitForConnection(Collection<String> nodeNames) {
|
||||||
LOGGER.info("waitForAllNodes:" + JsonUtil.toJson(nodeNames));
|
LOGGER.info("waitForAllNodes:" + JsonUtil.toJson(nodeNames));
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
boolean all = true;
|
boolean all = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user