mirror of
https://gitee.com/BDWare/agent-backend
synced 2025-01-10 01:44:14 +00:00
refactor: optimize logs
This commit is contained in:
parent
0e85394612
commit
4a589474b4
@ -21,12 +21,12 @@ import java.util.Map;
|
|||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
public class AliveCheckClientAction {
|
public class AliveCheckClientAction {
|
||||||
private static final Logger LOGGER = LogManager.getLogger(AliveCheckClientAction.class);
|
|
||||||
protected boolean waitForSetNode = false;
|
|
||||||
|
|
||||||
public static final int sendDelay = 2000;
|
public static final int sendDelay = 2000;
|
||||||
public static final int checkDelay = 5000;
|
public static final int checkDelay = 5000;
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger(AliveCheckClientAction.class);
|
||||||
|
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd.HH:mm:ss");
|
||||||
private final String masterPubkey;
|
private final String masterPubkey;
|
||||||
|
protected boolean waitForSetNode = false;
|
||||||
TimerTask sendPingTask;
|
TimerTask sendPingTask;
|
||||||
TimerTask checkAliveTask;
|
TimerTask checkAliveTask;
|
||||||
private long lastMasterPongTime = System.currentTimeMillis();
|
private long lastMasterPongTime = System.currentTimeMillis();
|
||||||
@ -66,7 +66,7 @@ public class AliveCheckClientAction {
|
|||||||
LOGGER.debug(
|
LOGGER.debug(
|
||||||
String.format(
|
String.format(
|
||||||
"f %s",
|
"f %s",
|
||||||
new SimpleDateFormat("yyyy-MM-dd.HH:mm:ss")
|
DATE_FORMAT
|
||||||
.format(System.currentTimeMillis())));
|
.format(System.currentTimeMillis())));
|
||||||
Map<String, String> ping = new HashMap<>();
|
Map<String, String> ping = new HashMap<>();
|
||||||
ping.put("action", "masterPing");
|
ping.put("action", "masterPing");
|
||||||
@ -93,10 +93,9 @@ public class AliveCheckClientAction {
|
|||||||
long cur = System.currentTimeMillis();
|
long cur = System.currentTimeMillis();
|
||||||
if (cur - lastMasterPongTime >= (2 * sendDelay)) {
|
if (cur - lastMasterPongTime >= (2 * sendDelay)) {
|
||||||
LOGGER.info(
|
LOGGER.info(
|
||||||
"lastMasterPongTime="
|
"master maybe crash down, because lastMasterPongTime="
|
||||||
+ new SimpleDateFormat("yyyy-MM-dd.HH:mm:ss")
|
+ DATE_FORMAT.format(lastMasterPongTime)
|
||||||
.format(lastMasterPongTime)
|
+ "!");
|
||||||
+ " 认为master崩溃!");
|
|
||||||
|
|
||||||
// 向NC发通知重新选举master,如果NC没有收到所有节点的重选请求,就认为是这个节点和master连接断开
|
// 向NC发通知重新选举master,如果NC没有收到所有节点的重选请求,就认为是这个节点和master连接断开
|
||||||
// 这个节点需要重连master
|
// 这个节点需要重连master
|
||||||
@ -107,9 +106,9 @@ public class AliveCheckClientAction {
|
|||||||
for (MultiContractMeta meta : CMActions.manager.multiContractRecorder.getStatus().values()) {
|
for (MultiContractMeta meta : CMActions.manager.multiContractRecorder.getStatus().values()) {
|
||||||
if (meta.getMasterNode().equals(masterPubkey)) {
|
if (meta.getMasterNode().equals(masterPubkey)) {
|
||||||
LOGGER.info(
|
LOGGER.info(
|
||||||
"认为合约 "
|
"master of contract "
|
||||||
+ meta.getContractID()
|
+ meta.getContractID()
|
||||||
+ " 的master崩溃 master="
|
+ " maybe crash down! master="
|
||||||
+ masterPubkey);
|
+ masterPubkey);
|
||||||
request.put("contractID", meta.getContractID());
|
request.put("contractID", meta.getContractID());
|
||||||
int lastSeq = meta.getLastExeSeq();
|
int lastSeq = meta.getLastExeSeq();
|
||||||
@ -130,8 +129,7 @@ public class AliveCheckClientAction {
|
|||||||
};
|
};
|
||||||
lastMasterPongTime = System.currentTimeMillis();
|
lastMasterPongTime = System.currentTimeMillis();
|
||||||
LOGGER.info(
|
LOGGER.info(
|
||||||
"设置 lastMasterPongTime="
|
"lastMasterPongTime=" + DATE_FORMAT.format(lastMasterPongTime));
|
||||||
+ new SimpleDateFormat("yyyy-MM-dd.HH:mm:ss").format(lastMasterPongTime));
|
|
||||||
HeartBeatUtil.getInstance().schedule(sendPingTask, sendDelay / 2, checkDelay);
|
HeartBeatUtil.getInstance().schedule(sendPingTask, sendDelay / 2, checkDelay);
|
||||||
HeartBeatUtil.getInstance().schedule(checkAliveTask, sendDelay, checkDelay);
|
HeartBeatUtil.getInstance().schedule(checkAliveTask, sendDelay, checkDelay);
|
||||||
}
|
}
|
||||||
|
@ -324,7 +324,7 @@ public class NodeCenterClientController implements NodeCenterConn {
|
|||||||
|
|
||||||
@Action(async = true)
|
@Action(async = true)
|
||||||
public void onQueryNodeAddress(JsonObject jo, ResultCallback cb) {
|
public void onQueryNodeAddress(JsonObject jo, ResultCallback cb) {
|
||||||
LOGGER.info("onQueryNodeAddress:" + jo.toString());
|
LOGGER.debug("onQueryNodeAddress:" + jo.toString());
|
||||||
sync.wakeUp(jo.get("responseID").getAsString(), jo.toString());
|
sync.wakeUp(jo.get("responseID").getAsString(), jo.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,7 +349,8 @@ public class NodeCenterClientController implements NodeCenterConn {
|
|||||||
sendMsg(JsonUtil.toJson(req));
|
sendMsg(JsonUtil.toJson(req));
|
||||||
//TODO use async instead?
|
//TODO use async instead?
|
||||||
ContractResult cr = sync.syncSleep(requestID);
|
ContractResult cr = sync.syncSleep(requestID);
|
||||||
LOGGER.info("connectToNode result:" + JsonUtil.toJson(cr));
|
LOGGER.debug("result: " + JsonUtil.toJson(cr));
|
||||||
|
LOGGER.info("node " + pubKey + " succeed!");
|
||||||
if (!cr.result.equals(JsonNull.INSTANCE)) {
|
if (!cr.result.equals(JsonNull.INSTANCE)) {
|
||||||
try {
|
try {
|
||||||
JsonObject jo = cr.result.getAsJsonObject();
|
JsonObject jo = cr.result.getAsJsonObject();
|
||||||
|
@ -70,7 +70,7 @@ public class AgentManager implements AgentPeerManagerIntf {
|
|||||||
@Override
|
@Override
|
||||||
public boolean deliverEvent(String pubKey, String event) {
|
public boolean deliverEvent(String pubKey, String event) {
|
||||||
if (null != pubKey && !CMActions.manager.nodeCenterConn.getNodeId().equals(pubKey)) {
|
if (null != pubKey && !CMActions.manager.nodeCenterConn.getNodeId().equals(pubKey)) {
|
||||||
LOGGER.info("Deliver event message in node " + pubKey.substring(0, 6));
|
LOGGER.info("Deliver event message to node " + pubKey.substring(0, 6));
|
||||||
JsonObject msg = new JsonObject();
|
JsonObject msg = new JsonObject();
|
||||||
msg.addProperty("action", "deliverEvent");
|
msg.addProperty("action", "deliverEvent");
|
||||||
msg.addProperty("data", event);
|
msg.addProperty("data", event);
|
||||||
|
Loading…
Reference in New Issue
Block a user