未验证 提交 7ddec79a 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #17937 from taosdata/enh/TD-20043

refact: adjust sync log
...@@ -263,8 +263,8 @@ enum { ...@@ -263,8 +263,8 @@ enum {
TD_DEF_MSG_TYPE(TDMT_SYNC_UNKNOWN, "sync-unknown", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SYNC_UNKNOWN, "sync-unknown", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_SYNC_COMMON_RESPONSE, "sync-common-response", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SYNC_COMMON_RESPONSE, "sync-common-response", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_SYNC_APPLY_MSG, "sync-apply-msg", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SYNC_APPLY_MSG, "sync-apply-msg", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_SYNC_CONFIG_CHANGE, "sync-config-change", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SYNC_CONFIG_CHANGE, "sync-config-change", NULL, NULL) // no longer used
TD_DEF_MSG_TYPE(TDMT_SYNC_CONFIG_CHANGE_FINISH, "sync-config-change-finish", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SYNC_CONFIG_CHANGE_FINISH, "sync-config-change-finish", NULL, NULL) // no longer used
TD_DEF_MSG_TYPE(TDMT_SYNC_SNAPSHOT_SEND, "sync-snapshot-send", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SYNC_SNAPSHOT_SEND, "sync-snapshot-send", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_SYNC_SNAPSHOT_RSP, "sync-snapshot-rsp", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SYNC_SNAPSHOT_RSP, "sync-snapshot-rsp", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_SYNC_LEADER_TRANSFER, "sync-leader-transfer", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SYNC_LEADER_TRANSFER, "sync-leader-transfer", NULL, NULL)
......
...@@ -398,7 +398,7 @@ int32_t* taosGetErrno(); ...@@ -398,7 +398,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_SYN_NOT_LEADER TAOS_DEF_ERROR_CODE(0, 0x090C) #define TSDB_CODE_SYN_NOT_LEADER TAOS_DEF_ERROR_CODE(0, 0x090C)
#define TSDB_CODE_SYN_ONE_REPLICA TAOS_DEF_ERROR_CODE(0, 0x090D) #define TSDB_CODE_SYN_ONE_REPLICA TAOS_DEF_ERROR_CODE(0, 0x090D)
#define TSDB_CODE_SYN_NOT_IN_NEW_CONFIG TAOS_DEF_ERROR_CODE(0, 0x090E) #define TSDB_CODE_SYN_NOT_IN_NEW_CONFIG TAOS_DEF_ERROR_CODE(0, 0x090E)
#define TSDB_CODE_SYN_NEW_CONFIG_ERROR TAOS_DEF_ERROR_CODE(0, 0x090F) #define TSDB_CODE_SYN_NEW_CONFIG_ERROR TAOS_DEF_ERROR_CODE(0, 0x090F) // internal
#define TSDB_CODE_SYN_RECONFIG_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0910) #define TSDB_CODE_SYN_RECONFIG_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0910)
#define TSDB_CODE_SYN_PROPOSE_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0911) #define TSDB_CODE_SYN_PROPOSE_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0911)
#define TSDB_CODE_SYN_STANDBY_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0912) #define TSDB_CODE_SYN_STANDBY_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0912)
......
...@@ -28,18 +28,42 @@ extern "C" { ...@@ -28,18 +28,42 @@ extern "C" {
#include "ttimer.h" #include "ttimer.h"
// clang-format off // clang-format off
#define sFatal(...) do { if (sDebugFlag & DEBUG_FATAL) { taosPrintLog("SYN FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0)
#define sError(...) do { if (sDebugFlag & DEBUG_ERROR) { taosPrintLog("SYN ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0) #define sFatal(...) if (sDebugFlag & DEBUG_FATAL) { taosPrintLog("SYN FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }
#define sWarn(...) do { if (sDebugFlag & DEBUG_WARN) { taosPrintLog("SYN WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0) #define sError(...) if (sDebugFlag & DEBUG_ERROR) { taosPrintLog("SYN ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }
#define sInfo(...) do { if (sDebugFlag & DEBUG_INFO) { taosPrintLog("SYN ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0) #define sWarn(...) if (sDebugFlag & DEBUG_WARN) { taosPrintLog("SYN WARN ", DEBUG_WARN, 255, __VA_ARGS__); }
#define sDebug(...) do { if (sDebugFlag & DEBUG_DEBUG) { taosPrintLog("SYN ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__); }} while(0) #define sInfo(...) if (sDebugFlag & DEBUG_INFO) { taosPrintLog("SYN ", DEBUG_INFO, 255, __VA_ARGS__); }
#define sTrace(...) do { if (sDebugFlag & DEBUG_TRACE) { taosPrintLog("SYN ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__); }} while(0) #define sDebug(...) if (sDebugFlag & DEBUG_DEBUG) { taosPrintLog("SYN ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__); }
#define sFatalLong(...) do { if (sDebugFlag & DEBUG_FATAL) { taosPrintLongString("SYN FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0) #define sTrace(...) if (sDebugFlag & DEBUG_TRACE) { taosPrintLog("SYN ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__); }
#define sErrorLong(...) do { if (sDebugFlag & DEBUG_ERROR) { taosPrintLongString("SYN ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0)
#define sWarnLong(...) do { if (sDebugFlag & DEBUG_WARN) { taosPrintLongString("SYN WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0) #define sLFatal(...) if (sDebugFlag & DEBUG_FATAL) { taosPrintLongString("SYN FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }
#define sInfoLong(...) do { if (sDebugFlag & DEBUG_INFO) { taosPrintLongString("SYN ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0) #define sLError(...) if (sDebugFlag & DEBUG_ERROR) { taosPrintLongString("SYN ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }
#define sDebugLong(...) do { if (sDebugFlag & DEBUG_DEBUG) { taosPrintLongString("SYN ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__); }} while(0) #define sLWarn(...) if (sDebugFlag & DEBUG_WARN) { taosPrintLongString("SYN WARN ", DEBUG_WARN, 255, __VA_ARGS__); }
#define sTraceLong(...) do { if (sDebugFlag & DEBUG_TRACE) { taosPrintLongString("SYN ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__); }} while(0) #define sLInfo(...) if (sDebugFlag & DEBUG_INFO) { taosPrintLongString("SYN ", DEBUG_INFO, 255, __VA_ARGS__); }
#define sLDebug(...) if (sDebugFlag & DEBUG_DEBUG) { taosPrintLongString("SYN ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__); }
#define sLTrace(...) if (sDebugFlag & DEBUG_TRACE) { taosPrintLongString("SYN ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__); }
#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,13 +274,10 @@ int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, S ...@@ -250,13 +274,10 @@ 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);
SyncIndex syncMinMatchIndex(SSyncNode* pSyncNode); SyncIndex syncMinMatchIndex(SSyncNode* pSyncNode);
char* syncNodePeerState2Str(const SSyncNode* pSyncNode);
// raft state change -------------- // raft state change --------------
void syncNodeUpdateTerm(SSyncNode* pSyncNode, SyncTerm term); void syncNodeUpdateTerm(SSyncNode* pSyncNode, SyncTerm term);
...@@ -350,12 +371,12 @@ void syncLogRecvSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* p ...@@ -350,12 +371,12 @@ void syncLogRecvSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* p
void syncLogSendSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s); void syncLogSendSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s);
void syncLogRecvSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s); void syncLogRecvSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s);
// for debug -------------- // syncUtil.h
void syncNodePrint(SSyncNode* pObj); void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNode* pNode, const char* format, ...);
void syncNodePrint2(char* s, SSyncNode* pObj); void syncPrintSnapshotSenderLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotSender* pSender,
void syncNodeLog(SSyncNode* pObj); const char* format, ...);
void syncNodeLog2(char* s, SSyncNode* pObj); void syncPrintSnapshotReceiverLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotReceiver* pReceiver,
void syncNodeLog3(char* s, SSyncNode* pObj); const char* format, ...);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -45,8 +45,8 @@ int32_t raftCfgIndexClose(SRaftCfgIndex *pRaftCfgIndex); ...@@ -45,8 +45,8 @@ int32_t raftCfgIndexClose(SRaftCfgIndex *pRaftCfgIndex);
int32_t raftCfgIndexPersist(SRaftCfgIndex *pRaftCfgIndex); int32_t raftCfgIndexPersist(SRaftCfgIndex *pRaftCfgIndex);
int32_t raftCfgIndexAddConfigIndex(SRaftCfgIndex *pRaftCfgIndex, SyncIndex configIndex); int32_t raftCfgIndexAddConfigIndex(SRaftCfgIndex *pRaftCfgIndex, SyncIndex configIndex);
cJSON * raftCfgIndex2Json(SRaftCfgIndex *pRaftCfgIndex); cJSON *raftCfgIndex2Json(SRaftCfgIndex *pRaftCfgIndex);
char * raftCfgIndex2Str(SRaftCfgIndex *pRaftCfgIndex); char *raftCfgIndex2Str(SRaftCfgIndex *pRaftCfgIndex);
int32_t raftCfgIndexFromJson(const cJSON *pRoot, SRaftCfgIndex *pRaftCfgIndex); int32_t raftCfgIndexFromJson(const cJSON *pRoot, SRaftCfgIndex *pRaftCfgIndex);
int32_t raftCfgIndexFromStr(const char *s, SRaftCfgIndex *pRaftCfgIndex); int32_t raftCfgIndexFromStr(const char *s, SRaftCfgIndex *pRaftCfgIndex);
...@@ -73,14 +73,14 @@ int32_t raftCfgClose(SRaftCfg *pRaftCfg); ...@@ -73,14 +73,14 @@ int32_t raftCfgClose(SRaftCfg *pRaftCfg);
int32_t raftCfgPersist(SRaftCfg *pRaftCfg); int32_t raftCfgPersist(SRaftCfg *pRaftCfg);
int32_t raftCfgAddConfigIndex(SRaftCfg *pRaftCfg, SyncIndex configIndex); 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);
cJSON * raftCfg2Json(SRaftCfg *pRaftCfg); cJSON *raftCfg2Json(SRaftCfg *pRaftCfg);
char * raftCfg2Str(SRaftCfg *pRaftCfg); char *raftCfg2Str(SRaftCfg *pRaftCfg);
int32_t raftCfgFromJson(const cJSON *pRoot, SRaftCfg *pRaftCfg); int32_t raftCfgFromJson(const cJSON *pRoot, SRaftCfg *pRaftCfg);
int32_t raftCfgFromStr(const char *s, SRaftCfg *pRaftCfg); int32_t raftCfgFromStr(const char *s, SRaftCfg *pRaftCfg);
...@@ -93,23 +93,6 @@ typedef struct SRaftCfgMeta { ...@@ -93,23 +93,6 @@ 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 ----------------------
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);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -67,7 +67,6 @@ int32_t snapshotReSend(SSyncSnapshotSender *pSender); ...@@ -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 ...@@ -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
......
...@@ -26,8 +26,6 @@ typedef struct SRaftId { ...@@ -26,8 +26,6 @@ typedef struct SRaftId {
SyncGroupId vgId; SyncGroupId vgId;
} SRaftId; } SRaftId;
char* sync2SimpleStr(int64_t rid);
// for compatibility, the same as syncPropose // for compatibility, the same as syncPropose
int32_t syncForwardToPeer(int64_t rid, SRpcMsg* pMsg, bool isWeak); int32_t syncForwardToPeer(int64_t rid, SRpcMsg* pMsg, bool isWeak);
...@@ -688,45 +686,6 @@ SyncLeaderTransfer* syncLeaderTransferFromRpcMsg2(const SRpcMsg* pRpcMsg); ...@@ -688,45 +686,6 @@ SyncLeaderTransfer* syncLeaderTransferFromRpcMsg2(const SRpcMsg* pRpcMsg);
cJSON* syncLeaderTransfer2Json(const SyncLeaderTransfer* pMsg); cJSON* syncLeaderTransfer2Json(const SyncLeaderTransfer* pMsg);
char* syncLeaderTransfer2Str(const SyncLeaderTransfer* pMsg); char* syncLeaderTransfer2Str(const SyncLeaderTransfer* pMsg);
// for debug ----------------------
void syncLeaderTransferPrint(const SyncLeaderTransfer* pMsg);
void syncLeaderTransferPrint2(char* s, const SyncLeaderTransfer* pMsg);
void syncLeaderTransferLog(const SyncLeaderTransfer* pMsg);
void syncLeaderTransferLog2(char* s, const SyncLeaderTransfer* pMsg);
// ---------------------------------------------
typedef struct SyncReconfigFinish {
uint32_t bytes;
int32_t vgId;
uint32_t msgType;
SSyncCfg oldCfg;
SSyncCfg newCfg;
SyncIndex newCfgIndex;
SyncTerm newCfgTerm;
uint64_t newCfgSeqNum;
} SyncReconfigFinish;
SyncReconfigFinish* syncReconfigFinishBuild(int32_t vgId);
void syncReconfigFinishDestroy(SyncReconfigFinish* pMsg);
void syncReconfigFinishSerialize(const SyncReconfigFinish* pMsg, char* buf, uint32_t bufLen);
void syncReconfigFinishDeserialize(const char* buf, uint32_t len, SyncReconfigFinish* pMsg);
char* syncReconfigFinishSerialize2(const SyncReconfigFinish* pMsg, uint32_t* len);
SyncReconfigFinish* syncReconfigFinishDeserialize2(const char* buf, uint32_t len);
void syncReconfigFinish2RpcMsg(const SyncReconfigFinish* pMsg, SRpcMsg* pRpcMsg);
void syncReconfigFinishFromRpcMsg(const SRpcMsg* pRpcMsg, SyncReconfigFinish* pMsg);
SyncReconfigFinish* syncReconfigFinishFromRpcMsg2(const SRpcMsg* pRpcMsg);
cJSON* syncReconfigFinish2Json(const SyncReconfigFinish* pMsg);
char* syncReconfigFinish2Str(const SyncReconfigFinish* pMsg);
// for debug ----------------------
void syncReconfigFinishPrint(const SyncReconfigFinish* pMsg);
void syncReconfigFinishPrint2(char* s, const SyncReconfigFinish* pMsg);
void syncReconfigFinishLog(const SyncReconfigFinish* pMsg);
void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg);
// ---------------------------------------------
typedef enum { typedef enum {
SYNC_LOCAL_CMD_STEP_DOWN = 100, SYNC_LOCAL_CMD_STEP_DOWN = 100,
SYNC_LOCAL_CMD_FOLLOWER_CMT, SYNC_LOCAL_CMD_FOLLOWER_CMT,
......
...@@ -20,48 +20,35 @@ ...@@ -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
} }
......
...@@ -20,15 +20,8 @@ ...@@ -20,15 +20,8 @@
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 "syncUtil.h"
#include "taosdef.h"
// SVotesGranted -----------------------------
typedef struct SVotesGranted { typedef struct SVotesGranted {
SRaftId (*replicas)[TSDB_MAX_REPLICA]; SRaftId (*replicas)[TSDB_MAX_REPLICA];
bool isGranted[TSDB_MAX_REPLICA]; bool isGranted[TSDB_MAX_REPLICA];
...@@ -49,13 +42,6 @@ void voteGrantedReset(SVotesGranted *pVotesGranted, SyncTerm term); ...@@ -49,13 +42,6 @@ void voteGrantedReset(SVotesGranted *pVotesGranted, SyncTerm term);
cJSON *voteGranted2Json(SVotesGranted *pVotesGranted); cJSON *voteGranted2Json(SVotesGranted *pVotesGranted);
char *voteGranted2Str(SVotesGranted *pVotesGranted); char *voteGranted2Str(SVotesGranted *pVotesGranted);
// for debug -------------------
void voteGrantedPrint(SVotesGranted *pObj);
void voteGrantedPrint2(char *s, SVotesGranted *pObj);
void voteGrantedLog(SVotesGranted *pObj);
void voteGrantedLog2(char *s, SVotesGranted *pObj);
// SVotesRespond -----------------------------
typedef struct SVotesRespond { typedef struct SVotesRespond {
SRaftId (*replicas)[TSDB_MAX_REPLICA]; SRaftId (*replicas)[TSDB_MAX_REPLICA];
bool isRespond[TSDB_MAX_REPLICA]; bool isRespond[TSDB_MAX_REPLICA];
...@@ -73,12 +59,6 @@ void votesRespondReset(SVotesRespond *pVotesRespond, SyncTerm term); ...@@ -73,12 +59,6 @@ void votesRespondReset(SVotesRespond *pVotesRespond, SyncTerm term);
cJSON *votesRespond2Json(SVotesRespond *pVotesRespond); cJSON *votesRespond2Json(SVotesRespond *pVotesRespond);
char *votesRespond2Str(SVotesRespond *pVotesRespond); char *votesRespond2Str(SVotesRespond *pVotesRespond);
// for debug -------------------
void votesRespondPrint(SVotesRespond *pObj);
void votesRespondPrint2(char *s, SVotesRespond *pObj);
void votesRespondLog(SVotesRespond *pObj);
void votesRespondLog2(char *s, SVotesRespond *pObj);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -91,7 +91,7 @@ ...@@ -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) { ...@@ -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) { ...@@ -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 @@ ...@@ -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 ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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;
} }
} }
......
...@@ -13,11 +13,13 @@ ...@@ -13,11 +13,13 @@
* 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 "syncElection.h" #include "syncElection.h"
#include "syncMessage.h" #include "syncMessage.h"
#include "syncRaftCfg.h" #include "syncRaftCfg.h"
#include "syncRaftStore.h" #include "syncRaftStore.h"
#include "syncVoteMgr.h" #include "syncVoteMgr.h"
#include "syncUtil.h"
// TLA+ Spec // TLA+ Spec
// RequestVote(i, j) == // RequestVote(i, j) ==
...@@ -32,7 +34,7 @@ ...@@ -32,7 +34,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 +42,7 @@ int32_t syncNodeElect(SSyncNode* pSyncNode) { ...@@ -40,7 +42,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 +84,7 @@ int32_t syncNodeElect(SSyncNode* pSyncNode) { ...@@ -82,7 +84,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;
} }
......
...@@ -83,11 +83,10 @@ void syncStop(int64_t rid) { ...@@ -83,11 +83,10 @@ void syncStop(int64_t rid) {
void syncPreStop(int64_t rid) { void syncPreStop(int64_t rid) {
SSyncNode* pSyncNode = syncNodeAcquire(rid); SSyncNode* pSyncNode = syncNodeAcquire(rid);
if (pSyncNode == NULL) return; if (pSyncNode != NULL) {
syncNodePreClose(pSyncNode);
syncNodePreClose(pSyncNode); syncNodeRelease(pSyncNode);
}
syncNodeRelease(pSyncNode);
} }
static bool syncNodeCheckNewConfig(SSyncNode* pSyncNode, const SSyncCfg* pCfg) { static bool syncNodeCheckNewConfig(SSyncNode* pSyncNode, const SSyncCfg* pCfg) {
...@@ -217,41 +216,6 @@ SyncIndex syncMinMatchIndex(SSyncNode* pSyncNode) { ...@@ -217,41 +216,6 @@ SyncIndex syncMinMatchIndex(SSyncNode* pSyncNode) {
return minMatchIndex; return minMatchIndex;
} }
char* syncNodePeerState2Str(const SSyncNode* pSyncNode) {
int32_t len = 128;
int32_t useLen = 0;
int32_t leftLen = len - useLen;
char* pStr = taosMemoryMalloc(len);
memset(pStr, 0, len);
char* p = pStr;
int32_t use = snprintf(p, leftLen, "{");
useLen += use;
leftLen -= use;
for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
SPeerState* pState = syncNodeGetPeerState((SSyncNode*)pSyncNode, &(pSyncNode->replicasId[i]));
if (pState == NULL) {
sError("vgId:%d, replica maybe dropped", pSyncNode->vgId);
break;
}
p = pStr + useLen;
use = snprintf(p, leftLen, "%d:%" PRId64 " ,%" PRId64, i, pState->lastSendIndex, pState->lastSendTime);
useLen += use;
leftLen -= use;
}
p = pStr + useLen;
use = snprintf(p, leftLen, "}");
useLen += use;
leftLen -= use;
// sTrace("vgId:%d, ------------------ syncNodePeerState2Str:%s", pSyncNode->vgId, pStr);
return pStr;
}
int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) { int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) {
SSyncNode* pSyncNode = syncNodeAcquire(rid); SSyncNode* pSyncNode = syncNodeAcquire(rid);
if (pSyncNode == NULL) { if (pSyncNode == NULL) {
...@@ -259,7 +223,7 @@ int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) { ...@@ -259,7 +223,7 @@ int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) {
sError("sync begin snapshot error"); sError("sync begin snapshot error");
return -1; return -1;
} }
ASSERT(rid == pSyncNode->rid);
int32_t code = 0; int32_t code = 0;
if (syncNodeIsMnode(pSyncNode)) { if (syncNodeIsMnode(pSyncNode)) {
...@@ -272,12 +236,8 @@ int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) { ...@@ -272,12 +236,8 @@ int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) {
bool isEmpty = pSyncNode->pLogStore->syncLogIsEmpty(pSyncNode->pLogStore); bool isEmpty = pSyncNode->pLogStore->syncLogIsEmpty(pSyncNode->pLogStore);
if (isEmpty || (!isEmpty && logNum < logRetention)) { if (isEmpty || (!isEmpty && logNum < logRetention)) {
char logBuf[256]; sNTrace(pSyncNode, "new-snapshot-index:%" PRId64 ", log-num:%" PRId64 ", empty:%d, do not delete wal",
snprintf(logBuf, sizeof(logBuf), lastApplyIndex, logNum, isEmpty);
"new-snapshot-index:%" PRId64 ", log-num:%" PRId64 ", empty:%d, do not delete wal", lastApplyIndex,
logNum, isEmpty);
syncNodeEventLog(pSyncNode, logBuf);
syncNodeRelease(pSyncNode); syncNodeRelease(pSyncNode);
return 0; return 0;
} }
...@@ -299,12 +259,10 @@ int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) { ...@@ -299,12 +259,10 @@ int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) {
char host[64]; char host[64];
uint16_t port; uint16_t port;
syncUtilU642Addr(pSyncNode->peersId[i].addr, host, sizeof(host), &port); syncUtilU642Addr(pSyncNode->peersId[i].addr, host, sizeof(host), &port);
char logBuf[256]; sNTrace(pSyncNode,
snprintf(logBuf, sizeof(logBuf), "new-snapshot-index:%" PRId64 " is greater than match-index:%" PRId64
"new-snapshot-index:%" PRId64 " is greater than match-index:%" PRId64 " of %s:%d, do not delete wal",
" of %s:%d, do not delete wal", lastApplyIndex, matchIndex, host, port);
lastApplyIndex, matchIndex, host, port);
syncNodeEventLog(pSyncNode, logBuf);
} while (0); } while (0);
syncNodeRelease(pSyncNode); syncNodeRelease(pSyncNode);
...@@ -314,30 +272,20 @@ int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) { ...@@ -314,30 +272,20 @@ int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) {
} else if (pSyncNode->state == TAOS_SYNC_STATE_FOLLOWER) { } else if (pSyncNode->state == TAOS_SYNC_STATE_FOLLOWER) {
if (lastApplyIndex > pSyncNode->minMatchIndex) { if (lastApplyIndex > pSyncNode->minMatchIndex) {
char logBuf[256]; sNTrace(pSyncNode,
snprintf(logBuf, sizeof(logBuf), "new-snapshot-index:%" PRId64 " is greater than min-match-index:%" PRId64 ", do not delete wal",
"new-snapshot-index:%" PRId64 " is greater than min-match-index:%" PRId64 ", do not delete wal", lastApplyIndex, pSyncNode->minMatchIndex);
lastApplyIndex, pSyncNode->minMatchIndex);
syncNodeEventLog(pSyncNode, logBuf);
syncNodeRelease(pSyncNode); syncNodeRelease(pSyncNode);
return 0; return 0;
} }
} else if (pSyncNode->state == TAOS_SYNC_STATE_CANDIDATE) { } else if (pSyncNode->state == TAOS_SYNC_STATE_CANDIDATE) {
char logBuf[256]; sNTrace(pSyncNode, "new-snapshot-index:%" PRId64 " candidate, do not delete wal", lastApplyIndex);
snprintf(logBuf, sizeof(logBuf), "new-snapshot-index:%" PRId64 " candidate, do not delete wal", lastApplyIndex);
syncNodeEventLog(pSyncNode, logBuf);
syncNodeRelease(pSyncNode); syncNodeRelease(pSyncNode);
return 0; return 0;
} else { } else {
char logBuf[256]; sNTrace(pSyncNode, "new-snapshot-index:%" PRId64 " unknown state, do not delete wal", lastApplyIndex);
snprintf(logBuf, sizeof(logBuf), "new-snapshot-index:%" PRId64 " unknown state, do not delete wal",
lastApplyIndex);
syncNodeEventLog(pSyncNode, logBuf);
syncNodeRelease(pSyncNode); syncNodeRelease(pSyncNode);
return 0; return 0;
} }
...@@ -363,27 +311,17 @@ _DEL_WAL: ...@@ -363,27 +311,17 @@ _DEL_WAL:
SSyncLogStoreData* pData = pSyncNode->pLogStore->data; SSyncLogStoreData* pData = pSyncNode->pLogStore->data;
code = walBeginSnapshot(pData->pWal, lastApplyIndex); code = walBeginSnapshot(pData->pWal, lastApplyIndex);
if (code == 0) { if (code == 0) {
char logBuf[256]; sNTrace(pSyncNode, "wal snapshot begin, index:%" PRId64 ", last apply index:%" PRId64,
snprintf(logBuf, sizeof(logBuf), "wal snapshot begin, index:%" PRId64 ", last apply index:%" PRId64, pSyncNode->snapshottingIndex, lastApplyIndex);
pSyncNode->snapshottingIndex, lastApplyIndex);
syncNodeEventLog(pSyncNode, logBuf);
} else { } else {
char logBuf[256]; sNError(pSyncNode, "wal snapshot begin error since:%s, index:%" PRId64 ", last apply index:%" PRId64,
snprintf(logBuf, sizeof(logBuf), terrstr(terrno), pSyncNode->snapshottingIndex, lastApplyIndex);
"wal snapshot begin error since:%s, index:%" PRId64 ", last apply index:%" PRId64, terrstr(terrno),
pSyncNode->snapshottingIndex, lastApplyIndex);
syncNodeErrorLog(pSyncNode, logBuf);
atomic_store_64(&pSyncNode->snapshottingIndex, SYNC_INDEX_INVALID); atomic_store_64(&pSyncNode->snapshottingIndex, SYNC_INDEX_INVALID);
} }
} else { } else {
char logBuf[256]; sNTrace(pSyncNode, "snapshotting for %" PRId64 ", do not delete wal for new-snapshot-index:%" PRId64,
snprintf(logBuf, sizeof(logBuf), snapshottingIndex, lastApplyIndex);
"snapshotting for %" PRId64 ", do not delete wal for new-snapshot-index:%" PRId64, snapshottingIndex,
lastApplyIndex);
syncNodeEventLog(pSyncNode, logBuf);
} }
} while (0); } while (0);
...@@ -394,29 +332,20 @@ _DEL_WAL: ...@@ -394,29 +332,20 @@ _DEL_WAL:
int32_t syncEndSnapshot(int64_t rid) { int32_t syncEndSnapshot(int64_t rid) {
SSyncNode* pSyncNode = syncNodeAcquire(rid); SSyncNode* pSyncNode = syncNodeAcquire(rid);
if (pSyncNode == NULL) { if (pSyncNode == NULL) {
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
sError("sync end snapshot error"); sError("sync end snapshot error");
return -1; return -1;
} }
ASSERT(rid == pSyncNode->rid);
int32_t code = 0; int32_t code = 0;
if (atomic_load_64(&pSyncNode->snapshottingIndex) != SYNC_INDEX_INVALID) { if (atomic_load_64(&pSyncNode->snapshottingIndex) != SYNC_INDEX_INVALID) {
SSyncLogStoreData* pData = pSyncNode->pLogStore->data; SSyncLogStoreData* pData = pSyncNode->pLogStore->data;
code = walEndSnapshot(pData->pWal); code = walEndSnapshot(pData->pWal);
if (code != 0) { if (code != 0) {
sError("vgId:%d, wal snapshot end error since:%s", pSyncNode->vgId, terrstr()); sNError(pSyncNode, "wal snapshot end error since:%s", terrstr());
syncNodeRelease(pSyncNode); syncNodeRelease(pSyncNode);
return -1; return -1;
} else { } else {
do { sNTrace(pSyncNode, "wal snapshot end, index:%" PRId64, atomic_load_64(&pSyncNode->snapshottingIndex));
char logBuf[256];
snprintf(logBuf, sizeof(logBuf), "wal snapshot end, index:%" PRId64,
atomic_load_64(&pSyncNode->snapshottingIndex));
syncNodeEventLog(pSyncNode, logBuf);
} while (0);
atomic_store_64(&pSyncNode->snapshottingIndex, SYNC_INDEX_INVALID); atomic_store_64(&pSyncNode->snapshottingIndex, SYNC_INDEX_INVALID);
} }
} }
...@@ -428,14 +357,11 @@ int32_t syncEndSnapshot(int64_t rid) { ...@@ -428,14 +357,11 @@ int32_t syncEndSnapshot(int64_t rid) {
int32_t syncStepDown(int64_t rid, SyncTerm newTerm) { int32_t syncStepDown(int64_t rid, SyncTerm newTerm) {
SSyncNode* pSyncNode = syncNodeAcquire(rid); SSyncNode* pSyncNode = syncNodeAcquire(rid);
if (pSyncNode == NULL) { if (pSyncNode == NULL) {
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
sError("sync step down error"); sError("sync step down error");
return -1; return -1;
} }
ASSERT(rid == pSyncNode->rid);
syncNodeStepDown(pSyncNode, newTerm); syncNodeStepDown(pSyncNode, newTerm);
syncNodeRelease(pSyncNode); syncNodeRelease(pSyncNode);
return 0; return 0;
} }
...@@ -443,11 +369,9 @@ int32_t syncStepDown(int64_t rid, SyncTerm newTerm) { ...@@ -443,11 +369,9 @@ int32_t syncStepDown(int64_t rid, SyncTerm newTerm) {
bool syncIsReadyForRead(int64_t rid) { bool syncIsReadyForRead(int64_t rid) {
SSyncNode* pSyncNode = syncNodeAcquire(rid); SSyncNode* pSyncNode = syncNodeAcquire(rid);
if (pSyncNode == NULL) { if (pSyncNode == NULL) {
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
sError("sync ready for read error"); sError("sync ready for read error");
return false; return false;
} }
ASSERT(rid == pSyncNode->rid);
if (pSyncNode->state == TAOS_SYNC_STATE_LEADER && pSyncNode->restoreFinish) { if (pSyncNode->state == TAOS_SYNC_STATE_LEADER && pSyncNode->restoreFinish) {
syncNodeRelease(pSyncNode); syncNodeRelease(pSyncNode);
...@@ -464,7 +388,7 @@ bool syncIsReadyForRead(int64_t rid) { ...@@ -464,7 +388,7 @@ bool syncIsReadyForRead(int64_t rid) {
if (!pSyncNode->pLogStore->syncLogIsEmpty(pSyncNode->pLogStore)) { if (!pSyncNode->pLogStore->syncLogIsEmpty(pSyncNode->pLogStore)) {
SSyncRaftEntry* pEntry = NULL; SSyncRaftEntry* pEntry = NULL;
int32_t code = pSyncNode->pLogStore->syncLogGetEntry( int32_t code = pSyncNode->pLogStore->syncLogGetEntry(
pSyncNode->pLogStore, pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore), &pEntry); pSyncNode->pLogStore, pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore), &pEntry);
if (code == 0 && pEntry != NULL) { if (code == 0 && pEntry != NULL) {
if (pEntry->originalRpcType == TDMT_SYNC_NOOP && pEntry->term == pSyncNode->pRaftStore->currentTerm) { if (pEntry->originalRpcType == TDMT_SYNC_NOOP && pEntry->term == pSyncNode->pRaftStore->currentTerm) {
ready = true; ready = true;
...@@ -505,19 +429,13 @@ int32_t syncNodeLeaderTransfer(SSyncNode* pSyncNode) { ...@@ -505,19 +429,13 @@ int32_t syncNodeLeaderTransfer(SSyncNode* pSyncNode) {
} }
int32_t syncNodeLeaderTransferTo(SSyncNode* pSyncNode, SNodeInfo newLeader) { int32_t syncNodeLeaderTransferTo(SSyncNode* pSyncNode, SNodeInfo newLeader) {
int32_t ret = 0;
if (pSyncNode->replicaNum == 1) { if (pSyncNode->replicaNum == 1) {
sDebug("only one replica, cannot leader transfer"); sDebug("only one replica, cannot leader transfer");
terrno = TSDB_CODE_SYN_ONE_REPLICA; terrno = TSDB_CODE_SYN_ONE_REPLICA;
return -1; return -1;
} }
do { sNTrace(pSyncNode, "begin leader transfer to %s:%u", newLeader.nodeFqdn, newLeader.nodePort);
char logBuf[128];
snprintf(logBuf, sizeof(logBuf), "begin leader transfer to %s:%u", newLeader.nodeFqdn, newLeader.nodePort);
syncNodeEventLog(pSyncNode, logBuf);
} while (0);
SyncLeaderTransfer* pMsg = syncLeaderTransferBuild(pSyncNode->vgId); SyncLeaderTransfer* pMsg = syncLeaderTransferBuild(pSyncNode->vgId);
pMsg->newLeaderId.addr = syncUtilAddr2U64(newLeader.nodeFqdn, newLeader.nodePort); pMsg->newLeaderId.addr = syncUtilAddr2U64(newLeader.nodeFqdn, newLeader.nodePort);
...@@ -528,42 +446,10 @@ int32_t syncNodeLeaderTransferTo(SSyncNode* pSyncNode, SNodeInfo newLeader) { ...@@ -528,42 +446,10 @@ int32_t syncNodeLeaderTransferTo(SSyncNode* pSyncNode, SNodeInfo newLeader) {
syncLeaderTransfer2RpcMsg(pMsg, &rpcMsg); syncLeaderTransfer2RpcMsg(pMsg, &rpcMsg);
syncLeaderTransferDestroy(pMsg); syncLeaderTransferDestroy(pMsg);
ret = syncNodePropose(pSyncNode, &rpcMsg, false); int32_t ret = syncNodePropose(pSyncNode, &rpcMsg, false);
return ret; return ret;
} }
bool syncCanLeaderTransfer(int64_t rid) {
SSyncNode* pSyncNode = syncNodeAcquire(rid);
if (pSyncNode == NULL) {
return false;
}
ASSERT(rid == pSyncNode->rid);
if (pSyncNode->replicaNum == 1) {
syncNodeRelease(pSyncNode);
return false;
}
if (pSyncNode->state == TAOS_SYNC_STATE_FOLLOWER) {
syncNodeRelease(pSyncNode);
return true;
}
bool matchOK = true;
if (pSyncNode->state == TAOS_SYNC_STATE_CANDIDATE || pSyncNode->state == TAOS_SYNC_STATE_LEADER) {
SyncIndex myCommitIndex = pSyncNode->commitIndex;
for (int i = 0; i < pSyncNode->peersNum; ++i) {
SyncIndex peerMatchIndex = syncIndexMgrGetIndex(pSyncNode->pMatchIndex, &(pSyncNode->peersId)[i]);
if (peerMatchIndex < myCommitIndex) {
matchOK = false;
}
}
}
syncNodeRelease(pSyncNode);
return matchOK;
}
int32_t syncForwardToPeer(int64_t rid, SRpcMsg* pMsg, bool isWeak) { int32_t syncForwardToPeer(int64_t rid, SRpcMsg* pMsg, bool isWeak) {
int32_t ret = syncPropose(rid, pMsg, isWeak); int32_t ret = syncPropose(rid, pMsg, isWeak);
return ret; return ret;
...@@ -746,7 +632,7 @@ void syncGetRetryEpSet(int64_t rid, SEpSet* pEpSet) { ...@@ -746,7 +632,7 @@ void syncGetRetryEpSet(int64_t rid, SEpSet* pEpSet) {
memset(pEpSet, 0, sizeof(*pEpSet)); memset(pEpSet, 0, sizeof(*pEpSet));
return; return;
} }
ASSERT(rid == pSyncNode->rid);
pEpSet->numOfEps = 0; pEpSet->numOfEps = 0;
for (int i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) { for (int i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) {
snprintf(pEpSet->eps[i].fqdn, sizeof(pEpSet->eps[i].fqdn), "%s", (pSyncNode->pRaftCfg->cfg.nodeInfo)[i].nodeFqdn); snprintf(pEpSet->eps[i].fqdn, sizeof(pEpSet->eps[i].fqdn), "%s", (pSyncNode->pRaftCfg->cfg.nodeInfo)[i].nodeFqdn);
...@@ -762,6 +648,7 @@ void syncGetRetryEpSet(int64_t rid, SEpSet* pEpSet) { ...@@ -762,6 +648,7 @@ void syncGetRetryEpSet(int64_t rid, SEpSet* pEpSet) {
syncNodeRelease(pSyncNode); syncNodeRelease(pSyncNode);
} }
static void syncGetAndDelRespRpc(SSyncNode* pSyncNode, uint64_t index, SRpcHandleInfo* pInfo) { static void syncGetAndDelRespRpc(SSyncNode* pSyncNode, uint64_t index, SRpcHandleInfo* pInfo) {
SRespStub stub; SRespStub stub;
int32_t ret = syncRespMgrGetAndDel(pSyncNode->pSyncRespMgr, index, &stub); int32_t ret = syncRespMgrGetAndDel(pSyncNode->pSyncRespMgr, index, &stub);
...@@ -772,23 +659,9 @@ static void syncGetAndDelRespRpc(SSyncNode* pSyncNode, uint64_t index, SRpcHandl ...@@ -772,23 +659,9 @@ static void syncGetAndDelRespRpc(SSyncNode* pSyncNode, uint64_t index, SRpcHandl
sTrace("vgId:%d, get seq:%" PRIu64 " rpc handle:%p", pSyncNode->vgId, index, pInfo->handle); sTrace("vgId:%d, get seq:%" PRIu64 " rpc handle:%p", pSyncNode->vgId, index, pInfo->handle);
} }
char* sync2SimpleStr(int64_t rid) {
SSyncNode* pSyncNode = syncNodeAcquire(rid);
if (pSyncNode == NULL) {
sTrace("syncSetRpc get pSyncNode is NULL, rid:%" PRId64, rid);
return NULL;
}
char* s = syncNode2SimpleStr(pSyncNode);
syncNodeRelease(pSyncNode);
return s;
}
int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak) { int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak) {
SSyncNode* pSyncNode = syncNodeAcquire(rid); SSyncNode* pSyncNode = syncNodeAcquire(rid);
if (pSyncNode == NULL) { if (pSyncNode == NULL) {
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
sError("sync propose error"); sError("sync propose error");
return -1; return -1;
} }
...@@ -798,50 +671,11 @@ int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak) { ...@@ -798,50 +671,11 @@ int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak) {
return ret; return ret;
} }
static bool syncNodeBatchOK(SRpcMsg** pMsgPArr, int32_t arrSize) {
for (int32_t i = 0; i < arrSize; ++i) {
if (pMsgPArr[i]->msgType == TDMT_SYNC_CONFIG_CHANGE) {
return false;
}
if (pMsgPArr[i]->msgType == TDMT_SYNC_CONFIG_CHANGE_FINISH) {
return false;
}
}
return true;
}
int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak) { int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak) {
int32_t ret = 0; int32_t ret = 0;
sNTrace(pSyncNode, "propose message, type:%s", TMSG_INFO(pMsg->msgType));
do {
char eventLog[128];
snprintf(eventLog, sizeof(eventLog), "propose message, type:%s", TMSG_INFO(pMsg->msgType));
syncNodeEventLog(pSyncNode, eventLog);
} while (0);
if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) { if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) {
if (pSyncNode->changing && pMsg->msgType != TDMT_SYNC_CONFIG_CHANGE_FINISH) {
ret = -1;
terrno = TSDB_CODE_SYN_PROPOSE_NOT_READY;
sError("vgId:%d, failed to sync propose since not ready, type:%s", pSyncNode->vgId, TMSG_INFO(pMsg->msgType));
goto _END;
}
// config change
if (pMsg->msgType == TDMT_SYNC_CONFIG_CHANGE) {
if (!syncNodeCanChange(pSyncNode)) {
ret = -1;
terrno = TSDB_CODE_SYN_RECONFIG_NOT_READY;
sError("vgId:%d, failed to sync reconfig since not ready, type:%s", pSyncNode->vgId, TMSG_INFO(pMsg->msgType));
goto _END;
}
ASSERT(!pSyncNode->changing);
pSyncNode->changing = true;
}
// not restored, vnode enable // not restored, vnode enable
if (!pSyncNode->restoreFinish && pSyncNode->vgId != 1) { if (!pSyncNode->restoreFinish && pSyncNode->vgId != 1) {
ret = -1; ret = -1;
...@@ -1135,7 +969,7 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) { ...@@ -1135,7 +969,7 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) {
} }
if (snapshot.lastApplyIndex > commitIndex) { if (snapshot.lastApplyIndex > commitIndex) {
commitIndex = snapshot.lastApplyIndex; commitIndex = snapshot.lastApplyIndex;
syncNodeEventLog(pSyncNode, "reset commit index by snapshot"); sNTrace(pSyncNode, "reset commit index by snapshot");
} }
} }
pSyncNode->commitIndex = commitIndex; pSyncNode->commitIndex = commitIndex;
...@@ -1226,7 +1060,7 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) { ...@@ -1226,7 +1060,7 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) {
// snapshotting // snapshotting
atomic_store_64(&pSyncNode->snapshottingIndex, SYNC_INDEX_INVALID); atomic_store_64(&pSyncNode->snapshottingIndex, SYNC_INDEX_INVALID);
syncNodeEventLog(pSyncNode, "sync open"); sNTrace(pSyncNode, "sync open");
return pSyncNode; return pSyncNode;
...@@ -1299,7 +1133,7 @@ void syncNodeClose(SSyncNode* pSyncNode) { ...@@ -1299,7 +1133,7 @@ void syncNodeClose(SSyncNode* pSyncNode) {
} }
int32_t ret; int32_t ret;
syncNodeEventLog(pSyncNode, "sync close"); sNTrace(pSyncNode, "sync close");
ret = raftStoreClose(pSyncNode->pRaftStore); ret = raftStoreClose(pSyncNode->pRaftStore);
ASSERT(ret == 0); ASSERT(ret == 0);
...@@ -1461,13 +1295,8 @@ int32_t syncNodeResetElectTimer(SSyncNode* pSyncNode) { ...@@ -1461,13 +1295,8 @@ int32_t syncNodeResetElectTimer(SSyncNode* pSyncNode) {
} }
ret = syncNodeRestartElectTimer(pSyncNode, electMS); ret = syncNodeRestartElectTimer(pSyncNode, electMS);
do { sNTrace(pSyncNode, "reset elect timer, min:%d, max:%d, ms:%d", pSyncNode->electBaseLine, 2 * pSyncNode->electBaseLine,
char logBuf[128]; electMS);
snprintf(logBuf, sizeof(logBuf), "reset elect timer, min:%d, max:%d, ms:%d", pSyncNode->electBaseLine,
2 * pSyncNode->electBaseLine, electMS);
syncNodeEventLog(pSyncNode, logBuf);
} while (0);
return ret; return ret;
} }
...@@ -1481,12 +1310,7 @@ static int32_t syncNodeDoStartHeartbeatTimer(SSyncNode* pSyncNode) { ...@@ -1481,12 +1310,7 @@ static int32_t syncNodeDoStartHeartbeatTimer(SSyncNode* pSyncNode) {
sError("vgId:%d, start heartbeat timer error, sync env is stop", pSyncNode->vgId); sError("vgId:%d, start heartbeat timer error, sync env is stop", pSyncNode->vgId);
} }
do { sNTrace(pSyncNode, "start heartbeat timer, ms:%d", pSyncNode->heartbeatTimerMS);
char logBuf[128];
snprintf(logBuf, sizeof(logBuf), "start heartbeat timer, ms:%d", pSyncNode->heartbeatTimerMS);
syncNodeEventLog(pSyncNode, logBuf);
} while (0);
return ret; return ret;
} }
...@@ -1733,158 +1557,6 @@ char* syncNode2Str(const SSyncNode* pSyncNode) { ...@@ -1733,158 +1557,6 @@ char* syncNode2Str(const SSyncNode* pSyncNode) {
return serialized; return serialized;
} }
inline void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) {
if (pSyncNode == NULL) {
return;
}
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
if (pSyncNode->pFsm != NULL && pSyncNode->pFsm->FpGetSnapshotInfo != NULL) {
pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot);
}
SyncIndex logLastIndex = SYNC_INDEX_INVALID;
SyncIndex logBeginIndex = SYNC_INDEX_INVALID;
if (pSyncNode->pLogStore != NULL) {
logLastIndex = pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore);
logBeginIndex = pSyncNode->pLogStore->syncLogBeginIndex(pSyncNode->pLogStore);
}
char* pCfgStr = syncCfg2SimpleStr(&(pSyncNode->pRaftCfg->cfg));
char* printStr = "";
if (pCfgStr != NULL) {
printStr = pCfgStr;
}
char* peerStateStr = syncNodePeerState2Str(pSyncNode);
int32_t userStrLen = strlen(str) + strlen(peerStateStr);
if (userStrLen < 256) {
char logBuf[256 + 256];
if (pSyncNode != NULL && pSyncNode->pRaftCfg != NULL && pSyncNode->pRaftStore != NULL) {
snprintf(logBuf, sizeof(logBuf),
"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",
pSyncNode->vgId, syncStr(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm,
pSyncNode->commitIndex, logBeginIndex, logLastIndex, pSyncNode->minMatchIndex, snapshot.lastApplyIndex,
snapshot.lastApplyTerm, pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy,
pSyncNode->pRaftCfg->batchSize, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex,
pSyncNode->changing, pSyncNode->restoreFinish, syncNodeDynamicQuorum(pSyncNode),
pSyncNode->electTimerLogicClock, pSyncNode->heartbeatTimerLogicClockUser, peerStateStr, printStr);
} else {
snprintf(logBuf, sizeof(logBuf), "%s", str);
}
// sDebug("%s", logBuf);
// sInfo("%s", logBuf);
sTrace("%s", logBuf);
} else {
int len = 256 + userStrLen;
char* s = (char*)taosMemoryMalloc(len);
if (pSyncNode != NULL && pSyncNode->pRaftCfg != NULL && pSyncNode->pRaftStore != NULL) {
snprintf(s, len,
"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",
pSyncNode->vgId, syncStr(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm,
pSyncNode->commitIndex, logBeginIndex, logLastIndex, pSyncNode->minMatchIndex, snapshot.lastApplyIndex,
snapshot.lastApplyTerm, pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy,
pSyncNode->pRaftCfg->batchSize, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex,
pSyncNode->changing, pSyncNode->restoreFinish, syncNodeDynamicQuorum(pSyncNode),
pSyncNode->electTimerLogicClock, pSyncNode->heartbeatTimerLogicClockUser, peerStateStr, printStr);
} else {
snprintf(s, len, "%s", str);
}
// sDebug("%s", s);
// sInfo("%s", s);
sTrace("%s", s);
taosMemoryFree(s);
}
taosMemoryFree(peerStateStr);
taosMemoryFree(pCfgStr);
}
inline void syncNodeErrorLog(const SSyncNode* pSyncNode, char* str) {
if (pSyncNode == NULL) {
return;
}
int32_t userStrLen = strlen(str);
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
if (pSyncNode->pFsm != NULL && pSyncNode->pFsm->FpGetSnapshotInfo != NULL) {
pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot);
}
SyncIndex logLastIndex = SYNC_INDEX_INVALID;
SyncIndex logBeginIndex = SYNC_INDEX_INVALID;
if (pSyncNode->pLogStore != NULL) {
logLastIndex = pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore);
logBeginIndex = pSyncNode->pLogStore->syncLogBeginIndex(pSyncNode->pLogStore);
}
char* pCfgStr = syncCfg2SimpleStr(&(pSyncNode->pRaftCfg->cfg));
char* printStr = "";
if (pCfgStr != NULL) {
printStr = pCfgStr;
}
if (userStrLen < 256) {
char logBuf[256 + 256];
if (pSyncNode != NULL && pSyncNode->pRaftCfg != NULL && pSyncNode->pRaftStore != NULL) {
snprintf(logBuf, sizeof(logBuf),
"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",
pSyncNode->vgId, syncStr(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm,
pSyncNode->commitIndex, logBeginIndex, logLastIndex, pSyncNode->minMatchIndex, snapshot.lastApplyIndex,
snapshot.lastApplyTerm, pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy,
pSyncNode->pRaftCfg->batchSize, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex,
pSyncNode->changing, pSyncNode->restoreFinish, syncNodeDynamicQuorum(pSyncNode),
pSyncNode->electTimerLogicClock, pSyncNode->heartbeatTimerLogicClockUser, printStr);
} else {
snprintf(logBuf, sizeof(logBuf), "%s", str);
}
sError("%s", logBuf);
} else {
int len = 256 + userStrLen;
char* s = (char*)taosMemoryMalloc(len);
if (pSyncNode != NULL && pSyncNode->pRaftCfg != NULL && pSyncNode->pRaftStore != NULL) {
snprintf(s, len,
"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",
pSyncNode->vgId, syncStr(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm,
pSyncNode->commitIndex, logBeginIndex, logLastIndex, pSyncNode->minMatchIndex, snapshot.lastApplyIndex,
snapshot.lastApplyTerm, pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy,
pSyncNode->pRaftCfg->batchSize, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex,
pSyncNode->changing, pSyncNode->restoreFinish, syncNodeDynamicQuorum(pSyncNode),
pSyncNode->electTimerLogicClock, pSyncNode->heartbeatTimerLogicClockUser, printStr);
} else {
snprintf(s, len, "%s", str);
}
sError("%s", s);
taosMemoryFree(s);
}
taosMemoryFree(pCfgStr);
}
inline char* syncNode2SimpleStr(const SSyncNode* pSyncNode) { inline char* syncNode2SimpleStr(const SSyncNode* pSyncNode) {
int len = 256; int len = 256;
char* s = (char*)taosMemoryMalloc(len); char* s = (char*)taosMemoryMalloc(len);
...@@ -1977,15 +1649,11 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde ...@@ -1977,15 +1649,11 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde
} }
// log begin config change // log begin config change
do { char oldCfgStr[1024] = {0};
char eventLog[256]; char newCfgStr[1024] = {0};
char* pOldCfgStr = syncCfg2SimpleStr(&oldConfig); syncCfg2SimpleStr(&oldConfig, oldCfgStr, sizeof(oldCfgStr));
char* pNewCfgStr = syncCfg2SimpleStr(pNewConfig); syncCfg2SimpleStr(pNewConfig, oldCfgStr, sizeof(oldCfgStr));
snprintf(eventLog, sizeof(eventLog), "begin do config change, from %s to %s", pOldCfgStr, pNewCfgStr); sNTrace(pSyncNode, "begin do config change, from %s to %s", oldCfgStr, oldCfgStr);
syncNodeEventLog(pSyncNode, eventLog);
taosMemoryFree(pOldCfgStr);
taosMemoryFree(pNewCfgStr);
} while (0);
if (IamInNew) { if (IamInNew) {
pSyncNode->pRaftCfg->isStandBy = 0; // change isStandBy to normal pSyncNode->pRaftCfg->isStandBy = 0; // change isStandBy to normal
...@@ -2008,10 +1676,7 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde ...@@ -2008,10 +1676,7 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde
SSyncSnapshotSender* oldSenders[TSDB_MAX_REPLICA]; SSyncSnapshotSender* oldSenders[TSDB_MAX_REPLICA];
for (int i = 0; i < TSDB_MAX_REPLICA; ++i) { for (int i = 0; i < TSDB_MAX_REPLICA; ++i) {
oldSenders[i] = (pSyncNode->senders)[i]; oldSenders[i] = (pSyncNode->senders)[i];
sSTrace(oldSenders[i], "snapshot sender save old");
char* eventLog = snapshotSender2SimpleStr(oldSenders[i], "snapshot sender save old");
syncNodeEventLog(pSyncNode, eventLog);
taosMemoryFree(eventLog);
} }
// init internal // init internal
...@@ -2061,13 +1726,8 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde ...@@ -2061,13 +1726,8 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde
char host[128]; char host[128];
uint16_t port; uint16_t port;
syncUtilU642Addr((pSyncNode->replicasId)[i].addr, host, sizeof(host), &port); syncUtilU642Addr((pSyncNode->replicasId)[i].addr, host, sizeof(host), &port);
sNTrace(pSyncNode, "snapshot sender reset for: %" PRIu64 ", newIndex:%d, %s:%d, %p",
do { (pSyncNode->replicasId)[i].addr, i, host, port, oldSenders[j]);
char eventLog[256];
snprintf(eventLog, sizeof(eventLog), "snapshot sender reset for: %" PRIu64 ", newIndex:%d, %s:%d, %p",
(pSyncNode->replicasId)[i].addr, i, host, port, oldSenders[j]);
syncNodeEventLog(pSyncNode, eventLog);
} while (0);
(pSyncNode->senders)[i] = oldSenders[j]; (pSyncNode->senders)[i] = oldSenders[j];
oldSenders[j] = NULL; oldSenders[j] = NULL;
...@@ -2077,13 +1737,8 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde ...@@ -2077,13 +1737,8 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde
int32_t oldreplicaIndex = (pSyncNode->senders)[i]->replicaIndex; int32_t oldreplicaIndex = (pSyncNode->senders)[i]->replicaIndex;
(pSyncNode->senders)[i]->replicaIndex = i; (pSyncNode->senders)[i]->replicaIndex = i;
do { sNTrace(pSyncNode, "snapshot sender udpate replicaIndex from %d to %d, %s:%d, %p, reset:%d", oldreplicaIndex,
char eventLog[256]; i, host, port, (pSyncNode->senders)[i], reset);
snprintf(eventLog, sizeof(eventLog),
"snapshot sender udpate replicaIndex from %d to %d, %s:%d, %p, reset:%d", oldreplicaIndex, i, host,
port, (pSyncNode->senders)[i], reset);
syncNodeEventLog(pSyncNode, eventLog);
} while (0);
} }
} }
} }
...@@ -2092,10 +1747,7 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde ...@@ -2092,10 +1747,7 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde
for (int i = 0; i < TSDB_MAX_REPLICA; ++i) { for (int i = 0; i < TSDB_MAX_REPLICA; ++i) {
if ((pSyncNode->senders)[i] == NULL) { if ((pSyncNode->senders)[i] == NULL) {
(pSyncNode->senders)[i] = snapshotSenderCreate(pSyncNode, i); (pSyncNode->senders)[i] = snapshotSenderCreate(pSyncNode, i);
sSTrace((pSyncNode->senders)[i], "snapshot sender create new");
char* eventLog = snapshotSender2SimpleStr((pSyncNode->senders)[i], "snapshot sender create new");
syncNodeEventLog(pSyncNode, eventLog);
taosMemoryFree(eventLog);
} }
} }
...@@ -2103,13 +1755,7 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde ...@@ -2103,13 +1755,7 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde
for (int i = 0; i < TSDB_MAX_REPLICA; ++i) { for (int i = 0; i < TSDB_MAX_REPLICA; ++i) {
if (oldSenders[i] != NULL) { if (oldSenders[i] != NULL) {
snapshotSenderDestroy(oldSenders[i]); snapshotSenderDestroy(oldSenders[i]);
sNTrace(pSyncNode, "snapshot sender delete old %p replica-index:%d", oldSenders[i], i);
do {
char eventLog[128];
snprintf(eventLog, sizeof(eventLog), "snapshot sender delete old %p replica-index:%d", oldSenders[i], i);
syncNodeEventLog(pSyncNode, eventLog);
} while (0);
oldSenders[i] = NULL; oldSenders[i] = NULL;
} }
} }
...@@ -2117,13 +1763,9 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde ...@@ -2117,13 +1763,9 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde
// persist cfg // persist cfg
raftCfgPersist(pSyncNode->pRaftCfg); raftCfgPersist(pSyncNode->pRaftCfg);
char tmpbuf[512]; char tmpbuf[1024] = {0};
char* oldStr = syncCfg2SimpleStr(&oldConfig);
char* newStr = syncCfg2SimpleStr(pNewConfig);
snprintf(tmpbuf, sizeof(tmpbuf), "config change from %d to %d, index:%" PRId64 ", %s --> %s", snprintf(tmpbuf, sizeof(tmpbuf), "config change from %d to %d, index:%" PRId64 ", %s --> %s",
oldConfig.replicaNum, pNewConfig->replicaNum, lastConfigChangeIndex, oldStr, newStr); oldConfig.replicaNum, pNewConfig->replicaNum, lastConfigChangeIndex, oldCfgStr, newCfgStr);
taosMemoryFree(oldStr);
taosMemoryFree(newStr);
// change isStandBy to normal (election timeout) // change isStandBy to normal (election timeout)
if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) { if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) {
...@@ -2139,30 +1781,13 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde ...@@ -2139,30 +1781,13 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde
} else { } else {
// persist cfg // persist cfg
raftCfgPersist(pSyncNode->pRaftCfg); raftCfgPersist(pSyncNode->pRaftCfg);
sNTrace(pSyncNode, "do not config change from %d to %d, index:%" PRId64 ", %s --> %s", oldConfig.replicaNum,
char tmpbuf[512]; pNewConfig->replicaNum, lastConfigChangeIndex, oldCfgStr, newCfgStr);
char* oldStr = syncCfg2SimpleStr(&oldConfig);
char* newStr = syncCfg2SimpleStr(pNewConfig);
snprintf(tmpbuf, sizeof(tmpbuf), "do not config change from %d to %d, index:%" PRId64 ", %s --> %s",
oldConfig.replicaNum, pNewConfig->replicaNum, lastConfigChangeIndex, oldStr, newStr);
taosMemoryFree(oldStr);
taosMemoryFree(newStr);
syncNodeEventLog(pSyncNode, tmpbuf);
} }
_END: _END:
// log end config change // log end config change
do { sNTrace(pSyncNode, "end do config change, from %s to %s", oldCfgStr, newCfgStr);
char eventLog[256];
char* pOldCfgStr = syncCfg2SimpleStr(&oldConfig);
char* pNewCfgStr = syncCfg2SimpleStr(pNewConfig);
snprintf(eventLog, sizeof(eventLog), "end do config change, from %s to %s", pOldCfgStr, pNewCfgStr);
syncNodeEventLog(pSyncNode, eventLog);
taosMemoryFree(pOldCfgStr);
taosMemoryFree(pNewCfgStr);
} while (0);
return;
} }
// raft state change -------------- // raft state change --------------
...@@ -2184,18 +1809,14 @@ void syncNodeUpdateTermWithoutStepDown(SSyncNode* pSyncNode, SyncTerm term) { ...@@ -2184,18 +1809,14 @@ void syncNodeUpdateTermWithoutStepDown(SSyncNode* pSyncNode, SyncTerm term) {
void syncNodeStepDown(SSyncNode* pSyncNode, SyncTerm newTerm) { void syncNodeStepDown(SSyncNode* pSyncNode, SyncTerm newTerm) {
if (pSyncNode->pRaftStore->currentTerm > newTerm) { if (pSyncNode->pRaftStore->currentTerm > newTerm) {
char logBuf[128]; sNTrace(pSyncNode, "step down, ignore, new-term:%" PRIu64 ", current-term:%" PRIu64, newTerm,
snprintf(logBuf, sizeof(logBuf), "step down, ignore, new-term:%" PRIu64 ", current-term:%" PRIu64, newTerm, pSyncNode->pRaftStore->currentTerm);
pSyncNode->pRaftStore->currentTerm);
syncNodeEventLog(pSyncNode, logBuf);
return; return;
} }
do { do {
char logBuf[128]; sNTrace(pSyncNode, "step down, new-term:%" PRIu64 ", current-term:%" PRIu64, newTerm,
snprintf(logBuf, sizeof(logBuf), "step down, new-term:%" PRIu64 ", current-term:%" PRIu64, newTerm, pSyncNode->pRaftStore->currentTerm);
pSyncNode->pRaftStore->currentTerm);
syncNodeEventLog(pSyncNode, logBuf);
} while (0); } while (0);
if (pSyncNode->pRaftStore->currentTerm < newTerm) { if (pSyncNode->pRaftStore->currentTerm < newTerm) {
...@@ -2239,19 +1860,7 @@ void syncNodeBecomeFollower(SSyncNode* pSyncNode, const char* debugStr) { ...@@ -2239,19 +1860,7 @@ void syncNodeBecomeFollower(SSyncNode* pSyncNode, const char* debugStr) {
pSyncNode->minMatchIndex = SYNC_INDEX_INVALID; pSyncNode->minMatchIndex = SYNC_INDEX_INVALID;
// trace log // trace log
do { sNTrace(pSyncNode, "become follower %s", debugStr);
int32_t debugStrLen = strlen(debugStr);
if (debugStrLen < 256) {
char eventLog[256 + 64];
snprintf(eventLog, sizeof(eventLog), "become follower %s", debugStr);
syncNodeEventLog(pSyncNode, eventLog);
} else {
char* eventLog = taosMemoryMalloc(debugStrLen + 64);
snprintf(eventLog, debugStrLen, "become follower %s", debugStr);
syncNodeEventLog(pSyncNode, eventLog);
taosMemoryFree(eventLog);
}
} while (0);
} }
// TLA+ Spec // TLA+ Spec
...@@ -2343,19 +1952,7 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) { ...@@ -2343,19 +1952,7 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) {
pSyncNode->minMatchIndex = SYNC_INDEX_INVALID; pSyncNode->minMatchIndex = SYNC_INDEX_INVALID;
// trace log // trace log
do { sNTrace(pSyncNode, "become leader %s", debugStr);
int32_t debugStrLen = strlen(debugStr);
if (debugStrLen < 256) {
char eventLog[256 + 64];
snprintf(eventLog, sizeof(eventLog), "become leader %s", debugStr);
syncNodeEventLog(pSyncNode, eventLog);
} else {
char* eventLog = taosMemoryMalloc(debugStrLen + 64);
snprintf(eventLog, debugStrLen, "become leader %s", debugStr);
syncNodeEventLog(pSyncNode, eventLog);
taosMemoryFree(eventLog);
}
} while (0);
} }
void syncNodeCandidate2Leader(SSyncNode* pSyncNode) { void syncNodeCandidate2Leader(SSyncNode* pSyncNode) {
...@@ -2363,7 +1960,7 @@ void syncNodeCandidate2Leader(SSyncNode* pSyncNode) { ...@@ -2363,7 +1960,7 @@ void syncNodeCandidate2Leader(SSyncNode* pSyncNode) {
ASSERT(voteGrantedMajority(pSyncNode->pVotesGranted)); ASSERT(voteGrantedMajority(pSyncNode->pVotesGranted));
syncNodeBecomeLeader(pSyncNode, "candidate to leader"); syncNodeBecomeLeader(pSyncNode, "candidate to leader");
syncNodeLog2("==state change syncNodeCandidate2Leader==", pSyncNode); sNTrace(pSyncNode, "state change syncNodeCandidate2Leader");
// Raft 3.6.2 Committing entries from previous terms // Raft 3.6.2 Committing entries from previous terms
syncNodeAppendNoop(pSyncNode); syncNodeAppendNoop(pSyncNode);
...@@ -2388,22 +1985,19 @@ int32_t syncNodePeerStateInit(SSyncNode* pSyncNode) { ...@@ -2388,22 +1985,19 @@ int32_t syncNodePeerStateInit(SSyncNode* pSyncNode) {
void syncNodeFollower2Candidate(SSyncNode* pSyncNode) { void syncNodeFollower2Candidate(SSyncNode* pSyncNode) {
ASSERT(pSyncNode->state == TAOS_SYNC_STATE_FOLLOWER); ASSERT(pSyncNode->state == TAOS_SYNC_STATE_FOLLOWER);
pSyncNode->state = TAOS_SYNC_STATE_CANDIDATE; pSyncNode->state = TAOS_SYNC_STATE_CANDIDATE;
sNTrace(pSyncNode, "follower to candidate");
syncNodeEventLog(pSyncNode, "follower to candidate");
} }
void syncNodeLeader2Follower(SSyncNode* pSyncNode) { void syncNodeLeader2Follower(SSyncNode* pSyncNode) {
ASSERT(pSyncNode->state == TAOS_SYNC_STATE_LEADER); ASSERT(pSyncNode->state == TAOS_SYNC_STATE_LEADER);
syncNodeBecomeFollower(pSyncNode, "leader to follower"); syncNodeBecomeFollower(pSyncNode, "leader to follower");
sNTrace(pSyncNode, "leader to follower");
syncNodeEventLog(pSyncNode, "leader to follower");
} }
void syncNodeCandidate2Follower(SSyncNode* pSyncNode) { void syncNodeCandidate2Follower(SSyncNode* pSyncNode) {
ASSERT(pSyncNode->state == TAOS_SYNC_STATE_CANDIDATE); ASSERT(pSyncNode->state == TAOS_SYNC_STATE_CANDIDATE);
syncNodeBecomeFollower(pSyncNode, "candidate to follower"); syncNodeBecomeFollower(pSyncNode, "candidate to follower");
sNTrace(pSyncNode, "candidate to follower");
syncNodeEventLog(pSyncNode, "candidate to follower");
} }
// raft vote -------------- // raft vote --------------
...@@ -2547,14 +2141,8 @@ SyncTerm syncNodeGetPreTerm(SSyncNode* pSyncNode, SyncIndex index) { ...@@ -2547,14 +2141,8 @@ SyncTerm syncNodeGetPreTerm(SSyncNode* pSyncNode, SyncIndex index) {
} }
} }
do { sNError(pSyncNode, "sync node get pre term error, index:%" PRId64 ", snap-index:%" PRId64 ", snap-term:%" PRIu64,
char logBuf[128]; index, snapshot.lastApplyIndex, snapshot.lastApplyTerm);
snprintf(logBuf, sizeof(logBuf),
"sync node get pre term error, index:%" PRId64 ", snap-index:%" PRId64 ", snap-term:%" PRIu64, index,
snapshot.lastApplyIndex, snapshot.lastApplyTerm);
syncNodeErrorLog(pSyncNode, logBuf);
} while (0);
return SYNC_TERM_INVALID; return SYNC_TERM_INVALID;
} }
...@@ -2565,41 +2153,6 @@ int32_t syncNodeGetPreIndexTerm(SSyncNode* pSyncNode, SyncIndex index, SyncIndex ...@@ -2565,41 +2153,6 @@ int32_t syncNodeGetPreIndexTerm(SSyncNode* pSyncNode, SyncIndex index, SyncIndex
return 0; return 0;
} }
// for debug --------------
void syncNodePrint(SSyncNode* pObj) {
char* serialized = syncNode2Str(pObj);
printf("syncNodePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
fflush(NULL);
taosMemoryFree(serialized);
}
void syncNodePrint2(char* s, SSyncNode* pObj) {
char* serialized = syncNode2Str(pObj);
printf("syncNodePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
fflush(NULL);
taosMemoryFree(serialized);
}
void syncNodeLog(SSyncNode* pObj) {
char* serialized = syncNode2Str(pObj);
sTraceLong("syncNodeLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
taosMemoryFree(serialized);
}
void syncNodeLog2(char* s, SSyncNode* pObj) {
if (gRaftDetailLog) {
char* serialized = syncNode2Str(pObj);
sTraceLong("syncNodeLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
taosMemoryFree(serialized);
}
}
void syncNodeLog3(char* s, SSyncNode* pObj) {
char* serialized = syncNode2Str(pObj);
sTraceLong("syncNodeLog3 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
taosMemoryFree(serialized);
}
// ------ local funciton --------- // ------ local funciton ---------
// enqueue message ---- // enqueue message ----
static void syncNodeEqPingTimer(void* param, void* tmrId) { static void syncNodeEqPingTimer(void* param, void* tmrId) {
...@@ -2653,13 +2206,7 @@ static void syncNodeEqElectTimer(void* param, void* tmrId) { ...@@ -2653,13 +2206,7 @@ static void syncNodeEqElectTimer(void* param, void* tmrId) {
taosMemoryFree(pElectTimer); taosMemoryFree(pElectTimer);
return; return;
} }
sNTrace(pSyncNode, "eq elect timer lc:%" PRIu64, pSyncMsg->logicClock);
do {
char logBuf[128];
snprintf(logBuf, sizeof(logBuf), "eq elect timer lc:%" PRIu64, pSyncMsg->logicClock);
syncNodeEventLog(pSyncNode, logBuf);
} while (0);
} else { } else {
sTrace("syncNodeEqElectTimer syncEqMsg is NULL"); sTrace("syncNodeEqElectTimer syncEqMsg is NULL");
} }
...@@ -2681,8 +2228,7 @@ static void syncNodeEqElectTimer(void* param, void* tmrId) { ...@@ -2681,8 +2228,7 @@ static void syncNodeEqElectTimer(void* param, void* tmrId) {
static void syncNodeEqHeartbeatTimer(void* param, void* tmrId) { static void syncNodeEqHeartbeatTimer(void* param, void* tmrId) {
SSyncNode* pSyncNode = (SSyncNode*)param; SSyncNode* pSyncNode = (SSyncNode*)param;
sNTrace(pSyncNode, "eq hb timer");
syncNodeEventLog(pSyncNode, "eq hb timer");
if (pSyncNode->replicaNum > 1) { if (pSyncNode->replicaNum > 1) {
if (atomic_load_64(&pSyncNode->heartbeatTimerLogicClockUser) <= if (atomic_load_64(&pSyncNode->heartbeatTimerLogicClockUser) <=
...@@ -2729,7 +2275,7 @@ static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId) { ...@@ -2729,7 +2275,7 @@ static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId) {
return; return;
} }
// syncNodeEventLog(pSyncNode, "eq peer hb timer"); // sNTrace(pSyncNode, "eq peer hb timer");
int64_t timerLogicClock = atomic_load_64(&pSyncTimer->logicClock); int64_t timerLogicClock = atomic_load_64(&pSyncTimer->logicClock);
int64_t msgLogicClock = atomic_load_64(&pData->logicClock); int64_t msgLogicClock = atomic_load_64(&pData->logicClock);
...@@ -2839,7 +2385,7 @@ static int32_t syncNodeAppendNoop(SSyncNode* ths) { ...@@ -2839,7 +2385,7 @@ static int32_t syncNodeAppendNoop(SSyncNode* ths) {
if (ths->state == TAOS_SYNC_STATE_LEADER) { if (ths->state == TAOS_SYNC_STATE_LEADER) {
int32_t code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pEntry); int32_t code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pEntry);
if (code != 0) { if (code != 0) {
syncNodeErrorLog(ths, "append noop error"); sNError(ths, "append noop error");
return -1; return -1;
} }
} }
...@@ -2972,7 +2518,7 @@ int32_t syncNodeOnLocalCmd(SSyncNode* ths, SyncLocalCmd* pMsg) { ...@@ -2972,7 +2518,7 @@ int32_t syncNodeOnLocalCmd(SSyncNode* ths, SyncLocalCmd* pMsg) {
syncNodeFollowerCommit(ths, pMsg->fcIndex); syncNodeFollowerCommit(ths, pMsg->fcIndex);
} else { } else {
syncNodeErrorLog(ths, "error local cmd"); sNError(ths, "error local cmd");
} }
return 0; return 0;
...@@ -2990,7 +2536,7 @@ int32_t syncNodeOnLocalCmd(SSyncNode* ths, SyncLocalCmd* pMsg) { ...@@ -2990,7 +2536,7 @@ int32_t syncNodeOnLocalCmd(SSyncNode* ths, SyncLocalCmd* pMsg) {
// //
int32_t syncNodeOnClientRequest(SSyncNode* ths, SyncClientRequest* pMsg, SyncIndex* pRetIndex) { int32_t syncNodeOnClientRequest(SSyncNode* ths, SyncClientRequest* pMsg, SyncIndex* pRetIndex) {
syncNodeEventLog(ths, "on client request"); sNTrace(ths, "on client request");
int32_t ret = 0; int32_t ret = 0;
int32_t code = 0; int32_t code = 0;
...@@ -3069,43 +2615,34 @@ const char* syncStr(ESyncState state) { ...@@ -3069,43 +2615,34 @@ const char* syncStr(ESyncState state) {
int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* pEntry) { int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* pEntry) {
if (ths->state != TAOS_SYNC_STATE_FOLLOWER) { if (ths->state != TAOS_SYNC_STATE_FOLLOWER) {
syncNodeEventLog(ths, "I am not follower, can not do leader transfer"); sNTrace(ths, "I am not follower, can not do leader transfer");
return 0; return 0;
} }
if (!ths->restoreFinish) { if (!ths->restoreFinish) {
syncNodeEventLog(ths, "restore not finish, can not do leader transfer"); sNTrace(ths, "restore not finish, can not do leader transfer");
return 0; return 0;
} }
if (pEntry->term < ths->pRaftStore->currentTerm) { if (pEntry->term < ths->pRaftStore->currentTerm) {
char logBuf[128]; sNTrace(ths, "little term:%" PRIu64 ", can not do leader transfer", pEntry->term);
snprintf(logBuf, sizeof(logBuf), "little term:%" PRIu64 ", can not do leader transfer", pEntry->term);
syncNodeEventLog(ths, logBuf);
return 0; return 0;
} }
if (pEntry->index < syncNodeGetLastIndex(ths)) { if (pEntry->index < syncNodeGetLastIndex(ths)) {
char logBuf[128]; sNTrace(ths, "little index:%" PRId64 ", can not do leader transfer", pEntry->index);
snprintf(logBuf, sizeof(logBuf), "little index:%" PRId64 ", can not do leader transfer", pEntry->index);
syncNodeEventLog(ths, logBuf);
return 0; return 0;
} }
/* /*
if (ths->vgId > 1) { if (ths->vgId > 1) {
syncNodeEventLog(ths, "I am vnode, can not do leader transfer"); sNTrace(ths, "I am vnode, can not do leader transfer");
return 0; return 0;
} }
*/ */
SyncLeaderTransfer* pSyncLeaderTransfer = syncLeaderTransferFromRpcMsg2(pRpcMsg); SyncLeaderTransfer* pSyncLeaderTransfer = syncLeaderTransferFromRpcMsg2(pRpcMsg);
sNTrace(ths, "do leader transfer, index:%" PRId64, pEntry->index);
do {
char logBuf[128];
snprintf(logBuf, sizeof(logBuf), "do leader transfer, index:%" PRId64, pEntry->index);
syncNodeEventLog(ths, logBuf);
} while (0);
bool sameId = syncUtilSameId(&(pSyncLeaderTransfer->newLeaderId), &(ths->myRaftId)); bool sameId = syncUtilSameId(&(pSyncLeaderTransfer->newLeaderId), &(ths->myRaftId));
bool sameNodeInfo = strcmp(pSyncLeaderTransfer->newNodeInfo.nodeFqdn, ths->myNodeInfo.nodeFqdn) == 0 && bool sameNodeInfo = strcmp(pSyncLeaderTransfer->newNodeInfo.nodeFqdn, ths->myNodeInfo.nodeFqdn) == 0 &&
...@@ -3118,11 +2655,8 @@ int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* p ...@@ -3118,11 +2655,8 @@ int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* p
int32_t ret = syncNodeRestartElectTimer(ths, electMS); int32_t ret = syncNodeRestartElectTimer(ths, electMS);
ASSERT(ret == 0); ASSERT(ret == 0);
char eventLog[256]; sNTrace(ths, "maybe leader transfer to %s:%d %" PRIu64, pSyncLeaderTransfer->newNodeInfo.nodeFqdn,
snprintf(eventLog, sizeof(eventLog), "maybe leader transfer to %s:%d %" PRIu64, pSyncLeaderTransfer->newNodeInfo.nodePort, pSyncLeaderTransfer->newLeaderId.addr);
pSyncLeaderTransfer->newNodeInfo.nodeFqdn, pSyncLeaderTransfer->newNodeInfo.nodePort,
pSyncLeaderTransfer->newLeaderId.addr);
syncNodeEventLog(ths, eventLog);
} }
if (ths->pFsm->FpLeaderTransferCb != NULL) { if (ths->pFsm->FpLeaderTransferCb != NULL) {
...@@ -3159,89 +2693,6 @@ int32_t syncNodeUpdateNewConfigIndex(SSyncNode* ths, SSyncCfg* pNewCfg) { ...@@ -3159,89 +2693,6 @@ int32_t syncNodeUpdateNewConfigIndex(SSyncNode* ths, SSyncCfg* pNewCfg) {
return -1; return -1;
} }
static int32_t syncNodeConfigChangeFinish(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* pEntry) {
SyncReconfigFinish* pFinish = syncReconfigFinishFromRpcMsg2(pRpcMsg);
ASSERT(pFinish);
if (ths->pFsm->FpReConfigCb != NULL) {
SReConfigCbMeta cbMeta = {0};
cbMeta.code = 0;
cbMeta.index = pEntry->index;
cbMeta.term = pEntry->term;
cbMeta.seqNum = pEntry->seqNum;
cbMeta.lastConfigIndex = syncNodeGetSnapshotConfigIndex(ths, pEntry->index);
cbMeta.state = ths->state;
cbMeta.currentTerm = ths->pRaftStore->currentTerm;
cbMeta.isWeak = pEntry->isWeak;
cbMeta.flag = 0;
cbMeta.oldCfg = pFinish->oldCfg;
cbMeta.newCfg = pFinish->newCfg;
cbMeta.newCfgIndex = pFinish->newCfgIndex;
cbMeta.newCfgTerm = pFinish->newCfgTerm;
cbMeta.newCfgSeqNum = pFinish->newCfgSeqNum;
ths->pFsm->FpReConfigCb(ths->pFsm, pRpcMsg, &cbMeta);
}
// clear changing
ths->changing = false;
char tmpbuf[512];
char* oldStr = syncCfg2SimpleStr(&(pFinish->oldCfg));
char* newStr = syncCfg2SimpleStr(&(pFinish->newCfg));
snprintf(tmpbuf, sizeof(tmpbuf), "config change finish from %d to %d, index:%" PRId64 ", %s --> %s",
pFinish->oldCfg.replicaNum, pFinish->newCfg.replicaNum, pFinish->newCfgIndex, oldStr, newStr);
taosMemoryFree(oldStr);
taosMemoryFree(newStr);
syncNodeEventLog(ths, tmpbuf);
syncReconfigFinishDestroy(pFinish);
return 0;
}
static int32_t syncNodeConfigChange(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* pEntry,
SyncReconfigFinish* pFinish) {
// set changing
ths->changing = true;
// old config
SSyncCfg oldSyncCfg = ths->pRaftCfg->cfg;
// new config
SSyncCfg newSyncCfg;
int32_t ret = syncCfgFromStr(pRpcMsg->pCont, &newSyncCfg);
ASSERT(ret == 0);
// update new config myIndex
syncNodeUpdateNewConfigIndex(ths, &newSyncCfg);
// do config change
syncNodeDoConfigChange(ths, &newSyncCfg, pEntry->index);
// set pFinish
pFinish->oldCfg = oldSyncCfg;
pFinish->newCfg = newSyncCfg;
pFinish->newCfgIndex = pEntry->index;
pFinish->newCfgTerm = pEntry->term;
pFinish->newCfgSeqNum = pEntry->seqNum;
return 0;
}
static int32_t syncNodeProposeConfigChangeFinish(SSyncNode* ths, SyncReconfigFinish* pFinish) {
SRpcMsg rpcMsg;
syncReconfigFinish2RpcMsg(pFinish, &rpcMsg);
int32_t code = syncNodePropose(ths, &rpcMsg, false);
if (code != 0) {
sError("syncNodeProposeConfigChangeFinish error");
ths->changing = false;
}
return 0;
}
bool syncNodeIsOptimizedOneReplica(SSyncNode* ths, SRpcMsg* pMsg) { bool syncNodeIsOptimizedOneReplica(SSyncNode* ths, SRpcMsg* pMsg) {
return (ths->replicaNum == 1 && syncUtilUserCommit(pMsg->msgType) && ths->vgId != 1); return (ths->replicaNum == 1 && syncUtilUserCommit(pMsg->msgType) && ths->vgId != 1);
} }
...@@ -3260,10 +2711,7 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde ...@@ -3260,10 +2711,7 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde
SSnapshot snapshot = {0}; SSnapshot snapshot = {0};
ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &snapshot); ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &snapshot);
if (snapshot.lastApplyIndex >= 0 && snapshot.lastApplyIndex >= beginIndex) { if (snapshot.lastApplyIndex >= 0 && snapshot.lastApplyIndex >= beginIndex) {
char eventLog[128]; sNTrace(ths, "commit by snapshot from index:%" PRId64 " to index:%" PRId64, beginIndex, snapshot.lastApplyIndex);
snprintf(eventLog, sizeof(eventLog), "commit by snapshot from index:%" PRId64 " to index:%" PRId64, beginIndex,
snapshot.lastApplyIndex);
syncNodeEventLog(ths, eventLog);
// update begin index // update begin index
beginIndex = snapshot.lastApplyIndex + 1; beginIndex = snapshot.lastApplyIndex + 1;
...@@ -3273,9 +2721,7 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde ...@@ -3273,9 +2721,7 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde
int32_t code = 0; int32_t code = 0;
ESyncState state = flag; ESyncState state = flag;
char eventLog[128]; sNTrace(ths, "commit by wal from index:%" PRId64 " to index:%" PRId64, beginIndex, endIndex);
snprintf(eventLog, sizeof(eventLog), "commit by wal from index:%" PRId64 " to index:%" PRId64, beginIndex, endIndex);
syncNodeEventLog(ths, eventLog);
// execute fsm // execute fsm
if (ths->pFsm != NULL) { if (ths->pFsm != NULL) {
...@@ -3291,7 +2737,7 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde ...@@ -3291,7 +2737,7 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde
// ASSERT(code == 0); // ASSERT(code == 0);
// ASSERT(pEntry != NULL); // ASSERT(pEntry != NULL);
if (code != 0 || pEntry == NULL) { if (code != 0 || pEntry == NULL) {
syncNodeErrorLog(ths, "get log entry error"); sNError(ths, "get log entry error");
sFatal("vgId:%d, get log entry %" PRId64 " error when commit since %s", ths->vgId, i, terrstr()); sFatal("vgId:%d, get log entry %" PRId64 " error when commit since %s", ths->vgId, i, terrstr());
continue; continue;
} }
...@@ -3307,11 +2753,7 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde ...@@ -3307,11 +2753,7 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde
internalExecute = false; internalExecute = false;
} }
do { sNTrace(ths, "commit index:%" PRId64 ", internal:%d", i, internalExecute);
char logBuf[128];
snprintf(logBuf, sizeof(logBuf), "commit index:%" PRId64 ", internal:%d", i, internalExecute);
syncNodeEventLog(ths, logBuf);
} while (0);
// execute fsm in apply thread, or execute outside syncPropose // execute fsm in apply thread, or execute outside syncPropose
if (internalExecute) { if (internalExecute) {
...@@ -3332,28 +2774,6 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde ...@@ -3332,28 +2774,6 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde
} }
} }
// config change
if (pEntry->originalRpcType == TDMT_SYNC_CONFIG_CHANGE) {
SyncReconfigFinish* pFinish = syncReconfigFinishBuild(ths->vgId);
ASSERT(pFinish != NULL);
code = syncNodeConfigChange(ths, &rpcMsg, pEntry, pFinish);
ASSERT(code == 0);
if (ths->state == TAOS_SYNC_STATE_LEADER) {
syncNodeProposeConfigChangeFinish(ths, pFinish);
}
syncReconfigFinishDestroy(pFinish);
}
// config change finish
if (pEntry->originalRpcType == TDMT_SYNC_CONFIG_CHANGE_FINISH) {
if (rpcMsg.pCont != NULL && rpcMsg.contLen > 0) {
code = syncNodeConfigChangeFinish(ths, &rpcMsg, pEntry);
ASSERT(code == 0);
}
}
#if 0 #if 0
// execute in pre-commit // execute in pre-commit
// leader transfer // leader transfer
...@@ -3373,11 +2793,7 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde ...@@ -3373,11 +2793,7 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde
ths->restoreFinish = true; ths->restoreFinish = true;
int64_t restoreDelay = taosGetTimestampMs() - ths->leaderTime; int64_t restoreDelay = taosGetTimestampMs() - ths->leaderTime;
sNTrace(ths, "restore finish, index:%" PRId64 ", elapsed:%" PRId64 " ms", pEntry->index, restoreDelay);
char eventLog[128];
snprintf(eventLog, sizeof(eventLog), "restore finish, index:%" PRId64 ", elapsed:%" PRId64 " ms, ",
pEntry->index, restoreDelay);
syncNodeEventLog(ths, eventLog);
} }
} }
...@@ -3487,21 +2903,16 @@ const char* syncTimerTypeStr(enum ESyncTimeoutType timerType) { ...@@ -3487,21 +2903,16 @@ const char* syncTimerTypeStr(enum ESyncTimeoutType timerType) {
} }
void syncLogRecvTimer(SSyncNode* pSyncNode, const SyncTimeout* pMsg, const char* s) { void syncLogRecvTimer(SSyncNode* pSyncNode, const SyncTimeout* pMsg, const char* s) {
char logBuf[256]; sNTrace(pSyncNode, "recv sync-timer {type:%s, lc:%" PRIu64 ", ms:%d, data:%p}, %s",
snprintf(logBuf, sizeof(logBuf), "recv sync-timer {type:%s, lc:%" PRIu64 ", ms:%d, data:%p}, %s", syncTimerTypeStr(pMsg->timeoutType), pMsg->logicClock, pMsg->timerMS, pMsg->data, s);
syncTimerTypeStr(pMsg->timeoutType), pMsg->logicClock, pMsg->timerMS, pMsg->data, s);
syncNodeEventLog(pSyncNode, logBuf);
} }
void syncLogSendRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s) { void syncLogSendRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s) {
char host[64]; char host[64];
uint16_t port; uint16_t port;
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port); syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
char logBuf[256]; sNTrace(pSyncNode, "send sync-request-vote to %s:%d {term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 "}, %s",
snprintf(logBuf, sizeof(logBuf), host, port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, s);
"send sync-request-vote to %s:%d {term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 "}, %s", host, port,
pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, s);
syncNodeEventLog(pSyncNode, logBuf);
} }
void syncLogRecvRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s) { void syncLogRecvRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s) {
...@@ -3509,202 +2920,167 @@ void syncLogRecvRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, c ...@@ -3509,202 +2920,167 @@ void syncLogRecvRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, c
char host[64]; char host[64];
uint16_t port; uint16_t port;
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
snprintf(logBuf, sizeof(logBuf), sNTrace(pSyncNode, "recv sync-request-vote from %s:%d, {term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 "}, %s",
"recv sync-request-vote from %s:%d, {term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 "}, %s", host, host, port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, s);
port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, s);
syncNodeEventLog(pSyncNode, logBuf);
} }
void syncLogSendRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s) { void syncLogSendRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s) {
char host[64]; char host[64];
uint16_t port; uint16_t port;
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port); syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
char logBuf[256]; sNTrace(pSyncNode, "send sync-request-vote-reply to %s:%d {term:%" PRIu64 ", grant:%d}, %s", host, port, pMsg->term,
snprintf(logBuf, sizeof(logBuf), "send sync-request-vote-reply to %s:%d {term:%" PRIu64 ", grant:%d}, %s", host, port, pMsg->voteGranted, s);
pMsg->term, pMsg->voteGranted, s);
syncNodeEventLog(pSyncNode, logBuf);
} }
void syncLogRecvRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s) { void syncLogRecvRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s) {
char host[64]; char host[64];
uint16_t port; uint16_t port;
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
char logBuf[256]; sNTrace(pSyncNode, "recv sync-request-vote-reply from %s:%d {term:%" PRIu64 ", grant:%d}, %s", host, port, pMsg->term,
snprintf(logBuf, sizeof(logBuf), "recv sync-request-vote-reply from %s:%d {term:%" PRIu64 ", grant:%d}, %s", host, pMsg->voteGranted, s);
port, pMsg->term, pMsg->voteGranted, s);
syncNodeEventLog(pSyncNode, logBuf);
} }
void syncLogSendAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s) { void syncLogSendAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s) {
char host[64]; char host[64];
uint16_t port; uint16_t port;
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port); syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
char logBuf[256]; sNTrace(pSyncNode,
snprintf(logBuf, sizeof(logBuf), "send sync-append-entries to %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64
"send sync-append-entries to %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64 ", pterm:%" PRIu64 ", cmt:%" PRId64 ", datalen:%d}, %s",
", pterm:%" PRIu64 ", cmt:%" PRId64 host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex,
", " pMsg->dataLen, s);
"datalen:%d}, %s",
host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex,
pMsg->dataLen, s);
syncNodeEventLog(pSyncNode, logBuf);
} }
void syncLogRecvAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s) { void syncLogRecvAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s) {
char host[64]; char host[64];
uint16_t port; uint16_t port;
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
char logBuf[256];
snprintf(logBuf, sizeof(logBuf), sNTrace(pSyncNode,
"recv sync-append-entries from %s:%d {term:%" PRIu64 ", pre-index:%" PRIu64 ", pre-term:%" PRIu64 "recv sync-append-entries from %s:%d {term:%" PRIu64 ", pre-index:%" PRIu64 ", pre-term:%" PRIu64
", cmt:%" PRIu64 ", pterm:%" PRIu64 ", cmt:%" PRIu64 ", pterm:%" PRIu64 ", datalen:%d}, %s",
", " host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm,
"datalen:%d}, %s", pMsg->dataLen, s);
host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm,
pMsg->dataLen, s);
syncNodeEventLog(pSyncNode, logBuf);
} }
void syncLogSendAppendEntriesBatch(SSyncNode* pSyncNode, const SyncAppendEntriesBatch* pMsg, const char* s) { void syncLogSendAppendEntriesBatch(SSyncNode* pSyncNode, const SyncAppendEntriesBatch* pMsg, const char* s) {
char host[64]; char host[64];
uint16_t port; uint16_t port;
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port); syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
char logBuf[256];
snprintf(logBuf, sizeof(logBuf), sNTrace(pSyncNode,
"send sync-append-entries-batch to %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64 "send sync-append-entries-batch to %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64
", pterm:%" PRIu64 ", cmt:%" PRId64 ", datalen:%d, count:%d}, %s", ", pterm:%" PRIu64 ", cmt:%" PRId64 ", datalen:%d, count:%d}, %s",
host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex, host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex,
pMsg->dataLen, pMsg->dataCount, s); pMsg->dataLen, pMsg->dataCount, s);
syncNodeEventLog(pSyncNode, logBuf);
} }
void syncLogRecvAppendEntriesBatch(SSyncNode* pSyncNode, const SyncAppendEntriesBatch* pMsg, const char* s) { void syncLogRecvAppendEntriesBatch(SSyncNode* pSyncNode, const SyncAppendEntriesBatch* pMsg, const char* s) {
char host[64]; char host[64];
uint16_t port; uint16_t port;
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
char logBuf[256];
snprintf(logBuf, sizeof(logBuf), sNTrace(pSyncNode,
"recv sync-append-entries-batch from %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64 "recv sync-append-entries-batch from %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64
", pterm:%" PRIu64 ", cmt:%" PRId64 ", datalen:%d, count:%d}, %s", ", pterm:%" PRIu64 ", cmt:%" PRId64 ", datalen:%d, count:%d}, %s",
host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex, host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex,
pMsg->dataLen, pMsg->dataCount, s); pMsg->dataLen, pMsg->dataCount, s);
syncNodeEventLog(pSyncNode, logBuf);
} }
void syncLogSendAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s) { void syncLogSendAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s) {
char host[64]; char host[64];
uint16_t port; uint16_t port;
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port); syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
char logBuf[256];
snprintf(logBuf, sizeof(logBuf), sNTrace(pSyncNode,
"send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 ", success:%d, match:%" PRId64 "send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 ", success:%d, match:%" PRId64
"}, %s", "}, %s",
host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, s); host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, s);
syncNodeEventLog(pSyncNode, logBuf);
} }
void syncLogRecvAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s) { void syncLogRecvAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s) {
char host[64]; char host[64];
uint16_t port; uint16_t port;
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
char logBuf[256];
snprintf(logBuf, sizeof(logBuf), sNTrace(pSyncNode,
"recv sync-append-entries-reply from %s:%d {term:%" PRIu64 ", pterm:%" PRIu64 ", success:%d, match:%" PRId64 "recv sync-append-entries-reply from %s:%d {term:%" PRIu64 ", pterm:%" PRIu64 ", success:%d, match:%" PRId64
"}, %s", "}, %s",
host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, s); host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, s);
syncNodeEventLog(pSyncNode, logBuf);
} }
void syncLogSendHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const char* s) { void syncLogSendHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const char* s) {
char host[64]; char host[64];
uint16_t port; uint16_t port;
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port); syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
char logBuf[256];
snprintf(logBuf, sizeof(logBuf), sNTrace(pSyncNode,
"send sync-heartbeat to %s:%d {term:%" PRIu64 ", cmt:%" PRId64 ", min-match:%" PRId64 ", pterm:%" PRIu64 "send sync-heartbeat to %s:%d {term:%" PRIu64 ", cmt:%" PRId64 ", min-match:%" PRId64 ", pterm:%" PRIu64
"}, %s", "}, %s",
host, port, pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->privateTerm, s); host, port, pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->privateTerm, s);
syncNodeEventLog(pSyncNode, logBuf);
} }
void syncLogRecvHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const char* s) { void syncLogRecvHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const char* s) {
char host[64]; char host[64];
uint16_t port; uint16_t port;
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
char logBuf[256];
snprintf(logBuf, sizeof(logBuf), sNTrace(pSyncNode,
"recv sync-heartbeat from %s:%d {term:%" PRIu64 ", cmt:%" PRId64 ", min-match:%" PRId64 ", pterm:%" PRIu64 "recv sync-heartbeat from %s:%d {term:%" PRIu64 ", cmt:%" PRId64 ", min-match:%" PRId64 ", pterm:%" PRIu64
"}, %s", "}, %s",
host, port, pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->privateTerm, s); host, port, pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->privateTerm, s);
syncNodeEventLog(pSyncNode, logBuf);
} }
void syncLogSendHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s) { void syncLogSendHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s) {
char host[64]; char host[64];
uint16_t port; uint16_t port;
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port); syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
char logBuf[256];
snprintf(logBuf, sizeof(logBuf), "send sync-heartbeat-reply from %s:%d {term:%" PRIu64 ", pterm:%" PRIu64 "}, %s", sNTrace(pSyncNode, "send sync-heartbeat-reply from %s:%d {term:%" PRIu64 ", pterm:%" PRIu64 "}, %s", host, port,
host, port, pMsg->term, pMsg->privateTerm, s); pMsg->term, pMsg->privateTerm, s);
syncNodeEventLog(pSyncNode, logBuf);
} }
void syncLogRecvHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s) { void syncLogRecvHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s) {
char host[64]; char host[64];
uint16_t port; uint16_t port;
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
char logBuf[256]; sNTrace(pSyncNode, "recv sync-heartbeat-reply from %s:%d {term:%" PRIu64 ", pterm:%" PRIu64 "}, %s", host, port,
snprintf(logBuf, sizeof(logBuf), "recv sync-heartbeat-reply from %s:%d {term:%" PRIu64 ", pterm:%" PRIu64 "}, %s", pMsg->term, pMsg->privateTerm, s);
host, port, pMsg->term, pMsg->privateTerm, s);
syncNodeEventLog(pSyncNode, logBuf);
} }
void syncLogRecvLocalCmd(SSyncNode* pSyncNode, const SyncLocalCmd* pMsg, const char* s) { void syncLogRecvLocalCmd(SSyncNode* pSyncNode, const SyncLocalCmd* pMsg, const char* s) {
char logBuf[256]; sNTrace(pSyncNode, "recv sync-local-cmd {cmd:%d-%s, sd-new-term:%" PRIu64 "}, %s", pMsg->cmd,
snprintf(logBuf, sizeof(logBuf), "recv sync-local-cmd {cmd:%d-%s, sd-new-term:%" PRIu64 "}, %s", pMsg->cmd, syncLocalCmdGetStr(pMsg->cmd), pMsg->sdNewTerm, s);
syncLocalCmdGetStr(pMsg->cmd), pMsg->sdNewTerm, s);
syncNodeEventLog(pSyncNode, logBuf);
} }
void syncLogSendSyncPreSnapshot(SSyncNode* pSyncNode, const SyncPreSnapshot* pMsg, const char* s) { void syncLogSendSyncPreSnapshot(SSyncNode* pSyncNode, const SyncPreSnapshot* pMsg, const char* s) {
char host[64]; char host[64];
uint16_t port; uint16_t port;
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port); syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
char logBuf[256]; sNTrace(pSyncNode, "send sync-pre-snapshot to %s:%d {term:%" PRIu64 "}, %s", host, port, pMsg->term, s);
snprintf(logBuf, sizeof(logBuf), "send sync-pre-snapshot to %s:%d {term:%" PRIu64 "}, %s", host, port, pMsg->term, s);
syncNodeEventLog(pSyncNode, logBuf);
} }
void syncLogRecvSyncPreSnapshot(SSyncNode* pSyncNode, const SyncPreSnapshot* pMsg, const char* s) { void syncLogRecvSyncPreSnapshot(SSyncNode* pSyncNode, const SyncPreSnapshot* pMsg, const char* s) {
char host[64]; char host[64];
uint16_t port; uint16_t port;
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
char logBuf[256]; sNTrace(pSyncNode, "recv sync-pre-snapshot from %s:%d {term:%" PRIu64 "}, %s", host, port, pMsg->term, s);
snprintf(logBuf, sizeof(logBuf), "recv sync-pre-snapshot from %s:%d {term:%" PRIu64 "}, %s", host, port, pMsg->term,
s);
syncNodeEventLog(pSyncNode, logBuf);
} }
void syncLogSendSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshotReply* pMsg, const char* s) { void syncLogSendSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshotReply* pMsg, const char* s) {
char host[64]; char host[64];
uint16_t port; uint16_t port;
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port); syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
char logBuf[256]; sNTrace(pSyncNode, "send sync-pre-snapshot-reply to %s:%d {term:%" PRIu64 ", snap-start:%" PRId64 "}, %s", host, port,
snprintf(logBuf, sizeof(logBuf), pMsg->term, pMsg->snapStart, s);
"send sync-pre-snapshot-reply to %s:%d {term:%" PRIu64 ", snap-start:%" PRId64 "}, %s", host, port,
pMsg->term, pMsg->snapStart, s);
syncNodeEventLog(pSyncNode, logBuf);
} }
void syncLogRecvSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshotReply* pMsg, const char* s) { void syncLogRecvSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshotReply* pMsg, const char* s) {
char host[64]; char host[64];
uint16_t port; uint16_t port;
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
char logBuf[256]; sNTrace(pSyncNode, "recv sync-pre-snapshot-reply from %s:%d {term:%" PRIu64 ", snap-start:%" PRId64 "}, %s", host,
snprintf(logBuf, sizeof(logBuf), port, pMsg->term, pMsg->snapStart, s);
"recv sync-pre-snapshot-reply from %s:%d {term:%" PRIu64 ", snap-start:%" PRId64 "}, %s", host, port,
pMsg->term, pMsg->snapStart, s);
syncNodeEventLog(pSyncNode, logBuf);
} }
void syncLogSendSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s) {} void syncLogSendSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s) {}
......
...@@ -85,20 +85,20 @@ cJSON* syncRpcMsg2Json(SRpcMsg* pRpcMsg) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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);
} }
...@@ -1138,7 +1138,7 @@ void syncClientRequestBatchLog(const SyncClientRequestBatch* pMsg) { ...@@ -1138,7 +1138,7 @@ void syncClientRequestBatchLog(const SyncClientRequestBatch* pMsg) {
void syncClientRequestBatchLog2(char* s, const SyncClientRequestBatch* pMsg) { void syncClientRequestBatchLog2(char* s, const SyncClientRequestBatch* pMsg) {
if (gRaftDetailLog) { if (gRaftDetailLog) {
char* serialized = syncClientRequestBatch2Str(pMsg); char* serialized = syncClientRequestBatch2Str(pMsg);
sTraceLong("syncClientRequestBatchLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); sLTrace("syncClientRequestBatchLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
taosMemoryFree(serialized); taosMemoryFree(serialized);
} }
} }
...@@ -1564,10 +1564,10 @@ cJSON* syncAppendEntries2Json(const SyncAppendEntries* pMsg) { ...@@ -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) { ...@@ -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);
} }
...@@ -1847,7 +1847,7 @@ void syncAppendEntriesBatchLog(const SyncAppendEntriesBatch* pMsg) { ...@@ -1847,7 +1847,7 @@ void syncAppendEntriesBatchLog(const SyncAppendEntriesBatch* pMsg) {
void syncAppendEntriesBatchLog2(char* s, const SyncAppendEntriesBatch* pMsg) { void syncAppendEntriesBatchLog2(char* s, const SyncAppendEntriesBatch* pMsg) {
if (gRaftDetailLog) { if (gRaftDetailLog) {
char* serialized = syncAppendEntriesBatch2Str(pMsg); char* serialized = syncAppendEntriesBatch2Str(pMsg);
sTraceLong("syncAppendEntriesBatchLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); sLTrace("syncAppendEntriesBatchLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
taosMemoryFree(serialized); taosMemoryFree(serialized);
} }
} }
...@@ -2716,10 +2716,10 @@ cJSON* syncApplyMsg2Json(const SyncApplyMsg* pMsg) { ...@@ -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) { ...@@ -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);
} }
...@@ -3238,165 +3238,6 @@ char* syncLeaderTransfer2Str(const SyncLeaderTransfer* pMsg) { ...@@ -3238,165 +3238,6 @@ char* syncLeaderTransfer2Str(const SyncLeaderTransfer* pMsg) {
return serialized; return serialized;
} }
// for debug ----------------------
void syncLeaderTransferPrint(const SyncLeaderTransfer* pMsg) {
char* serialized = syncLeaderTransfer2Str(pMsg);
printf("syncLeaderTransferPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
fflush(NULL);
taosMemoryFree(serialized);
}
void syncLeaderTransferPrint2(char* s, const SyncLeaderTransfer* pMsg) {
char* serialized = syncLeaderTransfer2Str(pMsg);
printf("syncLeaderTransferPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
fflush(NULL);
taosMemoryFree(serialized);
}
void syncLeaderTransferLog(const SyncLeaderTransfer* pMsg) {
char* serialized = syncLeaderTransfer2Str(pMsg);
sTrace("syncLeaderTransferLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
taosMemoryFree(serialized);
}
void syncLeaderTransferLog2(char* s, const SyncLeaderTransfer* pMsg) {
if (gRaftDetailLog) {
char* serialized = syncLeaderTransfer2Str(pMsg);
sTrace("syncLeaderTransferLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
taosMemoryFree(serialized);
}
}
// ---------------------------------------------
SyncReconfigFinish* syncReconfigFinishBuild(int32_t vgId) {
uint32_t bytes = sizeof(SyncReconfigFinish);
SyncReconfigFinish* pMsg = taosMemoryMalloc(bytes);
memset(pMsg, 0, bytes);
pMsg->bytes = bytes;
pMsg->vgId = vgId;
pMsg->msgType = TDMT_SYNC_CONFIG_CHANGE_FINISH;
return pMsg;
}
void syncReconfigFinishDestroy(SyncReconfigFinish* pMsg) {
if (pMsg != NULL) {
taosMemoryFree(pMsg);
}
}
void syncReconfigFinishSerialize(const SyncReconfigFinish* pMsg, char* buf, uint32_t bufLen) {
ASSERT(pMsg->bytes <= bufLen);
memcpy(buf, pMsg, pMsg->bytes);
}
void syncReconfigFinishDeserialize(const char* buf, uint32_t len, SyncReconfigFinish* pMsg) {
memcpy(pMsg, buf, len);
ASSERT(len == pMsg->bytes);
}
char* syncReconfigFinishSerialize2(const SyncReconfigFinish* pMsg, uint32_t* len) {
char* buf = taosMemoryMalloc(pMsg->bytes);
ASSERT(buf != NULL);
syncReconfigFinishSerialize(pMsg, buf, pMsg->bytes);
if (len != NULL) {
*len = pMsg->bytes;
}
return buf;
}
SyncReconfigFinish* syncReconfigFinishDeserialize2(const char* buf, uint32_t len) {
uint32_t bytes = *((uint32_t*)buf);
SyncReconfigFinish* pMsg = taosMemoryMalloc(bytes);
ASSERT(pMsg != NULL);
syncReconfigFinishDeserialize(buf, len, pMsg);
ASSERT(len == pMsg->bytes);
return pMsg;
}
void syncReconfigFinish2RpcMsg(const SyncReconfigFinish* pMsg, SRpcMsg* pRpcMsg) {
memset(pRpcMsg, 0, sizeof(*pRpcMsg));
pRpcMsg->msgType = pMsg->msgType;
pRpcMsg->contLen = pMsg->bytes;
pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
syncReconfigFinishSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
}
void syncReconfigFinishFromRpcMsg(const SRpcMsg* pRpcMsg, SyncReconfigFinish* pMsg) {
syncReconfigFinishDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
}
SyncReconfigFinish* syncReconfigFinishFromRpcMsg2(const SRpcMsg* pRpcMsg) {
SyncReconfigFinish* pMsg = syncReconfigFinishDeserialize2(pRpcMsg->pCont, (uint32_t)(pRpcMsg->contLen));
ASSERT(pMsg != NULL);
return pMsg;
}
cJSON* syncReconfigFinish2Json(const SyncReconfigFinish* pMsg) {
char u64buf[128];
cJSON* pRoot = cJSON_CreateObject();
if (pMsg != NULL) {
cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
cJSON* pOldCfg = syncCfg2Json((SSyncCfg*)(&(pMsg->oldCfg)));
cJSON* pNewCfg = syncCfg2Json((SSyncCfg*)(&(pMsg->newCfg)));
cJSON_AddItemToObject(pRoot, "oldCfg", pOldCfg);
cJSON_AddItemToObject(pRoot, "newCfg", pNewCfg);
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->newCfgIndex);
cJSON_AddStringToObject(pRoot, "newCfgIndex", u64buf);
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->newCfgTerm);
cJSON_AddStringToObject(pRoot, "newCfgTerm", u64buf);
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->newCfgSeqNum);
cJSON_AddStringToObject(pRoot, "newCfgSeqNum", u64buf);
}
cJSON* pJson = cJSON_CreateObject();
cJSON_AddItemToObject(pJson, "SyncReconfigFinish", pRoot);
return pJson;
}
char* syncReconfigFinish2Str(const SyncReconfigFinish* pMsg) {
cJSON* pJson = syncReconfigFinish2Json(pMsg);
char* serialized = cJSON_Print(pJson);
cJSON_Delete(pJson);
return serialized;
}
// for debug ----------------------
void syncReconfigFinishPrint(const SyncReconfigFinish* pMsg) {
char* serialized = syncReconfigFinish2Str(pMsg);
printf("syncReconfigFinishPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
fflush(NULL);
taosMemoryFree(serialized);
}
void syncReconfigFinishPrint2(char* s, const SyncReconfigFinish* pMsg) {
char* serialized = syncReconfigFinish2Str(pMsg);
printf("syncReconfigFinishPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
fflush(NULL);
taosMemoryFree(serialized);
}
void syncReconfigFinishLog(const SyncReconfigFinish* pMsg) {
char* serialized = syncReconfigFinish2Str(pMsg);
sTrace("syncReconfigFinishLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
taosMemoryFree(serialized);
}
void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg) {
if (gRaftDetailLog) {
char* serialized = syncReconfigFinish2Str(pMsg);
sTrace("syncReconfigFinishLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
taosMemoryFree(serialized);
}
}
// ---------------------------------------------
const char* syncLocalCmdGetStr(int32_t cmd) { const char* syncLocalCmdGetStr(int32_t cmd) {
if (cmd == SYNC_LOCAL_CMD_STEP_DOWN) { if (cmd == SYNC_LOCAL_CMD_STEP_DOWN) {
return "step-down"; return "step-down";
......
...@@ -249,33 +249,6 @@ char *syncCfg2Str(SSyncCfg *pSyncCfg) { ...@@ -249,33 +249,6 @@ char *syncCfg2Str(SSyncCfg *pSyncCfg) {
return serialized; return serialized;
} }
char *syncCfg2SimpleStr(SSyncCfg *pSyncCfg) {
if (pSyncCfg != NULL) {
int32_t len = 512;
char *s = taosMemoryMalloc(len);
memset(s, 0, len);
snprintf(s, len, "{r-num:%d, my:%d, ", pSyncCfg->replicaNum, pSyncCfg->myIndex);
char *p = s + strlen(s);
for (int i = 0; i < pSyncCfg->replicaNum; ++i) {
/*
if (p + 128 + 32 > s + len) {
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) {
memset(pSyncCfg, 0, sizeof(SSyncCfg)); memset(pSyncCfg, 0, sizeof(SSyncCfg));
// cJSON *pJson = cJSON_GetObjectItem(pRoot, "SSyncCfg"); // cJSON *pJson = cJSON_GetObjectItem(pRoot, "SSyncCfg");
...@@ -442,88 +415,3 @@ int32_t raftCfgFromStr(const char *s, SRaftCfg *pRaftCfg) { ...@@ -442,88 +415,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);
}
...@@ -143,11 +143,11 @@ cJSON* syncEntry2Json(const SSyncRaftEntry* pEntry) { ...@@ -143,11 +143,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);
} }
...@@ -225,9 +225,9 @@ SRaftEntryHashCache* raftCacheCreate(SSyncNode* pSyncNode, int32_t maxCount) { ...@@ -225,9 +225,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);
} }
...@@ -237,25 +237,20 @@ void raftCacheDestroy(SRaftEntryHashCache* pCache) { ...@@ -237,25 +237,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]; TMSG_INFO(pEntry->msgType), pEntry->msgType, TMSG_INFO(pEntry->originalRpcType), pEntry->originalRpcType,
snprintf(eventLog, sizeof(eventLog), "raft cache add, type:%s,%d, type2:%s,%d, index:%" PRId64 ", bytes:%d", pEntry->index, pEntry->bytes);
TMSG_INFO(pEntry->msgType), pEntry->msgType, TMSG_INFO(pEntry->originalRpcType), pEntry->originalRpcType, taosThreadMutexUnlock(&pCache->mutex);
pEntry->index, pEntry->bytes);
syncNodeEventLog(pCache->pSyncNode, eventLog);
} while (0);
taosThreadMutexUnlock(&(pCache->mutex));
return 1; return 1;
} }
...@@ -268,26 +263,21 @@ int32_t raftCacheGetEntry(struct SRaftEntryHashCache* pCache, SyncIndex index, S ...@@ -268,26 +263,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]; TMSG_INFO((*ppEntry)->msgType), (*ppEntry)->msgType, TMSG_INFO((*ppEntry)->originalRpcType),
snprintf(eventLog, sizeof(eventLog), "raft cache get, type:%s,%d, type2:%s,%d, index:%" PRId64, (*ppEntry)->originalRpcType, (*ppEntry)->index);
TMSG_INFO((*ppEntry)->msgType), (*ppEntry)->msgType, TMSG_INFO((*ppEntry)->originalRpcType), taosThreadMutexUnlock(&pCache->mutex);
(*ppEntry)->originalRpcType, (*ppEntry)->index);
syncNodeEventLog(pCache->pSyncNode, eventLog);
} 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;
} }
...@@ -301,34 +291,29 @@ int32_t raftCacheGetEntryP(struct SRaftEntryHashCache* pCache, SyncIndex index, ...@@ -301,34 +291,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]; TMSG_INFO((*ppEntry)->msgType), (*ppEntry)->msgType, TMSG_INFO((*ppEntry)->originalRpcType),
snprintf(eventLog, sizeof(eventLog), "raft cache get, type:%s,%d, type2:%s,%d, index:%" PRId64, (*ppEntry)->originalRpcType, (*ppEntry)->index);
TMSG_INFO((*ppEntry)->msgType), (*ppEntry)->msgType, TMSG_INFO((*ppEntry)->originalRpcType), taosThreadMutexUnlock(&pCache->mutex);
(*ppEntry)->originalRpcType, (*ppEntry)->index);
syncNodeEventLog(pCache->pSyncNode, eventLog);
} 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;
} }
...@@ -338,38 +323,34 @@ int32_t raftCacheGetAndDel(struct SRaftEntryHashCache* pCache, SyncIndex index, ...@@ -338,38 +323,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]; TMSG_INFO((*ppEntry)->msgType), (*ppEntry)->msgType, TMSG_INFO((*ppEntry)->originalRpcType),
snprintf(eventLog, sizeof(eventLog), "raft cache get-and-del, type:%s,%d, type2:%s,%d, index:%" PRId64, (*ppEntry)->originalRpcType, (*ppEntry)->index);
TMSG_INFO((*ppEntry)->msgType), (*ppEntry)->msgType, TMSG_INFO((*ppEntry)->originalRpcType),
(*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;
} }
...@@ -379,7 +360,7 @@ cJSON* raftCache2Json(SRaftEntryHashCache* pCache) { ...@@ -379,7 +360,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);
...@@ -401,7 +382,7 @@ cJSON* raftCache2Json(SRaftEntryHashCache* pCache) { ...@@ -401,7 +382,7 @@ cJSON* raftCache2Json(SRaftEntryHashCache* pCache) {
} }
} }
taosThreadMutexUnlock(&(pCache->mutex)); taosThreadMutexUnlock(&pCache->mutex);
} }
cJSON* pJson = cJSON_CreateObject(); cJSON* pJson = cJSON_CreateObject();
...@@ -439,7 +420,7 @@ void raftCacheLog(SRaftEntryHashCache* pCache) { ...@@ -439,7 +420,7 @@ void raftCacheLog(SRaftEntryHashCache* pCache) {
void raftCacheLog2(char* s, SRaftEntryHashCache* pCache) { void raftCacheLog2(char* s, SRaftEntryHashCache* pCache) {
if (gRaftDetailLog) { if (gRaftDetailLog) {
char* serialized = raftCache2Str(pCache); char* serialized = raftCache2Str(pCache);
sTraceLong("raftCacheLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); sLTrace("raftCacheLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
taosMemoryFree(serialized); taosMemoryFree(serialized);
} }
} }
...@@ -482,13 +463,13 @@ SRaftEntryCache* raftEntryCacheCreate(SSyncNode* pSyncNode, int32_t maxCount) { ...@@ -482,13 +463,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);
} }
...@@ -498,10 +479,10 @@ void raftEntryCacheDestroy(SRaftEntryCache* pCache) { ...@@ -498,10 +479,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;
} }
...@@ -512,15 +493,10 @@ int32_t raftEntryCachePutEntry(struct SRaftEntryCache* pCache, SSyncRaftEntry* p ...@@ -512,15 +493,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]; TMSG_INFO(pEntry->msgType), pEntry->msgType, TMSG_INFO(pEntry->originalRpcType), pEntry->originalRpcType,
snprintf(eventLog, sizeof(eventLog), "raft cache add, type:%s,%d, type2:%s,%d, index:%" PRId64 ", bytes:%d", pEntry->index, pEntry->bytes);
TMSG_INFO(pEntry->msgType), pEntry->msgType, TMSG_INFO(pEntry->originalRpcType), pEntry->originalRpcType, taosThreadMutexUnlock(&pCache->mutex);
pEntry->index, pEntry->bytes);
syncNodeEventLog(pCache->pSyncNode, eventLog);
} while (0);
taosThreadMutexUnlock(&(pCache->mutex));
return 1; return 1;
} }
...@@ -545,7 +521,7 @@ int32_t raftEntryCacheGetEntry(struct SRaftEntryCache* pCache, SyncIndex index, ...@@ -545,7 +521,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;
...@@ -569,7 +545,7 @@ int32_t raftEntryCacheGetEntryP(struct SRaftEntryCache* pCache, SyncIndex index, ...@@ -569,7 +545,7 @@ int32_t raftEntryCacheGetEntryP(struct SRaftEntryCache* pCache, SyncIndex index,
} }
taosArrayDestroy(entryPArray); taosArrayDestroy(entryPArray);
taosThreadMutexUnlock(&(pCache->mutex)); taosThreadMutexUnlock(&pCache->mutex);
return code; return code;
} }
...@@ -578,7 +554,7 @@ int32_t raftEntryCacheGetEntryP(struct SRaftEntryCache* pCache, SyncIndex index, ...@@ -578,7 +554,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) {
...@@ -633,7 +609,7 @@ int32_t raftEntryCacheClear(struct SRaftEntryCache* pCache, int32_t count) { ...@@ -633,7 +609,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;
} }
...@@ -642,7 +618,7 @@ cJSON* raftEntryCache2Json(SRaftEntryCache* pCache) { ...@@ -642,7 +618,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);
...@@ -660,7 +636,7 @@ cJSON* raftEntryCache2Json(SRaftEntryCache* pCache) { ...@@ -660,7 +636,7 @@ cJSON* raftEntryCache2Json(SRaftEntryCache* pCache) {
} }
tSkipListDestroyIter(pIter); tSkipListDestroyIter(pIter);
taosThreadMutexUnlock(&(pCache->mutex)); taosThreadMutexUnlock(&pCache->mutex);
} }
cJSON* pJson = cJSON_CreateObject(); cJSON* pJson = cJSON_CreateObject();
...@@ -698,7 +674,7 @@ void raftEntryCacheLog(SRaftEntryCache* pObj) { ...@@ -698,7 +674,7 @@ void raftEntryCacheLog(SRaftEntryCache* pObj) {
void raftEntryCacheLog2(char* s, SRaftEntryCache* pObj) { void raftEntryCacheLog2(char* s, SRaftEntryCache* pObj) {
if (gRaftDetailLog) { if (gRaftDetailLog) {
char* serialized = raftEntryCache2Str(pObj); char* serialized = raftEntryCache2Str(pObj);
sTraceLong("raftEntryCacheLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); sLTrace("raftEntryCacheLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
taosMemoryFree(serialized); taosMemoryFree(serialized);
} }
} }
...@@ -117,12 +117,9 @@ static int32_t raftLogRestoreFromSnapshot(struct SSyncLogStore* pLogStore, SyncI ...@@ -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 ...@@ -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]; TMSG_INFO(pEntry->msgType), TMSG_INFO(pEntry->originalRpcType));
snprintf(eventLog, sizeof(eventLog), "write index:%" PRId64 ", type:%s, origin type:%s", pEntry->index,
TMSG_INFO(pEntry->msgType), TMSG_INFO(pEntry->originalRpcType));
syncNodeEventLog(pData->pSyncNode, eventLog);
} while (0);
return 0; return 0;
} }
...@@ -263,20 +251,13 @@ static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, ...@@ -263,20 +251,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 { if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) {
char logBuf[128]; sNTrace(pData->pSyncNode, "wal read not exist, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", index,
if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) { err, err, errStr, sysErr, sysErrStr);
snprintf(logBuf, sizeof(logBuf), } else {
"wal read not exist, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", index, err, err, sNTrace(pData->pSyncNode, "wal read error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", index,
errStr, sysErr, sysErrStr); err, err, errStr, sysErr, sysErrStr);
syncNodeEventLog(pData->pSyncNode, logBuf); }
} else {
snprintf(logBuf, sizeof(logBuf), "wal read error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s",
index, err, err, errStr, sysErr, sysErrStr);
syncNodeErrorLog(pData->pSyncNode, logBuf);
}
} while (0);
/* /*
int32_t saveErr = terrno; int32_t saveErr = terrno;
...@@ -333,12 +314,7 @@ static int32_t raftLogTruncate(struct SSyncLogStore* pLogStore, SyncIndex fromIn ...@@ -333,12 +314,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;
} }
...@@ -523,7 +499,7 @@ void logStorePrint2(char* s, SSyncLogStore* pLogStore) { ...@@ -523,7 +499,7 @@ void logStorePrint2(char* s, SSyncLogStore* pLogStore) {
void logStoreLog(SSyncLogStore* pLogStore) { void logStoreLog(SSyncLogStore* pLogStore) {
if (gRaftDetailLog) { if (gRaftDetailLog) {
char* serialized = logStore2Str(pLogStore); char* serialized = logStore2Str(pLogStore);
sTraceLong("logStoreLog | len:%d | %s", (int32_t)strlen(serialized), serialized); sLTrace("logStoreLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
taosMemoryFree(serialized); taosMemoryFree(serialized);
} }
} }
...@@ -531,7 +507,7 @@ void logStoreLog(SSyncLogStore* pLogStore) { ...@@ -531,7 +507,7 @@ void logStoreLog(SSyncLogStore* pLogStore) {
void logStoreLog2(char* s, SSyncLogStore* pLogStore) { void logStoreLog2(char* s, SSyncLogStore* pLogStore) {
if (gRaftDetailLog) { if (gRaftDetailLog) {
char* serialized = logStore2Str(pLogStore); char* serialized = logStore2Str(pLogStore);
sTraceLong("logStoreLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); sLTrace("logStoreLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
taosMemoryFree(serialized); taosMemoryFree(serialized);
} }
} }
......
...@@ -56,14 +56,10 @@ int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId) { ...@@ -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) { ...@@ -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) { ...@@ -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 ...@@ -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 ...@@ -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]; "logok:0, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64
snprintf(logBuf, sizeof(logBuf), ", recv-term:%" PRIu64 "}",
"logok:0, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64 myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term);
", recv-term:%" PRIu64 "}",
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]; "logok:0, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64
snprintf(logBuf, sizeof(logBuf), ", recv-term:%" PRIu64 "}",
"logok:0, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64 myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term);
", recv-term:%" PRIu64 "}",
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]; "logok:1, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64
snprintf(logBuf, sizeof(logBuf), ", recv-term:%" PRIu64 "}",
"logok:1, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64 myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term);
", recv-term:%" PRIu64 "}",
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]; "logok:1, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64
snprintf(logBuf, sizeof(logBuf), ", recv-term:%" PRIu64 "}",
"logok:1, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64 myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term);
", recv-term:%" PRIu64 "}",
myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term);
syncNodeEventLog(pSyncNode, logBuf);
} while (0);
return true; return true;
} }
do { sNTrace(pSyncNode,
char logBuf[128]; "logok:0, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64
snprintf(logBuf, sizeof(logBuf), ", recv-term:%" PRIu64 "}",
"logok:0, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64 myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term);
", recv-term:%" PRIu64 "}",
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) { ...@@ -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) { ...@@ -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) { ...@@ -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 ...@@ -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]; TMSG_INFO(pStub->rpcMsg.msgType), index, pStub->rpcMsg.info.handle);
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);
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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -212,17 +202,11 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender) {
syncSnapshotSendDestroy(pMsg); syncSnapshotSendDestroy(pMsg);
// event log // event log
do { if (pSender->seq == SYNC_SNAPSHOT_SEQ_END) {
char *eventLog = NULL; sSTrace(pSender, "snapshot sender finish");
if (pSender->seq == SYNC_SNAPSHOT_SEQ_END) { } else {
eventLog = snapshotSender2SimpleStr(pSender, "snapshot sender finish"); sSTrace(pSender, "snapshot sender sending");
} else { }
eventLog = snapshotSender2SimpleStr(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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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 ...@@ -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) { ...@@ -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) { ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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) { ...@@ -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) { ...@@ -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 ...@@ -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 ...@@ -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) { ...@@ -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) ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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,59 +13,38 @@ ...@@ -13,59 +13,38 @@
* 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 "syncRaftCfg.h"
#include "syncRaftStore.h"
#include "syncSnapshot.h"
#include "syncEnv.h" extern void addEpIntoEpSet(SEpSet* pEpSet, const char* fqdn, uint16_t port);
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);
terrno = TSDB_CODE_TSC_INVALID_FQDN; terrno = TSDB_CODE_TSC_INVALID_FQDN;
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 +52,22 @@ void syncUtilraftId2EpSet(const SRaftId* raftId, SEpSet* pEpSet) { ...@@ -73,28 +52,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 +79,9 @@ bool syncUtilSameId(const SRaftId* pId1, const SRaftId* pId2) { ...@@ -106,31 +79,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 +127,7 @@ char* syncUtilRaftId2Str(const SRaftId* p) { ...@@ -176,7 +127,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 +135,7 @@ bool syncUtilCanPrint(char c) { ...@@ -184,7 +135,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 +150,7 @@ char* syncUtilprintBin(char* ptr, uint32_t len) { ...@@ -199,7 +150,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 +164,6 @@ char* syncUtilprintBin2(char* ptr, uint32_t len) { ...@@ -213,16 +164,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,18 +178,8 @@ void syncUtilMsgNtoH(void* msg) { ...@@ -237,18 +178,8 @@ 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_LEADER_TRANSFER) {
msgType != TDMT_SYNC_LEADER_TRANSFER) {
return true; return true;
} }
...@@ -256,8 +187,7 @@ bool syncUtilUserPreCommit(tmsg_t msgType) { ...@@ -256,8 +187,7 @@ bool syncUtilUserPreCommit(tmsg_t msgType) {
} }
bool syncUtilUserCommit(tmsg_t msgType) { bool syncUtilUserCommit(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_LEADER_TRANSFER) {
msgType != TDMT_SYNC_LEADER_TRANSFER) {
return true; return true;
} }
...@@ -265,32 +195,185 @@ bool syncUtilUserCommit(tmsg_t msgType) { ...@@ -265,32 +195,185 @@ bool syncUtilUserCommit(tmsg_t msgType) {
} }
bool syncUtilUserRollback(tmsg_t msgType) { bool syncUtilUserRollback(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_LEADER_TRANSFER) {
msgType != TDMT_SYNC_LEADER_TRANSFER) {
return true; return true;
} }
return false; return false;
} }
void syncUtilJson2Line(char* jsonStr) { void syncCfg2SimpleStr(const SSyncCfg* pCfg, char* buf, int32_t bufLen) {
int p, q, len; int32_t len = snprintf(buf, bufLen, "{r-num:%d, my:%d, ", pCfg->replicaNum, pCfg->myIndex);
p = 0;
q = 1; for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
len = strlen(jsonStr); if (i < pCfg->replicaNum - 1) {
while (1) { len += snprintf(buf + len, bufLen - len, "%s:%d, ", pCfg->nodeInfo[i].nodeFqdn, pCfg->nodeInfo[i].nodePort);
if (jsonStr[q] == '\0') { } else {
jsonStr[p + 1] = '\0'; len += snprintf(buf + len, bufLen - len, "%s:%d}", pCfg->nodeInfo[i].nodeFqdn, pCfg->nodeInfo[i].nodePort);
break;
} }
}
}
static void syncPeerState2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
int32_t len = 1;
if (jsonStr[q] == '\n' || jsonStr[q] == ' ' || jsonStr[q] == '\t') { for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
q++; SPeerState* pState = syncNodeGetPeerState(pSyncNode, &(pSyncNode->replicasId[i]));
continue; if (pState == NULL) break;
if (i < pSyncNode->replicaNum - 1) {
len += snprintf(buf + len, bufLen - len, "%d:%" PRId64 " %" PRId64 ", ", i, pState->lastSendIndex,
pState->lastSendTime);
} else { } else {
jsonStr[p + 1] = jsonStr[q]; len += snprintf(buf + len, bufLen - len, "%d:%" PRId64 " %" PRId64 "}", i, pState->lastSendIndex,
p++; pState->lastSendTime);
q++;
} }
} }
} }
void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNode* pNode, const char* format, ...) {
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 peerStr[1024] = "{";
syncPeerState2Str(pNode, peerStr, sizeof(peerStr));
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, peerStr, cfgStr);
}
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 peerStr[1024] = "{";
syncPeerState2Str(pNode, peerStr, sizeof(peerStr));
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, peerStr, cfgStr);
}
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 peerStr[1024] = "{";
syncPeerState2Str(pNode, peerStr, sizeof(peerStr));
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, peerStr, cfgStr);
}
...@@ -13,10 +13,10 @@ ...@@ -13,10 +13,10 @@
* 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 "syncVoteMgr.h" #include "syncVoteMgr.h"
#include "syncUtil.h" #include "syncUtil.h"
// SVotesGranted -----------------------------
static void voteGrantedClearVotes(SVotesGranted *pVotesGranted) { static void voteGrantedClearVotes(SVotesGranted *pVotesGranted) {
memset(pVotesGranted->isGranted, 0, sizeof(pVotesGranted->isGranted)); memset(pVotesGranted->isGranted, 0, sizeof(pVotesGranted->isGranted));
pVotesGranted->votes = 0; pVotesGranted->votes = 0;
...@@ -68,7 +68,7 @@ void voteGrantedVote(SVotesGranted *pVotesGranted, SyncRequestVoteReply *pMsg) { ...@@ -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;
} }
...@@ -140,34 +140,6 @@ char *voteGranted2Str(SVotesGranted *pVotesGranted) { ...@@ -140,34 +140,6 @@ char *voteGranted2Str(SVotesGranted *pVotesGranted) {
return serialized; return serialized;
} }
// for debug -------------------
void voteGrantedPrint(SVotesGranted *pObj) {
char *serialized = voteGranted2Str(pObj);
printf("voteGrantedPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
fflush(NULL);
taosMemoryFree(serialized);
}
void voteGrantedPrint2(char *s, SVotesGranted *pObj) {
char *serialized = voteGranted2Str(pObj);
printf("voteGrantedPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
fflush(NULL);
taosMemoryFree(serialized);
}
void voteGrantedLog(SVotesGranted *pObj) {
char *serialized = voteGranted2Str(pObj);
sTrace("voteGrantedLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
taosMemoryFree(serialized);
}
void voteGrantedLog2(char *s, SVotesGranted *pObj) {
char *serialized = voteGranted2Str(pObj);
sTrace("voteGrantedLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
taosMemoryFree(serialized);
}
// SVotesRespond -----------------------------
SVotesRespond *votesRespondCreate(SSyncNode *pSyncNode) { SVotesRespond *votesRespondCreate(SSyncNode *pSyncNode) {
SVotesRespond *pVotesRespond = taosMemoryMalloc(sizeof(SVotesRespond)); SVotesRespond *pVotesRespond = taosMemoryMalloc(sizeof(SVotesRespond));
ASSERT(pVotesRespond != NULL); ASSERT(pVotesRespond != NULL);
...@@ -207,7 +179,7 @@ bool votesResponded(SVotesRespond *pVotesRespond, const SRaftId *pRaftId) { ...@@ -207,7 +179,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;
} }
...@@ -272,30 +244,3 @@ char *votesRespond2Str(SVotesRespond *pVotesRespond) { ...@@ -272,30 +244,3 @@ char *votesRespond2Str(SVotesRespond *pVotesRespond) {
cJSON_Delete(pJson); cJSON_Delete(pJson);
return serialized; return serialized;
} }
// for debug -------------------
void votesRespondPrint(SVotesRespond *pObj) {
char *serialized = votesRespond2Str(pObj);
printf("votesRespondPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
fflush(NULL);
taosMemoryFree(serialized);
}
void votesRespondPrint2(char *s, SVotesRespond *pObj) {
char *serialized = votesRespond2Str(pObj);
printf("votesRespondPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
fflush(NULL);
taosMemoryFree(serialized);
}
void votesRespondLog(SVotesRespond *pObj) {
char *serialized = votesRespond2Str(pObj);
sTrace("votesRespondLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
taosMemoryFree(serialized);
}
void votesRespondLog2(char *s, SVotesRespond *pObj) {
char *serialized = votesRespond2Str(pObj);
sTrace("votesRespondLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
taosMemoryFree(serialized);
}
...@@ -54,7 +54,6 @@ add_executable(syncRaftLogTest "") ...@@ -54,7 +54,6 @@ add_executable(syncRaftLogTest "")
add_executable(syncRaftLogTest2 "") add_executable(syncRaftLogTest2 "")
add_executable(syncRaftLogTest3 "") add_executable(syncRaftLogTest3 "")
add_executable(syncLeaderTransferTest "") add_executable(syncLeaderTransferTest "")
add_executable(syncReconfigFinishTest "")
add_executable(syncRestoreFromSnapshot "") add_executable(syncRestoreFromSnapshot "")
add_executable(syncRaftCfgIndexTest "") add_executable(syncRaftCfgIndexTest "")
add_executable(syncHeartbeatTest "") add_executable(syncHeartbeatTest "")
......
...@@ -107,7 +107,7 @@ int main(int argc, char** argv) { ...@@ -107,7 +107,7 @@ int main(int argc, char** argv) {
SSyncNode* pSyncNode = createSyncNode(replicaNum, myIndex, gVgId, pWal, (char*)gDir); SSyncNode* pSyncNode = createSyncNode(replicaNum, myIndex, gVgId, pWal, (char*)gDir);
assert(pSyncNode != NULL); assert(pSyncNode != NULL);
syncNodeLog2((char*)"==syncElectTest==", pSyncNode); sNTrace(pSyncNode, "==syncElectTest==");
//--------------------------- //---------------------------
while (1) { while (1) {
......
...@@ -191,7 +191,7 @@ int main(int argc, char **argv) { ...@@ -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);
......
...@@ -87,7 +87,7 @@ int main(int argc, char** argv) { ...@@ -87,7 +87,7 @@ int main(int argc, char** argv) {
SSyncNode* pSyncNode = syncInitTest(); SSyncNode* pSyncNode = syncInitTest();
assert(pSyncNode != NULL); assert(pSyncNode != NULL);
syncNodeLog2((char*)"syncInitTest", pSyncNode); sNTrace(pSyncNode, "syncInitTest");
initRaftId(pSyncNode); initRaftId(pSyncNode);
......
...@@ -88,7 +88,7 @@ int main(int argc, char** argv) { ...@@ -88,7 +88,7 @@ int main(int argc, char** argv) {
SSyncNode* pSyncNode = syncInitTest(); SSyncNode* pSyncNode = syncInitTest();
assert(pSyncNode != NULL); assert(pSyncNode != NULL);
syncNodeLog2((char*)"syncInitTest", pSyncNode); sNTrace(pSyncNode, "syncInitTest");
initRaftId(pSyncNode); initRaftId(pSyncNode);
......
...@@ -87,7 +87,7 @@ int main(int argc, char** argv) { ...@@ -87,7 +87,7 @@ int main(int argc, char** argv) {
SSyncNode* pSyncNode = syncInitTest(); SSyncNode* pSyncNode = syncInitTest();
assert(pSyncNode != NULL); assert(pSyncNode != NULL);
syncNodeLog2((char*)"syncInitTest", pSyncNode); sNTrace(pSyncNode, "syncInitTest");
initRaftId(pSyncNode); initRaftId(pSyncNode);
syncNodeClose(pSyncNode); syncNodeClose(pSyncNode);
......
...@@ -27,6 +27,35 @@ SyncLeaderTransfer *createMsg() { ...@@ -27,6 +27,35 @@ SyncLeaderTransfer *createMsg() {
return pMsg; return pMsg;
} }
// for debug ----------------------
void syncLeaderTransferPrint(const SyncLeaderTransfer *pMsg) {
char *serialized = syncLeaderTransfer2Str(pMsg);
printf("syncLeaderTransferPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
fflush(NULL);
taosMemoryFree(serialized);
}
void syncLeaderTransferPrint2(char *s, const SyncLeaderTransfer *pMsg) {
char *serialized = syncLeaderTransfer2Str(pMsg);
printf("syncLeaderTransferPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
fflush(NULL);
taosMemoryFree(serialized);
}
void syncLeaderTransferLog(const SyncLeaderTransfer *pMsg) {
char *serialized = syncLeaderTransfer2Str(pMsg);
sTrace("syncLeaderTransferLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
taosMemoryFree(serialized);
}
void syncLeaderTransferLog2(char *s, const SyncLeaderTransfer *pMsg) {
if (gRaftDetailLog) {
char *serialized = syncLeaderTransfer2Str(pMsg);
sTrace("syncLeaderTransferLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
taosMemoryFree(serialized);
}
}
void test1() { void test1() {
SyncLeaderTransfer *pMsg = createMsg(); SyncLeaderTransfer *pMsg = createMsg();
syncLeaderTransferLog2((char *)"test1:", pMsg); syncLeaderTransferLog2((char *)"test1:", pMsg);
......
...@@ -86,7 +86,7 @@ int main(int argc, char** argv) { ...@@ -86,7 +86,7 @@ int main(int argc, char** argv) {
SSyncNode* pSyncNode = syncInitTest(); SSyncNode* pSyncNode = syncInitTest();
assert(pSyncNode != NULL); assert(pSyncNode != NULL);
syncNodeLog2((char*)"", pSyncNode); sNTrace(pSyncNode, "");
initRaftId(pSyncNode); initRaftId(pSyncNode);
......
...@@ -86,7 +86,7 @@ int main(int argc, char** argv) { ...@@ -86,7 +86,7 @@ int main(int argc, char** argv) {
SSyncNode* pSyncNode = syncInitTest(); SSyncNode* pSyncNode = syncInitTest();
assert(pSyncNode != NULL); assert(pSyncNode != NULL);
syncNodeLog2((char*)"----1", pSyncNode); sNTrace(pSyncNode, "----1");
initRaftId(pSyncNode); initRaftId(pSyncNode);
...@@ -95,7 +95,7 @@ int main(int argc, char** argv) { ...@@ -95,7 +95,7 @@ int main(int argc, char** argv) {
sTrace("syncNodeStartPingTimer ..."); sTrace("syncNodeStartPingTimer ...");
ret = syncNodeStartPingTimer(pSyncNode); ret = syncNodeStartPingTimer(pSyncNode);
assert(ret == 0); assert(ret == 0);
syncNodeLog2((char*)"----2", pSyncNode); sNTrace(pSyncNode, "----2");
sTrace("sleep ..."); sTrace("sleep ...");
taosMsleep(10000); taosMsleep(10000);
...@@ -103,7 +103,7 @@ int main(int argc, char** argv) { ...@@ -103,7 +103,7 @@ int main(int argc, char** argv) {
sTrace("syncNodeStopPingTimer ..."); sTrace("syncNodeStopPingTimer ...");
ret = syncNodeStopPingTimer(pSyncNode); ret = syncNodeStopPingTimer(pSyncNode);
assert(ret == 0); assert(ret == 0);
syncNodeLog2((char*)"----3", pSyncNode); sNTrace(pSyncNode, "----3");
sTrace("sleep ..."); sTrace("sleep ...");
taosMsleep(5000); taosMsleep(5000);
...@@ -111,7 +111,7 @@ int main(int argc, char** argv) { ...@@ -111,7 +111,7 @@ int main(int argc, char** argv) {
sTrace("syncNodeStartPingTimer ..."); sTrace("syncNodeStartPingTimer ...");
ret = syncNodeStartPingTimer(pSyncNode); ret = syncNodeStartPingTimer(pSyncNode);
assert(ret == 0); assert(ret == 0);
syncNodeLog2((char*)"----4", pSyncNode); sNTrace(pSyncNode, "----4");
sTrace("sleep ..."); sTrace("sleep ...");
taosMsleep(10000); taosMsleep(10000);
...@@ -119,7 +119,7 @@ int main(int argc, char** argv) { ...@@ -119,7 +119,7 @@ int main(int argc, char** argv) {
sTrace("syncNodeStopPingTimer ..."); sTrace("syncNodeStopPingTimer ...");
ret = syncNodeStopPingTimer(pSyncNode); ret = syncNodeStopPingTimer(pSyncNode);
assert(ret == 0); assert(ret == 0);
syncNodeLog2((char*)"----5", pSyncNode); sNTrace(pSyncNode, "----5");
while (1) { while (1) {
sTrace("while 1 sleep ..."); sTrace("while 1 sleep ...");
......
...@@ -86,7 +86,7 @@ int main(int argc, char** argv) { ...@@ -86,7 +86,7 @@ int main(int argc, char** argv) {
SSyncNode* pSyncNode = syncInitTest(); SSyncNode* pSyncNode = syncInitTest();
assert(pSyncNode != NULL); assert(pSyncNode != NULL);
syncNodeLog2((char*)"", pSyncNode); sNTrace(pSyncNode, "");
initRaftId(pSyncNode); initRaftId(pSyncNode);
......
...@@ -60,7 +60,6 @@ void test1() { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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();
......
#include <gtest/gtest.h>
#include <stdio.h>
#include "syncIO.h"
#include "syncInt.h"
#include "syncMessage.h"
#include "syncUtil.h"
void logTest() {
sTrace("--- sync log test: trace");
sDebug("--- sync log test: debug");
sInfo("--- sync log test: info");
sWarn("--- sync log test: warn");
sError("--- sync log test: error");
sFatal("--- sync log test: fatal");
}
SSyncCfg *createSyncOldCfg() {
SSyncCfg *pCfg = (SSyncCfg *)taosMemoryMalloc(sizeof(SSyncCfg));
memset(pCfg, 0, sizeof(SSyncCfg));
pCfg->replicaNum = 3;
pCfg->myIndex = 1;
for (int i = 0; i < pCfg->replicaNum; ++i) {
((pCfg->nodeInfo)[i]).nodePort = i * 100;
snprintf(((pCfg->nodeInfo)[i]).nodeFqdn, sizeof(((pCfg->nodeInfo)[i]).nodeFqdn), "100.200.300.%d", i);
}
return pCfg;
}
SSyncCfg *createSyncNewCfg() {
SSyncCfg *pCfg = (SSyncCfg *)taosMemoryMalloc(sizeof(SSyncCfg));
memset(pCfg, 0, sizeof(SSyncCfg));
pCfg->replicaNum = 3;
pCfg->myIndex = 1;
for (int i = 0; i < pCfg->replicaNum; ++i) {
((pCfg->nodeInfo)[i]).nodePort = i * 100;
snprintf(((pCfg->nodeInfo)[i]).nodeFqdn, sizeof(((pCfg->nodeInfo)[i]).nodeFqdn), "500.600.700.%d", i);
}
return pCfg;
}
SyncReconfigFinish *createMsg() {
SyncReconfigFinish *pMsg = syncReconfigFinishBuild(1234);
SSyncCfg *pOld = createSyncOldCfg();
SSyncCfg *pNew = createSyncNewCfg();
pMsg->oldCfg = *pOld;
pMsg->newCfg = *pNew;
pMsg->newCfgIndex = 11;
pMsg->newCfgTerm = 22;
pMsg->newCfgSeqNum = 33;
taosMemoryFree(pOld);
taosMemoryFree(pNew);
return pMsg;
}
void test1() {
SyncReconfigFinish *pMsg = createMsg();
syncReconfigFinishLog2((char *)"test1:", pMsg);
syncReconfigFinishDestroy(pMsg);
}
void test2() {
SyncReconfigFinish *pMsg = createMsg();
uint32_t len = pMsg->bytes;
char *serialized = (char *)taosMemoryMalloc(len);
syncReconfigFinishSerialize(pMsg, serialized, len);
SyncReconfigFinish *pMsg2 = syncReconfigFinishBuild(1000);
syncReconfigFinishDeserialize(serialized, len, pMsg2);
syncReconfigFinishLog2((char *)"test2: syncReconfigFinishSerialize -> syncReconfigFinishDeserialize ", pMsg2);
taosMemoryFree(serialized);
syncReconfigFinishDestroy(pMsg);
syncReconfigFinishDestroy(pMsg2);
}
void test3() {
SyncReconfigFinish *pMsg = createMsg();
uint32_t len;
char *serialized = syncReconfigFinishSerialize2(pMsg, &len);
SyncReconfigFinish *pMsg2 = syncReconfigFinishDeserialize2(serialized, len);
syncReconfigFinishLog2((char *)"test3: SyncReconfigFinishSerialize2 -> syncReconfigFinishDeserialize2 ", pMsg2);
taosMemoryFree(serialized);
syncReconfigFinishDestroy(pMsg);
syncReconfigFinishDestroy(pMsg2);
}
void test4() {
SyncReconfigFinish *pMsg = createMsg();
SRpcMsg rpcMsg;
syncReconfigFinish2RpcMsg(pMsg, &rpcMsg);
SyncReconfigFinish *pMsg2 = (SyncReconfigFinish *)taosMemoryMalloc(rpcMsg.contLen);
syncReconfigFinishFromRpcMsg(&rpcMsg, pMsg2);
syncReconfigFinishLog2((char *)"test4: syncReconfigFinish2RpcMsg -> syncReconfigFinishFromRpcMsg ", pMsg2);
rpcFreeCont(rpcMsg.pCont);
syncReconfigFinishDestroy(pMsg);
syncReconfigFinishDestroy(pMsg2);
}
void test5() {
SyncReconfigFinish *pMsg = createMsg();
SRpcMsg rpcMsg;
syncReconfigFinish2RpcMsg(pMsg, &rpcMsg);
SyncReconfigFinish *pMsg2 = syncReconfigFinishFromRpcMsg2(&rpcMsg);
syncReconfigFinishLog2((char *)"test5: syncReconfigFinish2RpcMsg -> syncReconfigFinishFromRpcMsg2 ", pMsg2);
rpcFreeCont(rpcMsg.pCont);
syncReconfigFinishDestroy(pMsg);
syncReconfigFinishDestroy(pMsg2);
}
int main() {
gRaftDetailLog = true;
tsAsyncLog = 0;
sDebugFlag = DEBUG_TRACE + DEBUG_SCREEN + DEBUG_FILE;
logTest();
test1();
test2();
test3();
test4();
test5();
return 0;
}
...@@ -192,7 +192,7 @@ int main(int argc, char **argv) { ...@@ -192,7 +192,7 @@ int main(int argc, char **argv) {
gSyncNode = syncInitTest(); gSyncNode = syncInitTest();
assert(gSyncNode != NULL); assert(gSyncNode != NULL);
syncNodeLog2((char *)"", gSyncNode); sNTrace(gSyncNode, "");
initRaftId(gSyncNode); initRaftId(gSyncNode);
......
...@@ -78,6 +78,28 @@ void test5() { ...@@ -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);
......
...@@ -167,7 +167,7 @@ int main(int argc, char **argv) { ...@@ -167,7 +167,7 @@ int main(int argc, char **argv) {
gSyncNode = syncInitTest(); gSyncNode = syncInitTest();
assert(gSyncNode != NULL); assert(gSyncNode != NULL);
syncNodeLog2((char *)"", gSyncNode); sNTrace(gSyncNode, "");
initRaftId(gSyncNode); initRaftId(gSyncNode);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册