From 71dad1ea78414755a3589c793464f2f72525f417 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Tue, 14 Jun 2022 15:50:44 +0800 Subject: [PATCH 1/5] refactor(sync): add test syncRaftIdCheck --- source/libs/sync/src/syncUtil.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/source/libs/sync/src/syncUtil.c b/source/libs/sync/src/syncUtil.c index d12c5058cc..99950c54e5 100644 --- a/source/libs/sync/src/syncUtil.c +++ b/source/libs/sync/src/syncUtil.c @@ -14,6 +14,12 @@ */ #include "syncUtil.h" +#include +#include +#include +#include +#include + #include "syncEnv.h" void addEpIntoEpSet(SEpSet* pEpSet, const char* fqdn, uint16_t port); @@ -22,7 +28,20 @@ void addEpIntoEpSet(SEpSet* pEpSet, const char* fqdn, uint16_t port); uint64_t syncUtilAddr2U64(const char* host, uint16_t port) { uint64_t u64; uint32_t hostU32 = (uint32_t)taosInetAddr(host); - // assert(hostU32 != (uint32_t)-1); + if (hostU32 == (uint32_t)-1) { + struct hostent* hostEnt = gethostbyname(host); + if (hostEnt == NULL) { + sError("Get IP address error"); + return -1; + } + + const char* newHost = taosInetNtoa(*(struct in_addr*)(hostEnt->h_addr_list[0])); + hostU32 = (uint32_t)taosInetAddr(newHost); + if (hostU32 == (uint32_t)-1) { + sError("change %s to id, error", newHost); + } + // ASSERT(hostU32 != (uint32_t)-1); + } u64 = (((uint64_t)hostU32) << 32) | (((uint32_t)port) << 16); return u64; } From e4da993c15ae93c156085c8c29d60c12f462d057 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Tue, 14 Jun 2022 17:19:54 +0800 Subject: [PATCH 2/5] refactor(sync): add test syncRaftIdCheck --- source/libs/sync/src/syncUtil.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/source/libs/sync/src/syncUtil.c b/source/libs/sync/src/syncUtil.c index 99950c54e5..3c4eb4a447 100644 --- a/source/libs/sync/src/syncUtil.c +++ b/source/libs/sync/src/syncUtil.c @@ -14,11 +14,8 @@ */ #include "syncUtil.h" -#include #include -#include #include -#include #include "syncEnv.h" From b25840ebd458ca521661404698fa42f285f0c41b Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Tue, 14 Jun 2022 20:19:56 +0800 Subject: [PATCH 3/5] refactor(sync): add test syncRaftIdCheck --- source/libs/sync/src/syncUtil.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/source/libs/sync/src/syncUtil.c b/source/libs/sync/src/syncUtil.c index 3c4eb4a447..4026596548 100644 --- a/source/libs/sync/src/syncUtil.c +++ b/source/libs/sync/src/syncUtil.c @@ -14,7 +14,6 @@ */ #include "syncUtil.h" -#include #include #include "syncEnv.h" @@ -24,6 +23,14 @@ void addEpIntoEpSet(SEpSet* pEpSet, const char* fqdn, uint16_t port); // ---- encode / decode uint64_t syncUtilAddr2U64(const char* host, uint16_t port) { uint64_t u64; + + uint32_t hostU32 = taosGetIpv4FromFqdn(host); + if (hostU32 == (uint32_t)-1) { + sError("Get IP address error"); + return -1; + } + + /* uint32_t hostU32 = (uint32_t)taosInetAddr(host); if (hostU32 == (uint32_t)-1) { struct hostent* hostEnt = gethostbyname(host); @@ -39,6 +46,8 @@ uint64_t syncUtilAddr2U64(const char* host, uint16_t port) { } // ASSERT(hostU32 != (uint32_t)-1); } + */ + u64 = (((uint64_t)hostU32) << 32) | (((uint32_t)port) << 16); return u64; } From b60fde8f739ef0a641d53c1fafd4671cf2d7fc6a Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Tue, 14 Jun 2022 20:33:57 +0800 Subject: [PATCH 4/5] refactor(sync): add trace log --- source/libs/sync/src/syncMain.c | 6 +++--- source/libs/sync/src/syncRespMgr.c | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index feced0afdf..8ff22ff173 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -561,8 +561,8 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, const SRpcMsg* pMsg, bool isWeak) stub.createTime = taosGetTimestampMs(); stub.rpcMsg = *pMsg; uint64_t seqNum = syncRespMgrAdd(pSyncNode->pSyncRespMgr, &stub); - sDebug("vgId:%d sync event propose, type:%s seq:%" PRIu64 " handle:%p", pSyncNode->vgId, TMSG_INFO(pMsg->msgType), - seqNum, pMsg->info.handle); + sDebug("vgId:%d sync event resp mgr add, type:%s seq:%" PRIu64 " handle:%p", pSyncNode->vgId, + TMSG_INFO(pMsg->msgType), seqNum, pMsg->info.handle); SyncClientRequest* pSyncMsg = syncClientRequestBuild2(pMsg, seqNum, isWeak, pSyncNode->vgId); SRpcMsg rpcMsg; @@ -771,7 +771,7 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) { } // tools - pSyncNode->pSyncRespMgr = syncRespMgrCreate(NULL, 0); + pSyncNode->pSyncRespMgr = syncRespMgrCreate(pSyncNode, 0); assert(pSyncNode->pSyncRespMgr != NULL); // restore state diff --git a/source/libs/sync/src/syncRespMgr.c b/source/libs/sync/src/syncRespMgr.c index 642e572434..9bd9af3b48 100644 --- a/source/libs/sync/src/syncRespMgr.c +++ b/source/libs/sync/src/syncRespMgr.c @@ -63,6 +63,11 @@ int32_t syncRespMgrGet(SSyncRespMgr *pObj, uint64_t index, SRespStub *pStub) { void *pTmp = taosHashGet(pObj->pRespHash, &index, sizeof(index)); if (pTmp != NULL) { memcpy(pStub, pTmp, sizeof(SRespStub)); + + SSyncNode *pSyncNode = pObj->data; + sDebug("vgId:%d sync event resp mgr get, type:%s seq:%lu handle:%p", pSyncNode->vgId, + TMSG_INFO(pStub->rpcMsg.msgType), index, pStub->rpcMsg.info.handle); + taosThreadMutexUnlock(&(pObj->mutex)); return 1; // get one object } @@ -76,6 +81,11 @@ int32_t syncRespMgrGetAndDel(SSyncRespMgr *pObj, uint64_t index, SRespStub *pStu void *pTmp = taosHashGet(pObj->pRespHash, &index, sizeof(index)); if (pTmp != NULL) { memcpy(pStub, pTmp, sizeof(SRespStub)); + + SSyncNode *pSyncNode = pObj->data; + sDebug("vgId:%d sync event resp mgr get and del, type:%s seq:%lu handle:%p", pSyncNode->vgId, + TMSG_INFO(pStub->rpcMsg.msgType), index, pStub->rpcMsg.info.handle); + taosHashRemove(pObj->pRespHash, &index, sizeof(index)); taosThreadMutexUnlock(&(pObj->mutex)); return 1; // get one object From a51eee06eb80106d0de5e88aa3727d2b6b2e9223 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Tue, 14 Jun 2022 20:39:53 +0800 Subject: [PATCH 5/5] refactor(sync): add trace log --- source/libs/sync/src/syncMain.c | 2 -- source/libs/sync/src/syncRespMgr.c | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 8ff22ff173..ae3c12c31f 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -561,8 +561,6 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, const SRpcMsg* pMsg, bool isWeak) stub.createTime = taosGetTimestampMs(); stub.rpcMsg = *pMsg; uint64_t seqNum = syncRespMgrAdd(pSyncNode->pSyncRespMgr, &stub); - sDebug("vgId:%d sync event resp mgr add, type:%s seq:%" PRIu64 " handle:%p", pSyncNode->vgId, - TMSG_INFO(pMsg->msgType), seqNum, pMsg->info.handle); SyncClientRequest* pSyncMsg = syncClientRequestBuild2(pMsg, seqNum, isWeak, pSyncNode->vgId); SRpcMsg rpcMsg; diff --git a/source/libs/sync/src/syncRespMgr.c b/source/libs/sync/src/syncRespMgr.c index 9bd9af3b48..5087cacd02 100644 --- a/source/libs/sync/src/syncRespMgr.c +++ b/source/libs/sync/src/syncRespMgr.c @@ -44,6 +44,10 @@ int64_t syncRespMgrAdd(SSyncRespMgr *pObj, SRespStub *pStub) { uint64_t keyCode = ++(pObj->seqNum); taosHashPut(pObj->pRespHash, &keyCode, sizeof(keyCode), pStub, sizeof(SRespStub)); + SSyncNode *pSyncNode = pObj->data; + sDebug("vgId:%d sync event resp mgr add, type:%s seq:%lu handle:%p", pSyncNode->vgId, + TMSG_INFO(pStub->rpcMsg.msgType), keyCode, pStub->rpcMsg.info.handle); + taosThreadMutexUnlock(&(pObj->mutex)); return keyCode; }