From 6d6e7bdf3d854bb6d423ac4cf8d9fa75bc420dbb Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 2 Mar 2022 18:30:21 +0800 Subject: [PATCH] sync modify timer --- source/libs/sync/inc/syncMessage.h | 2 +- source/libs/sync/src/syncIO.c | 7 +++++-- source/libs/sync/src/syncMain.c | 12 ++++++++++++ source/libs/sync/src/syncMessage.c | 1 + source/libs/sync/test/syncIOSendMsgClientTest.cpp | 2 +- source/libs/sync/test/syncIOSendMsgTest.cpp | 2 +- source/libs/sync/test/syncPingTest.cpp | 1 + 7 files changed, 22 insertions(+), 5 deletions(-) diff --git a/source/libs/sync/inc/syncMessage.h b/source/libs/sync/inc/syncMessage.h index 603ef00517..a4ae910608 100644 --- a/source/libs/sync/inc/syncMessage.h +++ b/source/libs/sync/inc/syncMessage.h @@ -30,7 +30,7 @@ extern "C" { // encode as uint64 typedef enum ESyncMessageType { - SYNC_PING = 0, + SYNC_PING = 100, SYNC_PING_REPLY, SYNC_CLIENT_REQUEST, SYNC_CLIENT_REQUEST_REPLY, diff --git a/source/libs/sync/src/syncIO.c b/source/libs/sync/src/syncIO.c index 74f848338f..bd49b04375 100644 --- a/source/libs/sync/src/syncIO.c +++ b/source/libs/sync/src/syncIO.c @@ -41,8 +41,11 @@ static void syncIOTickPingFunc(void *param, void *tmrId); // public function ------------ int32_t syncIOSendMsg(void *clientRpc, const SEpSet *pEpSet, SRpcMsg *pMsg) { - sTrace("<--- syncIOSendMsg ---> clientRpc:%p, numOfEps:%d, inUse:%d, destAddr:%s-%u", clientRpc, pEpSet->numOfEps, - pEpSet->inUse, pEpSet->eps[0].fqdn, pEpSet->eps[0].port); + sTrace( + "<--- syncIOSendMsg ---> clientRpc:%p, numOfEps:%d, inUse:%d, destAddr:%s-%u, pMsg->ahandle:%p, pMsg->handle:%p, " + "pMsg->msgType:%d, pMsg->contLen:%d", + clientRpc, pEpSet->numOfEps, pEpSet->inUse, pEpSet->eps[0].fqdn, pEpSet->eps[0].port, pMsg->ahandle, pMsg->handle, + pMsg->msgType, pMsg->contLen); pMsg->handle = NULL; rpcSendRequest(clientRpc, pEpSet, pMsg, NULL); return 0; diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index d19c51900f..180a2b13a1 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -168,8 +168,19 @@ int32_t syncNodeStopPingTimer(SSyncNode* pSyncNode) { static int32_t syncNodePing(SSyncNode* pSyncNode, const SRaftId* destRaftId, SyncPing* pMsg) { sTrace("syncNodePing pSyncNode:%p ", pSyncNode); int32_t ret = 0; + SRpcMsg rpcMsg; syncPing2RpcMsg(pMsg, &rpcMsg); + + /* + SRpcMsg rpcMsg; + rpcMsg.contLen = 64; + rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen); + snprintf((char*)rpcMsg.pCont, rpcMsg.contLen, "%s", "xxxxxxxxxxxxxx"); + rpcMsg.handle = NULL; + rpcMsg.msgType = 1; + */ + syncNodeSendMsgById(destRaftId, pSyncNode, &rpcMsg); { @@ -219,6 +230,7 @@ static int32_t syncNodeSendMsgByInfo(const SNodeInfo* nodeInfo, SSyncNode* pSync static int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg) { int32_t ret = 0; + sTrace("syncNodeOnPingCb ---- ========="); return ret; } diff --git a/source/libs/sync/src/syncMessage.c b/source/libs/sync/src/syncMessage.c index 8e7dc8ba61..1d1b2e6965 100644 --- a/source/libs/sync/src/syncMessage.c +++ b/source/libs/sync/src/syncMessage.c @@ -47,6 +47,7 @@ void syncPingDeserialize(const char* buf, uint32_t len, SyncPing* pMsg) { } void syncPing2RpcMsg(const SyncPing* pMsg, SRpcMsg* pRpcMsg) { + memset(pRpcMsg, 0, sizeof(*pRpcMsg)); pRpcMsg->msgType = pMsg->msgType; pRpcMsg->contLen = pMsg->bytes; pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen); diff --git a/source/libs/sync/test/syncIOSendMsgClientTest.cpp b/source/libs/sync/test/syncIOSendMsgClientTest.cpp index 8adaff1a2f..9e8c7c8b65 100644 --- a/source/libs/sync/test/syncIOSendMsgClientTest.cpp +++ b/source/libs/sync/test/syncIOSendMsgClientTest.cpp @@ -28,7 +28,7 @@ int main() { for (int i = 0; i < 10; ++i) { SEpSet epSet; epSet.inUse = 0; - epSet.numOfEps = 1; + epSet.numOfEps = 0; addEpIntoEpSet(&epSet, "127.0.0.1", 7030); SRpcMsg rpcMsg; diff --git a/source/libs/sync/test/syncIOSendMsgTest.cpp b/source/libs/sync/test/syncIOSendMsgTest.cpp index 33af51f23d..a297981ee5 100644 --- a/source/libs/sync/test/syncIOSendMsgTest.cpp +++ b/source/libs/sync/test/syncIOSendMsgTest.cpp @@ -28,7 +28,7 @@ int main() { for (int i = 0; i < 10; ++i) { SEpSet epSet; epSet.inUse = 0; - epSet.numOfEps = 1; + epSet.numOfEps = 0; addEpIntoEpSet(&epSet, "127.0.0.1", 7010); SRpcMsg rpcMsg; diff --git a/source/libs/sync/test/syncPingTest.cpp b/source/libs/sync/test/syncPingTest.cpp index 902513f7cb..002838b010 100644 --- a/source/libs/sync/test/syncPingTest.cpp +++ b/source/libs/sync/test/syncPingTest.cpp @@ -67,6 +67,7 @@ int main() { assert(ret == 0); SSyncNode* pSyncNode = doSync(); + gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing; ret = syncNodeStartPingTimer(pSyncNode); assert(ret == 0); -- GitLab