diff --git a/source/libs/sync/inc/syncRaftCfg.h b/source/libs/sync/inc/syncRaftCfg.h index 6b6ca21399d15c191a5d932faf279e55d44420c6..823983e732c88baaf8ef17ad398902ccf71346d8 100644 --- a/source/libs/sync/inc/syncRaftCfg.h +++ b/source/libs/sync/inc/syncRaftCfg.h @@ -22,11 +22,9 @@ extern "C" { #include "syncInt.h" -#define CONFIG_FILE_LEN 2048 - +#define CONFIG_FILE_LEN 2048 #define MAX_CONFIG_INDEX_COUNT 256 -// SRaftCfgIndex ------------------------------------------ typedef struct SRaftCfgIndex { TdFilePtr pFile; char path[TSDB_FILENAME_LEN * 2]; @@ -44,11 +42,8 @@ cJSON *raftCfgIndex2Json(SRaftCfgIndex *pRaftCfgIndex); char *raftCfgIndex2Str(SRaftCfgIndex *pRaftCfgIndex); int32_t raftCfgIndexFromJson(const cJSON *pRoot, SRaftCfgIndex *pRaftCfgIndex); int32_t raftCfgIndexFromStr(const char *s, SRaftCfgIndex *pRaftCfgIndex); - int32_t raftCfgIndexCreateFile(const char *path); -// --------------------------------------------------------- - typedef struct SRaftCfg { SSyncCfg cfg; TdFilePtr pFile; @@ -68,11 +63,9 @@ int32_t raftCfgClose(SRaftCfg *pRaftCfg); int32_t raftCfgPersist(SRaftCfg *pRaftCfg); int32_t raftCfgAddConfigIndex(SRaftCfg *pRaftCfg, SyncIndex configIndex); -cJSON *syncCfg2Json(SSyncCfg *pSyncCfg); -char *syncCfg2Str(SSyncCfg *pSyncCfg); void syncCfg2SimpleStr(const SSyncCfg *pCfg, char *str, int32_t bufLen); +cJSON *syncCfg2Json(SSyncCfg *pSyncCfg); int32_t syncCfgFromJson(const cJSON *pRoot, SSyncCfg *pSyncCfg); -int32_t syncCfgFromStr(const char *s, SSyncCfg *pSyncCfg); cJSON *raftCfg2Json(SRaftCfg *pRaftCfg); char *raftCfg2Str(SRaftCfg *pRaftCfg); diff --git a/source/libs/sync/src/syncRaftCfg.c b/source/libs/sync/src/syncRaftCfg.c index 66c399d15af671634a2a86da9ccc13b1894f8ff4..b6b2616973420cd502e2c0d54e33ae74bb75923c 100644 --- a/source/libs/sync/src/syncRaftCfg.c +++ b/source/libs/sync/src/syncRaftCfg.c @@ -13,10 +13,8 @@ * along with this program. If not, see . */ +#define _DEFAULT_SOURCE #include "syncRaftCfg.h" -#include "cJSON.h" -#include "syncEnv.h" -#include "syncUtil.h" // file must already exist! SRaftCfgIndex *raftCfgIndexOpen(const char *path) { @@ -242,13 +240,6 @@ cJSON *syncCfg2Json(SSyncCfg *pSyncCfg) { return pRoot; } -char *syncCfg2Str(SSyncCfg *pSyncCfg) { - cJSON *pJson = syncCfg2Json(pSyncCfg); - char *serialized = cJSON_Print(pJson); - cJSON_Delete(pJson); - return serialized; -} - int32_t syncCfgFromJson(const cJSON *pRoot, SSyncCfg *pSyncCfg) { memset(pSyncCfg, 0, sizeof(SSyncCfg)); // cJSON *pJson = cJSON_GetObjectItem(pRoot, "SSyncCfg"); @@ -283,17 +274,6 @@ int32_t syncCfgFromJson(const cJSON *pRoot, SSyncCfg *pSyncCfg) { return 0; } -int32_t syncCfgFromStr(const char *s, SSyncCfg *pSyncCfg) { - cJSON *pRoot = cJSON_Parse(s); - ASSERT(pRoot != NULL); - - int32_t ret = syncCfgFromJson(pRoot, pSyncCfg); - ASSERT(ret == 0); - - cJSON_Delete(pRoot); - return 0; -} - cJSON *raftCfg2Json(SRaftCfg *pRaftCfg) { cJSON *pRoot = cJSON_CreateObject(); cJSON_AddItemToObject(pRoot, "SSyncCfg", syncCfg2Json(&(pRaftCfg->cfg))); diff --git a/source/libs/sync/src/syncRaftEntry.c b/source/libs/sync/src/syncRaftEntry.c index 262a7b08792ef663aea31f12274f5c07338beed9..540054e4731f5990565b3d6424a89b6d05da8a44 100644 --- a/source/libs/sync/src/syncRaftEntry.c +++ b/source/libs/sync/src/syncRaftEntry.c @@ -102,7 +102,6 @@ void syncEntry2OriginalRpc(const SSyncRaftEntry* pEntry, SRpcMsg* pRpcMsg) { memcpy(pRpcMsg->pCont, pEntry->data, pRpcMsg->contLen); } -//----------------------------------- SRaftEntryHashCache* raftCacheCreate(SSyncNode* pSyncNode, int32_t maxCount) { SRaftEntryHashCache* pCache = taosMemoryMalloc(sizeof(SRaftEntryHashCache)); if (pCache == NULL) { @@ -256,8 +255,6 @@ int32_t raftCacheClear(struct SRaftEntryHashCache* pCache) { return 0; } - -//----------------------------------- static char* keyFn(const void* pData) { SSyncRaftEntry* pEntry = (SSyncRaftEntry*)pData; return (char*)(&(pEntry->index)); diff --git a/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp b/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp index a6d33aa6745a8a145fd3f4870bb33be9bd6834c5..fb227dfad34d7bfcdcea58806ce7ab00317d3bcd 100644 --- a/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp +++ b/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp @@ -143,7 +143,8 @@ int32_t SnapshotDoWrite(struct SSyncFSM* pFsm, void* pWriter, void* pBuf, int32_ void RestoreFinishCb(struct SSyncFSM* pFsm) { sTrace("==callback== ==RestoreFinishCb=="); } void ReConfigCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta* cbMeta) { - sTrace("==callback== ==ReConfigCb== flag:0x%lX, index:%" PRId64 ", code:%d, currentTerm:%" PRIu64 ", term:%" PRIu64, + sTrace("==callback== ==ReConfigCb== flag:0x%" PRIx64 ", index:%" PRId64 ", code:%d, currentTerm:%" PRIu64 + ", term:%" PRIu64, cbMeta->flag, cbMeta->index, cbMeta->code, cbMeta->currentTerm, cbMeta->term); } diff --git a/source/libs/sync/test/syncConfigChangeTest.cpp b/source/libs/sync/test/syncConfigChangeTest.cpp index cf498933e189d3f261933a2379293cf786a3bd98..23acadc0ccc3261cb7862ea435210b86d82c6306 100644 --- a/source/libs/sync/test/syncConfigChangeTest.cpp +++ b/source/libs/sync/test/syncConfigChangeTest.cpp @@ -73,7 +73,8 @@ int32_t GetSnapshotCb(const struct SSyncFSM* pFsm, SSnapshot* pSnapshot) { void RestoreFinishCb(struct SSyncFSM* pFsm) { sTrace("==callback== ==RestoreFinishCb=="); } void ReConfigCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta* cbMeta) { - sTrace("==callback== ==ReConfigCb== flag:0x%lX, index:%" PRId64 ", code:%d, currentTerm:%" PRIu64 ", term:%" PRIu64, + sTrace("==callback== ==ReConfigCb== flag:%" PRIx64 ", index:%" PRId64 ", code:%d, currentTerm:%" PRIu64 + ", term:%" PRIu64, cbMeta->flag, cbMeta->index, cbMeta->code, cbMeta->currentTerm, cbMeta->term); } diff --git a/source/libs/sync/test/syncTestTool.cpp b/source/libs/sync/test/syncTestTool.cpp index b0fe612b7f05a4fc51642ff323f3c1f8e3a44142..e8d40d5054fe4e560faa498a49d85a490f6226bc 100644 --- a/source/libs/sync/test/syncTestTool.cpp +++ b/source/libs/sync/test/syncTestTool.cpp @@ -148,8 +148,8 @@ void RestoreFinishCb(struct SSyncFSM* pFsm) { sTrace("==callback== ==RestoreFini void ReConfigCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta* cbMeta) { char* s = syncCfg2Str(&(cbMeta->newCfg)); - sTrace("==callback== ==ReConfigCb== flag:0x%lX, index:%" PRId64 ", code:%d, currentTerm:%" PRIu64 ", term:%" PRIu64 - ", newCfg:%s", + sTrace("==callback== ==ReConfigCb== flag:%" PRIx64 ", index:%" PRId64 ", code:%d, currentTerm:%" PRIu64 + ", term:%" PRIu64 ", newCfg:%s", cbMeta->flag, cbMeta->index, cbMeta->code, cbMeta->currentTerm, cbMeta->term, s); taosMemoryFree(s); } diff --git a/source/libs/sync/test/sync_test_lib/inc/syncTest.h b/source/libs/sync/test/sync_test_lib/inc/syncTest.h index 34ce8c3175b9c7fd2ef39faa064bb0e5c88a29be..50d9d12eeed947cf2fefda1966e5b4abc188c003 100644 --- a/source/libs/sync/test/sync_test_lib/inc/syncTest.h +++ b/source/libs/sync/test/sync_test_lib/inc/syncTest.h @@ -49,6 +49,9 @@ void syncEntryPrint2(char* s, const SSyncRaftEntry* pObj); void syncEntryLog(const SSyncRaftEntry* pObj); void syncEntryLog2(char* s, const SSyncRaftEntry* pObj); +char* syncCfg2Str(SSyncCfg* pSyncCfg); +int32_t syncCfgFromStr(const char* s, SSyncCfg* pSyncCfg); + cJSON* raftCache2Json(SRaftEntryHashCache* pObj); char* raftCache2Str(SRaftEntryHashCache* pObj); void raftCachePrint(SRaftEntryHashCache* pObj); diff --git a/source/libs/sync/test/sync_test_lib/src/syncRaftCfgDebug.c b/source/libs/sync/test/sync_test_lib/src/syncRaftCfgDebug.c index 88b697fbf14e463772c48ac569e81876175624c4..50ecc5d47804d54a4fa00aab34ec169706fcc1a5 100644 --- a/source/libs/sync/test/sync_test_lib/src/syncRaftCfgDebug.c +++ b/source/libs/sync/test/sync_test_lib/src/syncRaftCfgDebug.c @@ -16,4 +16,20 @@ #define _DEFAULT_SOURCE #include "syncTest.h" +char *syncCfg2Str(SSyncCfg *pSyncCfg) { + cJSON *pJson = syncCfg2Json(pSyncCfg); + char *serialized = cJSON_Print(pJson); + cJSON_Delete(pJson); + return serialized; +} +int32_t syncCfgFromStr(const char *s, SSyncCfg *pSyncCfg) { + cJSON *pRoot = cJSON_Parse(s); + ASSERT(pRoot != NULL); + + int32_t ret = syncCfgFromJson(pRoot, pSyncCfg); + ASSERT(ret == 0); + + cJSON_Delete(pRoot); + return 0; +}