sync refactor
This commit is contained in:
parent
ffe442301c
commit
54c260738f
|
@ -231,6 +231,61 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
|
|||
|
||||
// tla+ log vars
|
||||
|
||||
// ping timer
|
||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pPingTimer);
|
||||
cJSON_AddStringToObject(pRoot, "pPingTimer", u64buf);
|
||||
cJSON_AddNumberToObject(pRoot, "pingTimerMS", pSyncNode->pingTimerMS);
|
||||
snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->pingTimerLogicClock);
|
||||
cJSON_AddStringToObject(pRoot, "pingTimerLogicClock", u64buf);
|
||||
snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->pingTimerLogicClockUser);
|
||||
cJSON_AddStringToObject(pRoot, "pingTimerLogicClockUser", u64buf);
|
||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpPingTimer);
|
||||
cJSON_AddStringToObject(pRoot, "FpPingTimer", u64buf);
|
||||
snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->pingTimerCounter);
|
||||
cJSON_AddStringToObject(pRoot, "pingTimerCounter", u64buf);
|
||||
|
||||
// elect timer
|
||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pElectTimer);
|
||||
cJSON_AddStringToObject(pRoot, "pElectTimer", u64buf);
|
||||
cJSON_AddNumberToObject(pRoot, "electTimerMS", pSyncNode->electTimerMS);
|
||||
snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->electTimerLogicClock);
|
||||
cJSON_AddStringToObject(pRoot, "electTimerLogicClock", u64buf);
|
||||
snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->electTimerLogicClockUser);
|
||||
cJSON_AddStringToObject(pRoot, "electTimerLogicClockUser", u64buf);
|
||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpElectTimer);
|
||||
cJSON_AddStringToObject(pRoot, "FpElectTimer", u64buf);
|
||||
snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->electTimerCounter);
|
||||
cJSON_AddStringToObject(pRoot, "electTimerCounter", u64buf);
|
||||
|
||||
// heartbeat timer
|
||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pHeartbeatTimer);
|
||||
cJSON_AddStringToObject(pRoot, "pHeartbeatTimer", u64buf);
|
||||
cJSON_AddNumberToObject(pRoot, "heartbeatTimerMS", pSyncNode->heartbeatTimerMS);
|
||||
snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->heartbeatTimerLogicClock);
|
||||
cJSON_AddStringToObject(pRoot, "heartbeatTimerLogicClock", u64buf);
|
||||
snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->heartbeatTimerLogicClockUser);
|
||||
cJSON_AddStringToObject(pRoot, "heartbeatTimerLogicClockUser", u64buf);
|
||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpHeartbeatTimer);
|
||||
cJSON_AddStringToObject(pRoot, "FpHeartbeatTimer", u64buf);
|
||||
snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->heartbeatTimerCounter);
|
||||
cJSON_AddStringToObject(pRoot, "heartbeatTimerCounter", u64buf);
|
||||
|
||||
// callback
|
||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnPing);
|
||||
cJSON_AddStringToObject(pRoot, "FpOnPing", u64buf);
|
||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnPingReply);
|
||||
cJSON_AddStringToObject(pRoot, "FpOnPingReply", u64buf);
|
||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnRequestVote);
|
||||
cJSON_AddStringToObject(pRoot, "FpOnRequestVote", u64buf);
|
||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnRequestVoteReply);
|
||||
cJSON_AddStringToObject(pRoot, "FpOnRequestVoteReply", u64buf);
|
||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnAppendEntries);
|
||||
cJSON_AddStringToObject(pRoot, "FpOnAppendEntries", u64buf);
|
||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnAppendEntriesReply);
|
||||
cJSON_AddStringToObject(pRoot, "FpOnAppendEntriesReply", u64buf);
|
||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnTimeout);
|
||||
cJSON_AddStringToObject(pRoot, "FpOnTimeout", u64buf);
|
||||
|
||||
cJSON* pJson = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(pJson, "SSyncNode", pRoot);
|
||||
return pJson;
|
||||
|
|
|
@ -97,7 +97,7 @@ void syncUtilbufCopyDeep(const SSyncBuffer* src, SSyncBuffer* dest) {
|
|||
|
||||
int32_t syncUtilRand(int32_t max) { return rand() % max; }
|
||||
|
||||
int32_t syncUtilElectRandomMS() { ELECT_TIMER_MS_MIN + syncUtilRand(ELECT_TIMER_MS_RANGE); }
|
||||
int32_t syncUtilElectRandomMS() { return ELECT_TIMER_MS_MIN + syncUtilRand(ELECT_TIMER_MS_RANGE); }
|
||||
|
||||
int32_t syncUtilQuorum(int32_t replicaNum) { return replicaNum / 2 + 1; }
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ add_executable(syncRaftStoreTest "")
|
|||
add_executable(syncEnqTest "")
|
||||
add_executable(syncIndexTest "")
|
||||
add_executable(syncInitTest "")
|
||||
add_executable(syncUtilTest "")
|
||||
|
||||
|
||||
target_sources(syncTest
|
||||
|
@ -65,6 +66,10 @@ target_sources(syncInitTest
|
|||
PRIVATE
|
||||
"syncInitTest.cpp"
|
||||
)
|
||||
target_sources(syncUtilTest
|
||||
PRIVATE
|
||||
"syncUtilTest.cpp"
|
||||
)
|
||||
|
||||
|
||||
target_include_directories(syncTest
|
||||
|
@ -132,6 +137,11 @@ target_include_directories(syncInitTest
|
|||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncUtilTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
|
||||
|
||||
target_link_libraries(syncTest
|
||||
|
@ -186,6 +196,10 @@ target_link_libraries(syncInitTest
|
|||
sync
|
||||
gtest_main
|
||||
)
|
||||
target_link_libraries(syncUtilTest
|
||||
sync
|
||||
gtest_main
|
||||
)
|
||||
|
||||
|
||||
enable_testing()
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
#include "syncUtil.h"
|
||||
//#include <gtest/gtest.h>
|
||||
#include <stdio.h>
|
||||
#include "syncIO.h"
|
||||
#include "syncInt.h"
|
||||
#include "syncRaftStore.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");
|
||||
}
|
||||
|
||||
void electRandomMSTest() {
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
int32_t ms = syncUtilElectRandomMS();
|
||||
printf("syncUtilElectRandomMS: %d \n", ms);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
// taosInitLog((char *)"syncTest.log", 100000, 10);
|
||||
tsAsyncLog = 0;
|
||||
sDebugFlag = 143 + 64;
|
||||
logTest();
|
||||
electRandomMSTest();
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue