feat: sharding executor exec locally
This commit is contained in:
parent
afa327419b
commit
46d1ebb9bf
@ -1 +1 @@
|
|||||||
Subproject commit 5a4fdb8a13f4eb60d7cf63c040b53be81392ea45
|
Subproject commit da1f524a06bfb1a05753145bcd1f765ea4a42e81
|
@ -0,0 +1,8 @@
|
|||||||
|
package org.bdware.sdk.consistency.api.context;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import org.bdware.sc.conn.ResultCallback;
|
||||||
|
|
||||||
|
public interface IMasterClientTCPAction {
|
||||||
|
void asyncExecuteContractLocally(JsonObject jo, ResultCallback rc);
|
||||||
|
}
|
@ -1,6 +1,8 @@
|
|||||||
package org.bdware.sdk.consistency.api.context;
|
package org.bdware.sdk.consistency.api.context;
|
||||||
|
|
||||||
public interface ISDKContext {
|
public interface ISDKContext {
|
||||||
|
IMasterClientTCPAction getMasterClientTCPAction();
|
||||||
|
|
||||||
IMasterServerTCPAction getMasterServerTCPAction();
|
IMasterServerTCPAction getMasterServerTCPAction();
|
||||||
|
|
||||||
INetworkManager getNetworkManager();
|
INetworkManager getNetworkManager();
|
||||||
|
@ -8,6 +8,7 @@ public abstract class AbstractContextContractExecutor implements ContractExecuto
|
|||||||
static protected IGlobalConf globalConf = ConsistencyPluginManager.getContext().getGlobalConf();
|
static protected IGlobalConf globalConf = ConsistencyPluginManager.getContext().getGlobalConf();
|
||||||
static protected ICMActions cmActions = ConsistencyPluginManager.getContext().getCMActions();
|
static protected ICMActions cmActions = ConsistencyPluginManager.getContext().getCMActions();
|
||||||
static protected INetworkManager networkManager = ConsistencyPluginManager.getContext().getNetworkManager();
|
static protected INetworkManager networkManager = ConsistencyPluginManager.getContext().getNetworkManager();
|
||||||
|
static protected IMasterClientTCPAction masterClientTCPAction = ConsistencyPluginManager.getContext().getMasterClientTCPAction();
|
||||||
static protected IMasterServerTCPAction masterServerTCPAction = ConsistencyPluginManager.getContext().getMasterServerTCPAction();
|
static protected IMasterServerTCPAction masterServerTCPAction = ConsistencyPluginManager.getContext().getMasterServerTCPAction();
|
||||||
static protected IMasterServerRecoverMechAction masterServerRecoverMechAction = ConsistencyPluginManager.getContext().getMasterServerRecoverMechAction();
|
static protected IMasterServerRecoverMechAction masterServerRecoverMechAction = ConsistencyPluginManager.getContext().getMasterServerRecoverMechAction();
|
||||||
}
|
}
|
||||||
|
@ -65,13 +65,13 @@ public class MultiPointCooperationExecutor extends AbstractContextContractExecut
|
|||||||
count); // 把count改成了1,设置成获得1个响应就行
|
count); // 把count改成了1,设置成获得1个响应就行
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendRequest(String id, ContractRequest req, String[] nodes) {
|
public void sendRequest(String id, ContractRequest req, String[] nodes, ResultCallback rc) {
|
||||||
Map<String, Object> reqStr = new HashMap<>();
|
|
||||||
reqStr.put("uniReqID", id);
|
|
||||||
reqStr.put("data", req);
|
|
||||||
req.needSeq = false;
|
req.needSeq = false;
|
||||||
reqStr.put("action", "executeContractLocally");
|
JsonObject jo = new JsonObject();
|
||||||
String sendStr = JsonUtil.toJson(reqStr);
|
jo.addProperty("uniReqID", id);
|
||||||
|
jo.add("data", JsonUtil.parseObject(req));
|
||||||
|
jo.addProperty("action", "executeContractLocally");
|
||||||
|
String sendStr = jo.toString();
|
||||||
// master负责缓存请求
|
// master负责缓存请求
|
||||||
if (!masterServerTCPAction.getReqCache().containsKey(contractID)) {
|
if (!masterServerTCPAction.getReqCache().containsKey(contractID)) {
|
||||||
masterServerTCPAction.getReqCache().put(contractID, new RequestCache());
|
masterServerTCPAction.getReqCache().put(contractID, new RequestCache());
|
||||||
@ -82,13 +82,17 @@ public class MultiPointCooperationExecutor extends AbstractContextContractExecut
|
|||||||
LOGGER.info("node size = " + nodes.length);
|
LOGGER.info("node size = " + nodes.length);
|
||||||
LOGGER.debug("nodes:" + JsonUtil.toJson(nodes));
|
LOGGER.debug("nodes:" + JsonUtil.toJson(nodes));
|
||||||
for (String node : nodes) {
|
for (String node : nodes) {
|
||||||
LOGGER.info(
|
if (node.equals(globalConf.getNodeID())) {
|
||||||
"[sendRequests] get cmNode "
|
masterClientTCPAction.asyncExecuteContractLocally(jo, rc);
|
||||||
+ node.substring(0, 5)
|
} else {
|
||||||
+ " not null "
|
LOGGER.info(
|
||||||
+ "RequestAllExecutor 发送请求给 "
|
"[sendRequests] get cmNode "
|
||||||
+ node.substring(0, 5));
|
+ node.substring(0, 5)
|
||||||
networkManager.sendToAgent(node, sendStr);
|
+ " not null "
|
||||||
|
+ "RequestAllExecutor 发送请求给 "
|
||||||
|
+ node.substring(0, 5));
|
||||||
|
networkManager.sendToAgent(node, sendStr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +222,7 @@ public class MultiPointCooperationExecutor extends AbstractContextContractExecut
|
|||||||
createResultCallback(id, rc, count, req.seq, req.getContractID(), joinInfo); // 初始化结果收集器
|
createResultCallback(id, rc, count, req.seq, req.getContractID(), joinInfo); // 初始化结果收集器
|
||||||
masterServerTCPAction.getSync().sleep(id, collector);
|
masterServerTCPAction.getSync().sleep(id, collector);
|
||||||
LOGGER.info("requestID=" + requestID + " master broadcasts request " + req.seq);
|
LOGGER.info("requestID=" + requestID + " master broadcasts request " + req.seq);
|
||||||
sendRequest(id, req, nodes); // 发送请求
|
sendRequest(id, req, nodes, collector); // 发送请求
|
||||||
} else {
|
} else {
|
||||||
LOGGER.info("invalidNodeNumOnResult");
|
LOGGER.info("invalidNodeNumOnResult");
|
||||||
request_index.getAndDecrement();
|
request_index.getAndDecrement();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user