diff --git a/source/libs/sync/inc/syncIndexMgr.h b/source/libs/sync/inc/syncIndexMgr.h index 7116ae9d46..63f24b104f 100644 --- a/source/libs/sync/inc/syncIndexMgr.h +++ b/source/libs/sync/inc/syncIndexMgr.h @@ -42,6 +42,12 @@ SyncIndex syncIndexMgrGetIndex(SSyncIndexMgr *pSyncIndexMgr, const SRaftId cJSON * syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr); char * syncIndexMgr2Str(SSyncIndexMgr *pSyncIndexMgr); +// for debug ------------------- +void syncIndexMgrPrint(SSyncIndexMgr *pObj); +void syncIndexMgrPrint2(char *s, SSyncIndexMgr *pObj); +void syncIndexMgrLog(SSyncIndexMgr *pObj); +void syncIndexMgrLog2(char *s, SSyncIndexMgr *pObj); + #ifdef __cplusplus } #endif diff --git a/source/libs/sync/inc/syncInt.h b/source/libs/sync/inc/syncInt.h index 2932240ec1..df277e2d7e 100644 --- a/source/libs/sync/inc/syncInt.h +++ b/source/libs/sync/inc/syncInt.h @@ -211,11 +211,14 @@ int32_t syncNodeStopElectTimer(SSyncNode* pSyncNode); int32_t syncNodeRestartElectTimer(SSyncNode* pSyncNode, int32_t ms); int32_t syncNodeStartHeartbeatTimer(SSyncNode* pSyncNode); int32_t syncNodeStopHeartbeatTimer(SSyncNode* pSyncNode); +cJSON* syncNode2Json(const SSyncNode* pSyncNode); +char* syncNode2Str(const SSyncNode* pSyncNode); -// for debug -cJSON* syncNode2Json(const SSyncNode* pSyncNode); -char* syncNode2Str(const SSyncNode* pSyncNode); -void syncNodePrint(char* s, const SSyncNode* pSyncNode); +// for debug -------------- +void syncNodePrint(SSyncNode* pObj); +void syncNodePrint2(char* s, SSyncNode* pObj); +void syncNodeLog(SSyncNode* pObj); +void syncNodeLog2(char* s, SSyncNode* pObj); #ifdef __cplusplus } diff --git a/source/libs/sync/inc/syncRaftEntry.h b/source/libs/sync/inc/syncRaftEntry.h index e471488f5c..335d23ea8e 100644 --- a/source/libs/sync/inc/syncRaftEntry.h +++ b/source/libs/sync/inc/syncRaftEntry.h @@ -48,10 +48,10 @@ cJSON* syncEntry2Json(const SSyncRaftEntry* pEntry); char* syncEntry2Str(const SSyncRaftEntry* pEntry); // for debug -void syncEntryPrint(const SSyncRaftEntry* pEntry); -void syncEntryPrint2(char* s, const SSyncRaftEntry* pEntry); -void syncEntryLog(const SSyncRaftEntry* pEntry); -void syncEntryLog2(char* s, const SSyncRaftEntry* pEntry); +void syncEntryPrint(const SSyncRaftEntry* pObj); +void syncEntryPrint2(char* s, const SSyncRaftEntry* pObj); +void syncEntryLog(const SSyncRaftEntry* pObj); +void syncEntryLog2(char* s, const SSyncRaftEntry* pObj); #ifdef __cplusplus } diff --git a/source/libs/sync/inc/syncRaftStore.h b/source/libs/sync/inc/syncRaftStore.h index 1c25b799b4..4058d3bd1c 100644 --- a/source/libs/sync/inc/syncRaftStore.h +++ b/source/libs/sync/inc/syncRaftStore.h @@ -42,7 +42,12 @@ int32_t raftStoreClose(SRaftStore *pRaftStore); int32_t raftStorePersist(SRaftStore *pRaftStore); int32_t raftStoreSerialize(SRaftStore *pRaftStore, char *buf, size_t len); int32_t raftStoreDeserialize(SRaftStore *pRaftStore, char *buf, size_t len); -void raftStorePrint(SRaftStore *pRaftStore); + +// for debug ------------------- +void raftStorePrint(SRaftStore *pObj); +void raftStorePrint2(char *s, SRaftStore *pObj); +void raftStoreLog(SRaftStore *pObj); +void raftStoreLog2(char *s, SRaftStore *pObj); #ifdef __cplusplus } diff --git a/source/libs/sync/inc/syncVoteMgr.h b/source/libs/sync/inc/syncVoteMgr.h index ae9cfe8d01..5bc240e921 100644 --- a/source/libs/sync/inc/syncVoteMgr.h +++ b/source/libs/sync/inc/syncVoteMgr.h @@ -48,6 +48,12 @@ void voteGrantedReset(SVotesGranted *pVotesGranted, SyncTerm term); cJSON * voteGranted2Json(SVotesGranted *pVotesGranted); char * voteGranted2Str(SVotesGranted *pVotesGranted); +// for debug ------------------- +void voteGrantedPrint(SVotesGranted *pObj); +void voteGrantedPrint2(char *s, SVotesGranted *pObj); +void voteGrantedLog(SVotesGranted *pObj); +void voteGrantedLog2(char *s, SVotesGranted *pObj); + // SVotesRespond ----------------------------- typedef struct SVotesRespond { SRaftId (*replicas)[TSDB_MAX_REPLICA]; @@ -65,6 +71,12 @@ void votesRespondReset(SVotesRespond *pVotesRespond, SyncTerm term); cJSON * votesRespond2Json(SVotesRespond *pVotesRespond); char * votesRespond2Str(SVotesRespond *pVotesRespond); +// for debug ------------------- +void votesRespondPrint(SVotesRespond *pObj); +void votesRespondPrint2(char *s, SVotesRespond *pObj); +void votesRespondLog(SVotesRespond *pObj); +void votesRespondLog2(char *s, SVotesRespond *pObj); + #ifdef __cplusplus } #endif diff --git a/source/libs/sync/src/syncIndexMgr.c b/source/libs/sync/src/syncIndexMgr.c index fff54638e2..9567938197 100644 --- a/source/libs/sync/src/syncIndexMgr.c +++ b/source/libs/sync/src/syncIndexMgr.c @@ -97,4 +97,31 @@ char *syncIndexMgr2Str(SSyncIndexMgr *pSyncIndexMgr) { char * serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; +} + +// for debug ------------------- +void syncIndexMgrPrint(SSyncIndexMgr *pObj) { + char *serialized = syncIndexMgr2Str(pObj); + printf("syncIndexMgrPrint | len:%lu | %s \n", strlen(serialized), serialized); + fflush(NULL); + free(serialized); +} + +void syncIndexMgrPrint2(char *s, SSyncIndexMgr *pObj) { + char *serialized = syncIndexMgr2Str(pObj); + printf("syncIndexMgrPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + fflush(NULL); + free(serialized); +} + +void syncIndexMgrLog(SSyncIndexMgr *pObj) { + char *serialized = syncIndexMgr2Str(pObj); + sTrace("syncIndexMgrLog | len:%lu | %s", strlen(serialized), serialized); + free(serialized); +} + +void syncIndexMgrLog2(char *s, SSyncIndexMgr *pObj) { + char *serialized = syncIndexMgr2Str(pObj); + sTrace("syncIndexMgrLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + free(serialized); } \ No newline at end of file diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 5cd7149b72..860dd96cdf 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -327,11 +327,31 @@ char* syncNode2Str(const SSyncNode* pSyncNode) { return serialized; } -void syncNodePrint(char* s, const SSyncNode* pSyncNode) { - char* ss = syncNode2Str(pSyncNode); - // sTrace("syncNodePrint: %s [len:%lu]| %s", s, strlen(ss), ss); - fprintf(stderr, "syncNodePrint: %s [len:%lu]| %s", s, strlen(ss), ss); - free(ss); +// for debug -------------- +void syncNodePrint(SSyncNode* pObj) { + char* serialized = syncNode2Str(pObj); + printf("syncNodePrint | len:%lu | %s \n", strlen(serialized), serialized); + fflush(NULL); + free(serialized); +} + +void syncNodePrint2(char* s, SSyncNode* pObj) { + char* serialized = syncNode2Str(pObj); + printf("syncNodePrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + fflush(NULL); + free(serialized); +} + +void syncNodeLog(SSyncNode* pObj) { + char* serialized = syncNode2Str(pObj); + sTrace("syncNodeLog | len:%lu | %s", strlen(serialized), serialized); + free(serialized); +} + +void syncNodeLog2(char* s, SSyncNode* pObj) { + char* serialized = syncNode2Str(pObj); + sTrace("syncNodeLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + free(serialized); } int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, SRpcMsg* pMsg) { diff --git a/source/libs/sync/src/syncRaftEntry.c b/source/libs/sync/src/syncRaftEntry.c index d2feb98c90..1a5d9c9455 100644 --- a/source/libs/sync/src/syncRaftEntry.c +++ b/source/libs/sync/src/syncRaftEntry.c @@ -105,28 +105,28 @@ char* syncEntry2Str(const SSyncRaftEntry* pEntry) { } // for debug ----------- -void syncEntryPrint(const SSyncRaftEntry* pEntry) { - char* serialized = syncEntry2Str(pEntry); +void syncEntryPrint(const SSyncRaftEntry* pObj) { + char* serialized = syncEntry2Str(pObj); printf("syncEntryPrint | len:%lu | %s \n", strlen(serialized), serialized); fflush(NULL); free(serialized); } -void syncEntryPrint2(char* s, const SSyncRaftEntry* pEntry) { - char* serialized = syncEntry2Str(pEntry); - printf("syncEntryPrint | len:%lu | %s | %s \n", strlen(serialized), s, serialized); +void syncEntryPrint2(char* s, const SSyncRaftEntry* pObj) { + char* serialized = syncEntry2Str(pObj); + printf("syncEntryPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); free(serialized); } -void syncEntryLog(const SSyncRaftEntry* pEntry) { - char* serialized = syncEntry2Str(pEntry); - sTrace("syncEntryPrint | len:%lu | %s", strlen(serialized), serialized); +void syncEntryLog(const SSyncRaftEntry* pObj) { + char* serialized = syncEntry2Str(pObj); + sTrace("syncEntryLog | len:%lu | %s", strlen(serialized), serialized); free(serialized); } -void syncEntryLog2(char* s, const SSyncRaftEntry* pEntry) { - char* serialized = syncEntry2Str(pEntry); - sTrace("syncEntryPrint | len:%lu | %s | %s", strlen(serialized), s, serialized); +void syncEntryLog2(char* s, const SSyncRaftEntry* pObj) { + char* serialized = syncEntry2Str(pObj); + sTrace("syncEntryLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); free(serialized); } \ No newline at end of file diff --git a/source/libs/sync/src/syncRaftStore.c b/source/libs/sync/src/syncRaftStore.c index 7154a21bd1..3a26caa161 100644 --- a/source/libs/sync/src/syncRaftStore.c +++ b/source/libs/sync/src/syncRaftStore.c @@ -135,8 +135,30 @@ int32_t raftStoreDeserialize(SRaftStore *pRaftStore, char *buf, size_t len) { return 0; } -void raftStorePrint(SRaftStore *pRaftStore) { - char storeBuf[RAFT_STORE_BLOCK_SIZE]; - raftStoreSerialize(pRaftStore, storeBuf, sizeof(storeBuf)); - printf("%s\n", storeBuf); +// for debug ------------------- +void raftStorePrint(SRaftStore *pObj) { + char serialized[RAFT_STORE_BLOCK_SIZE]; + raftStoreSerialize(pObj, serialized, sizeof(serialized)); + printf("raftStorePrint | len:%lu | %s \n", strlen(serialized), serialized); + fflush(NULL); +} + +void raftStorePrint2(char *s, SRaftStore *pObj) { + char serialized[RAFT_STORE_BLOCK_SIZE]; + raftStoreSerialize(pObj, serialized, sizeof(serialized)); + printf("raftStorePrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + fflush(NULL); +} +void raftStoreLog(SRaftStore *pObj) { + char serialized[RAFT_STORE_BLOCK_SIZE]; + raftStoreSerialize(pObj, serialized, sizeof(serialized)); + sTrace("raftStoreLog | len:%lu | %s", strlen(serialized), serialized); + fflush(NULL); +} + +void raftStoreLog2(char *s, SRaftStore *pObj) { + char serialized[RAFT_STORE_BLOCK_SIZE]; + raftStoreSerialize(pObj, serialized, sizeof(serialized)); + sTrace("raftStoreLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + fflush(NULL); } diff --git a/source/libs/sync/src/syncVoteMgr.c b/source/libs/sync/src/syncVoteMgr.c index a2f10ce339..5c8e70979c 100644 --- a/source/libs/sync/src/syncVoteMgr.c +++ b/source/libs/sync/src/syncVoteMgr.c @@ -119,6 +119,33 @@ char *voteGranted2Str(SVotesGranted *pVotesGranted) { return serialized; } +// for debug ------------------- +void voteGrantedPrint(SVotesGranted *pObj) { + char *serialized = voteGranted2Str(pObj); + printf("voteGrantedPrint | len:%lu | %s \n", strlen(serialized), serialized); + fflush(NULL); + free(serialized); +} + +void voteGrantedPrint2(char *s, SVotesGranted *pObj) { + char *serialized = voteGranted2Str(pObj); + printf("voteGrantedPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + fflush(NULL); + free(serialized); +} + +void voteGrantedLog(SVotesGranted *pObj) { + char *serialized = voteGranted2Str(pObj); + sTrace("voteGrantedLog | len:%lu | %s", strlen(serialized), serialized); + free(serialized); +} + +void voteGrantedLog2(char *s, SVotesGranted *pObj) { + char *serialized = voteGranted2Str(pObj); + sTrace("voteGrantedLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + free(serialized); +} + // SVotesRespond ----------------------------- SVotesRespond *votesRespondCreate(SSyncNode *pSyncNode) { SVotesRespond *pVotesRespond = malloc(sizeof(SVotesRespond)); @@ -210,4 +237,31 @@ char *votesRespond2Str(SVotesRespond *pVotesRespond) { char * serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; +} + +// for debug ------------------- +void votesRespondPrint(SVotesRespond *pObj) { + char *serialized = votesRespond2Str(pObj); + printf("votesRespondPrint | len:%lu | %s \n", strlen(serialized), serialized); + fflush(NULL); + free(serialized); +} + +void votesRespondPrint2(char *s, SVotesRespond *pObj) { + char *serialized = votesRespond2Str(pObj); + printf("votesRespondPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + fflush(NULL); + free(serialized); +} + +void votesRespondLog(SVotesRespond *pObj) { + char *serialized = votesRespond2Str(pObj); + sTrace("votesRespondLog | len:%lu | %s", strlen(serialized), serialized); + free(serialized); +} + +void votesRespondLog2(char *s, SVotesRespond *pObj) { + char *serialized = votesRespond2Str(pObj); + sTrace("votesRespondLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + free(serialized); } \ No newline at end of file diff --git a/source/libs/sync/test/syncInitTest.cpp b/source/libs/sync/test/syncInitTest.cpp index b6794544eb..7898fda8c0 100644 --- a/source/libs/sync/test/syncInitTest.cpp +++ b/source/libs/sync/test/syncInitTest.cpp @@ -89,7 +89,7 @@ int main(int argc, char** argv) { SSyncNode* pSyncNode = syncInitTest(); assert(pSyncNode != NULL); - syncNodePrint((char*)"syncInitTest", pSyncNode); + syncNodePrint2((char*)"syncInitTest", pSyncNode); initRaftId(pSyncNode); diff --git a/source/libs/sync/test/syncLogStoreTest.cpp b/source/libs/sync/test/syncLogStoreTest.cpp index a5eb748de6..602fdee8c2 100644 --- a/source/libs/sync/test/syncLogStoreTest.cpp +++ b/source/libs/sync/test/syncLogStoreTest.cpp @@ -83,7 +83,7 @@ SSyncNode* syncInitTest() { return syncNodeInit(); } void logStoreTest() { logStorePrint(pSyncNode->pLogStore); for (int i = 0; i < 5; ++i) { - int32_t dataLen = 10; + int32_t dataLen = 10; SSyncRaftEntry* pEntry = syncEntryBuild(dataLen); assert(pEntry != NULL); pEntry->msgType = 1; @@ -94,7 +94,7 @@ void logStoreTest() { pEntry->index = pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore) + 1; snprintf(pEntry->data, dataLen, "value%d", i); - //syncEntryPrint2((char*)"write entry:", pEntry); + // syncEntryPrint2((char*)"write entry:", pEntry); pSyncNode->pLogStore->appendEntry(pSyncNode->pLogStore, pEntry); syncEntryDestory(pEntry); } @@ -132,8 +132,8 @@ int main(int argc, char** argv) { pSyncNode = syncInitTest(); assert(pSyncNode != NULL); - //syncNodePrint((char*)"syncLogStoreTest", pSyncNode); - //initRaftId(pSyncNode); + // syncNodePrint((char*)"syncLogStoreTest", pSyncNode); + // initRaftId(pSyncNode); logStoreTest(); diff --git a/source/libs/sync/test/syncPingTest.cpp b/source/libs/sync/test/syncPingTest.cpp index 83f1f67eb1..e69878632f 100644 --- a/source/libs/sync/test/syncPingTest.cpp +++ b/source/libs/sync/test/syncPingTest.cpp @@ -86,7 +86,7 @@ int main(int argc, char** argv) { SSyncNode* pSyncNode = syncInitTest(); assert(pSyncNode != NULL); - syncNodePrint((char*)"----1", pSyncNode); + syncNodePrint2((char*)"----1", pSyncNode); initRaftId(pSyncNode); @@ -95,7 +95,7 @@ int main(int argc, char** argv) { sTrace("syncNodeStartPingTimer ..."); ret = syncNodeStartPingTimer(pSyncNode); assert(ret == 0); - syncNodePrint((char*)"----2", pSyncNode); + syncNodePrint2((char*)"----2", pSyncNode); sTrace("sleep ..."); taosMsleep(10000); @@ -103,7 +103,7 @@ int main(int argc, char** argv) { sTrace("syncNodeStopPingTimer ..."); ret = syncNodeStopPingTimer(pSyncNode); assert(ret == 0); - syncNodePrint((char*)"----3", pSyncNode); + syncNodePrint2((char*)"----3", pSyncNode); sTrace("sleep ..."); taosMsleep(5000); @@ -111,7 +111,7 @@ int main(int argc, char** argv) { sTrace("syncNodeStartPingTimer ..."); ret = syncNodeStartPingTimer(pSyncNode); assert(ret == 0); - syncNodePrint((char*)"----4", pSyncNode); + syncNodePrint2((char*)"----4", pSyncNode); sTrace("sleep ..."); taosMsleep(10000); @@ -119,7 +119,7 @@ int main(int argc, char** argv) { sTrace("syncNodeStopPingTimer ..."); ret = syncNodeStopPingTimer(pSyncNode); assert(ret == 0); - syncNodePrint((char*)"----5", pSyncNode); + syncNodePrint2((char*)"----5", pSyncNode); while (1) { sTrace("while 1 sleep ..."); diff --git a/source/libs/sync/test/syncRaftStoreTest.cpp b/source/libs/sync/test/syncRaftStoreTest.cpp index 71c0138c8d..0c1c9b881e 100644 --- a/source/libs/sync/test/syncRaftStoreTest.cpp +++ b/source/libs/sync/test/syncRaftStoreTest.cpp @@ -22,15 +22,21 @@ int main() { SRaftStore *pRaftStore = raftStoreOpen("./raft_store.json"); assert(pRaftStore != NULL); - raftStorePrint(pRaftStore); +#if 0 pRaftStore->currentTerm = 100; pRaftStore->voteFor.addr = 200; pRaftStore->voteFor.vgId = 300; - - raftStorePrint(pRaftStore); raftStorePersist(pRaftStore); + raftStorePrint(pRaftStore); +#endif + + ++(pRaftStore->currentTerm); + ++(pRaftStore->voteFor.addr); + ++(pRaftStore->voteFor.vgId); + raftStorePersist(pRaftStore); + raftStorePrint(pRaftStore); return 0; }