From e060de705904cd475b3ea7d3d472b793ed316ba7 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 7 Nov 2022 19:30:23 +0800 Subject: [PATCH] refact: remove config change codes --- source/libs/sync/inc/syncTools.h | 39 ----- source/libs/sync/src/syncMain.c | 136 --------------- source/libs/sync/src/syncMessage.c | 159 ------------------ source/libs/sync/src/syncUtil.c | 9 +- source/libs/sync/test/CMakeLists.txt | 1 - .../libs/sync/test/syncLeaderTransferTest.cpp | 29 ++++ .../libs/sync/test/syncReconfigFinishTest.cpp | 133 --------------- 7 files changed, 32 insertions(+), 474 deletions(-) delete mode 100644 source/libs/sync/test/syncReconfigFinishTest.cpp diff --git a/source/libs/sync/inc/syncTools.h b/source/libs/sync/inc/syncTools.h index 2d87fcf7fa..87bd9cb13d 100644 --- a/source/libs/sync/inc/syncTools.h +++ b/source/libs/sync/inc/syncTools.h @@ -688,45 +688,6 @@ SyncLeaderTransfer* syncLeaderTransferFromRpcMsg2(const SRpcMsg* pRpcMsg); cJSON* syncLeaderTransfer2Json(const SyncLeaderTransfer* pMsg); char* syncLeaderTransfer2Str(const SyncLeaderTransfer* pMsg); -// for debug ---------------------- -void syncLeaderTransferPrint(const SyncLeaderTransfer* pMsg); -void syncLeaderTransferPrint2(char* s, const SyncLeaderTransfer* pMsg); -void syncLeaderTransferLog(const SyncLeaderTransfer* pMsg); -void syncLeaderTransferLog2(char* s, const SyncLeaderTransfer* pMsg); - -// --------------------------------------------- -typedef struct SyncReconfigFinish { - uint32_t bytes; - int32_t vgId; - uint32_t msgType; - SSyncCfg oldCfg; - SSyncCfg newCfg; - SyncIndex newCfgIndex; - SyncTerm newCfgTerm; - uint64_t newCfgSeqNum; - -} SyncReconfigFinish; - -SyncReconfigFinish* syncReconfigFinishBuild(int32_t vgId); -void syncReconfigFinishDestroy(SyncReconfigFinish* pMsg); -void syncReconfigFinishSerialize(const SyncReconfigFinish* pMsg, char* buf, uint32_t bufLen); -void syncReconfigFinishDeserialize(const char* buf, uint32_t len, SyncReconfigFinish* pMsg); -char* syncReconfigFinishSerialize2(const SyncReconfigFinish* pMsg, uint32_t* len); -SyncReconfigFinish* syncReconfigFinishDeserialize2(const char* buf, uint32_t len); -void syncReconfigFinish2RpcMsg(const SyncReconfigFinish* pMsg, SRpcMsg* pRpcMsg); -void syncReconfigFinishFromRpcMsg(const SRpcMsg* pRpcMsg, SyncReconfigFinish* pMsg); -SyncReconfigFinish* syncReconfigFinishFromRpcMsg2(const SRpcMsg* pRpcMsg); -cJSON* syncReconfigFinish2Json(const SyncReconfigFinish* pMsg); -char* syncReconfigFinish2Str(const SyncReconfigFinish* pMsg); - -// for debug ---------------------- -void syncReconfigFinishPrint(const SyncReconfigFinish* pMsg); -void syncReconfigFinishPrint2(char* s, const SyncReconfigFinish* pMsg); -void syncReconfigFinishLog(const SyncReconfigFinish* pMsg); -void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg); - -// --------------------------------------------- - typedef enum { SYNC_LOCAL_CMD_STEP_DOWN = 100, SYNC_LOCAL_CMD_FOLLOWER_CMT, diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 1a7964258d..bcca19b907 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -754,45 +754,11 @@ int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak) { return ret; } -static bool syncNodeBatchOK(SRpcMsg** pMsgPArr, int32_t arrSize) { - for (int32_t i = 0; i < arrSize; ++i) { - if (pMsgPArr[i]->msgType == TDMT_SYNC_CONFIG_CHANGE) { - return false; - } - - if (pMsgPArr[i]->msgType == TDMT_SYNC_CONFIG_CHANGE_FINISH) { - return false; - } - } - - return true; -} - int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak) { int32_t ret = 0; sNTrace(pSyncNode, "propose message, type:%s", TMSG_INFO(pMsg->msgType)); if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) { - if (pSyncNode->changing && pMsg->msgType != TDMT_SYNC_CONFIG_CHANGE_FINISH) { - ret = -1; - terrno = TSDB_CODE_SYN_PROPOSE_NOT_READY; - sError("vgId:%d, failed to sync propose since not ready, type:%s", pSyncNode->vgId, TMSG_INFO(pMsg->msgType)); - goto _END; - } - - // config change - if (pMsg->msgType == TDMT_SYNC_CONFIG_CHANGE) { - if (!syncNodeCanChange(pSyncNode)) { - ret = -1; - terrno = TSDB_CODE_SYN_RECONFIG_NOT_READY; - sError("vgId:%d, failed to sync reconfig since not ready, type:%s", pSyncNode->vgId, TMSG_INFO(pMsg->msgType)); - goto _END; - } - - ASSERT(!pSyncNode->changing); - pSyncNode->changing = true; - } - // not restored, vnode enable if (!pSyncNode->restoreFinish && pSyncNode->vgId != 1) { ret = -1; @@ -2800,86 +2766,6 @@ int32_t syncNodeUpdateNewConfigIndex(SSyncNode* ths, SSyncCfg* pNewCfg) { return -1; } -static int32_t syncNodeConfigChangeFinish(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* pEntry) { - SyncReconfigFinish* pFinish = syncReconfigFinishFromRpcMsg2(pRpcMsg); - ASSERT(pFinish); - - if (ths->pFsm->FpReConfigCb != NULL) { - SReConfigCbMeta cbMeta = {0}; - cbMeta.code = 0; - cbMeta.index = pEntry->index; - cbMeta.term = pEntry->term; - cbMeta.seqNum = pEntry->seqNum; - cbMeta.lastConfigIndex = syncNodeGetSnapshotConfigIndex(ths, pEntry->index); - cbMeta.state = ths->state; - cbMeta.currentTerm = ths->pRaftStore->currentTerm; - cbMeta.isWeak = pEntry->isWeak; - cbMeta.flag = 0; - - cbMeta.oldCfg = pFinish->oldCfg; - cbMeta.newCfg = pFinish->newCfg; - cbMeta.newCfgIndex = pFinish->newCfgIndex; - cbMeta.newCfgTerm = pFinish->newCfgTerm; - cbMeta.newCfgSeqNum = pFinish->newCfgSeqNum; - - ths->pFsm->FpReConfigCb(ths->pFsm, pRpcMsg, &cbMeta); - } - - // clear changing - ths->changing = false; - - char oldCfgStr[1024] = {0}; - char newCfgStr[1024] = {0}; - syncCfg2SimpleStr(&pFinish->oldCfg, oldCfgStr, sizeof(oldCfgStr)); - syncCfg2SimpleStr(&pFinish->newCfg, oldCfgStr, sizeof(oldCfgStr)); - sNTrace(ths, "config change finish from %d to %d, index:%" PRId64 ", %s --> %s", pFinish->oldCfg.replicaNum, - pFinish->newCfg.replicaNum, pFinish->newCfgIndex, oldCfgStr, newCfgStr); - - syncReconfigFinishDestroy(pFinish); - return 0; -} - -static int32_t syncNodeConfigChange(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* pEntry, - SyncReconfigFinish* pFinish) { - // set changing - ths->changing = true; - - // old config - SSyncCfg oldSyncCfg = ths->pRaftCfg->cfg; - - // new config - SSyncCfg newSyncCfg; - int32_t ret = syncCfgFromStr(pRpcMsg->pCont, &newSyncCfg); - ASSERT(ret == 0); - - // update new config myIndex - syncNodeUpdateNewConfigIndex(ths, &newSyncCfg); - - // do config change - syncNodeDoConfigChange(ths, &newSyncCfg, pEntry->index); - - // set pFinish - pFinish->oldCfg = oldSyncCfg; - pFinish->newCfg = newSyncCfg; - pFinish->newCfgIndex = pEntry->index; - pFinish->newCfgTerm = pEntry->term; - pFinish->newCfgSeqNum = pEntry->seqNum; - - return 0; -} - -static int32_t syncNodeProposeConfigChangeFinish(SSyncNode* ths, SyncReconfigFinish* pFinish) { - SRpcMsg rpcMsg; - syncReconfigFinish2RpcMsg(pFinish, &rpcMsg); - - int32_t code = syncNodePropose(ths, &rpcMsg, false); - if (code != 0) { - sError("syncNodeProposeConfigChangeFinish error"); - ths->changing = false; - } - return 0; -} - bool syncNodeIsOptimizedOneReplica(SSyncNode* ths, SRpcMsg* pMsg) { return (ths->replicaNum == 1 && syncUtilUserCommit(pMsg->msgType) && ths->vgId != 1); } @@ -2961,28 +2847,6 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde } } - // config change - if (pEntry->originalRpcType == TDMT_SYNC_CONFIG_CHANGE) { - SyncReconfigFinish* pFinish = syncReconfigFinishBuild(ths->vgId); - ASSERT(pFinish != NULL); - - code = syncNodeConfigChange(ths, &rpcMsg, pEntry, pFinish); - ASSERT(code == 0); - - if (ths->state == TAOS_SYNC_STATE_LEADER) { - syncNodeProposeConfigChangeFinish(ths, pFinish); - } - syncReconfigFinishDestroy(pFinish); - } - - // config change finish - if (pEntry->originalRpcType == TDMT_SYNC_CONFIG_CHANGE_FINISH) { - if (rpcMsg.pCont != NULL && rpcMsg.contLen > 0) { - code = syncNodeConfigChangeFinish(ths, &rpcMsg, pEntry); - ASSERT(code == 0); - } - } - #if 0 // execute in pre-commit // leader transfer diff --git a/source/libs/sync/src/syncMessage.c b/source/libs/sync/src/syncMessage.c index ff53da9b44..f4e9d83503 100644 --- a/source/libs/sync/src/syncMessage.c +++ b/source/libs/sync/src/syncMessage.c @@ -3238,165 +3238,6 @@ char* syncLeaderTransfer2Str(const SyncLeaderTransfer* pMsg) { return serialized; } -// for debug ---------------------- -void syncLeaderTransferPrint(const SyncLeaderTransfer* pMsg) { - char* serialized = syncLeaderTransfer2Str(pMsg); - printf("syncLeaderTransferPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void syncLeaderTransferPrint2(char* s, const SyncLeaderTransfer* pMsg) { - char* serialized = syncLeaderTransfer2Str(pMsg); - printf("syncLeaderTransferPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void syncLeaderTransferLog(const SyncLeaderTransfer* pMsg) { - char* serialized = syncLeaderTransfer2Str(pMsg); - sTrace("syncLeaderTransferLog | len:%d | %s", (int32_t)strlen(serialized), serialized); - taosMemoryFree(serialized); -} - -void syncLeaderTransferLog2(char* s, const SyncLeaderTransfer* pMsg) { - if (gRaftDetailLog) { - char* serialized = syncLeaderTransfer2Str(pMsg); - sTrace("syncLeaderTransferLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); - taosMemoryFree(serialized); - } -} - -// --------------------------------------------- -SyncReconfigFinish* syncReconfigFinishBuild(int32_t vgId) { - uint32_t bytes = sizeof(SyncReconfigFinish); - SyncReconfigFinish* pMsg = taosMemoryMalloc(bytes); - memset(pMsg, 0, bytes); - pMsg->bytes = bytes; - pMsg->vgId = vgId; - pMsg->msgType = TDMT_SYNC_CONFIG_CHANGE_FINISH; - return pMsg; -} - -void syncReconfigFinishDestroy(SyncReconfigFinish* pMsg) { - if (pMsg != NULL) { - taosMemoryFree(pMsg); - } -} - -void syncReconfigFinishSerialize(const SyncReconfigFinish* pMsg, char* buf, uint32_t bufLen) { - ASSERT(pMsg->bytes <= bufLen); - memcpy(buf, pMsg, pMsg->bytes); -} - -void syncReconfigFinishDeserialize(const char* buf, uint32_t len, SyncReconfigFinish* pMsg) { - memcpy(pMsg, buf, len); - ASSERT(len == pMsg->bytes); -} - -char* syncReconfigFinishSerialize2(const SyncReconfigFinish* pMsg, uint32_t* len) { - char* buf = taosMemoryMalloc(pMsg->bytes); - ASSERT(buf != NULL); - syncReconfigFinishSerialize(pMsg, buf, pMsg->bytes); - if (len != NULL) { - *len = pMsg->bytes; - } - return buf; -} - -SyncReconfigFinish* syncReconfigFinishDeserialize2(const char* buf, uint32_t len) { - uint32_t bytes = *((uint32_t*)buf); - SyncReconfigFinish* pMsg = taosMemoryMalloc(bytes); - ASSERT(pMsg != NULL); - syncReconfigFinishDeserialize(buf, len, pMsg); - ASSERT(len == pMsg->bytes); - return pMsg; -} - -void syncReconfigFinish2RpcMsg(const SyncReconfigFinish* pMsg, SRpcMsg* pRpcMsg) { - memset(pRpcMsg, 0, sizeof(*pRpcMsg)); - pRpcMsg->msgType = pMsg->msgType; - pRpcMsg->contLen = pMsg->bytes; - pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen); - syncReconfigFinishSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen); -} - -void syncReconfigFinishFromRpcMsg(const SRpcMsg* pRpcMsg, SyncReconfigFinish* pMsg) { - syncReconfigFinishDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg); -} - -SyncReconfigFinish* syncReconfigFinishFromRpcMsg2(const SRpcMsg* pRpcMsg) { - SyncReconfigFinish* pMsg = syncReconfigFinishDeserialize2(pRpcMsg->pCont, (uint32_t)(pRpcMsg->contLen)); - ASSERT(pMsg != NULL); - return pMsg; -} - -cJSON* syncReconfigFinish2Json(const SyncReconfigFinish* pMsg) { - char u64buf[128]; - cJSON* pRoot = cJSON_CreateObject(); - - if (pMsg != NULL) { - cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes); - cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId); - cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); - - cJSON* pOldCfg = syncCfg2Json((SSyncCfg*)(&(pMsg->oldCfg))); - cJSON* pNewCfg = syncCfg2Json((SSyncCfg*)(&(pMsg->newCfg))); - cJSON_AddItemToObject(pRoot, "oldCfg", pOldCfg); - cJSON_AddItemToObject(pRoot, "newCfg", pNewCfg); - - snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->newCfgIndex); - cJSON_AddStringToObject(pRoot, "newCfgIndex", u64buf); - - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->newCfgTerm); - cJSON_AddStringToObject(pRoot, "newCfgTerm", u64buf); - - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->newCfgSeqNum); - cJSON_AddStringToObject(pRoot, "newCfgSeqNum", u64buf); - } - - cJSON* pJson = cJSON_CreateObject(); - cJSON_AddItemToObject(pJson, "SyncReconfigFinish", pRoot); - return pJson; -} - -char* syncReconfigFinish2Str(const SyncReconfigFinish* pMsg) { - cJSON* pJson = syncReconfigFinish2Json(pMsg); - char* serialized = cJSON_Print(pJson); - cJSON_Delete(pJson); - return serialized; -} - -// for debug ---------------------- -void syncReconfigFinishPrint(const SyncReconfigFinish* pMsg) { - char* serialized = syncReconfigFinish2Str(pMsg); - printf("syncReconfigFinishPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void syncReconfigFinishPrint2(char* s, const SyncReconfigFinish* pMsg) { - char* serialized = syncReconfigFinish2Str(pMsg); - printf("syncReconfigFinishPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void syncReconfigFinishLog(const SyncReconfigFinish* pMsg) { - char* serialized = syncReconfigFinish2Str(pMsg); - sTrace("syncReconfigFinishLog | len:%d | %s", (int32_t)strlen(serialized), serialized); - taosMemoryFree(serialized); -} - -void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg) { - if (gRaftDetailLog) { - char* serialized = syncReconfigFinish2Str(pMsg); - sTrace("syncReconfigFinishLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); - taosMemoryFree(serialized); - } -} - -// --------------------------------------------- const char* syncLocalCmdGetStr(int32_t cmd) { if (cmd == SYNC_LOCAL_CMD_STEP_DOWN) { return "step-down"; diff --git a/source/libs/sync/src/syncUtil.c b/source/libs/sync/src/syncUtil.c index 6ec5c20d04..e22e0d6a47 100644 --- a/source/libs/sync/src/syncUtil.c +++ b/source/libs/sync/src/syncUtil.c @@ -179,8 +179,7 @@ void syncUtilMsgNtoH(void* msg) { } bool syncUtilUserPreCommit(tmsg_t msgType) { - if (msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_CONFIG_CHANGE && msgType != TDMT_SYNC_CONFIG_CHANGE_FINISH && - msgType != TDMT_SYNC_LEADER_TRANSFER) { + if (msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER) { return true; } @@ -188,8 +187,7 @@ bool syncUtilUserPreCommit(tmsg_t msgType) { } bool syncUtilUserCommit(tmsg_t msgType) { - if (msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_CONFIG_CHANGE && msgType != TDMT_SYNC_CONFIG_CHANGE_FINISH && - msgType != TDMT_SYNC_LEADER_TRANSFER) { + if (msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER) { return true; } @@ -197,8 +195,7 @@ bool syncUtilUserCommit(tmsg_t msgType) { } bool syncUtilUserRollback(tmsg_t msgType) { - if (msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_CONFIG_CHANGE && msgType != TDMT_SYNC_CONFIG_CHANGE_FINISH && - msgType != TDMT_SYNC_LEADER_TRANSFER) { + if (msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER) { return true; } diff --git a/source/libs/sync/test/CMakeLists.txt b/source/libs/sync/test/CMakeLists.txt index 1b7ec7f0df..e584893ae0 100644 --- a/source/libs/sync/test/CMakeLists.txt +++ b/source/libs/sync/test/CMakeLists.txt @@ -54,7 +54,6 @@ add_executable(syncRaftLogTest "") add_executable(syncRaftLogTest2 "") add_executable(syncRaftLogTest3 "") add_executable(syncLeaderTransferTest "") -add_executable(syncReconfigFinishTest "") add_executable(syncRestoreFromSnapshot "") add_executable(syncRaftCfgIndexTest "") add_executable(syncHeartbeatTest "") diff --git a/source/libs/sync/test/syncLeaderTransferTest.cpp b/source/libs/sync/test/syncLeaderTransferTest.cpp index 62a9106c15..bd1f22edff 100644 --- a/source/libs/sync/test/syncLeaderTransferTest.cpp +++ b/source/libs/sync/test/syncLeaderTransferTest.cpp @@ -27,6 +27,35 @@ SyncLeaderTransfer *createMsg() { return pMsg; } +// for debug ---------------------- +void syncLeaderTransferPrint(const SyncLeaderTransfer *pMsg) { + char *serialized = syncLeaderTransfer2Str(pMsg); + printf("syncLeaderTransferPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void syncLeaderTransferPrint2(char *s, const SyncLeaderTransfer *pMsg) { + char *serialized = syncLeaderTransfer2Str(pMsg); + printf("syncLeaderTransferPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void syncLeaderTransferLog(const SyncLeaderTransfer *pMsg) { + char *serialized = syncLeaderTransfer2Str(pMsg); + sTrace("syncLeaderTransferLog | len:%d | %s", (int32_t)strlen(serialized), serialized); + taosMemoryFree(serialized); +} + +void syncLeaderTransferLog2(char *s, const SyncLeaderTransfer *pMsg) { + if (gRaftDetailLog) { + char *serialized = syncLeaderTransfer2Str(pMsg); + sTrace("syncLeaderTransferLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); + taosMemoryFree(serialized); + } +} + void test1() { SyncLeaderTransfer *pMsg = createMsg(); syncLeaderTransferLog2((char *)"test1:", pMsg); diff --git a/source/libs/sync/test/syncReconfigFinishTest.cpp b/source/libs/sync/test/syncReconfigFinishTest.cpp deleted file mode 100644 index 5b283c5829..0000000000 --- a/source/libs/sync/test/syncReconfigFinishTest.cpp +++ /dev/null @@ -1,133 +0,0 @@ -#include -#include -#include "syncIO.h" -#include "syncInt.h" -#include "syncMessage.h" -#include "syncUtil.h" - -void logTest() { - sTrace("--- sync log test: trace"); - sDebug("--- sync log test: debug"); - sInfo("--- sync log test: info"); - sWarn("--- sync log test: warn"); - sError("--- sync log test: error"); - sFatal("--- sync log test: fatal"); -} - -SSyncCfg *createSyncOldCfg() { - SSyncCfg *pCfg = (SSyncCfg *)taosMemoryMalloc(sizeof(SSyncCfg)); - memset(pCfg, 0, sizeof(SSyncCfg)); - - pCfg->replicaNum = 3; - pCfg->myIndex = 1; - for (int i = 0; i < pCfg->replicaNum; ++i) { - ((pCfg->nodeInfo)[i]).nodePort = i * 100; - snprintf(((pCfg->nodeInfo)[i]).nodeFqdn, sizeof(((pCfg->nodeInfo)[i]).nodeFqdn), "100.200.300.%d", i); - } - - return pCfg; -} - -SSyncCfg *createSyncNewCfg() { - SSyncCfg *pCfg = (SSyncCfg *)taosMemoryMalloc(sizeof(SSyncCfg)); - memset(pCfg, 0, sizeof(SSyncCfg)); - - pCfg->replicaNum = 3; - pCfg->myIndex = 1; - for (int i = 0; i < pCfg->replicaNum; ++i) { - ((pCfg->nodeInfo)[i]).nodePort = i * 100; - snprintf(((pCfg->nodeInfo)[i]).nodeFqdn, sizeof(((pCfg->nodeInfo)[i]).nodeFqdn), "500.600.700.%d", i); - } - - return pCfg; -} - -SyncReconfigFinish *createMsg() { - SyncReconfigFinish *pMsg = syncReconfigFinishBuild(1234); - - SSyncCfg *pOld = createSyncOldCfg(); - SSyncCfg *pNew = createSyncNewCfg(); - pMsg->oldCfg = *pOld; - pMsg->newCfg = *pNew; - - pMsg->newCfgIndex = 11; - pMsg->newCfgTerm = 22; - pMsg->newCfgSeqNum = 33; - - taosMemoryFree(pOld); - taosMemoryFree(pNew); - - return pMsg; -} - -void test1() { - SyncReconfigFinish *pMsg = createMsg(); - syncReconfigFinishLog2((char *)"test1:", pMsg); - syncReconfigFinishDestroy(pMsg); -} - -void test2() { - SyncReconfigFinish *pMsg = createMsg(); - uint32_t len = pMsg->bytes; - char *serialized = (char *)taosMemoryMalloc(len); - syncReconfigFinishSerialize(pMsg, serialized, len); - SyncReconfigFinish *pMsg2 = syncReconfigFinishBuild(1000); - syncReconfigFinishDeserialize(serialized, len, pMsg2); - syncReconfigFinishLog2((char *)"test2: syncReconfigFinishSerialize -> syncReconfigFinishDeserialize ", pMsg2); - - taosMemoryFree(serialized); - syncReconfigFinishDestroy(pMsg); - syncReconfigFinishDestroy(pMsg2); -} - -void test3() { - SyncReconfigFinish *pMsg = createMsg(); - uint32_t len; - char *serialized = syncReconfigFinishSerialize2(pMsg, &len); - SyncReconfigFinish *pMsg2 = syncReconfigFinishDeserialize2(serialized, len); - syncReconfigFinishLog2((char *)"test3: SyncReconfigFinishSerialize2 -> syncReconfigFinishDeserialize2 ", pMsg2); - - taosMemoryFree(serialized); - syncReconfigFinishDestroy(pMsg); - syncReconfigFinishDestroy(pMsg2); -} - -void test4() { - SyncReconfigFinish *pMsg = createMsg(); - SRpcMsg rpcMsg; - syncReconfigFinish2RpcMsg(pMsg, &rpcMsg); - SyncReconfigFinish *pMsg2 = (SyncReconfigFinish *)taosMemoryMalloc(rpcMsg.contLen); - syncReconfigFinishFromRpcMsg(&rpcMsg, pMsg2); - syncReconfigFinishLog2((char *)"test4: syncReconfigFinish2RpcMsg -> syncReconfigFinishFromRpcMsg ", pMsg2); - - rpcFreeCont(rpcMsg.pCont); - syncReconfigFinishDestroy(pMsg); - syncReconfigFinishDestroy(pMsg2); -} - -void test5() { - SyncReconfigFinish *pMsg = createMsg(); - SRpcMsg rpcMsg; - syncReconfigFinish2RpcMsg(pMsg, &rpcMsg); - SyncReconfigFinish *pMsg2 = syncReconfigFinishFromRpcMsg2(&rpcMsg); - syncReconfigFinishLog2((char *)"test5: syncReconfigFinish2RpcMsg -> syncReconfigFinishFromRpcMsg2 ", pMsg2); - - rpcFreeCont(rpcMsg.pCont); - syncReconfigFinishDestroy(pMsg); - syncReconfigFinishDestroy(pMsg2); -} - -int main() { - gRaftDetailLog = true; - tsAsyncLog = 0; - sDebugFlag = DEBUG_TRACE + DEBUG_SCREEN + DEBUG_FILE; - logTest(); - - test1(); - test2(); - test3(); - test4(); - test5(); - - return 0; -}