Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
7ddec79a
T
TDengine
项目概览
taosdata
/
TDengine
接近 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
7ddec79a
编写于
11月 07, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
11月 07, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #17937 from taosdata/enh/TD-20043
refact: adjust sync log
上级
8c97a5c1
70d60a76
变更
41
展开全部
隐藏空白更改
内联
并排
Showing
41 changed file
with
659 addition
and
1968 deletion
+659
-1968
include/common/tmsgdef.h
include/common/tmsgdef.h
+2
-2
include/util/taoserror.h
include/util/taoserror.h
+1
-1
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+42
-21
source/libs/sync/inc/syncRaftCfg.h
source/libs/sync/inc/syncRaftCfg.h
+7
-24
source/libs/sync/inc/syncSnapshot.h
source/libs/sync/inc/syncSnapshot.h
+0
-2
source/libs/sync/inc/syncTools.h
source/libs/sync/inc/syncTools.h
+0
-41
source/libs/sync/inc/syncUtil.h
source/libs/sync/inc/syncUtil.h
+11
-24
source/libs/sync/inc/syncVoteMgr.h
source/libs/sync/inc/syncVoteMgr.h
+0
-20
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+3
-11
source/libs/sync/src/syncAppendEntriesReply.c
source/libs/sync/src/syncAppendEntriesReply.c
+2
-12
source/libs/sync/src/syncCommit.c
source/libs/sync/src/syncCommit.c
+11
-33
source/libs/sync/src/syncElection.c
source/libs/sync/src/syncElection.c
+5
-3
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+150
-774
source/libs/sync/src/syncMessage.c
source/libs/sync/src/syncMessage.c
+22
-181
source/libs/sync/src/syncRaftCfg.c
source/libs/sync/src/syncRaftCfg.c
+0
-112
source/libs/sync/src/syncRaftEntry.c
source/libs/sync/src/syncRaftEntry.c
+50
-74
source/libs/sync/src/syncRaftLog.c
source/libs/sync/src/syncRaftLog.c
+17
-41
source/libs/sync/src/syncReplication.c
source/libs/sync/src/syncReplication.c
+5
-14
source/libs/sync/src/syncRequestVote.c
source/libs/sync/src/syncRequestVote.c
+20
-44
source/libs/sync/src/syncRequestVoteReply.c
source/libs/sync/src/syncRequestVoteReply.c
+2
-4
source/libs/sync/src/syncRespMgr.c
source/libs/sync/src/syncRespMgr.c
+6
-18
source/libs/sync/src/syncSnapshot.c
source/libs/sync/src/syncSnapshot.c
+40
-167
source/libs/sync/src/syncTimeout.c
source/libs/sync/src/syncTimeout.c
+3
-13
source/libs/sync/src/syncUtil.c
source/libs/sync/src/syncUtil.c
+192
-109
source/libs/sync/src/syncVoteMgr.c
source/libs/sync/src/syncVoteMgr.c
+3
-58
source/libs/sync/test/CMakeLists.txt
source/libs/sync/test/CMakeLists.txt
+0
-1
source/libs/sync/test/syncElectTest.cpp
source/libs/sync/test/syncElectTest.cpp
+1
-1
source/libs/sync/test/syncEncodeTest.cpp
source/libs/sync/test/syncEncodeTest.cpp
+1
-1
source/libs/sync/test/syncEnqTest.cpp
source/libs/sync/test/syncEnqTest.cpp
+1
-1
source/libs/sync/test/syncIOSendMsgTest.cpp
source/libs/sync/test/syncIOSendMsgTest.cpp
+1
-1
source/libs/sync/test/syncInitTest.cpp
source/libs/sync/test/syncInitTest.cpp
+1
-1
source/libs/sync/test/syncLeaderTransferTest.cpp
source/libs/sync/test/syncLeaderTransferTest.cpp
+29
-0
source/libs/sync/test/syncPingSelfTest.cpp
source/libs/sync/test/syncPingSelfTest.cpp
+1
-1
source/libs/sync/test/syncPingTimerTest.cpp
source/libs/sync/test/syncPingTimerTest.cpp
+5
-5
source/libs/sync/test/syncPingTimerTest2.cpp
source/libs/sync/test/syncPingTimerTest2.cpp
+1
-1
source/libs/sync/test/syncRaftCfgIndexTest.cpp
source/libs/sync/test/syncRaftCfgIndexTest.cpp
+0
-5
source/libs/sync/test/syncRaftCfgTest.cpp
source/libs/sync/test/syncRaftCfgTest.cpp
+0
-12
source/libs/sync/test/syncReconfigFinishTest.cpp
source/libs/sync/test/syncReconfigFinishTest.cpp
+0
-133
source/libs/sync/test/syncSnapshotTest.cpp
source/libs/sync/test/syncSnapshotTest.cpp
+1
-1
source/libs/sync/test/syncTimeoutTest.cpp
source/libs/sync/test/syncTimeoutTest.cpp
+22
-0
source/libs/sync/test/syncWriteTest.cpp
source/libs/sync/test/syncWriteTest.cpp
+1
-1
未找到文件。
include/common/tmsgdef.h
浏览文件 @
7ddec79a
...
@@ -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
)
...
...
include/util/taoserror.h
浏览文件 @
7ddec79a
...
@@ -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)
...
...
source/libs/sync/inc/syncInt.h
浏览文件 @
7ddec79a
...
@@ -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
sync
NodePrint
(
SSyncNode
*
pObj
);
void
sync
PrintNodeLog
(
const
char
*
flags
,
ELogLevel
level
,
int32_t
dflag
,
SSyncNode
*
pNode
,
const
char
*
format
,
...
);
void
sync
NodePrint2
(
char
*
s
,
SSyncNode
*
pObj
);
void
sync
PrintSnapshotSenderLog
(
const
char
*
flags
,
ELogLevel
level
,
int32_t
dflag
,
SSyncSnapshotSender
*
pSender
,
void
syncNodeLog
(
SSyncNode
*
pObj
);
const
char
*
format
,
...
);
void
sync
NodeLog2
(
char
*
s
,
SSyncNode
*
pObj
);
void
sync
PrintSnapshotReceiverLog
(
const
char
*
flags
,
ELogLevel
level
,
int32_t
dflag
,
SSyncSnapshotReceiver
*
pReceiver
,
void
syncNodeLog3
(
char
*
s
,
SSyncNode
*
pObj
);
const
char
*
format
,
...
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
source/libs/sync/inc/syncRaftCfg.h
浏览文件 @
7ddec79a
...
@@ -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
...
...
source/libs/sync/inc/syncSnapshot.h
浏览文件 @
7ddec79a
...
@@ -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
...
...
source/libs/sync/inc/syncTools.h
浏览文件 @
7ddec79a
...
@@ -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
,
...
...
source/libs/sync/inc/syncUtil.h
浏览文件 @
7ddec79a
...
@@ -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
*
p
Node
Info
,
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
*
p
Node
Info
,
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
}
}
...
...
source/libs/sync/inc/syncVoteMgr.h
浏览文件 @
7ddec79a
...
@@ -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
...
...
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
7ddec79a
...
@@ -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
)
{
s
yncNodeEventLog
(
ths
,
"can not do follower commit"
);
s
NTrace
(
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
);
...
...
source/libs/sync/src/syncAppendEntriesReply.c
浏览文件 @
7ddec79a
...
@@ -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
;
}
}
...
...
source/libs/sync/src/syncCommit.c
浏览文件 @
7ddec79a
...
@@ -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
)
{
s
yncNodeErrorLog
(
pSyncNode
,
"not leader, can not advance commit index"
);
s
NError
(
pSyncNode
,
"not leader, can not advance commit index"
);
return
;
return
;
}
}
if
(
pSyncNode
->
replicaNum
!=
1
)
{
if
(
pSyncNode
->
replicaNum
!=
1
)
{
s
yncNodeErrorLog
(
pSyncNode
,
"not one replica, can not advance commit index"
);
s
NError
(
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
)
{
s
yncNodeErrorLog
(
pSyncNode
,
"not leader, can not advance commit index"
);
s
NError
(
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
;
}
}
}
}
...
...
source/libs/sync/src/syncElection.c
浏览文件 @
7ddec79a
...
@@ -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
)
{
s
yncNodeEventLog
(
pSyncNode
,
"begin election"
);
s
NTrace
(
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
)
{
s
yncNodeErrorLog
(
pSyncNode
,
"not candidate, can not elect"
);
s
NError
(
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
)
{
s
yncNodeEventLog
(
pSyncNode
,
"not candidate, stop elect"
);
s
NTrace
(
pSyncNode
,
"not candidate, stop elect"
);
return
0
;
return
0
;
}
}
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
7ddec79a
此差异已折叠。
点击以展开。
source/libs/sync/src/syncMessage.c
浏览文件 @
7ddec79a
...
@@ -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
=
syncUtil
p
rintBin
((
char
*
)(
pRpcMsg
->
pCont
),
pRpcMsg
->
contLen
);
s
=
syncUtil
P
rintBin
((
char
*
)(
pRpcMsg
->
pCont
),
pRpcMsg
->
contLen
);
cJSON_AddStringToObject
(
pRoot
,
"pCont"
,
s
);
cJSON_AddStringToObject
(
pRoot
,
"pCont"
,
s
);
taosMemoryFree
(
s
);
taosMemoryFree
(
s
);
s
=
syncUtil
p
rintBin2
((
char
*
)(
pRpcMsg
->
pCont
),
pRpcMsg
->
contLen
);
s
=
syncUtil
P
rintBin2
((
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
=
syncUtil
p
rintBin
((
char
*
)(
pRpcMsg
->
pCont
),
pRpcMsg
->
contLen
);
s
=
syncUtil
P
rintBin
((
char
*
)(
pRpcMsg
->
pCont
),
pRpcMsg
->
contLen
);
cJSON_AddStringToObject
(
pRoot
,
"pCont"
,
s
);
cJSON_AddStringToObject
(
pRoot
,
"pCont"
,
s
);
taosMemoryFree
(
s
);
taosMemoryFree
(
s
);
s
=
syncUtil
p
rintBin2
((
char
*
)(
pRpcMsg
->
pCont
),
pRpcMsg
->
contLen
);
s
=
syncUtil
P
rintBin2
((
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
=
syncUtil
p
rintBin
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
s
=
syncUtil
P
rintBin
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
cJSON_AddStringToObject
(
pRoot
,
"data"
,
s
);
cJSON_AddStringToObject
(
pRoot
,
"data"
,
s
);
taosMemoryFree
(
s
);
taosMemoryFree
(
s
);
s
=
syncUtil
p
rintBin2
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
s
=
syncUtil
P
rintBin2
((
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
=
syncUtil
p
rintBin
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
s
=
syncUtil
P
rintBin
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
cJSON_AddStringToObject
(
pRoot
,
"data"
,
s
);
cJSON_AddStringToObject
(
pRoot
,
"data"
,
s
);
taosMemoryFree
(
s
);
taosMemoryFree
(
s
);
s
=
syncUtil
p
rintBin2
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
s
=
syncUtil
P
rintBin2
((
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
=
syncUtil
p
rintBin
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
s
=
syncUtil
P
rintBin
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
cJSON_AddStringToObject
(
pRoot
,
"data"
,
s
);
cJSON_AddStringToObject
(
pRoot
,
"data"
,
s
);
taosMemoryFree
(
s
);
taosMemoryFree
(
s
);
s
=
syncUtil
p
rintBin2
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
s
=
syncUtil
P
rintBin2
((
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
=
syncUtil
p
rintBin
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
s
=
syncUtil
P
rintBin
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
cJSON_AddStringToObject
(
pRoot
,
"data"
,
s
);
cJSON_AddStringToObject
(
pRoot
,
"data"
,
s
);
taosMemoryFree
(
s
);
taosMemoryFree
(
s
);
s
=
syncUtil
p
rintBin2
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
s
=
syncUtil
P
rintBin2
((
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
);
s
TraceLong
(
"syncClientRequestBatchLog2 | len:%d | %s | %s"
,
(
int32_t
)
strlen
(
serialized
),
s
,
serialized
);
s
LTrace
(
"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
=
syncUtil
p
rintBin
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
s
=
syncUtil
P
rintBin
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
cJSON_AddStringToObject
(
pRoot
,
"data"
,
s
);
cJSON_AddStringToObject
(
pRoot
,
"data"
,
s
);
taosMemoryFree
(
s
);
taosMemoryFree
(
s
);
s
=
syncUtil
p
rintBin2
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
s
=
syncUtil
P
rintBin2
((
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
=
syncUtil
p
rintBin
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
s
=
syncUtil
P
rintBin
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
cJSON_AddStringToObject
(
pRoot
,
"data"
,
s
);
cJSON_AddStringToObject
(
pRoot
,
"data"
,
s
);
taosMemoryFree
(
s
);
taosMemoryFree
(
s
);
s
=
syncUtil
p
rintBin2
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
s
=
syncUtil
P
rintBin2
((
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
);
s
TraceLong
(
"syncAppendEntriesBatchLog2 | len:%d | %s | %s"
,
(
int32_t
)
strlen
(
serialized
),
s
,
serialized
);
s
LTrace
(
"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
=
syncUtil
p
rintBin
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
s
=
syncUtil
P
rintBin
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
cJSON_AddStringToObject
(
pRoot
,
"data"
,
s
);
cJSON_AddStringToObject
(
pRoot
,
"data"
,
s
);
taosMemoryFree
(
s
);
taosMemoryFree
(
s
);
s
=
syncUtil
p
rintBin2
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
s
=
syncUtil
P
rintBin2
((
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
=
syncUtil
p
rintBin
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
s
=
syncUtil
P
rintBin
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
cJSON_AddStringToObject
(
pRoot
,
"data"
,
s
);
cJSON_AddStringToObject
(
pRoot
,
"data"
,
s
);
taosMemoryFree
(
s
);
taosMemoryFree
(
s
);
s
=
syncUtil
p
rintBin2
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
s
=
syncUtil
P
rintBin2
((
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"
;
...
...
source/libs/sync/src/syncRaftCfg.c
浏览文件 @
7ddec79a
...
@@ -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
);
}
source/libs/sync/src/syncRaftEntry.c
浏览文件 @
7ddec79a
...
@@ -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
=
syncUtil
p
rintBin
((
char
*
)(
pEntry
->
data
),
pEntry
->
dataLen
);
s
=
syncUtil
P
rintBin
((
char
*
)(
pEntry
->
data
),
pEntry
->
dataLen
);
cJSON_AddStringToObject
(
pRoot
,
"data"
,
s
);
cJSON_AddStringToObject
(
pRoot
,
"data"
,
s
);
taosMemoryFree
(
s
);
taosMemoryFree
(
s
);
s
=
syncUtil
p
rintBin2
((
char
*
)(
pEntry
->
data
),
pEntry
->
dataLen
);
s
=
syncUtil
P
rintBin2
((
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
);
s
TraceLong
(
"raftCacheLog2 | len:%d | %s | %s"
,
(
int32_t
)
strlen
(
serialized
),
s
,
serialized
);
s
LTrace
(
"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
);
s
TraceLong
(
"raftEntryCacheLog2 | len:%d | %s | %s"
,
(
int32_t
)
strlen
(
serialized
),
s
,
serialized
);
s
LTrace
(
"raftEntryCacheLog2 | len:%d | %s | %s"
,
(
int32_t
)
strlen
(
serialized
),
s
,
serialized
);
taosMemoryFree
(
serialized
);
taosMemoryFree
(
serialized
);
}
}
}
}
source/libs/sync/src/syncRaftLog.c
浏览文件 @
7ddec79a
...
@@ -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
);
s
TraceLong
(
"logStoreLog | len:%d | %s"
,
(
int32_t
)
strlen
(
serialized
),
serialized
);
s
LTrace
(
"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
);
s
TraceLong
(
"logStoreLog2 | len:%d | %s | %s"
,
(
int32_t
)
strlen
(
serialized
),
s
,
serialized
);
s
LTrace
(
"logStoreLog2 | len:%d | %s | %s"
,
(
int32_t
)
strlen
(
serialized
),
s
,
serialized
);
taosMemoryFree
(
serialized
);
taosMemoryFree
(
serialized
);
}
}
}
}
...
...
source/libs/sync/src/syncReplication.c
浏览文件 @
7ddec79a
...
@@ -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
;
}
}
s
yncNodeEventLog
(
pSyncNode
,
"do replicate"
);
s
NTrace
(
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
;
...
...
source/libs/sync/src/syncRequestVote.c
浏览文件 @
7ddec79a
...
@@ -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
;
}
}
...
...
source/libs/sync/src/syncRequestVoteReply.c
浏览文件 @
7ddec79a
...
@@ -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
;
}
}
...
...
source/libs/sync/src/syncRespMgr.c
浏览文件 @
7ddec79a
...
@@ -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
...
...
source/libs/sync/src/syncSnapshot.c
浏览文件 @
7ddec79a
...
@@ -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
)
{
s
yncNodeErrorLog
(
pSender
->
pSyncNode
,
"stop reader error"
);
s
NError
(
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
=
syncUtil
p
rintBin
((
char
*
)(
pSender
->
pCurrentBlock
),
pSender
->
blockLen
);
s
=
syncUtil
P
rintBin
((
char
*
)(
pSender
->
pCurrentBlock
),
pSender
->
blockLen
);
cJSON_AddStringToObject
(
pRoot
,
"pCurrentBlock"
,
s
);
cJSON_AddStringToObject
(
pRoot
,
"pCurrentBlock"
,
s
);
taosMemoryFree
(
s
);
taosMemoryFree
(
s
);
s
=
syncUtil
p
rintBin2
((
char
*
)(
pSender
->
pCurrentBlock
),
pSender
->
blockLen
);
s
=
syncUtil
P
rintBin2
((
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
)
{
s
yncNodeEventLog
(
pSyncNode
,
"starting snapshot ..."
);
s
NTrace
(
pSyncNode
,
"starting snapshot ..."
);
SSyncSnapshotSender
*
pSender
=
syncNodeGetSnapshotSender
(
pSyncNode
,
pDestId
);
SSyncSnapshotSender
*
pSender
=
syncNodeGetSnapshotSender
(
pSyncNode
,
pDestId
);
if
(
pSender
==
NULL
)
{
if
(
pSender
==
NULL
)
{
s
yncNodeErrorLog
(
pSyncNode
,
"start snapshot error, sender is null"
);
s
NError
(
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
)
{
s
yncNodeErrorLog
(
pSyncNode
,
"snapshot sender stop error"
);
s
NError
(
pSyncNode
,
"snapshot sender stop error"
);
return
-
1
;
return
-
1
;
}
}
}
}
code
=
snapshotSenderStart
(
pSender
);
code
=
snapshotSenderStart
(
pSender
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
s
yncNodeErrorLog
(
pSyncNode
,
"snapshot sender start error"
);
s
NError
(
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
)
{
s
yncNodeErrorLog
(
pReceiver
->
pSyncNode
,
"snapshot write error"
);
s
NError
(
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
)
{
s
yncNodeErrorLog
(
pReceiver
->
pSyncNode
,
"wal restore from snapshot error"
);
s
NError
(
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
{
s
yncNodeErrorLog
(
pReceiver
->
pSyncNode
,
"snapshot stop writer true error"
);
s
NError
(
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
)
{
s
yncNodeErrorLog
(
pSyncNode
,
"snapshot receiver time skew too much"
);
s
NError
(
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
s
yncNodeEventLog
(
pSyncNode
,
"msg ignore"
);
s
NTrace
(
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
)
{
s
yncNodeErrorLog
(
pSyncNode
,
"snapshot receiver time skew too much"
);
s
NError
(
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
)
{
s
yncNodeErrorLog
(
pSyncNode
,
"snapshot last index too small"
);
s
NError
(
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
)
{
s
yncNodeErrorLog
(
pSyncNode
,
"create snapshot reader error"
);
s
NError
(
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
)
{
s
yncNodeErrorLog
(
ths
,
"truncate wal error"
);
s
NError
(
ths
,
"truncate wal error"
);
goto
_IGNORE
;
goto
_IGNORE
;
}
}
}
}
...
...
source/libs/sync/src/syncTimeout.c
浏览文件 @
7ddec79a
...
@@ -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
)
{
s
yncNodeEventLog
(
ths
,
"timer routines"
);
s
NTrace
(
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
);
}
}
}
}
...
...
source/libs/sync/src/syncUtil.c
浏览文件 @
7ddec79a
...
@@ -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
*
p
Node
Info
,
SEpSet
*
pEpSet
)
{
void
syncUtilnodeInfo2EpSet
(
const
SNodeInfo
*
pInfo
,
SEpSet
*
pEpSet
)
{
pEpSet
->
inUse
=
0
;
pEpSet
->
inUse
=
0
;
pEpSet
->
numOfEps
=
0
;
pEpSet
->
numOfEps
=
0
;
addEpIntoEpSet
(
pEpSet
,
p
NodeInfo
->
nodeFqdn
,
pNode
Info
->
nodePort
);
addEpIntoEpSet
(
pEpSet
,
p
Info
->
nodeFqdn
,
p
Info
->
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
*
p
Node
Info
,
SyncGroupId
vgId
,
SRaftId
*
raftId
)
{
bool
syncUtilnodeInfo2raftId
(
const
SNodeInfo
*
pInfo
,
SyncGroupId
vgId
,
SRaftId
*
raftId
)
{
uint32_t
ipv4
=
taosGetIpv4FromFqdn
(
p
Node
Info
->
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"
,
pNode
Info
->
nodeFqdn
);
sError
(
"failed to resolve ipv4 addr
, fqdn: %s"
,
p
Info
->
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
,
p
Node
Info
->
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
*
syncUtil
p
rintBin
(
char
*
ptr
,
uint32_t
len
)
{
char
*
syncUtil
P
rintBin
(
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
*
syncUtil
p
rintBin2
(
char
*
ptr
,
uint32_t
len
)
{
char
*
syncUtil
P
rintBin2
(
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
);
}
source/libs/sync/src/syncVoteMgr.c
浏览文件 @
7ddec79a
...
@@ -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
)
{
s
yncNodeEventLog
(
pVotesGranted
->
pSyncNode
,
"vote grant vnode error"
);
s
NTrace
(
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
)
{
s
yncNodeEventLog
(
pVotesRespond
->
pSyncNode
,
"vote respond add error"
);
s
NTrace
(
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
);
}
source/libs/sync/test/CMakeLists.txt
浏览文件 @
7ddec79a
...
@@ -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
""
)
...
...
source/libs/sync/test/syncElectTest.cpp
浏览文件 @
7ddec79a
...
@@ -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
);
s
yncNodeLog2
((
char
*
)
"==syncElectTest=="
,
pSyncNode
);
s
NTrace
(
pSyncNode
,
"==syncElectTest=="
);
//---------------------------
//---------------------------
while
(
1
)
{
while
(
1
)
{
...
...
source/libs/sync/test/syncEncodeTest.cpp
浏览文件 @
7ddec79a
...
@@ -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
=
syncUtil
p
rintBin
(
pMsg5
,
len
);
char
*
s
=
syncUtil
P
rintBin
(
pMsg5
,
len
);
printf
(
"==step5== [%s]
\n
"
,
s
);
printf
(
"==step5== [%s]
\n
"
,
s
);
taosMemoryFree
(
s
);
taosMemoryFree
(
s
);
...
...
source/libs/sync/test/syncEnqTest.cpp
浏览文件 @
7ddec79a
...
@@ -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
);
s
yncNodeLog2
((
char
*
)
"syncInitTest"
,
pSyncNode
);
s
NTrace
(
pSyncNode
,
"syncInitTest"
);
initRaftId
(
pSyncNode
);
initRaftId
(
pSyncNode
);
...
...
source/libs/sync/test/syncIOSendMsgTest.cpp
浏览文件 @
7ddec79a
...
@@ -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
);
s
yncNodeLog2
((
char
*
)
"syncInitTest"
,
pSyncNode
);
s
NTrace
(
pSyncNode
,
"syncInitTest"
);
initRaftId
(
pSyncNode
);
initRaftId
(
pSyncNode
);
...
...
source/libs/sync/test/syncInitTest.cpp
浏览文件 @
7ddec79a
...
@@ -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
);
s
yncNodeLog2
((
char
*
)
"syncInitTest"
,
pSyncNode
);
s
NTrace
(
pSyncNode
,
"syncInitTest"
);
initRaftId
(
pSyncNode
);
initRaftId
(
pSyncNode
);
syncNodeClose
(
pSyncNode
);
syncNodeClose
(
pSyncNode
);
...
...
source/libs/sync/test/syncLeaderTransferTest.cpp
浏览文件 @
7ddec79a
...
@@ -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
);
...
...
source/libs/sync/test/syncPingSelfTest.cpp
浏览文件 @
7ddec79a
...
@@ -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
);
s
yncNodeLog2
((
char
*
)
""
,
pSyncNode
);
s
NTrace
(
pSyncNode
,
""
);
initRaftId
(
pSyncNode
);
initRaftId
(
pSyncNode
);
...
...
source/libs/sync/test/syncPingTimerTest.cpp
浏览文件 @
7ddec79a
...
@@ -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
);
s
yncNodeLog2
((
char
*
)
"----1"
,
pSyncNode
);
s
NTrace
(
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
);
s
yncNodeLog2
((
char
*
)
"----2"
,
pSyncNode
);
s
NTrace
(
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
);
s
yncNodeLog2
((
char
*
)
"----3"
,
pSyncNode
);
s
NTrace
(
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
);
s
yncNodeLog2
((
char
*
)
"----4"
,
pSyncNode
);
s
NTrace
(
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
);
s
yncNodeLog2
((
char
*
)
"----5"
,
pSyncNode
);
s
NTrace
(
pSyncNode
,
"----5"
);
while
(
1
)
{
while
(
1
)
{
sTrace
(
"while 1 sleep ..."
);
sTrace
(
"while 1 sleep ..."
);
...
...
source/libs/sync/test/syncPingTimerTest2.cpp
浏览文件 @
7ddec79a
...
@@ -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
);
s
yncNodeLog2
((
char
*
)
""
,
pSyncNode
);
s
NTrace
(
pSyncNode
,
""
);
initRaftId
(
pSyncNode
);
initRaftId
(
pSyncNode
);
...
...
source/libs/sync/test/syncRaftCfgIndexTest.cpp
浏览文件 @
7ddec79a
...
@@ -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
);
}
}
...
...
source/libs/sync/test/syncRaftCfgTest.cpp
浏览文件 @
7ddec79a
...
@@ -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
();
...
...
source/libs/sync/test/syncReconfigFinishTest.cpp
已删除
100644 → 0
浏览文件 @
8c97a5c1
#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
;
}
source/libs/sync/test/syncSnapshotTest.cpp
浏览文件 @
7ddec79a
...
@@ -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
);
s
yncNodeLog2
((
char
*
)
""
,
gSyncNode
);
s
NTrace
(
gSyncNode
,
""
);
initRaftId
(
gSyncNode
);
initRaftId
(
gSyncNode
);
...
...
source/libs/sync/test/syncTimeoutTest.cpp
浏览文件 @
7ddec79a
...
@@ -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
);
...
...
source/libs/sync/test/syncWriteTest.cpp
浏览文件 @
7ddec79a
...
@@ -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
);
s
yncNodeLog2
((
char
*
)
""
,
gSyncNode
);
s
NTrace
(
gSyncNode
,
""
);
initRaftId
(
gSyncNode
);
initRaftId
(
gSyncNode
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录