refact: adjust sync log
This commit is contained in:
parent
76649005dd
commit
a1c8db0f88
|
@ -40,6 +40,28 @@ extern "C" {
|
||||||
#define sInfoLong(...) do { if (sDebugFlag & DEBUG_INFO) { taosPrintLongString("SYN ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0)
|
#define sInfoLong(...) do { if (sDebugFlag & DEBUG_INFO) { taosPrintLongString("SYN ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0)
|
||||||
#define sDebugLong(...) do { if (sDebugFlag & DEBUG_DEBUG) { taosPrintLongString("SYN ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__); }} while(0)
|
#define sDebugLong(...) do { if (sDebugFlag & DEBUG_DEBUG) { taosPrintLongString("SYN ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
#define sTraceLong(...) do { if (sDebugFlag & DEBUG_TRACE) { taosPrintLongString("SYN ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__); }} while(0)
|
#define sTraceLong(...) do { if (sDebugFlag & DEBUG_TRACE) { taosPrintLongString("SYN ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
|
|
||||||
|
#define sNFatal(pNode, ...) if (sDebugFlag & DEBUG_FATAL) { syncPrintNodeLog("SYN FATAL ", DEBUG_FATAL, 255, pNode, __VA_ARGS__); }
|
||||||
|
#define sNError(pNode, ...) if (sDebugFlag & DEBUG_ERROR) { syncPrintNodeLog("SYN ERROR ", DEBUG_ERROR, 255, pNode, __VA_ARGS__); }
|
||||||
|
#define sNWarn(pNode, ...) if (sDebugFlag & DEBUG_WARN) { syncPrintNodeLog("SYN WARN ", DEBUG_WARN, 255, pNode, __VA_ARGS__); }
|
||||||
|
#define sNInfo(pNode, ...) if (sDebugFlag & DEBUG_INFO) { syncPrintNodeLog("SYN ", DEBUG_INFO, 255, pNode, __VA_ARGS__); }
|
||||||
|
#define sNDebug(pNode, ...) if (sDebugFlag & DEBUG_DEBUG) { syncPrintNodeLog("SYN ", DEBUG_DEBUG, sDebugFlag, pNode, __VA_ARGS__); }
|
||||||
|
#define sNTrace(pNode, ...) if (sDebugFlag & DEBUG_TRACE) { syncPrintNodeLog("SYN ", DEBUG_TRACE, sDebugFlag, pNode, __VA_ARGS__); }
|
||||||
|
|
||||||
|
#define sSFatal(pSender, ...) if (sDebugFlag & DEBUG_FATAL) { syncPrintSnapshotSenderLog("SYN FATAL ", DEBUG_FATAL, 255, pSender, __VA_ARGS__); }
|
||||||
|
#define sSError(pSender, ...) if (sDebugFlag & DEBUG_ERROR) { syncPrintSnapshotSenderLog("SYN ERROR ", DEBUG_ERROR, 255, pSender, __VA_ARGS__); }
|
||||||
|
#define sSWarn(pSender, ...) if (sDebugFlag & DEBUG_WARN) { syncPrintSnapshotSenderLog("SYN WARN ", DEBUG_WARN, 255, pSender, __VA_ARGS__); }
|
||||||
|
#define sSInfo(pSender, ...) if (sDebugFlag & DEBUG_INFO) { syncPrintSnapshotSenderLog("SYN ", DEBUG_INFO, 255, pSender, __VA_ARGS__); }
|
||||||
|
#define sSDebug(pSender, ...) if (sDebugFlag & DEBUG_DEBUG) { syncPrintSnapshotSenderLog("SYN ", DEBUG_DEBUG, sDebugFlag, pSender, __VA_ARGS__); }
|
||||||
|
#define sSTrace(pSender, ...) if (sDebugFlag & DEBUG_TRACE) { syncPrintSnapshotSenderLog("SYN ", DEBUG_TRACE, sDebugFlag, pSender, __VA_ARGS__); }
|
||||||
|
|
||||||
|
#define sRFatal(pReceiver, ...) if (sDebugFlag & DEBUG_FATAL) { syncPrintSnapshotReceiverLog("SYN FATAL ", DEBUG_FATAL, 255, pReceiver, __VA_ARGS__); }
|
||||||
|
#define sRError(pReceiver, ...) if (sDebugFlag & DEBUG_ERROR) { syncPrintSnapshotReceiverLog("SYN ERROR ", DEBUG_ERROR, 255, pReceiver, __VA_ARGS__); }
|
||||||
|
#define sRWarn(pReceiver, ...) if (sDebugFlag & DEBUG_WARN) { syncPrintSnapshotReceiverLog("SYN WARN ", DEBUG_WARN, 255, pReceiver, __VA_ARGS__); }
|
||||||
|
#define sRInfo(pReceiver, ...) if (sDebugFlag & DEBUG_INFO) { syncPrintSnapshotReceiverLog("SYN ", DEBUG_INFO, 255, pReceiver, __VA_ARGS__); }
|
||||||
|
#define sRDebug(pReceiver, ...) if (sDebugFlag & DEBUG_DEBUG) { syncPrintSnapshotReceiverLog("SYN ", DEBUG_DEBUG, sDebugFlag, pReceiver, __VA_ARGS__); }
|
||||||
|
#define sRTrace(pReceiver, ...) if (sDebugFlag & DEBUG_TRACE) { syncPrintSnapshotReceiverLog("SYN ", DEBUG_TRACE, sDebugFlag, pReceiver, __VA_ARGS__); }
|
||||||
|
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
typedef struct SyncTimeout SyncTimeout;
|
typedef struct SyncTimeout SyncTimeout;
|
||||||
|
@ -250,8 +272,6 @@ int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, S
|
||||||
int32_t syncNodeSendMsgByInfo(const SNodeInfo* nodeInfo, SSyncNode* pSyncNode, SRpcMsg* pMsg);
|
int32_t syncNodeSendMsgByInfo(const SNodeInfo* nodeInfo, SSyncNode* pSyncNode, SRpcMsg* pMsg);
|
||||||
cJSON* syncNode2Json(const SSyncNode* pSyncNode);
|
cJSON* syncNode2Json(const SSyncNode* pSyncNode);
|
||||||
char* syncNode2Str(const SSyncNode* pSyncNode);
|
char* syncNode2Str(const SSyncNode* pSyncNode);
|
||||||
void syncNodeEventLog(const SSyncNode* pSyncNode, char* str);
|
|
||||||
void syncNodeErrorLog(const SSyncNode* pSyncNode, char* str);
|
|
||||||
char* syncNode2SimpleStr(const SSyncNode* pSyncNode);
|
char* syncNode2SimpleStr(const SSyncNode* pSyncNode);
|
||||||
bool syncNodeInConfig(SSyncNode* pSyncNode, const SSyncCfg* config);
|
bool syncNodeInConfig(SSyncNode* pSyncNode, const SSyncCfg* config);
|
||||||
void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* newConfig, SyncIndex lastConfigChangeIndex);
|
void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* newConfig, SyncIndex lastConfigChangeIndex);
|
||||||
|
@ -357,6 +377,13 @@ void syncNodeLog(SSyncNode* pObj);
|
||||||
void syncNodeLog2(char* s, SSyncNode* pObj);
|
void syncNodeLog2(char* s, SSyncNode* pObj);
|
||||||
void syncNodeLog3(char* s, SSyncNode* pObj);
|
void syncNodeLog3(char* s, SSyncNode* pObj);
|
||||||
|
|
||||||
|
// syncUtil.h
|
||||||
|
void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNode* pNode, const char* format, ...);
|
||||||
|
void syncPrintSnapshotSenderLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotSender* pSender,
|
||||||
|
const char* format, ...);
|
||||||
|
void syncPrintSnapshotReceiverLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotReceiver* pReceiver,
|
||||||
|
const char* format, ...);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -75,7 +75,7 @@ int32_t raftCfgAddConfigIndex(SRaftCfg *pRaftCfg, SyncIndex configIndex);
|
||||||
|
|
||||||
cJSON *syncCfg2Json(SSyncCfg *pSyncCfg);
|
cJSON *syncCfg2Json(SSyncCfg *pSyncCfg);
|
||||||
char *syncCfg2Str(SSyncCfg *pSyncCfg);
|
char *syncCfg2Str(SSyncCfg *pSyncCfg);
|
||||||
char * syncCfg2SimpleStr(SSyncCfg *pSyncCfg);
|
void syncCfg2SimpleStr(const SSyncCfg *pCfg, char *str, int32_t bufLen);
|
||||||
int32_t syncCfgFromJson(const cJSON *pRoot, SSyncCfg *pSyncCfg);
|
int32_t syncCfgFromJson(const cJSON *pRoot, SSyncCfg *pSyncCfg);
|
||||||
int32_t syncCfgFromStr(const char *s, SSyncCfg *pSyncCfg);
|
int32_t syncCfgFromStr(const char *s, SSyncCfg *pSyncCfg);
|
||||||
|
|
||||||
|
@ -93,21 +93,7 @@ typedef struct SRaftCfgMeta {
|
||||||
|
|
||||||
int32_t raftCfgCreateFile(SSyncCfg *pCfg, SRaftCfgMeta meta, const char *path);
|
int32_t raftCfgCreateFile(SSyncCfg *pCfg, SRaftCfgMeta meta, const char *path);
|
||||||
|
|
||||||
// for debug ----------------------
|
// for debug -------------------
|
||||||
void syncCfgPrint(SSyncCfg *pCfg);
|
|
||||||
void syncCfgPrint2(char *s, SSyncCfg *pCfg);
|
|
||||||
void syncCfgLog(SSyncCfg *pCfg);
|
|
||||||
void syncCfgLog2(char *s, SSyncCfg *pCfg);
|
|
||||||
void syncCfgLog3(char *s, SSyncCfg *pCfg);
|
|
||||||
|
|
||||||
void raftCfgPrint(SRaftCfg *pCfg);
|
|
||||||
void raftCfgPrint2(char *s, SRaftCfg *pCfg);
|
|
||||||
void raftCfgLog(SRaftCfg *pCfg);
|
|
||||||
void raftCfgLog2(char *s, SRaftCfg *pCfg);
|
|
||||||
|
|
||||||
void raftCfgIndexPrint(SRaftCfgIndex *pCfg);
|
|
||||||
void raftCfgIndexPrint2(char *s, SRaftCfgIndex *pCfg);
|
|
||||||
void raftCfgIndexLog(SRaftCfgIndex *pCfg);
|
|
||||||
void raftCfgIndexLog2(char *s, SRaftCfgIndex *pCfg);
|
void raftCfgIndexLog2(char *s, SRaftCfgIndex *pCfg);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -67,7 +67,6 @@ int32_t snapshotReSend(SSyncSnapshotSender *pSender);
|
||||||
|
|
||||||
cJSON *snapshotSender2Json(SSyncSnapshotSender *pSender);
|
cJSON *snapshotSender2Json(SSyncSnapshotSender *pSender);
|
||||||
char *snapshotSender2Str(SSyncSnapshotSender *pSender);
|
char *snapshotSender2Str(SSyncSnapshotSender *pSender);
|
||||||
char *snapshotSender2SimpleStr(SSyncSnapshotSender *pSender, char *event);
|
|
||||||
|
|
||||||
int32_t syncNodeStartSnapshot(SSyncNode *pSyncNode, SRaftId *pDestId);
|
int32_t syncNodeStartSnapshot(SSyncNode *pSyncNode, SRaftId *pDestId);
|
||||||
|
|
||||||
|
@ -96,7 +95,6 @@ void snapshotReceiverForceStop(SSyncSnapshotReceiver *pReceive
|
||||||
|
|
||||||
cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver);
|
cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver);
|
||||||
char *snapshotReceiver2Str(SSyncSnapshotReceiver *pReceiver);
|
char *snapshotReceiver2Str(SSyncSnapshotReceiver *pReceiver);
|
||||||
char *snapshotReceiver2SimpleStr(SSyncSnapshotReceiver *pReceiver, char *event);
|
|
||||||
|
|
||||||
//---------------------------------------------------
|
//---------------------------------------------------
|
||||||
// on message
|
// on message
|
||||||
|
|
|
@ -20,48 +20,35 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "syncInt.h"
|
#include "syncInt.h"
|
||||||
#include "syncMessage.h"
|
|
||||||
#include "taosdef.h"
|
|
||||||
|
|
||||||
// ---- encode / decode
|
|
||||||
uint64_t syncUtilAddr2U64(const char* host, uint16_t port);
|
uint64_t syncUtilAddr2U64(const char* host, uint16_t port);
|
||||||
void syncUtilU642Addr(uint64_t u64, char* host, size_t len, uint16_t* port);
|
void syncUtilU642Addr(uint64_t u64, char* host, int64_t len, uint16_t* port);
|
||||||
void syncUtilnodeInfo2EpSet(const SNodeInfo* pNodeInfo, SEpSet* pEpSet);
|
void syncUtilnodeInfo2EpSet(const SNodeInfo* pInfo, SEpSet* pEpSet);
|
||||||
void syncUtilraftId2EpSet(const SRaftId* raftId, SEpSet* pEpSet);
|
void syncUtilraftId2EpSet(const SRaftId* raftId, SEpSet* pEpSet);
|
||||||
bool syncUtilnodeInfo2raftId(const SNodeInfo* pNodeInfo, SyncGroupId vgId, SRaftId* raftId);
|
bool syncUtilnodeInfo2raftId(const SNodeInfo* pInfo, SyncGroupId vgId, SRaftId* raftId);
|
||||||
bool syncUtilSameId(const SRaftId* pId1, const SRaftId* pId2);
|
bool syncUtilSameId(const SRaftId* pId1, const SRaftId* pId2);
|
||||||
bool syncUtilEmptyId(const SRaftId* pId);
|
bool syncUtilEmptyId(const SRaftId* pId);
|
||||||
|
|
||||||
// ---- SSyncBuffer ----
|
|
||||||
void syncUtilbufBuild(SSyncBuffer* syncBuf, size_t len);
|
|
||||||
void syncUtilbufDestroy(SSyncBuffer* syncBuf);
|
|
||||||
void syncUtilbufCopy(const SSyncBuffer* src, SSyncBuffer* dest);
|
|
||||||
void syncUtilbufCopyDeep(const SSyncBuffer* src, SSyncBuffer* dest);
|
|
||||||
|
|
||||||
// ---- misc ----
|
|
||||||
int32_t syncUtilRand(int32_t max);
|
|
||||||
int32_t syncUtilElectRandomMS(int32_t min, int32_t max);
|
int32_t syncUtilElectRandomMS(int32_t min, int32_t max);
|
||||||
int32_t syncUtilQuorum(int32_t replicaNum);
|
int32_t syncUtilQuorum(int32_t replicaNum);
|
||||||
cJSON* syncUtilNodeInfo2Json(const SNodeInfo* p);
|
cJSON* syncUtilNodeInfo2Json(const SNodeInfo* p);
|
||||||
cJSON* syncUtilRaftId2Json(const SRaftId* p);
|
cJSON* syncUtilRaftId2Json(const SRaftId* p);
|
||||||
char* syncUtilRaftId2Str(const SRaftId* p);
|
char* syncUtilRaftId2Str(const SRaftId* p);
|
||||||
const char* syncStr(ESyncState state);
|
const char* syncStr(ESyncState state);
|
||||||
bool syncUtilCanPrint(char c);
|
char* syncUtilPrintBin(char* ptr, uint32_t len);
|
||||||
char* syncUtilprintBin(char* ptr, uint32_t len);
|
char* syncUtilPrintBin2(char* ptr, uint32_t len);
|
||||||
char* syncUtilprintBin2(char* ptr, uint32_t len);
|
|
||||||
SyncIndex syncUtilMinIndex(SyncIndex a, SyncIndex b);
|
|
||||||
SyncIndex syncUtilMaxIndex(SyncIndex a, SyncIndex b);
|
|
||||||
void syncUtilMsgHtoN(void* msg);
|
void syncUtilMsgHtoN(void* msg);
|
||||||
void syncUtilMsgNtoH(void* msg);
|
void syncUtilMsgNtoH(void* msg);
|
||||||
bool syncUtilIsData(tmsg_t msgType);
|
|
||||||
bool syncUtilUserPreCommit(tmsg_t msgType);
|
bool syncUtilUserPreCommit(tmsg_t msgType);
|
||||||
bool syncUtilUserCommit(tmsg_t msgType);
|
bool syncUtilUserCommit(tmsg_t msgType);
|
||||||
bool syncUtilUserRollback(tmsg_t msgType);
|
bool syncUtilUserRollback(tmsg_t msgType);
|
||||||
void syncUtilJson2Line(char* jsonStr);
|
|
||||||
|
void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNode* pNode, const char* format, ...);
|
||||||
|
void syncPrintSnapshotSenderLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotSender* pSender,
|
||||||
|
const char* format, ...);
|
||||||
|
void syncPrintSnapshotReceiverLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotReceiver* pReceiver,
|
||||||
|
const char* format, ...);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@
|
||||||
|
|
||||||
int32_t syncNodeFollowerCommit(SSyncNode* ths, SyncIndex newCommitIndex) {
|
int32_t syncNodeFollowerCommit(SSyncNode* ths, SyncIndex newCommitIndex) {
|
||||||
if (ths->state != TAOS_SYNC_STATE_FOLLOWER) {
|
if (ths->state != TAOS_SYNC_STATE_FOLLOWER) {
|
||||||
syncNodeEventLog(ths, "can not do follower commit");
|
sNTrace(ths, "can not do follower commit");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,11 +106,7 @@ int32_t syncNodeFollowerCommit(SSyncNode* ths, SyncIndex newCommitIndex) {
|
||||||
SyncIndex commitBegin = ths->commitIndex;
|
SyncIndex commitBegin = ths->commitIndex;
|
||||||
SyncIndex commitEnd = snapshot.lastApplyIndex;
|
SyncIndex commitEnd = snapshot.lastApplyIndex;
|
||||||
ths->commitIndex = snapshot.lastApplyIndex;
|
ths->commitIndex = snapshot.lastApplyIndex;
|
||||||
|
sNTrace(ths, "commit by snapshot from index:%" PRId64 " to index:%" PRId64, commitBegin, commitEnd);
|
||||||
char eventLog[128];
|
|
||||||
snprintf(eventLog, sizeof(eventLog), "commit by snapshot from index:%" PRId64 " to index:%" PRId64, commitBegin,
|
|
||||||
commitEnd);
|
|
||||||
syncNodeEventLog(ths, eventLog);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncIndex beginIndex = ths->commitIndex + 1;
|
SyncIndex beginIndex = ths->commitIndex + 1;
|
||||||
|
@ -192,11 +188,7 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
||||||
if (code == 0) {
|
if (code == 0) {
|
||||||
if (pLocalEntry->term == pAppendEntry->term) {
|
if (pLocalEntry->term == pAppendEntry->term) {
|
||||||
// do nothing
|
// do nothing
|
||||||
|
sNTrace(ths, "log match, do nothing, index:%" PRId64, appendIndex);
|
||||||
char logBuf[128];
|
|
||||||
snprintf(logBuf, sizeof(logBuf), "log match, do nothing, index:%" PRId64, appendIndex);
|
|
||||||
syncNodeEventLog(ths, logBuf);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// truncate
|
// truncate
|
||||||
code = ths->pLogStore->syncLogTruncate(ths->pLogStore, appendIndex);
|
code = ths->pLogStore->syncLogTruncate(ths->pLogStore, appendIndex);
|
||||||
|
|
|
@ -43,12 +43,7 @@
|
||||||
static void syncNodeStartSnapshotOnce(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, SyncTerm lastApplyTerm,
|
static void syncNodeStartSnapshotOnce(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, SyncTerm lastApplyTerm,
|
||||||
SyncAppendEntriesReply* pMsg) {
|
SyncAppendEntriesReply* pMsg) {
|
||||||
if (beginIndex > endIndex) {
|
if (beginIndex > endIndex) {
|
||||||
do {
|
sNError(ths, "snapshot param error, start:%" PRId64 ", end:%" PRId64, beginIndex, endIndex);
|
||||||
char logBuf[128];
|
|
||||||
snprintf(logBuf, sizeof(logBuf), "snapshot param error, start:%" PRId64 ", end:%" PRId64, beginIndex, endIndex);
|
|
||||||
syncNodeErrorLog(ths, logBuf);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,12 +52,7 @@ static void syncNodeStartSnapshotOnce(SSyncNode* ths, SyncIndex beginIndex, Sync
|
||||||
ASSERT(pSender != NULL);
|
ASSERT(pSender != NULL);
|
||||||
|
|
||||||
if (snapshotSenderIsStart(pSender)) {
|
if (snapshotSenderIsStart(pSender)) {
|
||||||
do {
|
sSError(pSender, "snapshot sender already start");
|
||||||
char* eventLog = snapshotSender2SimpleStr(pSender, "snapshot sender already start");
|
|
||||||
syncNodeErrorLog(ths, eventLog);
|
|
||||||
taosMemoryFree(eventLog);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,12 +51,12 @@ void syncOneReplicaAdvance(SSyncNode* pSyncNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) {
|
if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) {
|
||||||
syncNodeErrorLog(pSyncNode, "not leader, can not advance commit index");
|
sNError(pSyncNode, "not leader, can not advance commit index");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pSyncNode->replicaNum != 1) {
|
if (pSyncNode->replicaNum != 1) {
|
||||||
syncNodeErrorLog(pSyncNode, "not one replica, can not advance commit index");
|
sNError(pSyncNode, "not one replica, can not advance commit index");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,23 +67,13 @@ void syncOneReplicaAdvance(SSyncNode* pSyncNode) {
|
||||||
SyncIndex commitBegin = pSyncNode->commitIndex;
|
SyncIndex commitBegin = pSyncNode->commitIndex;
|
||||||
SyncIndex commitEnd = snapshot.lastApplyIndex;
|
SyncIndex commitEnd = snapshot.lastApplyIndex;
|
||||||
pSyncNode->commitIndex = snapshot.lastApplyIndex;
|
pSyncNode->commitIndex = snapshot.lastApplyIndex;
|
||||||
|
sNTrace(pSyncNode, "commit by snapshot from index:%" PRId64 " to index:%" PRId64, commitBegin, commitEnd);
|
||||||
char eventLog[128];
|
|
||||||
snprintf(eventLog, sizeof(eventLog), "commit by snapshot from index:%" PRId64 " to index:%" PRId64, commitBegin,
|
|
||||||
commitEnd);
|
|
||||||
syncNodeEventLog(pSyncNode, eventLog);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// advance commit index as large as possible
|
// advance commit index as large as possible
|
||||||
SyncIndex lastIndex = syncNodeGetLastIndex(pSyncNode);
|
SyncIndex lastIndex = syncNodeGetLastIndex(pSyncNode);
|
||||||
if (lastIndex > pSyncNode->commitIndex) {
|
if (lastIndex > pSyncNode->commitIndex) {
|
||||||
do {
|
sNTrace(pSyncNode, "commit by wal from index:%" PRId64 " to index:%" PRId64, pSyncNode->commitIndex + 1, lastIndex);
|
||||||
char eventLog[128];
|
|
||||||
snprintf(eventLog, sizeof(eventLog), "commit by wal from index:%" PRId64 " to index:%" PRId64,
|
|
||||||
pSyncNode->commitIndex + 1, lastIndex);
|
|
||||||
syncNodeEventLog(pSyncNode, eventLog);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
pSyncNode->commitIndex = lastIndex;
|
pSyncNode->commitIndex = lastIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +91,7 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) {
|
if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) {
|
||||||
syncNodeErrorLog(pSyncNode, "not leader, can not advance commit index");
|
sNError(pSyncNode, "not leader, can not advance commit index");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,11 +102,7 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
|
||||||
SyncIndex commitBegin = pSyncNode->commitIndex;
|
SyncIndex commitBegin = pSyncNode->commitIndex;
|
||||||
SyncIndex commitEnd = snapshot.lastApplyIndex;
|
SyncIndex commitEnd = snapshot.lastApplyIndex;
|
||||||
pSyncNode->commitIndex = snapshot.lastApplyIndex;
|
pSyncNode->commitIndex = snapshot.lastApplyIndex;
|
||||||
|
sNTrace(pSyncNode, "commit by snapshot from index:%" PRId64 " to index:%" PRId64, commitBegin, commitEnd);
|
||||||
char eventLog[128];
|
|
||||||
snprintf(eventLog, sizeof(eventLog), "commit by snapshot from index:%" PRId64 " to index:%" PRId64, commitBegin,
|
|
||||||
commitEnd);
|
|
||||||
syncNodeEventLog(pSyncNode, eventLog);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// update commit index
|
// update commit index
|
||||||
|
@ -134,9 +120,7 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
|
||||||
} else {
|
} else {
|
||||||
int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, index, &pEntry);
|
int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, index, &pEntry);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
char logBuf[128];
|
sNError(pSyncNode, "advance commit index error, read wal index:%" PRId64, index);
|
||||||
snprintf(logBuf, sizeof(logBuf), "advance commit index error, read wal index:%" PRId64, index);
|
|
||||||
syncNodeErrorLog(pSyncNode, logBuf);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,12 +137,8 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
|
||||||
|
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
do {
|
sNTrace(pSyncNode, "can not commit due to term not equal, index:%" PRId64 ", term:%" PRIu64, pEntry->index,
|
||||||
char logBuf[128];
|
pEntry->term);
|
||||||
snprintf(logBuf, sizeof(logBuf), "can not commit due to term not equal, index:%" PRId64 ", term:%" PRIu64,
|
|
||||||
pEntry->index, pEntry->term);
|
|
||||||
syncNodeEventLog(pSyncNode, logBuf);
|
|
||||||
} while (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (h) {
|
if (h) {
|
||||||
|
@ -190,10 +170,8 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
|
||||||
if (pSyncNode->pFsm != NULL) {
|
if (pSyncNode->pFsm != NULL) {
|
||||||
int32_t code = syncNodeDoCommit(pSyncNode, beginIndex, endIndex, pSyncNode->state);
|
int32_t code = syncNodeDoCommit(pSyncNode, beginIndex, endIndex, pSyncNode->state);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
char logBuf[128];
|
sNError(pSyncNode, "advance commit index error, do commit begin:%" PRId64 ", end:%" PRId64, beginIndex,
|
||||||
snprintf(logBuf, sizeof(logBuf), "advance commit index error, do commit begin:%" PRId64 ", end:%" PRId64,
|
endIndex);
|
||||||
beginIndex, endIndex);
|
|
||||||
syncNodeErrorLog(pSyncNode, logBuf);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
|
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
|
||||||
|
|
||||||
int32_t syncNodeElect(SSyncNode* pSyncNode) {
|
int32_t syncNodeElect(SSyncNode* pSyncNode) {
|
||||||
syncNodeEventLog(pSyncNode, "begin election");
|
sNTrace(pSyncNode, "begin election");
|
||||||
|
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
if (pSyncNode->state == TAOS_SYNC_STATE_FOLLOWER) {
|
if (pSyncNode->state == TAOS_SYNC_STATE_FOLLOWER) {
|
||||||
|
@ -40,7 +40,7 @@ int32_t syncNodeElect(SSyncNode* pSyncNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pSyncNode->state != TAOS_SYNC_STATE_CANDIDATE) {
|
if (pSyncNode->state != TAOS_SYNC_STATE_CANDIDATE) {
|
||||||
syncNodeErrorLog(pSyncNode, "not candidate, can not elect");
|
sNError(pSyncNode, "not candidate, can not elect");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ int32_t syncNodeElect(SSyncNode* pSyncNode) {
|
||||||
|
|
||||||
int32_t syncNodeRequestVotePeers(SSyncNode* pSyncNode) {
|
int32_t syncNodeRequestVotePeers(SSyncNode* pSyncNode) {
|
||||||
if (pSyncNode->state != TAOS_SYNC_STATE_CANDIDATE) {
|
if (pSyncNode->state != TAOS_SYNC_STATE_CANDIDATE) {
|
||||||
syncNodeEventLog(pSyncNode, "not candidate, stop elect");
|
sNTrace(pSyncNode, "not candidate, stop elect");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -85,20 +85,20 @@ cJSON* syncRpcMsg2Json(SRpcMsg* pRpcMsg) {
|
||||||
} else if (pRpcMsg->msgType == TDMT_SYNC_COMMON_RESPONSE) {
|
} else if (pRpcMsg->msgType == TDMT_SYNC_COMMON_RESPONSE) {
|
||||||
pRoot = cJSON_CreateObject();
|
pRoot = cJSON_CreateObject();
|
||||||
char* s;
|
char* s;
|
||||||
s = syncUtilprintBin((char*)(pRpcMsg->pCont), pRpcMsg->contLen);
|
s = syncUtilPrintBin((char*)(pRpcMsg->pCont), pRpcMsg->contLen);
|
||||||
cJSON_AddStringToObject(pRoot, "pCont", s);
|
cJSON_AddStringToObject(pRoot, "pCont", s);
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
s = syncUtilprintBin2((char*)(pRpcMsg->pCont), pRpcMsg->contLen);
|
s = syncUtilPrintBin2((char*)(pRpcMsg->pCont), pRpcMsg->contLen);
|
||||||
cJSON_AddStringToObject(pRoot, "pCont2", s);
|
cJSON_AddStringToObject(pRoot, "pCont2", s);
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
pRoot = cJSON_CreateObject();
|
pRoot = cJSON_CreateObject();
|
||||||
char* s;
|
char* s;
|
||||||
s = syncUtilprintBin((char*)(pRpcMsg->pCont), pRpcMsg->contLen);
|
s = syncUtilPrintBin((char*)(pRpcMsg->pCont), pRpcMsg->contLen);
|
||||||
cJSON_AddStringToObject(pRoot, "pCont", s);
|
cJSON_AddStringToObject(pRoot, "pCont", s);
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
s = syncUtilprintBin2((char*)(pRpcMsg->pCont), pRpcMsg->contLen);
|
s = syncUtilPrintBin2((char*)(pRpcMsg->pCont), pRpcMsg->contLen);
|
||||||
cJSON_AddStringToObject(pRoot, "pCont2", s);
|
cJSON_AddStringToObject(pRoot, "pCont2", s);
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
}
|
}
|
||||||
|
@ -511,10 +511,10 @@ cJSON* syncPing2Json(const SyncPing* pMsg) {
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
||||||
char* s;
|
char* s;
|
||||||
s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen);
|
s = syncUtilPrintBin((char*)(pMsg->data), pMsg->dataLen);
|
||||||
cJSON_AddStringToObject(pRoot, "data", s);
|
cJSON_AddStringToObject(pRoot, "data", s);
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen);
|
s = syncUtilPrintBin2((char*)(pMsg->data), pMsg->dataLen);
|
||||||
cJSON_AddStringToObject(pRoot, "data2", s);
|
cJSON_AddStringToObject(pRoot, "data2", s);
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
}
|
}
|
||||||
|
@ -781,10 +781,10 @@ cJSON* syncPingReply2Json(const SyncPingReply* pMsg) {
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
||||||
char* s;
|
char* s;
|
||||||
s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen);
|
s = syncUtilPrintBin((char*)(pMsg->data), pMsg->dataLen);
|
||||||
cJSON_AddStringToObject(pRoot, "data", s);
|
cJSON_AddStringToObject(pRoot, "data", s);
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen);
|
s = syncUtilPrintBin2((char*)(pMsg->data), pMsg->dataLen);
|
||||||
cJSON_AddStringToObject(pRoot, "data2", s);
|
cJSON_AddStringToObject(pRoot, "data2", s);
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
}
|
}
|
||||||
|
@ -924,10 +924,10 @@ cJSON* syncClientRequest2Json(const SyncClientRequest* pMsg) {
|
||||||
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
||||||
|
|
||||||
char* s;
|
char* s;
|
||||||
s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen);
|
s = syncUtilPrintBin((char*)(pMsg->data), pMsg->dataLen);
|
||||||
cJSON_AddStringToObject(pRoot, "data", s);
|
cJSON_AddStringToObject(pRoot, "data", s);
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen);
|
s = syncUtilPrintBin2((char*)(pMsg->data), pMsg->dataLen);
|
||||||
cJSON_AddStringToObject(pRoot, "data2", s);
|
cJSON_AddStringToObject(pRoot, "data2", s);
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
}
|
}
|
||||||
|
@ -1094,10 +1094,10 @@ cJSON* syncClientRequestBatch2Json(const SyncClientRequestBatch* pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char* s;
|
char* s;
|
||||||
s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen);
|
s = syncUtilPrintBin((char*)(pMsg->data), pMsg->dataLen);
|
||||||
cJSON_AddStringToObject(pRoot, "data", s);
|
cJSON_AddStringToObject(pRoot, "data", s);
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen);
|
s = syncUtilPrintBin2((char*)(pMsg->data), pMsg->dataLen);
|
||||||
cJSON_AddStringToObject(pRoot, "data2", s);
|
cJSON_AddStringToObject(pRoot, "data2", s);
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
}
|
}
|
||||||
|
@ -1564,10 +1564,10 @@ cJSON* syncAppendEntries2Json(const SyncAppendEntries* pMsg) {
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
||||||
char* s;
|
char* s;
|
||||||
s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen);
|
s = syncUtilPrintBin((char*)(pMsg->data), pMsg->dataLen);
|
||||||
cJSON_AddStringToObject(pRoot, "data", s);
|
cJSON_AddStringToObject(pRoot, "data", s);
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen);
|
s = syncUtilPrintBin2((char*)(pMsg->data), pMsg->dataLen);
|
||||||
cJSON_AddStringToObject(pRoot, "data2", s);
|
cJSON_AddStringToObject(pRoot, "data2", s);
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
}
|
}
|
||||||
|
@ -1803,10 +1803,10 @@ cJSON* syncAppendEntriesBatch2Json(const SyncAppendEntriesBatch* pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char* s;
|
char* s;
|
||||||
s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen);
|
s = syncUtilPrintBin((char*)(pMsg->data), pMsg->dataLen);
|
||||||
cJSON_AddStringToObject(pRoot, "data", s);
|
cJSON_AddStringToObject(pRoot, "data", s);
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen);
|
s = syncUtilPrintBin2((char*)(pMsg->data), pMsg->dataLen);
|
||||||
cJSON_AddStringToObject(pRoot, "data2", s);
|
cJSON_AddStringToObject(pRoot, "data2", s);
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
}
|
}
|
||||||
|
@ -2716,10 +2716,10 @@ cJSON* syncApplyMsg2Json(const SyncApplyMsg* pMsg) {
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
||||||
char* s;
|
char* s;
|
||||||
s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen);
|
s = syncUtilPrintBin((char*)(pMsg->data), pMsg->dataLen);
|
||||||
cJSON_AddStringToObject(pRoot, "data", s);
|
cJSON_AddStringToObject(pRoot, "data", s);
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen);
|
s = syncUtilPrintBin2((char*)(pMsg->data), pMsg->dataLen);
|
||||||
cJSON_AddStringToObject(pRoot, "data2", s);
|
cJSON_AddStringToObject(pRoot, "data2", s);
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
}
|
}
|
||||||
|
@ -2893,10 +2893,10 @@ cJSON* syncSnapshotSend2Json(const SyncSnapshotSend* pMsg) {
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
||||||
char* s;
|
char* s;
|
||||||
s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen);
|
s = syncUtilPrintBin((char*)(pMsg->data), pMsg->dataLen);
|
||||||
cJSON_AddStringToObject(pRoot, "data", s);
|
cJSON_AddStringToObject(pRoot, "data", s);
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen);
|
s = syncUtilPrintBin2((char*)(pMsg->data), pMsg->dataLen);
|
||||||
cJSON_AddStringToObject(pRoot, "data2", s);
|
cJSON_AddStringToObject(pRoot, "data2", s);
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,31 +249,16 @@ char *syncCfg2Str(SSyncCfg *pSyncCfg) {
|
||||||
return serialized;
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *syncCfg2SimpleStr(SSyncCfg *pSyncCfg) {
|
void syncCfg2SimpleStr(const SSyncCfg *pCfg, char *buf, int32_t bufLen) {
|
||||||
if (pSyncCfg != NULL) {
|
int32_t len = snprintf(buf, bufLen, "{r-num:%d, my:%d, ", pCfg->replicaNum, pCfg->myIndex);
|
||||||
int32_t len = 512;
|
|
||||||
char *s = taosMemoryMalloc(len);
|
|
||||||
memset(s, 0, len);
|
|
||||||
|
|
||||||
snprintf(s, len, "{r-num:%d, my:%d, ", pSyncCfg->replicaNum, pSyncCfg->myIndex);
|
for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
|
||||||
char *p = s + strlen(s);
|
if (i < pCfg->replicaNum - 1) {
|
||||||
for (int i = 0; i < pSyncCfg->replicaNum; ++i) {
|
len += snprintf(buf + len, bufLen - len, "%s:%d, ", pCfg->nodeInfo[i].nodeFqdn, pCfg->nodeInfo[i].nodePort);
|
||||||
/*
|
} else {
|
||||||
if (p + 128 + 32 > s + len) {
|
len += snprintf(buf + len, bufLen - len, "%s:%d}", pCfg->nodeInfo[i].nodeFqdn, pCfg->nodeInfo[i].nodePort);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
char buf[128 + 32];
|
|
||||||
snprintf(buf, sizeof(buf), "%s:%d, ", pSyncCfg->nodeInfo[i].nodeFqdn, pSyncCfg->nodeInfo[i].nodePort);
|
|
||||||
strncpy(p, buf, sizeof(buf));
|
|
||||||
p = s + strlen(s);
|
|
||||||
}
|
}
|
||||||
strcpy(p - 2, "}");
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncCfgFromJson(const cJSON *pRoot, SSyncCfg *pSyncCfg) {
|
int32_t syncCfgFromJson(const cJSON *pRoot, SSyncCfg *pSyncCfg) {
|
||||||
|
@ -442,88 +427,3 @@ int32_t raftCfgFromStr(const char *s, SRaftCfg *pRaftCfg) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// for debug ----------------------
|
|
||||||
void syncCfgPrint(SSyncCfg *pCfg) {
|
|
||||||
char *serialized = syncCfg2Str(pCfg);
|
|
||||||
printf("syncCfgPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
|
||||||
fflush(NULL);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncCfgPrint2(char *s, SSyncCfg *pCfg) {
|
|
||||||
char *serialized = syncCfg2Str(pCfg);
|
|
||||||
printf("syncCfgPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
|
||||||
fflush(NULL);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncCfgLog(SSyncCfg *pCfg) {
|
|
||||||
char *serialized = syncCfg2Str(pCfg);
|
|
||||||
sTrace("syncCfgLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncCfgLog2(char *s, SSyncCfg *pCfg) {
|
|
||||||
char *serialized = syncCfg2Str(pCfg);
|
|
||||||
sTrace("syncCfgLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncCfgLog3(char *s, SSyncCfg *pCfg) {
|
|
||||||
char *serialized = syncCfg2SimpleStr(pCfg);
|
|
||||||
sTrace("syncCfgLog3 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void raftCfgPrint(SRaftCfg *pCfg) {
|
|
||||||
char *serialized = raftCfg2Str(pCfg);
|
|
||||||
printf("raftCfgPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
|
||||||
fflush(NULL);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void raftCfgPrint2(char *s, SRaftCfg *pCfg) {
|
|
||||||
char *serialized = raftCfg2Str(pCfg);
|
|
||||||
printf("raftCfgPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
|
||||||
fflush(NULL);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void raftCfgLog(SRaftCfg *pCfg) {
|
|
||||||
char *serialized = raftCfg2Str(pCfg);
|
|
||||||
sTrace("raftCfgLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void raftCfgLog2(char *s, SRaftCfg *pCfg) {
|
|
||||||
char *serialized = raftCfg2Str(pCfg);
|
|
||||||
sTrace("raftCfgLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------
|
|
||||||
void raftCfgIndexPrint(SRaftCfgIndex *pCfg) {
|
|
||||||
char *serialized = raftCfgIndex2Str(pCfg);
|
|
||||||
printf("raftCfgIndexPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
|
||||||
fflush(NULL);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void raftCfgIndexPrint2(char *s, SRaftCfgIndex *pCfg) {
|
|
||||||
char *serialized = raftCfgIndex2Str(pCfg);
|
|
||||||
printf("raftCfgIndexPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
|
||||||
fflush(NULL);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void raftCfgIndexLog(SRaftCfgIndex *pCfg) {
|
|
||||||
char *serialized = raftCfgIndex2Str(pCfg);
|
|
||||||
sTrace("raftCfgIndexLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void raftCfgIndexLog2(char *s, SRaftCfgIndex *pCfg) {
|
|
||||||
char *serialized = raftCfgIndex2Str(pCfg);
|
|
||||||
sTrace("raftCfgIndexLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
|
@ -144,11 +144,11 @@ cJSON* syncEntry2Json(const SSyncRaftEntry* pEntry) {
|
||||||
cJSON_AddNumberToObject(pRoot, "dataLen", pEntry->dataLen);
|
cJSON_AddNumberToObject(pRoot, "dataLen", pEntry->dataLen);
|
||||||
|
|
||||||
char* s;
|
char* s;
|
||||||
s = syncUtilprintBin((char*)(pEntry->data), pEntry->dataLen);
|
s = syncUtilPrintBin((char*)(pEntry->data), pEntry->dataLen);
|
||||||
cJSON_AddStringToObject(pRoot, "data", s);
|
cJSON_AddStringToObject(pRoot, "data", s);
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
|
|
||||||
s = syncUtilprintBin2((char*)(pEntry->data), pEntry->dataLen);
|
s = syncUtilPrintBin2((char*)(pEntry->data), pEntry->dataLen);
|
||||||
cJSON_AddStringToObject(pRoot, "data2", s);
|
cJSON_AddStringToObject(pRoot, "data2", s);
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
}
|
}
|
||||||
|
@ -226,9 +226,9 @@ SRaftEntryHashCache* raftCacheCreate(SSyncNode* pSyncNode, int32_t maxCount) {
|
||||||
|
|
||||||
void raftCacheDestroy(SRaftEntryHashCache* pCache) {
|
void raftCacheDestroy(SRaftEntryHashCache* pCache) {
|
||||||
if (pCache != NULL) {
|
if (pCache != NULL) {
|
||||||
taosThreadMutexLock(&(pCache->mutex));
|
taosThreadMutexLock(&pCache->mutex);
|
||||||
taosHashCleanup(pCache->pEntryHash);
|
taosHashCleanup(pCache->pEntryHash);
|
||||||
taosThreadMutexUnlock(&(pCache->mutex));
|
taosThreadMutexUnlock(&pCache->mutex);
|
||||||
taosThreadMutexDestroy(&(pCache->mutex));
|
taosThreadMutexDestroy(&(pCache->mutex));
|
||||||
taosMemoryFree(pCache);
|
taosMemoryFree(pCache);
|
||||||
}
|
}
|
||||||
|
@ -238,25 +238,20 @@ void raftCacheDestroy(SRaftEntryHashCache* pCache) {
|
||||||
// max count, return 0
|
// max count, return 0
|
||||||
// error, return -1
|
// error, return -1
|
||||||
int32_t raftCachePutEntry(struct SRaftEntryHashCache* pCache, SSyncRaftEntry* pEntry) {
|
int32_t raftCachePutEntry(struct SRaftEntryHashCache* pCache, SSyncRaftEntry* pEntry) {
|
||||||
taosThreadMutexLock(&(pCache->mutex));
|
taosThreadMutexLock(&pCache->mutex);
|
||||||
|
|
||||||
if (pCache->currentCount >= pCache->maxCount) {
|
if (pCache->currentCount >= pCache->maxCount) {
|
||||||
taosThreadMutexUnlock(&(pCache->mutex));
|
taosThreadMutexUnlock(&pCache->mutex);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosHashPut(pCache->pEntryHash, &(pEntry->index), sizeof(pEntry->index), pEntry, pEntry->bytes);
|
taosHashPut(pCache->pEntryHash, &(pEntry->index), sizeof(pEntry->index), pEntry, pEntry->bytes);
|
||||||
++(pCache->currentCount);
|
++(pCache->currentCount);
|
||||||
|
|
||||||
do {
|
sNTrace(pCache->pSyncNode, "raft cache add, type:%s,%d, type2:%s,%d, index:%" PRId64 ", bytes:%d",
|
||||||
char eventLog[128];
|
|
||||||
snprintf(eventLog, sizeof(eventLog), "raft cache add, type:%s,%d, type2:%s,%d, index:%" PRId64 ", bytes:%d",
|
|
||||||
TMSG_INFO(pEntry->msgType), pEntry->msgType, TMSG_INFO(pEntry->originalRpcType), pEntry->originalRpcType,
|
TMSG_INFO(pEntry->msgType), pEntry->msgType, TMSG_INFO(pEntry->originalRpcType), pEntry->originalRpcType,
|
||||||
pEntry->index, pEntry->bytes);
|
pEntry->index, pEntry->bytes);
|
||||||
syncNodeEventLog(pCache->pSyncNode, eventLog);
|
taosThreadMutexUnlock(&pCache->mutex);
|
||||||
} while (0);
|
|
||||||
|
|
||||||
taosThreadMutexUnlock(&(pCache->mutex));
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,26 +264,21 @@ int32_t raftCacheGetEntry(struct SRaftEntryHashCache* pCache, SyncIndex index, S
|
||||||
}
|
}
|
||||||
*ppEntry = NULL;
|
*ppEntry = NULL;
|
||||||
|
|
||||||
taosThreadMutexLock(&(pCache->mutex));
|
taosThreadMutexLock(&pCache->mutex);
|
||||||
void* pTmp = taosHashGet(pCache->pEntryHash, &index, sizeof(index));
|
void* pTmp = taosHashGet(pCache->pEntryHash, &index, sizeof(index));
|
||||||
if (pTmp != NULL) {
|
if (pTmp != NULL) {
|
||||||
SSyncRaftEntry* pEntry = pTmp;
|
SSyncRaftEntry* pEntry = pTmp;
|
||||||
*ppEntry = taosMemoryMalloc(pEntry->bytes);
|
*ppEntry = taosMemoryMalloc(pEntry->bytes);
|
||||||
memcpy(*ppEntry, pTmp, pEntry->bytes);
|
memcpy(*ppEntry, pTmp, pEntry->bytes);
|
||||||
|
|
||||||
do {
|
sNTrace(pCache->pSyncNode, "raft cache get, type:%s,%d, type2:%s,%d, index:%" PRId64,
|
||||||
char eventLog[128];
|
|
||||||
snprintf(eventLog, sizeof(eventLog), "raft cache get, type:%s,%d, type2:%s,%d, index:%" PRId64,
|
|
||||||
TMSG_INFO((*ppEntry)->msgType), (*ppEntry)->msgType, TMSG_INFO((*ppEntry)->originalRpcType),
|
TMSG_INFO((*ppEntry)->msgType), (*ppEntry)->msgType, TMSG_INFO((*ppEntry)->originalRpcType),
|
||||||
(*ppEntry)->originalRpcType, (*ppEntry)->index);
|
(*ppEntry)->originalRpcType, (*ppEntry)->index);
|
||||||
syncNodeEventLog(pCache->pSyncNode, eventLog);
|
taosThreadMutexUnlock(&pCache->mutex);
|
||||||
} while (0);
|
|
||||||
|
|
||||||
taosThreadMutexUnlock(&(pCache->mutex));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadMutexUnlock(&(pCache->mutex));
|
taosThreadMutexUnlock(&pCache->mutex);
|
||||||
terrno = TSDB_CODE_WAL_LOG_NOT_EXIST;
|
terrno = TSDB_CODE_WAL_LOG_NOT_EXIST;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -302,34 +292,29 @@ int32_t raftCacheGetEntryP(struct SRaftEntryHashCache* pCache, SyncIndex index,
|
||||||
}
|
}
|
||||||
*ppEntry = NULL;
|
*ppEntry = NULL;
|
||||||
|
|
||||||
taosThreadMutexLock(&(pCache->mutex));
|
taosThreadMutexLock(&pCache->mutex);
|
||||||
void* pTmp = taosHashGet(pCache->pEntryHash, &index, sizeof(index));
|
void* pTmp = taosHashGet(pCache->pEntryHash, &index, sizeof(index));
|
||||||
if (pTmp != NULL) {
|
if (pTmp != NULL) {
|
||||||
SSyncRaftEntry* pEntry = pTmp;
|
SSyncRaftEntry* pEntry = pTmp;
|
||||||
*ppEntry = pEntry;
|
*ppEntry = pEntry;
|
||||||
|
|
||||||
do {
|
sNTrace(pCache->pSyncNode, "raft cache get, type:%s,%d, type2:%s,%d, index:%" PRId64,
|
||||||
char eventLog[128];
|
|
||||||
snprintf(eventLog, sizeof(eventLog), "raft cache get, type:%s,%d, type2:%s,%d, index:%" PRId64,
|
|
||||||
TMSG_INFO((*ppEntry)->msgType), (*ppEntry)->msgType, TMSG_INFO((*ppEntry)->originalRpcType),
|
TMSG_INFO((*ppEntry)->msgType), (*ppEntry)->msgType, TMSG_INFO((*ppEntry)->originalRpcType),
|
||||||
(*ppEntry)->originalRpcType, (*ppEntry)->index);
|
(*ppEntry)->originalRpcType, (*ppEntry)->index);
|
||||||
syncNodeEventLog(pCache->pSyncNode, eventLog);
|
taosThreadMutexUnlock(&pCache->mutex);
|
||||||
} while (0);
|
|
||||||
|
|
||||||
taosThreadMutexUnlock(&(pCache->mutex));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadMutexUnlock(&(pCache->mutex));
|
taosThreadMutexUnlock(&pCache->mutex);
|
||||||
terrno = TSDB_CODE_WAL_LOG_NOT_EXIST;
|
terrno = TSDB_CODE_WAL_LOG_NOT_EXIST;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t raftCacheDelEntry(struct SRaftEntryHashCache* pCache, SyncIndex index) {
|
int32_t raftCacheDelEntry(struct SRaftEntryHashCache* pCache, SyncIndex index) {
|
||||||
taosThreadMutexLock(&(pCache->mutex));
|
taosThreadMutexLock(&pCache->mutex);
|
||||||
taosHashRemove(pCache->pEntryHash, &index, sizeof(index));
|
taosHashRemove(pCache->pEntryHash, &index, sizeof(index));
|
||||||
--(pCache->currentCount);
|
--(pCache->currentCount);
|
||||||
taosThreadMutexUnlock(&(pCache->mutex));
|
taosThreadMutexUnlock(&pCache->mutex);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,38 +324,34 @@ int32_t raftCacheGetAndDel(struct SRaftEntryHashCache* pCache, SyncIndex index,
|
||||||
}
|
}
|
||||||
*ppEntry = NULL;
|
*ppEntry = NULL;
|
||||||
|
|
||||||
taosThreadMutexLock(&(pCache->mutex));
|
taosThreadMutexLock(&pCache->mutex);
|
||||||
void* pTmp = taosHashGet(pCache->pEntryHash, &index, sizeof(index));
|
void* pTmp = taosHashGet(pCache->pEntryHash, &index, sizeof(index));
|
||||||
if (pTmp != NULL) {
|
if (pTmp != NULL) {
|
||||||
SSyncRaftEntry* pEntry = pTmp;
|
SSyncRaftEntry* pEntry = pTmp;
|
||||||
*ppEntry = taosMemoryMalloc(pEntry->bytes);
|
*ppEntry = taosMemoryMalloc(pEntry->bytes);
|
||||||
memcpy(*ppEntry, pTmp, pEntry->bytes);
|
memcpy(*ppEntry, pTmp, pEntry->bytes);
|
||||||
|
|
||||||
do {
|
sNTrace(pCache->pSyncNode, "raft cache get-and-del, type:%s,%d, type2:%s,%d, index:%" PRId64,
|
||||||
char eventLog[128];
|
|
||||||
snprintf(eventLog, sizeof(eventLog), "raft cache get-and-del, type:%s,%d, type2:%s,%d, index:%" PRId64,
|
|
||||||
TMSG_INFO((*ppEntry)->msgType), (*ppEntry)->msgType, TMSG_INFO((*ppEntry)->originalRpcType),
|
TMSG_INFO((*ppEntry)->msgType), (*ppEntry)->msgType, TMSG_INFO((*ppEntry)->originalRpcType),
|
||||||
(*ppEntry)->originalRpcType, (*ppEntry)->index);
|
(*ppEntry)->originalRpcType, (*ppEntry)->index);
|
||||||
syncNodeEventLog(pCache->pSyncNode, eventLog);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
taosHashRemove(pCache->pEntryHash, &index, sizeof(index));
|
taosHashRemove(pCache->pEntryHash, &index, sizeof(index));
|
||||||
--(pCache->currentCount);
|
--(pCache->currentCount);
|
||||||
|
|
||||||
taosThreadMutexUnlock(&(pCache->mutex));
|
taosThreadMutexUnlock(&pCache->mutex);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadMutexUnlock(&(pCache->mutex));
|
taosThreadMutexUnlock(&pCache->mutex);
|
||||||
terrno = TSDB_CODE_WAL_LOG_NOT_EXIST;
|
terrno = TSDB_CODE_WAL_LOG_NOT_EXIST;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t raftCacheClear(struct SRaftEntryHashCache* pCache) {
|
int32_t raftCacheClear(struct SRaftEntryHashCache* pCache) {
|
||||||
taosThreadMutexLock(&(pCache->mutex));
|
taosThreadMutexLock(&pCache->mutex);
|
||||||
taosHashClear(pCache->pEntryHash);
|
taosHashClear(pCache->pEntryHash);
|
||||||
pCache->currentCount = 0;
|
pCache->currentCount = 0;
|
||||||
taosThreadMutexUnlock(&(pCache->mutex));
|
taosThreadMutexUnlock(&pCache->mutex);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,7 +361,7 @@ cJSON* raftCache2Json(SRaftEntryHashCache* pCache) {
|
||||||
cJSON* pRoot = cJSON_CreateObject();
|
cJSON* pRoot = cJSON_CreateObject();
|
||||||
|
|
||||||
if (pCache != NULL) {
|
if (pCache != NULL) {
|
||||||
taosThreadMutexLock(&(pCache->mutex));
|
taosThreadMutexLock(&pCache->mutex);
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pCache->pSyncNode);
|
snprintf(u64buf, sizeof(u64buf), "%p", pCache->pSyncNode);
|
||||||
cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf);
|
cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf);
|
||||||
|
@ -402,7 +383,7 @@ cJSON* raftCache2Json(SRaftEntryHashCache* pCache) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadMutexUnlock(&(pCache->mutex));
|
taosThreadMutexUnlock(&pCache->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
|
@ -483,13 +464,13 @@ SRaftEntryCache* raftEntryCacheCreate(SSyncNode* pSyncNode, int32_t maxCount) {
|
||||||
|
|
||||||
void raftEntryCacheDestroy(SRaftEntryCache* pCache) {
|
void raftEntryCacheDestroy(SRaftEntryCache* pCache) {
|
||||||
if (pCache != NULL) {
|
if (pCache != NULL) {
|
||||||
taosThreadMutexLock(&(pCache->mutex));
|
taosThreadMutexLock(&pCache->mutex);
|
||||||
tSkipListDestroy(pCache->pSkipList);
|
tSkipListDestroy(pCache->pSkipList);
|
||||||
if (pCache->refMgr != -1) {
|
if (pCache->refMgr != -1) {
|
||||||
taosCloseRef(pCache->refMgr);
|
taosCloseRef(pCache->refMgr);
|
||||||
pCache->refMgr = -1;
|
pCache->refMgr = -1;
|
||||||
}
|
}
|
||||||
taosThreadMutexUnlock(&(pCache->mutex));
|
taosThreadMutexUnlock(&pCache->mutex);
|
||||||
taosThreadMutexDestroy(&(pCache->mutex));
|
taosThreadMutexDestroy(&(pCache->mutex));
|
||||||
taosMemoryFree(pCache);
|
taosMemoryFree(pCache);
|
||||||
}
|
}
|
||||||
|
@ -499,10 +480,10 @@ void raftEntryCacheDestroy(SRaftEntryCache* pCache) {
|
||||||
// max count, return 0
|
// max count, return 0
|
||||||
// error, return -1
|
// error, return -1
|
||||||
int32_t raftEntryCachePutEntry(struct SRaftEntryCache* pCache, SSyncRaftEntry* pEntry) {
|
int32_t raftEntryCachePutEntry(struct SRaftEntryCache* pCache, SSyncRaftEntry* pEntry) {
|
||||||
taosThreadMutexLock(&(pCache->mutex));
|
taosThreadMutexLock(&pCache->mutex);
|
||||||
|
|
||||||
if (pCache->currentCount >= pCache->maxCount) {
|
if (pCache->currentCount >= pCache->maxCount) {
|
||||||
taosThreadMutexUnlock(&(pCache->mutex));
|
taosThreadMutexUnlock(&pCache->mutex);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -513,15 +494,10 @@ int32_t raftEntryCachePutEntry(struct SRaftEntryCache* pCache, SSyncRaftEntry* p
|
||||||
pEntry->rid = taosAddRef(pCache->refMgr, pEntry);
|
pEntry->rid = taosAddRef(pCache->refMgr, pEntry);
|
||||||
ASSERT(pEntry->rid >= 0);
|
ASSERT(pEntry->rid >= 0);
|
||||||
|
|
||||||
do {
|
sNTrace(pCache->pSyncNode, "raft cache add, type:%s,%d, type2:%s,%d, index:%" PRId64 ", bytes:%d",
|
||||||
char eventLog[128];
|
|
||||||
snprintf(eventLog, sizeof(eventLog), "raft cache add, type:%s,%d, type2:%s,%d, index:%" PRId64 ", bytes:%d",
|
|
||||||
TMSG_INFO(pEntry->msgType), pEntry->msgType, TMSG_INFO(pEntry->originalRpcType), pEntry->originalRpcType,
|
TMSG_INFO(pEntry->msgType), pEntry->msgType, TMSG_INFO(pEntry->originalRpcType), pEntry->originalRpcType,
|
||||||
pEntry->index, pEntry->bytes);
|
pEntry->index, pEntry->bytes);
|
||||||
syncNodeEventLog(pCache->pSyncNode, eventLog);
|
taosThreadMutexUnlock(&pCache->mutex);
|
||||||
} while (0);
|
|
||||||
|
|
||||||
taosThreadMutexUnlock(&(pCache->mutex));
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -546,7 +522,7 @@ int32_t raftEntryCacheGetEntry(struct SRaftEntryCache* pCache, SyncIndex index,
|
||||||
// not found, return 0
|
// not found, return 0
|
||||||
// error, return -1
|
// error, return -1
|
||||||
int32_t raftEntryCacheGetEntryP(struct SRaftEntryCache* pCache, SyncIndex index, SSyncRaftEntry** ppEntry) {
|
int32_t raftEntryCacheGetEntryP(struct SRaftEntryCache* pCache, SyncIndex index, SSyncRaftEntry** ppEntry) {
|
||||||
taosThreadMutexLock(&(pCache->mutex));
|
taosThreadMutexLock(&pCache->mutex);
|
||||||
|
|
||||||
SyncIndex index2 = index;
|
SyncIndex index2 = index;
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
@ -570,7 +546,7 @@ int32_t raftEntryCacheGetEntryP(struct SRaftEntryCache* pCache, SyncIndex index,
|
||||||
}
|
}
|
||||||
taosArrayDestroy(entryPArray);
|
taosArrayDestroy(entryPArray);
|
||||||
|
|
||||||
taosThreadMutexUnlock(&(pCache->mutex));
|
taosThreadMutexUnlock(&pCache->mutex);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,7 +555,7 @@ int32_t raftEntryCacheGetEntryP(struct SRaftEntryCache* pCache, SyncIndex index,
|
||||||
// return -1, error
|
// return -1, error
|
||||||
// return delete count
|
// return delete count
|
||||||
int32_t raftEntryCacheClear(struct SRaftEntryCache* pCache, int32_t count) {
|
int32_t raftEntryCacheClear(struct SRaftEntryCache* pCache, int32_t count) {
|
||||||
taosThreadMutexLock(&(pCache->mutex));
|
taosThreadMutexLock(&pCache->mutex);
|
||||||
int32_t returnCnt = 0;
|
int32_t returnCnt = 0;
|
||||||
|
|
||||||
if (count == -1) {
|
if (count == -1) {
|
||||||
|
@ -634,7 +610,7 @@ int32_t raftEntryCacheClear(struct SRaftEntryCache* pCache, int32_t count) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pCache->currentCount -= returnCnt;
|
pCache->currentCount -= returnCnt;
|
||||||
taosThreadMutexUnlock(&(pCache->mutex));
|
taosThreadMutexUnlock(&pCache->mutex);
|
||||||
return returnCnt;
|
return returnCnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -643,7 +619,7 @@ cJSON* raftEntryCache2Json(SRaftEntryCache* pCache) {
|
||||||
cJSON* pRoot = cJSON_CreateObject();
|
cJSON* pRoot = cJSON_CreateObject();
|
||||||
|
|
||||||
if (pCache != NULL) {
|
if (pCache != NULL) {
|
||||||
taosThreadMutexLock(&(pCache->mutex));
|
taosThreadMutexLock(&pCache->mutex);
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pCache->pSyncNode);
|
snprintf(u64buf, sizeof(u64buf), "%p", pCache->pSyncNode);
|
||||||
cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf);
|
cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf);
|
||||||
|
@ -661,7 +637,7 @@ cJSON* raftEntryCache2Json(SRaftEntryCache* pCache) {
|
||||||
}
|
}
|
||||||
tSkipListDestroyIter(pIter);
|
tSkipListDestroyIter(pIter);
|
||||||
|
|
||||||
taosThreadMutexUnlock(&(pCache->mutex));
|
taosThreadMutexUnlock(&pCache->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
|
|
|
@ -117,12 +117,9 @@ static int32_t raftLogRestoreFromSnapshot(struct SSyncLogStore* pLogStore, SyncI
|
||||||
int32_t sysErr = errno;
|
int32_t sysErr = errno;
|
||||||
const char* sysErrStr = strerror(errno);
|
const char* sysErrStr = strerror(errno);
|
||||||
|
|
||||||
char logBuf[128];
|
sNError(pData->pSyncNode,
|
||||||
snprintf(logBuf, sizeof(logBuf),
|
|
||||||
"wal restore from snapshot error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s",
|
"wal restore from snapshot error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s",
|
||||||
snapshotIndex, err, err, errStr, sysErr, sysErrStr);
|
snapshotIndex, err, err, errStr, sysErr, sysErrStr);
|
||||||
syncNodeErrorLog(pData->pSyncNode, logBuf);
|
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,23 +211,14 @@ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntr
|
||||||
int32_t sysErr = errno;
|
int32_t sysErr = errno;
|
||||||
const char* sysErrStr = strerror(errno);
|
const char* sysErrStr = strerror(errno);
|
||||||
|
|
||||||
char logBuf[128];
|
sNError(pData->pSyncNode, "wal write error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s",
|
||||||
snprintf(logBuf, sizeof(logBuf), "wal write error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s",
|
|
||||||
pEntry->index, err, err, errStr, sysErr, sysErrStr);
|
pEntry->index, err, err, errStr, sysErr, sysErrStr);
|
||||||
syncNodeErrorLog(pData->pSyncNode, logBuf);
|
|
||||||
|
|
||||||
// ASSERT(0);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
pEntry->index = index;
|
pEntry->index = index;
|
||||||
|
|
||||||
do {
|
sNTrace(pData->pSyncNode, "write index:%" PRId64 ", type:%s, origin type:%s", pEntry->index,
|
||||||
char eventLog[128];
|
|
||||||
snprintf(eventLog, sizeof(eventLog), "write index:%" PRId64 ", type:%s, origin type:%s", pEntry->index,
|
|
||||||
TMSG_INFO(pEntry->msgType), TMSG_INFO(pEntry->originalRpcType));
|
TMSG_INFO(pEntry->msgType), TMSG_INFO(pEntry->originalRpcType));
|
||||||
syncNodeEventLog(pData->pSyncNode, eventLog);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,20 +249,13 @@ static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index,
|
||||||
int32_t sysErr = errno;
|
int32_t sysErr = errno;
|
||||||
const char* sysErrStr = strerror(errno);
|
const char* sysErrStr = strerror(errno);
|
||||||
|
|
||||||
do {
|
|
||||||
char logBuf[128];
|
|
||||||
if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) {
|
if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) {
|
||||||
snprintf(logBuf, sizeof(logBuf),
|
sNTrace(pData->pSyncNode, "wal read not exist, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", index,
|
||||||
"wal read not exist, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", index, err, err,
|
err, err, errStr, sysErr, sysErrStr);
|
||||||
errStr, sysErr, sysErrStr);
|
|
||||||
syncNodeEventLog(pData->pSyncNode, logBuf);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
snprintf(logBuf, sizeof(logBuf), "wal read error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s",
|
sNTrace(pData->pSyncNode, "wal read error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", index,
|
||||||
index, err, err, errStr, sysErr, sysErrStr);
|
err, err, errStr, sysErr, sysErrStr);
|
||||||
syncNodeErrorLog(pData->pSyncNode, logBuf);
|
|
||||||
}
|
}
|
||||||
} while (0);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
int32_t saveErr = terrno;
|
int32_t saveErr = terrno;
|
||||||
|
@ -331,12 +312,7 @@ static int32_t raftLogTruncate(struct SSyncLogStore* pLogStore, SyncIndex fromIn
|
||||||
}
|
}
|
||||||
|
|
||||||
// event log
|
// event log
|
||||||
do {
|
sNTrace(pData->pSyncNode, "log truncate, from-index:%" PRId64, fromIndex);
|
||||||
char logBuf[128];
|
|
||||||
snprintf(logBuf, sizeof(logBuf), "log truncate, from-index:%" PRId64, fromIndex);
|
|
||||||
syncNodeEventLog(pData->pSyncNode, logBuf);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,14 +56,10 @@ int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId) {
|
||||||
SyncIndex logStartIndex = pSyncNode->pLogStore->syncLogBeginIndex(pSyncNode->pLogStore);
|
SyncIndex logStartIndex = pSyncNode->pLogStore->syncLogBeginIndex(pSyncNode->pLogStore);
|
||||||
SyncIndex logEndIndex = pSyncNode->pLogStore->syncLogEndIndex(pSyncNode->pLogStore);
|
SyncIndex logEndIndex = pSyncNode->pLogStore->syncLogEndIndex(pSyncNode->pLogStore);
|
||||||
if (nextIndex < logStartIndex || nextIndex - 1 > logEndIndex) {
|
if (nextIndex < logStartIndex || nextIndex - 1 > logEndIndex) {
|
||||||
char logBuf[128];
|
sNTrace(pSyncNode, "maybe start snapshot for next-index:%" PRId64 ", start:%" PRId64 ", end:%" PRId64, nextIndex,
|
||||||
snprintf(logBuf, sizeof(logBuf), "maybe start snapshot for next-index:%" PRId64 ", start:%" PRId64 ", end:%" PRId64,
|
logStartIndex, logEndIndex);
|
||||||
nextIndex, logStartIndex, logEndIndex);
|
|
||||||
syncNodeEventLog(pSyncNode, logBuf);
|
|
||||||
|
|
||||||
// start snapshot
|
// start snapshot
|
||||||
// int32_t code = syncNodeStartSnapshot(pSyncNode, pDestId);
|
// int32_t code = syncNodeStartSnapshot(pSyncNode, pDestId);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,10 +99,7 @@ int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId) {
|
||||||
char host[64];
|
char host[64];
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
syncUtilU642Addr(pDestId->addr, host, sizeof(host), &port);
|
syncUtilU642Addr(pDestId->addr, host, sizeof(host), &port);
|
||||||
|
sNError(pSyncNode, "replicate to %s:%d error, next-index:%" PRId64, host, port, nextIndex);
|
||||||
char logBuf[128];
|
|
||||||
snprintf(logBuf, sizeof(logBuf), "replicate to %s:%d error, next-index:%" PRId64, host, port, nextIndex);
|
|
||||||
syncNodeErrorLog(pSyncNode, logBuf);
|
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
syncAppendEntriesDestroy(pMsg);
|
syncAppendEntriesDestroy(pMsg);
|
||||||
|
@ -137,7 +130,7 @@ int32_t syncNodeReplicate(SSyncNode* pSyncNode) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
syncNodeEventLog(pSyncNode, "do replicate");
|
sNTrace(pSyncNode, "do replicate");
|
||||||
|
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
for (int i = 0; i < pSyncNode->peersNum; ++i) {
|
for (int i = 0; i < pSyncNode->peersNum; ++i) {
|
||||||
|
@ -186,9 +179,7 @@ int32_t syncNodeMaybeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* dest
|
||||||
char host[64];
|
char host[64];
|
||||||
int16_t port;
|
int16_t port;
|
||||||
syncUtilU642Addr(destRaftId->addr, host, sizeof(host), &port);
|
syncUtilU642Addr(destRaftId->addr, host, sizeof(host), &port);
|
||||||
|
sNTrace(pSyncNode, "do not repcate to %s:%d for index:%" PRId64, host, port, pMsg->prevLogIndex + 1);
|
||||||
snprintf(logBuf, sizeof(logBuf), "do not repcate to %s:%d for index:%" PRId64, host, port, pMsg->prevLogIndex + 1);
|
|
||||||
syncNodeEventLog(pSyncNode, logBuf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -48,66 +48,42 @@ static bool syncNodeOnRequestVoteLogOK(SSyncNode* pSyncNode, SyncRequestVote* pM
|
||||||
SyncIndex myLastIndex = syncNodeGetLastIndex(pSyncNode);
|
SyncIndex myLastIndex = syncNodeGetLastIndex(pSyncNode);
|
||||||
|
|
||||||
if (pMsg->lastLogIndex < pSyncNode->commitIndex) {
|
if (pMsg->lastLogIndex < pSyncNode->commitIndex) {
|
||||||
do {
|
sNTrace(pSyncNode,
|
||||||
char logBuf[128];
|
|
||||||
snprintf(logBuf, sizeof(logBuf),
|
|
||||||
"logok:0, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64
|
"logok:0, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64
|
||||||
", recv-term:%" PRIu64 "}",
|
", recv-term:%" PRIu64 "}",
|
||||||
myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term);
|
myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term);
|
||||||
syncNodeEventLog(pSyncNode, logBuf);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myLastTerm == SYNC_TERM_INVALID) {
|
if (myLastTerm == SYNC_TERM_INVALID) {
|
||||||
do {
|
sNTrace(pSyncNode,
|
||||||
char logBuf[128];
|
|
||||||
snprintf(logBuf, sizeof(logBuf),
|
|
||||||
"logok:0, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64
|
"logok:0, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64
|
||||||
", recv-term:%" PRIu64 "}",
|
", recv-term:%" PRIu64 "}",
|
||||||
myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term);
|
myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term);
|
||||||
syncNodeEventLog(pSyncNode, logBuf);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMsg->lastLogTerm > myLastTerm) {
|
if (pMsg->lastLogTerm > myLastTerm) {
|
||||||
do {
|
sNTrace(pSyncNode,
|
||||||
char logBuf[128];
|
|
||||||
snprintf(logBuf, sizeof(logBuf),
|
|
||||||
"logok:1, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64
|
"logok:1, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64
|
||||||
", recv-term:%" PRIu64 "}",
|
", recv-term:%" PRIu64 "}",
|
||||||
myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term);
|
myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term);
|
||||||
syncNodeEventLog(pSyncNode, logBuf);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMsg->lastLogTerm == myLastTerm && pMsg->lastLogIndex >= myLastIndex) {
|
if (pMsg->lastLogTerm == myLastTerm && pMsg->lastLogIndex >= myLastIndex) {
|
||||||
do {
|
sNTrace(pSyncNode,
|
||||||
char logBuf[128];
|
|
||||||
snprintf(logBuf, sizeof(logBuf),
|
|
||||||
"logok:1, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64
|
"logok:1, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64
|
||||||
", recv-term:%" PRIu64 "}",
|
", recv-term:%" PRIu64 "}",
|
||||||
myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term);
|
myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term);
|
||||||
syncNodeEventLog(pSyncNode, logBuf);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
sNTrace(pSyncNode,
|
||||||
char logBuf[128];
|
|
||||||
snprintf(logBuf, sizeof(logBuf),
|
|
||||||
"logok:0, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64
|
"logok:0, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64
|
||||||
", recv-term:%" PRIu64 "}",
|
", recv-term:%" PRIu64 "}",
|
||||||
myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term);
|
myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term);
|
||||||
syncNodeEventLog(pSyncNode, logBuf);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,10 +71,8 @@ int32_t syncNodeOnRequestVoteReply(SSyncNode* ths, SyncRequestVoteReply* pMsg) {
|
||||||
// but they won't be looked at, so it doesn't matter.
|
// but they won't be looked at, so it doesn't matter.
|
||||||
if (ths->state == TAOS_SYNC_STATE_CANDIDATE) {
|
if (ths->state == TAOS_SYNC_STATE_CANDIDATE) {
|
||||||
if (ths->pVotesRespond->term != pMsg->term) {
|
if (ths->pVotesRespond->term != pMsg->term) {
|
||||||
char logBuf[128];
|
sNError(ths, "vote respond error vote-respond-mgr term:%" PRIu64 ", msg term:%" PRIu64 "",
|
||||||
snprintf(logBuf, sizeof(logBuf), "vote respond error vote-respond-mgr term:%" PRIu64 ", msg term:%" PRIu64 "",
|
|
||||||
ths->pVotesRespond->term, pMsg->term);
|
ths->pVotesRespond->term, pMsg->term);
|
||||||
syncNodeErrorLog(ths, logBuf);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,12 +52,8 @@ int64_t syncRespMgrAdd(SSyncRespMgr *pObj, SRespStub *pStub) {
|
||||||
uint64_t keyCode = ++(pObj->seqNum);
|
uint64_t keyCode = ++(pObj->seqNum);
|
||||||
taosHashPut(pObj->pRespHash, &keyCode, sizeof(keyCode), pStub, sizeof(SRespStub));
|
taosHashPut(pObj->pRespHash, &keyCode, sizeof(keyCode), pStub, sizeof(SRespStub));
|
||||||
|
|
||||||
SSyncNode *pSyncNode = pObj->data;
|
sNTrace(pObj->data, "save message handle, type:%s seq:%" PRIu64 " handle:%p", TMSG_INFO(pStub->rpcMsg.msgType),
|
||||||
char eventLog[128];
|
keyCode, pStub->rpcMsg.info.handle);
|
||||||
snprintf(eventLog, sizeof(eventLog), "save message handle, type:%s seq:%" PRIu64 " handle:%p",
|
|
||||||
TMSG_INFO(pStub->rpcMsg.msgType), keyCode, pStub->rpcMsg.info.handle);
|
|
||||||
syncNodeEventLog(pSyncNode, eventLog);
|
|
||||||
|
|
||||||
taosThreadMutexUnlock(&(pObj->mutex));
|
taosThreadMutexUnlock(&(pObj->mutex));
|
||||||
return keyCode;
|
return keyCode;
|
||||||
}
|
}
|
||||||
|
@ -78,12 +74,8 @@ int32_t syncRespMgrGet(SSyncRespMgr *pObj, uint64_t index, SRespStub *pStub) {
|
||||||
if (pTmp != NULL) {
|
if (pTmp != NULL) {
|
||||||
memcpy(pStub, pTmp, sizeof(SRespStub));
|
memcpy(pStub, pTmp, sizeof(SRespStub));
|
||||||
|
|
||||||
SSyncNode *pSyncNode = pObj->data;
|
sNTrace(pObj->data, "get message handle, type:%s seq:%" PRIu64 " handle:%p", TMSG_INFO(pStub->rpcMsg.msgType),
|
||||||
char eventLog[128];
|
index, pStub->rpcMsg.info.handle);
|
||||||
snprintf(eventLog, sizeof(eventLog), "get message handle, type:%s seq:%" PRIu64 " handle:%p",
|
|
||||||
TMSG_INFO(pStub->rpcMsg.msgType), index, pStub->rpcMsg.info.handle);
|
|
||||||
syncNodeEventLog(pSyncNode, eventLog);
|
|
||||||
|
|
||||||
taosThreadMutexUnlock(&(pObj->mutex));
|
taosThreadMutexUnlock(&(pObj->mutex));
|
||||||
return 1; // get one object
|
return 1; // get one object
|
||||||
}
|
}
|
||||||
|
@ -98,12 +90,8 @@ int32_t syncRespMgrGetAndDel(SSyncRespMgr *pObj, uint64_t index, SRespStub *pStu
|
||||||
if (pTmp != NULL) {
|
if (pTmp != NULL) {
|
||||||
memcpy(pStub, pTmp, sizeof(SRespStub));
|
memcpy(pStub, pTmp, sizeof(SRespStub));
|
||||||
|
|
||||||
SSyncNode *pSyncNode = pObj->data;
|
sNTrace(pObj->data, "get-and-del message handle, type:%s seq:%" PRIu64 " handle:%p",
|
||||||
char eventLog[128];
|
|
||||||
snprintf(eventLog, sizeof(eventLog), "get-and-del message handle, type:%s seq:%" PRIu64 " handle:%p",
|
|
||||||
TMSG_INFO(pStub->rpcMsg.msgType), index, pStub->rpcMsg.info.handle);
|
TMSG_INFO(pStub->rpcMsg.msgType), index, pStub->rpcMsg.info.handle);
|
||||||
syncNodeEventLog(pSyncNode, eventLog);
|
|
||||||
|
|
||||||
taosHashRemove(pObj->pRespHash, &index, sizeof(index));
|
taosHashRemove(pObj->pRespHash, &index, sizeof(index));
|
||||||
taosThreadMutexUnlock(&(pObj->mutex));
|
taosThreadMutexUnlock(&(pObj->mutex));
|
||||||
return 1; // get one object
|
return 1; // get one object
|
||||||
|
|
|
@ -73,7 +73,7 @@ void snapshotSenderDestroy(SSyncSnapshotSender *pSender) {
|
||||||
if (pSender->pReader != NULL) {
|
if (pSender->pReader != NULL) {
|
||||||
int32_t ret = pSender->pSyncNode->pFsm->FpSnapshotStopRead(pSender->pSyncNode->pFsm, pSender->pReader);
|
int32_t ret = pSender->pSyncNode->pFsm->FpSnapshotStopRead(pSender->pSyncNode->pFsm, pSender->pReader);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
syncNodeErrorLog(pSender->pSyncNode, "stop reader error");
|
sNError(pSender->pSyncNode, "stop reader error");
|
||||||
}
|
}
|
||||||
pSender->pReader = NULL;
|
pSender->pReader = NULL;
|
||||||
}
|
}
|
||||||
|
@ -130,12 +130,7 @@ int32_t snapshotSenderStart(SSyncSnapshotSender *pSender) {
|
||||||
syncSnapshotSendDestroy(pMsg);
|
syncSnapshotSendDestroy(pMsg);
|
||||||
|
|
||||||
// event log
|
// event log
|
||||||
do {
|
sSTrace(pSender, "snapshot sender start");
|
||||||
char *eventLog = snapshotSender2SimpleStr(pSender, "snapshot sender start");
|
|
||||||
syncNodeEventLog(pSender->pSyncNode, eventLog);
|
|
||||||
taosMemoryFree(eventLog);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,12 +154,7 @@ int32_t snapshotSenderStop(SSyncSnapshotSender *pSender, bool finish) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// event log
|
// event log
|
||||||
do {
|
sSTrace(pSender, "snapshot sender stop");
|
||||||
char *eventLog = snapshotSender2SimpleStr(pSender, "snapshot sender stop");
|
|
||||||
syncNodeEventLog(pSender->pSyncNode, eventLog);
|
|
||||||
taosMemoryFree(eventLog);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,17 +202,11 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender) {
|
||||||
syncSnapshotSendDestroy(pMsg);
|
syncSnapshotSendDestroy(pMsg);
|
||||||
|
|
||||||
// event log
|
// event log
|
||||||
do {
|
|
||||||
char *eventLog = NULL;
|
|
||||||
if (pSender->seq == SYNC_SNAPSHOT_SEQ_END) {
|
if (pSender->seq == SYNC_SNAPSHOT_SEQ_END) {
|
||||||
eventLog = snapshotSender2SimpleStr(pSender, "snapshot sender finish");
|
sSTrace(pSender, "snapshot sender finish");
|
||||||
} else {
|
} else {
|
||||||
eventLog = snapshotSender2SimpleStr(pSender, "snapshot sender sending");
|
sSTrace(pSender, "snapshot sender sending");
|
||||||
}
|
}
|
||||||
syncNodeEventLog(pSender->pSyncNode, eventLog);
|
|
||||||
taosMemoryFree(eventLog);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,11 +237,7 @@ int32_t snapshotReSend(SSyncSnapshotSender *pSender) {
|
||||||
syncSnapshotSendDestroy(pMsg);
|
syncSnapshotSendDestroy(pMsg);
|
||||||
|
|
||||||
// event log
|
// event log
|
||||||
do {
|
sSTrace(pSender, "snapshot sender resend");
|
||||||
char *eventLog = snapshotSender2SimpleStr(pSender, "snapshot sender resend");
|
|
||||||
syncNodeEventLog(pSender->pSyncNode, eventLog);
|
|
||||||
taosMemoryFree(eventLog);
|
|
||||||
} while (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -287,10 +267,10 @@ cJSON *snapshotSender2Json(SSyncSnapshotSender *pSender) {
|
||||||
|
|
||||||
if (pSender->pCurrentBlock != NULL) {
|
if (pSender->pCurrentBlock != NULL) {
|
||||||
char *s;
|
char *s;
|
||||||
s = syncUtilprintBin((char *)(pSender->pCurrentBlock), pSender->blockLen);
|
s = syncUtilPrintBin((char *)(pSender->pCurrentBlock), pSender->blockLen);
|
||||||
cJSON_AddStringToObject(pRoot, "pCurrentBlock", s);
|
cJSON_AddStringToObject(pRoot, "pCurrentBlock", s);
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
s = syncUtilprintBin2((char *)(pSender->pCurrentBlock), pSender->blockLen);
|
s = syncUtilPrintBin2((char *)(pSender->pCurrentBlock), pSender->blockLen);
|
||||||
cJSON_AddStringToObject(pRoot, "pCurrentBlock2", s);
|
cJSON_AddStringToObject(pRoot, "pCurrentBlock2", s);
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
}
|
}
|
||||||
|
@ -327,31 +307,12 @@ char *snapshotSender2Str(SSyncSnapshotSender *pSender) {
|
||||||
return serialized;
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *snapshotSender2SimpleStr(SSyncSnapshotSender *pSender, char *event) {
|
|
||||||
int32_t len = 256;
|
|
||||||
char *s = taosMemoryMalloc(len);
|
|
||||||
|
|
||||||
SRaftId destId = pSender->pSyncNode->replicasId[pSender->replicaIndex];
|
|
||||||
char host[64];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(destId.addr, host, sizeof(host), &port);
|
|
||||||
|
|
||||||
snprintf(s, len,
|
|
||||||
"%s {%p s-param:%" PRId64 " e-param:%" PRId64 " laindex:%" PRId64 " laterm:%" PRIu64 " lcindex:%" PRId64
|
|
||||||
" seq:%d ack:%d finish:%d replica-index:%d %s:%d}",
|
|
||||||
event, pSender, pSender->snapshotParam.start, pSender->snapshotParam.end, pSender->snapshot.lastApplyIndex,
|
|
||||||
pSender->snapshot.lastApplyTerm, pSender->snapshot.lastConfigIndex, pSender->seq, pSender->ack,
|
|
||||||
pSender->finish, pSender->replicaIndex, host, port);
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t syncNodeStartSnapshot(SSyncNode *pSyncNode, SRaftId *pDestId) {
|
int32_t syncNodeStartSnapshot(SSyncNode *pSyncNode, SRaftId *pDestId) {
|
||||||
syncNodeEventLog(pSyncNode, "starting snapshot ...");
|
sNTrace(pSyncNode, "starting snapshot ...");
|
||||||
|
|
||||||
SSyncSnapshotSender *pSender = syncNodeGetSnapshotSender(pSyncNode, pDestId);
|
SSyncSnapshotSender *pSender = syncNodeGetSnapshotSender(pSyncNode, pDestId);
|
||||||
if (pSender == NULL) {
|
if (pSender == NULL) {
|
||||||
syncNodeErrorLog(pSyncNode, "start snapshot error, sender is null");
|
sNError(pSyncNode, "start snapshot error, sender is null");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,14 +321,14 @@ int32_t syncNodeStartSnapshot(SSyncNode *pSyncNode, SRaftId *pDestId) {
|
||||||
if (snapshotSenderIsStart(pSender)) {
|
if (snapshotSenderIsStart(pSender)) {
|
||||||
code = snapshotSenderStop(pSender, false);
|
code = snapshotSenderStop(pSender, false);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
syncNodeErrorLog(pSyncNode, "snapshot sender stop error");
|
sNError(pSyncNode, "snapshot sender stop error");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
code = snapshotSenderStart(pSender);
|
code = snapshotSenderStart(pSender);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
syncNodeErrorLog(pSyncNode, "snapshot sender start error");
|
sNError(pSyncNode, "snapshot sender start error");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -447,11 +408,7 @@ static void snapshotReceiverDoStart(SSyncSnapshotReceiver *pReceiver, SyncSnapsh
|
||||||
pReceiver->startTime = pBeginMsg->startTime;
|
pReceiver->startTime = pBeginMsg->startTime;
|
||||||
|
|
||||||
// event log
|
// event log
|
||||||
do {
|
sRTrace(pReceiver, "snapshot receiver start");
|
||||||
char *eventLog = snapshotReceiver2SimpleStr(pReceiver, "snapshot receiver start");
|
|
||||||
syncNodeEventLog(pReceiver->pSyncNode, eventLog);
|
|
||||||
taosMemoryFree(eventLog);
|
|
||||||
} while (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// force stop
|
// force stop
|
||||||
|
@ -467,11 +424,7 @@ void snapshotReceiverForceStop(SSyncSnapshotReceiver *pReceiver) {
|
||||||
pReceiver->start = false;
|
pReceiver->start = false;
|
||||||
|
|
||||||
// event log
|
// event log
|
||||||
do {
|
sRTrace(pReceiver, "snapshot receiver force stop");
|
||||||
char *eventLog = snapshotReceiver2SimpleStr(pReceiver, "snapshot receiver force stop");
|
|
||||||
syncNodeEventLog(pReceiver->pSyncNode, eventLog);
|
|
||||||
taosMemoryFree(eventLog);
|
|
||||||
} while (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if receiver receive msg from seq = SYNC_SNAPSHOT_SEQ_BEGIN, start receiver
|
// if receiver receive msg from seq = SYNC_SNAPSHOT_SEQ_BEGIN, start receiver
|
||||||
|
@ -495,14 +448,7 @@ int32_t snapshotReceiverStop(SSyncSnapshotReceiver *pReceiver) {
|
||||||
pReceiver->start = false;
|
pReceiver->start = false;
|
||||||
|
|
||||||
// event log
|
// event log
|
||||||
do {
|
sRTrace(pReceiver, "snapshot receiver stop");
|
||||||
SSnapshot snapshot;
|
|
||||||
pReceiver->pSyncNode->pFsm->FpGetSnapshotInfo(pReceiver->pSyncNode->pFsm, &snapshot);
|
|
||||||
char *eventLog = snapshotReceiver2SimpleStr(pReceiver, "snapshot receiver stop");
|
|
||||||
syncNodeEventLog(pReceiver->pSyncNode, eventLog);
|
|
||||||
taosMemoryFree(eventLog);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -517,7 +463,7 @@ static int32_t snapshotReceiverFinish(SSyncSnapshotReceiver *pReceiver, SyncSnap
|
||||||
code = pReceiver->pSyncNode->pFsm->FpSnapshotDoWrite(pReceiver->pSyncNode->pFsm, pReceiver->pWriter, pMsg->data,
|
code = pReceiver->pSyncNode->pFsm->FpSnapshotDoWrite(pReceiver->pSyncNode->pFsm, pReceiver->pWriter, pMsg->data,
|
||||||
pMsg->dataLen);
|
pMsg->dataLen);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
syncNodeErrorLog(pReceiver->pSyncNode, "snapshot write error");
|
sNError(pReceiver->pSyncNode, "snapshot write error");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -526,7 +472,7 @@ static int32_t snapshotReceiverFinish(SSyncSnapshotReceiver *pReceiver, SyncSnap
|
||||||
code =
|
code =
|
||||||
pReceiver->pSyncNode->pLogStore->syncLogRestoreFromSnapshot(pReceiver->pSyncNode->pLogStore, pMsg->lastIndex);
|
pReceiver->pSyncNode->pLogStore->syncLogRestoreFromSnapshot(pReceiver->pSyncNode->pLogStore, pMsg->lastIndex);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
syncNodeErrorLog(pReceiver->pSyncNode, "wal restore from snapshot error");
|
sNError(pReceiver->pSyncNode, "wal restore from snapshot error");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -545,8 +491,7 @@ static int32_t snapshotReceiverFinish(SSyncSnapshotReceiver *pReceiver, SyncSnap
|
||||||
code = pReceiver->pSyncNode->pFsm->FpSnapshotStopWrite(pReceiver->pSyncNode->pFsm, pReceiver->pWriter, true,
|
code = pReceiver->pSyncNode->pFsm->FpSnapshotStopWrite(pReceiver->pSyncNode->pFsm, pReceiver->pWriter, true,
|
||||||
&(pReceiver->snapshot));
|
&(pReceiver->snapshot));
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
syncNodeErrorLog(pReceiver->pSyncNode, "snapshot stop writer true error");
|
sNError(pReceiver->pSyncNode, "snapshot stop writer true error");
|
||||||
// ASSERT(0);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
pReceiver->pWriter = NULL;
|
pReceiver->pWriter = NULL;
|
||||||
|
@ -555,19 +500,12 @@ static int32_t snapshotReceiverFinish(SSyncSnapshotReceiver *pReceiver, SyncSnap
|
||||||
pReceiver->ack = SYNC_SNAPSHOT_SEQ_END;
|
pReceiver->ack = SYNC_SNAPSHOT_SEQ_END;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
syncNodeErrorLog(pReceiver->pSyncNode, "snapshot stop writer true error");
|
sNError(pReceiver->pSyncNode, "snapshot stop writer true error");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// event log
|
// event log
|
||||||
do {
|
sRTrace(pReceiver, "snapshot receiver got last data, finish, apply snapshot");
|
||||||
SSnapshot snapshot;
|
|
||||||
pReceiver->pSyncNode->pFsm->FpGetSnapshotInfo(pReceiver->pSyncNode->pFsm, &snapshot);
|
|
||||||
char *eventLog = snapshotReceiver2SimpleStr(pReceiver, "snapshot receiver got last data, finish, apply snapshot");
|
|
||||||
syncNodeEventLog(pReceiver->pSyncNode, eventLog);
|
|
||||||
taosMemoryFree(eventLog);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -588,11 +526,7 @@ static void snapshotReceiverGotData(SSyncSnapshotReceiver *pReceiver, SyncSnapsh
|
||||||
pReceiver->ack = pMsg->seq;
|
pReceiver->ack = pMsg->seq;
|
||||||
|
|
||||||
// event log
|
// event log
|
||||||
do {
|
sRTrace(pReceiver, "snapshot receiver receiving");
|
||||||
char *eventLog = snapshotReceiver2SimpleStr(pReceiver, "snapshot receiver receiving");
|
|
||||||
syncNodeEventLog(pReceiver->pSyncNode, eventLog);
|
|
||||||
taosMemoryFree(eventLog);
|
|
||||||
} while (0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -653,27 +587,6 @@ char *snapshotReceiver2Str(SSyncSnapshotReceiver *pReceiver) {
|
||||||
return serialized;
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *snapshotReceiver2SimpleStr(SSyncSnapshotReceiver *pReceiver, char *event) {
|
|
||||||
int32_t len = 256;
|
|
||||||
char *s = taosMemoryMalloc(len);
|
|
||||||
|
|
||||||
SRaftId fromId = pReceiver->fromId;
|
|
||||||
char host[128];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(fromId.addr, host, sizeof(host), &port);
|
|
||||||
|
|
||||||
snprintf(s, len,
|
|
||||||
"%s {%p start:%d ack:%d term:%" PRIu64 " start-time:%" PRId64 " from:%s:%d s-param:%" PRId64
|
|
||||||
" e-param:%" PRId64 " laindex:%" PRId64 " laterm:%" PRIu64
|
|
||||||
" "
|
|
||||||
"lcindex:%" PRId64 "}",
|
|
||||||
event, pReceiver, pReceiver->start, pReceiver->ack, pReceiver->term, pReceiver->startTime, host, port,
|
|
||||||
pReceiver->snapshotParam.start, pReceiver->snapshotParam.end, pReceiver->snapshot.lastApplyIndex,
|
|
||||||
pReceiver->snapshot.lastApplyTerm, pReceiver->snapshot.lastConfigIndex);
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
SyncIndex syncNodeGetSnapBeginIndex(SSyncNode *ths) {
|
SyncIndex syncNodeGetSnapBeginIndex(SSyncNode *ths) {
|
||||||
SyncIndex snapStart = SYNC_INDEX_INVALID;
|
SyncIndex snapStart = SYNC_INDEX_INVALID;
|
||||||
|
|
||||||
|
@ -688,11 +601,8 @@ SyncIndex syncNodeGetSnapBeginIndex(SSyncNode *ths) {
|
||||||
int64_t walCommitVer = walGetCommittedVer(pWal);
|
int64_t walCommitVer = walGetCommittedVer(pWal);
|
||||||
|
|
||||||
if (!isEmpty && ths->commitIndex != walCommitVer) {
|
if (!isEmpty && ths->commitIndex != walCommitVer) {
|
||||||
char logBuf[128];
|
sNError(ths, "commit not same, wal-commit:%" PRId64 ", commit:%" PRId64 ", ignore", walCommitVer,
|
||||||
snprintf(logBuf, sizeof(logBuf), "commit not same, wal-commit:%" PRId64 ", commit:%" PRId64 ", ignore",
|
ths->commitIndex);
|
||||||
walCommitVer, ths->commitIndex);
|
|
||||||
syncNodeErrorLog(ths, logBuf);
|
|
||||||
|
|
||||||
snapStart = walCommitVer + 1;
|
snapStart = walCommitVer + 1;
|
||||||
} else {
|
} else {
|
||||||
snapStart = ths->commitIndex + 1;
|
snapStart = ths->commitIndex + 1;
|
||||||
|
@ -726,7 +636,7 @@ static int32_t syncNodeOnSnapshotPre(SSyncNode *pSyncNode, SyncSnapshotSend *pMs
|
||||||
|
|
||||||
_START_RECEIVER:
|
_START_RECEIVER:
|
||||||
if (taosGetTimestampMs() - pMsg->startTime > SNAPSHOT_MAX_CLOCK_SKEW_MS) {
|
if (taosGetTimestampMs() - pMsg->startTime > SNAPSHOT_MAX_CLOCK_SKEW_MS) {
|
||||||
syncNodeErrorLog(pSyncNode, "snapshot receiver time skew too much");
|
sNError(pSyncNode, "snapshot receiver time skew too much");
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
// waiting for clock match
|
// waiting for clock match
|
||||||
|
@ -772,14 +682,14 @@ static int32_t syncNodeOnSnapshotBegin(SSyncNode *pSyncNode, SyncSnapshotSend *p
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
// ignore
|
// ignore
|
||||||
syncNodeEventLog(pSyncNode, "msg ignore");
|
sNTrace(pSyncNode, "msg ignore");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_START_RECEIVER:
|
_START_RECEIVER:
|
||||||
if (taosGetTimestampMs() - pMsg->startTime > SNAPSHOT_MAX_CLOCK_SKEW_MS) {
|
if (taosGetTimestampMs() - pMsg->startTime > SNAPSHOT_MAX_CLOCK_SKEW_MS) {
|
||||||
syncNodeErrorLog(pSyncNode, "snapshot receiver time skew too much");
|
sNError(pSyncNode, "snapshot receiver time skew too much");
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
// waiting for clock match
|
// waiting for clock match
|
||||||
|
@ -899,35 +809,18 @@ int32_t syncNodeOnSnapshot(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// error log
|
// error log
|
||||||
do {
|
sRTrace(pReceiver, "snapshot receiver recv error seq:%d, my ack:%d", pMsg->seq, pReceiver->ack);
|
||||||
char logBuf[96];
|
|
||||||
snprintf(logBuf, sizeof(logBuf), "snapshot receiver recv error seq:%d, my ack:%d", pMsg->seq, pReceiver->ack);
|
|
||||||
char *eventLog = snapshotReceiver2SimpleStr(pReceiver, logBuf);
|
|
||||||
syncNodeErrorLog(pSyncNode, eventLog);
|
|
||||||
taosMemoryFree(eventLog);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// error log
|
// error log
|
||||||
do {
|
sRTrace(pReceiver, "snapshot receiver term not equal");
|
||||||
char *eventLog = snapshotReceiver2SimpleStr(pReceiver, "snapshot receiver term not equal");
|
|
||||||
syncNodeErrorLog(pSyncNode, eventLog);
|
|
||||||
taosMemoryFree(eventLog);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// error log
|
// error log
|
||||||
do {
|
sRTrace(pReceiver, "snapshot receiver not follower");
|
||||||
char *eventLog = snapshotReceiver2SimpleStr(pReceiver, "snapshot receiver not follower");
|
|
||||||
syncNodeErrorLog(pSyncNode, eventLog);
|
|
||||||
taosMemoryFree(eventLog);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -947,14 +840,14 @@ int32_t syncNodeOnSnapshotReplyPre(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg)
|
||||||
pSender->snapshotParam.end = snapshot.lastApplyIndex;
|
pSender->snapshotParam.end = snapshot.lastApplyIndex;
|
||||||
|
|
||||||
if (pMsg->snapBeginIndex > snapshot.lastApplyIndex) {
|
if (pMsg->snapBeginIndex > snapshot.lastApplyIndex) {
|
||||||
syncNodeErrorLog(pSyncNode, "snapshot last index too small");
|
sNError(pSyncNode, "snapshot last index too small");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// start reader
|
// start reader
|
||||||
int32_t code = pSyncNode->pFsm->FpSnapshotStartRead(pSyncNode->pFsm, &(pSender->snapshotParam), &(pSender->pReader));
|
int32_t code = pSyncNode->pFsm->FpSnapshotStartRead(pSyncNode->pFsm, &(pSender->snapshotParam), &(pSender->pReader));
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
syncNodeErrorLog(pSyncNode, "create snapshot reader error");
|
sNError(pSyncNode, "create snapshot reader error");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1029,34 +922,17 @@ int32_t syncNodeOnSnapshotReply(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// error log
|
// error log
|
||||||
do {
|
sSError(pSender, "snapshot sender recv error ack:%d, my seq:%d", pMsg->ack, pSender->seq);
|
||||||
char logBuf[96];
|
|
||||||
snprintf(logBuf, sizeof(logBuf), "snapshot sender recv error ack:%d, my seq:%d", pMsg->ack, pSender->seq);
|
|
||||||
char *eventLog = snapshotSender2SimpleStr(pSender, logBuf);
|
|
||||||
syncNodeErrorLog(pSyncNode, eventLog);
|
|
||||||
taosMemoryFree(eventLog);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// error log
|
// error log
|
||||||
do {
|
sSError(pSender, "snapshot sender term not equal");
|
||||||
char *eventLog = snapshotSender2SimpleStr(pSender, "snapshot sender term not equal");
|
|
||||||
syncNodeErrorLog(pSyncNode, eventLog);
|
|
||||||
taosMemoryFree(eventLog);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// error log
|
// error log
|
||||||
do {
|
sSError(pSender, "snapshot sender not leader");
|
||||||
char *eventLog = snapshotSender2SimpleStr(pSender, "snapshot sender not leader");
|
|
||||||
syncNodeErrorLog(pSyncNode, eventLog);
|
|
||||||
taosMemoryFree(eventLog);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1082,11 +958,8 @@ int32_t syncNodeOnPreSnapshot(SSyncNode *ths, SyncPreSnapshot *pMsg) {
|
||||||
int64_t walCommitVer = walGetCommittedVer(pWal);
|
int64_t walCommitVer = walGetCommittedVer(pWal);
|
||||||
|
|
||||||
if (!isEmpty && ths->commitIndex != walCommitVer) {
|
if (!isEmpty && ths->commitIndex != walCommitVer) {
|
||||||
char logBuf[128];
|
sNError(ths, "commit not same, wal-commit:%" PRId64 ", commit:%" PRId64 ", ignore", walCommitVer,
|
||||||
snprintf(logBuf, sizeof(logBuf), "commit not same, wal-commit:%" PRId64 ", commit:%" PRId64 ", ignore",
|
ths->commitIndex);
|
||||||
walCommitVer, ths->commitIndex);
|
|
||||||
syncNodeErrorLog(ths, logBuf);
|
|
||||||
|
|
||||||
goto _IGNORE;
|
goto _IGNORE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1095,7 +968,7 @@ int32_t syncNodeOnPreSnapshot(SSyncNode *ths, SyncPreSnapshot *pMsg) {
|
||||||
// make local log clean
|
// make local log clean
|
||||||
int32_t code = ths->pLogStore->syncLogTruncate(ths->pLogStore, pMsgReply->snapStart);
|
int32_t code = ths->pLogStore->syncLogTruncate(ths->pLogStore, pMsgReply->snapStart);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
syncNodeErrorLog(ths, "truncate wal error");
|
sNError(ths, "truncate wal error");
|
||||||
goto _IGNORE;
|
goto _IGNORE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,17 +49,12 @@ static void syncNodeCleanConfigIndex(SSyncNode* ths) {
|
||||||
int32_t code = raftCfgPersist(ths->pRaftCfg);
|
int32_t code = raftCfgPersist(ths->pRaftCfg);
|
||||||
ASSERT(code == 0);
|
ASSERT(code == 0);
|
||||||
|
|
||||||
do {
|
sNTrace(ths, "clean config index arr, old-cnt:%d, new-cnt:%d", oldCnt, ths->pRaftCfg->configIndexCount);
|
||||||
char logBuf[128];
|
|
||||||
snprintf(logBuf, sizeof(logBuf), "clean config index arr, old-cnt:%d, new-cnt:%d", oldCnt,
|
|
||||||
ths->pRaftCfg->configIndexCount);
|
|
||||||
syncNodeEventLog(ths, logBuf);
|
|
||||||
} while (0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncNodeTimerRoutine(SSyncNode* ths) {
|
int32_t syncNodeTimerRoutine(SSyncNode* ths) {
|
||||||
syncNodeEventLog(ths, "timer routines");
|
sNTrace(ths, "timer routines");
|
||||||
|
|
||||||
// timer replicate
|
// timer replicate
|
||||||
syncNodeReplicate(ths);
|
syncNodeReplicate(ths);
|
||||||
|
@ -79,12 +74,7 @@ int32_t syncNodeTimerRoutine(SSyncNode* ths) {
|
||||||
sError("vgId:%d, timer wal snapshot end error since:%s", ths->vgId, terrstr());
|
sError("vgId:%d, timer wal snapshot end error since:%s", ths->vgId, terrstr());
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
do {
|
sNTrace(ths, "wal snapshot end, index:%" PRId64, atomic_load_64(&ths->snapshottingIndex));
|
||||||
char logBuf[256];
|
|
||||||
snprintf(logBuf, sizeof(logBuf), "wal snapshot end, index:%" PRId64, atomic_load_64(&ths->snapshottingIndex));
|
|
||||||
syncNodeEventLog(ths, logBuf);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
atomic_store_64(&ths->snapshottingIndex, SYNC_INDEX_INVALID);
|
atomic_store_64(&ths->snapshottingIndex, SYNC_INDEX_INVALID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,17 +13,17 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
#include "syncUtil.h"
|
#include "syncUtil.h"
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "syncEnv.h"
|
#include "syncEnv.h"
|
||||||
|
#include "syncInt.h"
|
||||||
|
#include "syncRaftCfg.h"
|
||||||
|
#include "syncRaftStore.h"
|
||||||
|
#include "syncSnapshot.h"
|
||||||
|
|
||||||
void addEpIntoEpSet(SEpSet* pEpSet, const char* fqdn, uint16_t port);
|
extern void addEpIntoEpSet(SEpSet* pEpSet, const char* fqdn, uint16_t port);
|
||||||
|
|
||||||
// ---- encode / decode
|
|
||||||
uint64_t syncUtilAddr2U64(const char* host, uint16_t port) {
|
uint64_t syncUtilAddr2U64(const char* host, uint16_t port) {
|
||||||
uint64_t u64;
|
|
||||||
|
|
||||||
uint32_t hostU32 = taosGetIpv4FromFqdn(host);
|
uint32_t hostU32 = taosGetIpv4FromFqdn(host);
|
||||||
if (hostU32 == (uint32_t)-1) {
|
if (hostU32 == (uint32_t)-1) {
|
||||||
sError("failed to resolve ipv4 addr. host:%s", host);
|
sError("failed to resolve ipv4 addr. host:%s", host);
|
||||||
|
@ -31,41 +31,22 @@ uint64_t syncUtilAddr2U64(const char* host, uint16_t port) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
uint64_t u64 = (((uint64_t)hostU32) << 32) | (((uint32_t)port) << 16);
|
||||||
uint32_t hostU32 = (uint32_t)taosInetAddr(host);
|
|
||||||
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;
|
return u64;
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncUtilU642Addr(uint64_t u64, char* host, size_t len, uint16_t* port) {
|
void syncUtilU642Addr(uint64_t u64, char* host, int64_t len, uint16_t* port) {
|
||||||
uint32_t hostU32 = (uint32_t)((u64 >> 32) & 0x00000000FFFFFFFF);
|
uint32_t hostU32 = (uint32_t)((u64 >> 32) & 0x00000000FFFFFFFF);
|
||||||
|
|
||||||
struct in_addr addr;
|
struct in_addr addr = {.s_addr = hostU32};
|
||||||
addr.s_addr = hostU32;
|
|
||||||
taosInetNtoa(addr, host, len);
|
taosInetNtoa(addr, host, len);
|
||||||
*port = (uint16_t)((u64 & 0x00000000FFFF0000) >> 16);
|
*port = (uint16_t)((u64 & 0x00000000FFFF0000) >> 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncUtilnodeInfo2EpSet(const SNodeInfo* pNodeInfo, SEpSet* pEpSet) {
|
void syncUtilnodeInfo2EpSet(const SNodeInfo* pInfo, SEpSet* pEpSet) {
|
||||||
pEpSet->inUse = 0;
|
pEpSet->inUse = 0;
|
||||||
pEpSet->numOfEps = 0;
|
pEpSet->numOfEps = 0;
|
||||||
addEpIntoEpSet(pEpSet, pNodeInfo->nodeFqdn, pNodeInfo->nodePort);
|
addEpIntoEpSet(pEpSet, pInfo->nodeFqdn, pInfo->nodePort);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncUtilraftId2EpSet(const SRaftId* raftId, SEpSet* pEpSet) {
|
void syncUtilraftId2EpSet(const SRaftId* raftId, SEpSet* pEpSet) {
|
||||||
|
@ -73,28 +54,22 @@ void syncUtilraftId2EpSet(const SRaftId* raftId, SEpSet* pEpSet) {
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
|
|
||||||
syncUtilU642Addr(raftId->addr, host, sizeof(host), &port);
|
syncUtilU642Addr(raftId->addr, host, sizeof(host), &port);
|
||||||
|
|
||||||
/*
|
|
||||||
pEpSet->numOfEps = 1;
|
|
||||||
pEpSet->inUse = 0;
|
|
||||||
pEpSet->eps[0].port = port;
|
|
||||||
snprintf(pEpSet->eps[0].fqdn, sizeof(pEpSet->eps[0].fqdn), "%s", host);
|
|
||||||
*/
|
|
||||||
pEpSet->inUse = 0;
|
pEpSet->inUse = 0;
|
||||||
pEpSet->numOfEps = 0;
|
pEpSet->numOfEps = 0;
|
||||||
addEpIntoEpSet(pEpSet, host, port);
|
addEpIntoEpSet(pEpSet, host, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool syncUtilnodeInfo2raftId(const SNodeInfo* pNodeInfo, SyncGroupId vgId, SRaftId* raftId) {
|
bool syncUtilnodeInfo2raftId(const SNodeInfo* pInfo, SyncGroupId vgId, SRaftId* raftId) {
|
||||||
uint32_t ipv4 = taosGetIpv4FromFqdn(pNodeInfo->nodeFqdn);
|
uint32_t ipv4 = taosGetIpv4FromFqdn(pInfo->nodeFqdn);
|
||||||
if (ipv4 == 0xFFFFFFFF || ipv4 == 1) {
|
if (ipv4 == 0xFFFFFFFF || ipv4 == 1) {
|
||||||
sError("failed to resolve ipv4 addr. fqdn: %s", pNodeInfo->nodeFqdn);
|
sError("failed to resolve ipv4 addr. fqdn: %s", pInfo->nodeFqdn);
|
||||||
terrno = TSDB_CODE_TSC_INVALID_FQDN;
|
terrno = TSDB_CODE_TSC_INVALID_FQDN;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char ipbuf[128] = {0};
|
char ipbuf[128] = {0};
|
||||||
tinet_ntoa(ipbuf, ipv4);
|
tinet_ntoa(ipbuf, ipv4);
|
||||||
raftId->addr = syncUtilAddr2U64(ipbuf, pNodeInfo->nodePort);
|
raftId->addr = syncUtilAddr2U64(ipbuf, pInfo->nodePort);
|
||||||
raftId->vgId = vgId;
|
raftId->vgId = vgId;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -106,31 +81,9 @@ bool syncUtilSameId(const SRaftId* pId1, const SRaftId* pId2) {
|
||||||
|
|
||||||
bool syncUtilEmptyId(const SRaftId* pId) { return (pId->addr == 0 && pId->vgId == 0); }
|
bool syncUtilEmptyId(const SRaftId* pId) { return (pId->addr == 0 && pId->vgId == 0); }
|
||||||
|
|
||||||
// ---- SSyncBuffer -----
|
static inline int32_t syncUtilRand(int32_t max) { return taosRand() % max; }
|
||||||
void syncUtilbufBuild(SSyncBuffer* syncBuf, size_t len) {
|
|
||||||
syncBuf->len = len;
|
|
||||||
syncBuf->data = taosMemoryMalloc(syncBuf->len);
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncUtilbufDestroy(SSyncBuffer* syncBuf) { taosMemoryFree(syncBuf->data); }
|
|
||||||
|
|
||||||
void syncUtilbufCopy(const SSyncBuffer* src, SSyncBuffer* dest) {
|
|
||||||
dest->len = src->len;
|
|
||||||
dest->data = src->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncUtilbufCopyDeep(const SSyncBuffer* src, SSyncBuffer* dest) {
|
|
||||||
dest->len = src->len;
|
|
||||||
dest->data = taosMemoryMalloc(dest->len);
|
|
||||||
memcpy(dest->data, src->data, dest->len);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---- misc ----
|
|
||||||
|
|
||||||
int32_t syncUtilRand(int32_t max) { return taosRand() % max; }
|
|
||||||
|
|
||||||
int32_t syncUtilElectRandomMS(int32_t min, int32_t max) {
|
int32_t syncUtilElectRandomMS(int32_t min, int32_t max) {
|
||||||
ASSERT(min > 0 && max > 0 && max >= min);
|
|
||||||
int32_t rdm = min + syncUtilRand(max - min);
|
int32_t rdm = min + syncUtilRand(max - min);
|
||||||
|
|
||||||
// sDebug("random min:%d, max:%d, rdm:%d", min, max, rdm);
|
// sDebug("random min:%d, max:%d, rdm:%d", min, max, rdm);
|
||||||
|
@ -176,7 +129,7 @@ char* syncUtilRaftId2Str(const SRaftId* p) {
|
||||||
return serialized;
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool syncUtilCanPrint(char c) {
|
static inline bool syncUtilCanPrint(char c) {
|
||||||
if (c >= 32 && c <= 126) {
|
if (c >= 32 && c <= 126) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -184,7 +137,7 @@ bool syncUtilCanPrint(char c) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char* syncUtilprintBin(char* ptr, uint32_t len) {
|
char* syncUtilPrintBin(char* ptr, uint32_t len) {
|
||||||
int64_t memLen = (int64_t)(len + 1);
|
int64_t memLen = (int64_t)(len + 1);
|
||||||
char* s = taosMemoryMalloc(memLen);
|
char* s = taosMemoryMalloc(memLen);
|
||||||
ASSERT(s != NULL);
|
ASSERT(s != NULL);
|
||||||
|
@ -199,7 +152,7 @@ char* syncUtilprintBin(char* ptr, uint32_t len) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* syncUtilprintBin2(char* ptr, uint32_t len) {
|
char* syncUtilPrintBin2(char* ptr, uint32_t len) {
|
||||||
uint32_t len2 = len * 4 + 1;
|
uint32_t len2 = len * 4 + 1;
|
||||||
char* s = taosMemoryMalloc(len2);
|
char* s = taosMemoryMalloc(len2);
|
||||||
ASSERT(s != NULL);
|
ASSERT(s != NULL);
|
||||||
|
@ -213,16 +166,6 @@ char* syncUtilprintBin2(char* ptr, uint32_t len) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncIndex syncUtilMinIndex(SyncIndex a, SyncIndex b) {
|
|
||||||
SyncIndex r = a < b ? a : b;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
SyncIndex syncUtilMaxIndex(SyncIndex a, SyncIndex b) {
|
|
||||||
SyncIndex r = a > b ? a : b;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncUtilMsgHtoN(void* msg) {
|
void syncUtilMsgHtoN(void* msg) {
|
||||||
// htonl
|
// htonl
|
||||||
SMsgHead* pHead = msg;
|
SMsgHead* pHead = msg;
|
||||||
|
@ -237,15 +180,6 @@ void syncUtilMsgNtoH(void* msg) {
|
||||||
pHead->vgId = ntohl(pHead->vgId);
|
pHead->vgId = ntohl(pHead->vgId);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
bool syncUtilIsData(tmsg_t msgType) {
|
|
||||||
if (msgType == TDMT_SYNC_NOOP || msgType == TDMT_SYNC_CONFIG_CHANGE) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool syncUtilUserPreCommit(tmsg_t msgType) {
|
bool syncUtilUserPreCommit(tmsg_t msgType) {
|
||||||
if (msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_CONFIG_CHANGE && msgType != TDMT_SYNC_CONFIG_CHANGE_FINISH &&
|
if (msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_CONFIG_CHANGE && msgType != TDMT_SYNC_CONFIG_CHANGE_FINISH &&
|
||||||
msgType != TDMT_SYNC_LEADER_TRANSFER) {
|
msgType != TDMT_SYNC_LEADER_TRANSFER) {
|
||||||
|
@ -273,24 +207,149 @@ bool syncUtilUserRollback(tmsg_t msgType) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncUtilJson2Line(char* jsonStr) {
|
void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNode* pNode, const char* format, ...) {
|
||||||
int p, q, len;
|
if (pNode == NULL || pNode->pRaftCfg != NULL && pNode->pRaftStore == NULL || pNode->pLogStore == NULL) return;
|
||||||
p = 0;
|
|
||||||
q = 1;
|
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
|
||||||
len = strlen(jsonStr);
|
if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) {
|
||||||
while (1) {
|
pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot);
|
||||||
if (jsonStr[q] == '\0') {
|
|
||||||
jsonStr[p + 1] = '\0';
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jsonStr[q] == '\n' || jsonStr[q] == ' ' || jsonStr[q] == '\t') {
|
SyncIndex logLastIndex = SYNC_INDEX_INVALID;
|
||||||
q++;
|
SyncIndex logBeginIndex = SYNC_INDEX_INVALID;
|
||||||
continue;
|
if (pNode->pLogStore != NULL) {
|
||||||
} else {
|
logLastIndex = pNode->pLogStore->syncLogLastIndex(pNode->pLogStore);
|
||||||
jsonStr[p + 1] = jsonStr[q];
|
logBeginIndex = pNode->pLogStore->syncLogBeginIndex(pNode->pLogStore);
|
||||||
p++;
|
|
||||||
q++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char cfgStr[1024];
|
||||||
|
syncCfg2SimpleStr(&(pNode->pRaftCfg->cfg), cfgStr, sizeof(cfgStr));
|
||||||
|
|
||||||
|
char* pPeerStateStr = syncNodePeerState2Str(pNode);
|
||||||
|
int32_t quorum = syncNodeDynamicQuorum(pNode);
|
||||||
|
|
||||||
|
char eventLog[512]; // {0};
|
||||||
|
va_list argpointer;
|
||||||
|
va_start(argpointer, format);
|
||||||
|
int32_t writeLen = vsnprintf(eventLog, sizeof(eventLog), format, argpointer);
|
||||||
|
va_end(argpointer);
|
||||||
|
|
||||||
|
taosPrintLog(flags, level, dflag,
|
||||||
|
"vgId:%d, sync %s "
|
||||||
|
"%s"
|
||||||
|
", tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", min:%" PRId64 ", snap:%" PRId64
|
||||||
|
", snap-tm:%" PRIu64 ", sby:%d, stgy:%d, bch:%d, r-num:%d, lcfg:%" PRId64
|
||||||
|
", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s, %s",
|
||||||
|
pNode->vgId, syncStr(pNode->state), eventLog, pNode->pRaftStore->currentTerm, pNode->commitIndex,
|
||||||
|
logBeginIndex, logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm,
|
||||||
|
pNode->pRaftCfg->isStandBy, pNode->pRaftCfg->snapshotStrategy, pNode->pRaftCfg->batchSize,
|
||||||
|
pNode->replicaNum, pNode->pRaftCfg->lastConfigIndex, pNode->changing, pNode->restoreFinish, quorum,
|
||||||
|
pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, pPeerStateStr, cfgStr);
|
||||||
|
|
||||||
|
taosMemoryFree(pPeerStateStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void syncPrintSnapshotSenderLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotSender* pSender,
|
||||||
|
const char* format, ...) {
|
||||||
|
SSyncNode* pNode = pSender->pSyncNode;
|
||||||
|
if (pNode == NULL || pNode->pRaftCfg != NULL && pNode->pRaftStore == NULL || pNode->pLogStore == NULL) return;
|
||||||
|
|
||||||
|
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
|
||||||
|
if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) {
|
||||||
|
pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot);
|
||||||
|
}
|
||||||
|
|
||||||
|
SyncIndex logLastIndex = SYNC_INDEX_INVALID;
|
||||||
|
SyncIndex logBeginIndex = SYNC_INDEX_INVALID;
|
||||||
|
if (pNode->pLogStore != NULL) {
|
||||||
|
logLastIndex = pNode->pLogStore->syncLogLastIndex(pNode->pLogStore);
|
||||||
|
logBeginIndex = pNode->pLogStore->syncLogBeginIndex(pNode->pLogStore);
|
||||||
|
}
|
||||||
|
|
||||||
|
char cfgStr[1024];
|
||||||
|
syncCfg2SimpleStr(&(pNode->pRaftCfg->cfg), cfgStr, sizeof(cfgStr));
|
||||||
|
|
||||||
|
char* pPeerStateStr = syncNodePeerState2Str(pNode);
|
||||||
|
int32_t quorum = syncNodeDynamicQuorum(pNode);
|
||||||
|
SRaftId destId = pNode->replicasId[pSender->replicaIndex];
|
||||||
|
char host[64];
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(destId.addr, host, sizeof(host), &port);
|
||||||
|
|
||||||
|
char eventLog[512]; // {0};
|
||||||
|
va_list argpointer;
|
||||||
|
va_start(argpointer, format);
|
||||||
|
int32_t writeLen = vsnprintf(eventLog, sizeof(eventLog), format, argpointer);
|
||||||
|
va_end(argpointer);
|
||||||
|
|
||||||
|
taosPrintLog(flags, level, dflag,
|
||||||
|
"vgId:%d, sync %s "
|
||||||
|
"%s {%p s-param:%" PRId64 " e-param:%" PRId64 " laindex:%" PRId64 " laterm:%" PRIu64 " lcindex:%" PRId64
|
||||||
|
" seq:%d ack:%d finish:%d replica-index:%d %s:%d}"
|
||||||
|
", tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", min:%" PRId64 ", snap:%" PRId64
|
||||||
|
", snap-tm:%" PRIu64 ", sby:%d, stgy:%d, bch:%d, r-num:%d, lcfg:%" PRId64
|
||||||
|
", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s, %s",
|
||||||
|
pNode->vgId, syncStr(pNode->state), eventLog, pSender, pSender->snapshotParam.start,
|
||||||
|
pSender->snapshotParam.end, pSender->snapshot.lastApplyIndex, pSender->snapshot.lastApplyTerm,
|
||||||
|
pSender->snapshot.lastConfigIndex, pSender->seq, pSender->ack, pSender->finish, pSender->replicaIndex,
|
||||||
|
host, port, pNode->pRaftStore->currentTerm, pNode->commitIndex, logBeginIndex, logLastIndex,
|
||||||
|
pNode->minMatchIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm, pNode->pRaftCfg->isStandBy,
|
||||||
|
pNode->pRaftCfg->snapshotStrategy, pNode->pRaftCfg->batchSize, pNode->replicaNum,
|
||||||
|
pNode->pRaftCfg->lastConfigIndex, pNode->changing, pNode->restoreFinish, quorum,
|
||||||
|
pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, pPeerStateStr, cfgStr);
|
||||||
|
|
||||||
|
taosMemoryFree(pPeerStateStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncPrintSnapshotReceiverLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotReceiver* pReceiver,
|
||||||
|
const char* format, ...) {
|
||||||
|
SSyncNode* pNode = pReceiver->pSyncNode;
|
||||||
|
if (pNode == NULL || pNode->pRaftCfg != NULL && pNode->pRaftStore == NULL || pNode->pLogStore == NULL) return;
|
||||||
|
|
||||||
|
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
|
||||||
|
if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) {
|
||||||
|
pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot);
|
||||||
|
}
|
||||||
|
|
||||||
|
SyncIndex logLastIndex = SYNC_INDEX_INVALID;
|
||||||
|
SyncIndex logBeginIndex = SYNC_INDEX_INVALID;
|
||||||
|
if (pNode->pLogStore != NULL) {
|
||||||
|
logLastIndex = pNode->pLogStore->syncLogLastIndex(pNode->pLogStore);
|
||||||
|
logBeginIndex = pNode->pLogStore->syncLogBeginIndex(pNode->pLogStore);
|
||||||
|
}
|
||||||
|
|
||||||
|
char cfgStr[1024];
|
||||||
|
syncCfg2SimpleStr(&(pNode->pRaftCfg->cfg), cfgStr, sizeof(cfgStr));
|
||||||
|
|
||||||
|
char* pPeerStateStr = syncNodePeerState2Str(pNode);
|
||||||
|
int32_t quorum = syncNodeDynamicQuorum(pNode);
|
||||||
|
SRaftId fromId = pReceiver->fromId;
|
||||||
|
char host[128];
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(fromId.addr, host, sizeof(host), &port);
|
||||||
|
|
||||||
|
char eventLog[512]; // {0};
|
||||||
|
va_list argpointer;
|
||||||
|
va_start(argpointer, format);
|
||||||
|
int32_t writeLen = vsnprintf(eventLog, sizeof(eventLog), format, argpointer);
|
||||||
|
va_end(argpointer);
|
||||||
|
|
||||||
|
taosPrintLog(flags, level, dflag,
|
||||||
|
"vgId:%d, sync %s "
|
||||||
|
"%s {%p start:%d ack:%d term:%" PRIu64 " start-time:%" PRId64 " from:%s:%d s-param:%" PRId64
|
||||||
|
" e-param:%" PRId64 " laindex:%" PRId64 " laterm:%" PRIu64 " lcindex:%" PRId64
|
||||||
|
"}"
|
||||||
|
", tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", min:%" PRId64 ", snap:%" PRId64
|
||||||
|
", snap-tm:%" PRIu64 ", sby:%d, stgy:%d, bch:%d, r-num:%d, lcfg:%" PRId64
|
||||||
|
", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s, %s",
|
||||||
|
pNode->vgId, syncStr(pNode->state), eventLog, pReceiver, pReceiver->start, pReceiver->ack,
|
||||||
|
pReceiver->term, pReceiver->startTime, host, port, pReceiver->snapshotParam.start,
|
||||||
|
pReceiver->snapshotParam.end, pReceiver->snapshot.lastApplyIndex, pReceiver->snapshot.lastApplyTerm,
|
||||||
|
pReceiver->snapshot.lastConfigIndex, pNode->pRaftStore->currentTerm, pNode->commitIndex, logBeginIndex,
|
||||||
|
logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm,
|
||||||
|
pNode->pRaftCfg->isStandBy, pNode->pRaftCfg->snapshotStrategy, pNode->pRaftCfg->batchSize,
|
||||||
|
pNode->replicaNum, pNode->pRaftCfg->lastConfigIndex, pNode->changing, pNode->restoreFinish, quorum,
|
||||||
|
pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, pPeerStateStr, cfgStr);
|
||||||
|
|
||||||
|
taosMemoryFree(pPeerStateStr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ void voteGrantedVote(SVotesGranted *pVotesGranted, SyncRequestVoteReply *pMsg) {
|
||||||
ASSERT(pMsg->voteGranted == true);
|
ASSERT(pMsg->voteGranted == true);
|
||||||
|
|
||||||
if (pMsg->term != pVotesGranted->term) {
|
if (pMsg->term != pVotesGranted->term) {
|
||||||
syncNodeEventLog(pVotesGranted->pSyncNode, "vote grant vnode error");
|
sNTrace(pVotesGranted->pSyncNode, "vote grant vnode error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ bool votesResponded(SVotesRespond *pVotesRespond, const SRaftId *pRaftId) {
|
||||||
|
|
||||||
void votesRespondAdd(SVotesRespond *pVotesRespond, const SyncRequestVoteReply *pMsg) {
|
void votesRespondAdd(SVotesRespond *pVotesRespond, const SyncRequestVoteReply *pMsg) {
|
||||||
if (pVotesRespond->term != pMsg->term) {
|
if (pVotesRespond->term != pMsg->term) {
|
||||||
syncNodeEventLog(pVotesRespond->pSyncNode, "vote respond add error");
|
sNTrace(pVotesRespond->pSyncNode, "vote respond add error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -191,7 +191,7 @@ int main(int argc, char **argv) {
|
||||||
// step5
|
// step5
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
char *pMsg5 = step5(pMsg4, &len);
|
char *pMsg5 = step5(pMsg4, &len);
|
||||||
char *s = syncUtilprintBin(pMsg5, len);
|
char *s = syncUtilPrintBin(pMsg5, len);
|
||||||
printf("==step5== [%s] \n", s);
|
printf("==step5== [%s] \n", s);
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,6 @@ void test1() {
|
||||||
ASSERT(code == 0);
|
ASSERT(code == 0);
|
||||||
|
|
||||||
SRaftCfgIndex* pRaftCfgIndex = raftCfgIndexOpen(pFile);
|
SRaftCfgIndex* pRaftCfgIndex = raftCfgIndexOpen(pFile);
|
||||||
raftCfgIndexLog2((char*)"==test1==", pRaftCfgIndex);
|
|
||||||
|
|
||||||
raftCfgIndexClose(pRaftCfgIndex);
|
raftCfgIndexClose(pRaftCfgIndex);
|
||||||
}
|
}
|
||||||
|
@ -71,15 +70,11 @@ void test2() {
|
||||||
raftCfgIndexAddConfigIndex(pRaftCfgIndex, i);
|
raftCfgIndexAddConfigIndex(pRaftCfgIndex, i);
|
||||||
}
|
}
|
||||||
raftCfgIndexPersist(pRaftCfgIndex);
|
raftCfgIndexPersist(pRaftCfgIndex);
|
||||||
|
|
||||||
raftCfgIndexLog2((char*)"==test2==", pRaftCfgIndex);
|
|
||||||
raftCfgIndexClose(pRaftCfgIndex);
|
raftCfgIndexClose(pRaftCfgIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test3() {
|
void test3() {
|
||||||
SRaftCfgIndex* pRaftCfgIndex = raftCfgIndexOpen(pFile);
|
SRaftCfgIndex* pRaftCfgIndex = raftCfgIndexOpen(pFile);
|
||||||
|
|
||||||
raftCfgIndexLog2((char*)"==test3==", pRaftCfgIndex);
|
|
||||||
raftCfgIndexClose(pRaftCfgIndex);
|
raftCfgIndexClose(pRaftCfgIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,14 +53,6 @@ SSyncCfg* createSyncCfg() {
|
||||||
return pCfg;
|
return pCfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void test1() {
|
|
||||||
SSyncCfg* pCfg = createSyncCfg();
|
|
||||||
syncCfgLog2((char*)__FUNCTION__, pCfg);
|
|
||||||
syncCfgLog3((char*)__FUNCTION__, pCfg);
|
|
||||||
|
|
||||||
taosMemoryFree(pCfg);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test2() {
|
void test2() {
|
||||||
SSyncCfg* pCfg = createSyncCfg();
|
SSyncCfg* pCfg = createSyncCfg();
|
||||||
char* s = syncCfg2Str(pCfg);
|
char* s = syncCfg2Str(pCfg);
|
||||||
|
@ -68,7 +60,6 @@ void test2() {
|
||||||
SSyncCfg* pCfg2 = (SSyncCfg*)taosMemoryMalloc(sizeof(SSyncCfg));
|
SSyncCfg* pCfg2 = (SSyncCfg*)taosMemoryMalloc(sizeof(SSyncCfg));
|
||||||
int32_t ret = syncCfgFromStr(s, pCfg2);
|
int32_t ret = syncCfgFromStr(s, pCfg2);
|
||||||
assert(ret == 0);
|
assert(ret == 0);
|
||||||
syncCfgLog2((char*)__FUNCTION__, pCfg2);
|
|
||||||
|
|
||||||
taosMemoryFree(pCfg);
|
taosMemoryFree(pCfg);
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
|
@ -98,8 +89,6 @@ void test4() {
|
||||||
SRaftCfg* pCfg = raftCfgOpen("./test3_raft_cfg.json");
|
SRaftCfg* pCfg = raftCfgOpen("./test3_raft_cfg.json");
|
||||||
assert(pCfg != NULL);
|
assert(pCfg != NULL);
|
||||||
|
|
||||||
raftCfgLog2((char*)__FUNCTION__, pCfg);
|
|
||||||
|
|
||||||
int32_t ret = raftCfgClose(pCfg);
|
int32_t ret = raftCfgClose(pCfg);
|
||||||
assert(ret == 0);
|
assert(ret == 0);
|
||||||
}
|
}
|
||||||
|
@ -135,7 +124,6 @@ int main() {
|
||||||
sDebugFlag = DEBUG_TRACE + DEBUG_SCREEN + DEBUG_FILE;
|
sDebugFlag = DEBUG_TRACE + DEBUG_SCREEN + DEBUG_FILE;
|
||||||
|
|
||||||
logTest();
|
logTest();
|
||||||
test1();
|
|
||||||
test2();
|
test2();
|
||||||
test3();
|
test3();
|
||||||
test4();
|
test4();
|
||||||
|
|
|
@ -78,6 +78,28 @@ void test5() {
|
||||||
syncTimeoutDestroy(pMsg2);
|
syncTimeoutDestroy(pMsg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void syncUtilJson2Line(char *jsonStr) {
|
||||||
|
int p, q, len;
|
||||||
|
p = 0;
|
||||||
|
q = 1;
|
||||||
|
len = strlen(jsonStr);
|
||||||
|
while (1) {
|
||||||
|
if (jsonStr[q] == '\0') {
|
||||||
|
jsonStr[p + 1] = '\0';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jsonStr[q] == '\n' || jsonStr[q] == ' ' || jsonStr[q] == '\t') {
|
||||||
|
q++;
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
jsonStr[p + 1] = jsonStr[q];
|
||||||
|
p++;
|
||||||
|
q++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void test6() {
|
void test6() {
|
||||||
SyncTimeout *pMsg = createMsg();
|
SyncTimeout *pMsg = createMsg();
|
||||||
char *jsonStr = syncTimeout2Str(pMsg);
|
char *jsonStr = syncTimeout2Str(pMsg);
|
||||||
|
|
Loading…
Reference in New Issue