Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
24f31b0f
T
TDengine
项目概览
taosdata
/
TDengine
12 个月 前同步成功
通知
1180
Star
22014
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
24f31b0f
编写于
10月 29, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
10月 29, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #17746 from taosdata/feature/3.0_mhli
refactor(sync): adjust elect timer, add some tests
上级
a501dc3f
43878650
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
352 addition
and
49 deletion
+352
-49
include/common/tmsgdef.h
include/common/tmsgdef.h
+1
-0
include/libs/sync/syncTools.h
include/libs/sync/syncTools.h
+43
-6
source/dnode/mnode/impl/src/mndMain.c
source/dnode/mnode/impl/src/mndMain.c
+2
-2
source/dnode/vnode/src/vnd/vnodeSync.c
source/dnode/vnode/src/vnd/vnodeSync.c
+2
-2
source/libs/sync/inc/syncEnv.h
source/libs/sync/inc/syncEnv.h
+6
-6
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+14
-13
source/libs/sync/src/syncMessage.c
source/libs/sync/src/syncMessage.c
+150
-0
source/libs/sync/src/syncReplication.c
source/libs/sync/src/syncReplication.c
+1
-1
source/libs/sync/test/CMakeLists.txt
source/libs/sync/test/CMakeLists.txt
+14
-0
source/libs/sync/test/syncConfigChangeSnapshotTest.cpp
source/libs/sync/test/syncConfigChangeSnapshotTest.cpp
+1
-1
source/libs/sync/test/syncConfigChangeTest.cpp
source/libs/sync/test/syncConfigChangeTest.cpp
+1
-1
source/libs/sync/test/syncEncodeTest.cpp
source/libs/sync/test/syncEncodeTest.cpp
+1
-1
source/libs/sync/test/syncIndexTest.cpp
source/libs/sync/test/syncIndexTest.cpp
+1
-1
source/libs/sync/test/syncLocalCmdTest.cpp
source/libs/sync/test/syncLocalCmdTest.cpp
+100
-0
source/libs/sync/test/syncRaftIdCheck.cpp
source/libs/sync/test/syncRaftIdCheck.cpp
+1
-1
source/libs/sync/test/syncRaftLogTest3.cpp
source/libs/sync/test/syncRaftLogTest3.cpp
+8
-8
source/libs/sync/test/syncReplicateTest.cpp
source/libs/sync/test/syncReplicateTest.cpp
+1
-1
source/libs/sync/test/syncRespMgrTest.cpp
source/libs/sync/test/syncRespMgrTest.cpp
+3
-3
source/libs/sync/test/syncTestTool.cpp
source/libs/sync/test/syncTestTool.cpp
+2
-2
未找到文件。
include/common/tmsgdef.h
浏览文件 @
24f31b0f
...
...
@@ -269,6 +269,7 @@ enum {
TD_DEF_MSG_TYPE
(
TDMT_SYNC_SET_VNODE_STANDBY
,
"set-vnode-standby"
,
NULL
,
NULL
)
// no longer used
TD_DEF_MSG_TYPE
(
TDMT_SYNC_HEARTBEAT
,
"sync-heartbeat"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_HEARTBEAT_REPLY
,
"sync-heartbeat-reply"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_LOCAL_CMD
,
"sync-local-cmd"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_MAX_MSG
,
"sync-max"
,
NULL
,
NULL
)
#if defined(TD_MSG_NUMBER_)
...
...
include/libs/sync/syncTools.h
浏览文件 @
24f31b0f
...
...
@@ -678,24 +678,61 @@ void syncReconfigFinishPrint2(char* s, const SyncReconfigFinish* pMsg);
void
syncReconfigFinishLog
(
const
SyncReconfigFinish
*
pMsg
);
void
syncReconfigFinishLog2
(
char
*
s
,
const
SyncReconfigFinish
*
pMsg
);
// ---------------------------------------------
typedef
enum
{
SYNC_LOCAL_CMD_STEP_DOWN
=
100
,
}
ESyncLocalCmd
;
typedef
struct
SyncLocalCmd
{
uint32_t
bytes
;
int32_t
vgId
;
uint32_t
msgType
;
SRaftId
srcId
;
SRaftId
destId
;
int32_t
cmd
;
SyncTerm
sdNewTerm
;
// step down new term
}
SyncLocalCmd
;
SyncLocalCmd
*
syncLocalCmdBuild
(
int32_t
vgId
);
void
syncLocalCmdDestroy
(
SyncLocalCmd
*
pMsg
);
void
syncLocalCmdSerialize
(
const
SyncLocalCmd
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
);
void
syncLocalCmdDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncLocalCmd
*
pMsg
);
char
*
syncLocalCmdSerialize2
(
const
SyncLocalCmd
*
pMsg
,
uint32_t
*
len
);
SyncLocalCmd
*
syncLocalCmdDeserialize2
(
const
char
*
buf
,
uint32_t
len
);
void
syncLocalCmd2RpcMsg
(
const
SyncLocalCmd
*
pMsg
,
SRpcMsg
*
pRpcMsg
);
void
syncLocalCmdFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncLocalCmd
*
pMsg
);
SyncLocalCmd
*
syncLocalCmdFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
);
cJSON
*
syncLocalCmd2Json
(
const
SyncLocalCmd
*
pMsg
);
char
*
syncLocalCmd2Str
(
const
SyncLocalCmd
*
pMsg
);
// for debug ----------------------
void
syncLocalCmdPrint
(
const
SyncLocalCmd
*
pMsg
);
void
syncLocalCmdPrint2
(
char
*
s
,
const
SyncLocalCmd
*
pMsg
);
void
syncLocalCmdLog
(
const
SyncLocalCmd
*
pMsg
);
void
syncLocalCmdLog2
(
char
*
s
,
const
SyncLocalCmd
*
pMsg
);
// on message ----------------------
int32_t
syncNodeOnPingCb
(
SSyncNode
*
ths
,
SyncPing
*
pMsg
);
int32_t
syncNodeOnPingReplyCb
(
SSyncNode
*
ths
,
SyncPingReply
*
pMsg
);
int32_t
syncNodeOnTimer
(
SSyncNode
*
ths
,
SyncTimeout
*
pMsg
);
int32_t
syncNodeOnPing
(
SSyncNode
*
ths
,
SyncPing
*
pMsg
);
int32_t
syncNodeOnPingReply
(
SSyncNode
*
ths
,
SyncPingReply
*
pMsg
);
int32_t
syncNodeOnHeartbeat
(
SSyncNode
*
ths
,
SyncHeartbeat
*
pMsg
);
int32_t
syncNodeOnHeartbeatReply
(
SSyncNode
*
ths
,
SyncHeartbeatReply
*
pMsg
);
int32_t
syncNodeOnClientRequest
(
SSyncNode
*
ths
,
SyncClientRequest
*
pMsg
,
SyncIndex
*
pRetIndex
);
int32_t
syncNodeOnRequestVote
(
SSyncNode
*
ths
,
SyncRequestVote
*
pMsg
);
int32_t
syncNodeOnRequestVoteReply
(
SSyncNode
*
ths
,
SyncRequestVoteReply
*
pMsg
);
int32_t
syncNodeOnAppendEntries
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
);
int32_t
syncNodeOnAppendEntriesReply
(
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
);
int32_t
syncNodeOnSnapshot
(
SSyncNode
*
ths
,
SyncSnapshotSend
*
pMsg
);
int32_t
syncNodeOnSnapshotReply
(
SSyncNode
*
ths
,
SyncSnapshotRsp
*
pMsg
);
int32_t
syncNodeOnHeartbeat
(
SSyncNode
*
ths
,
SyncHeartbeat
*
pMsg
);
int32_t
syncNodeOnHeartbeatReply
(
SSyncNode
*
ths
,
SyncHeartbeatReply
*
pMsg
);
int32_t
syncNodeOnClientRequest
(
SSyncNode
*
ths
,
SyncClientRequest
*
pMsg
,
SyncIndex
*
pRetIndex
);
int32_t
syncNodeOnTimer
(
SSyncNode
*
ths
,
SyncTimeout
*
pMsg
);
int32_t
syncNodeOnLocalCmd
(
SSyncNode
*
ths
,
SyncLocalCmd
*
pMsg
);
// -----------------------------------------
typedef
int32_t
(
*
FpOnPingCb
)(
SSyncNode
*
ths
,
SyncPing
*
pMsg
);
typedef
int32_t
(
*
FpOnPingReplyCb
)(
SSyncNode
*
ths
,
SyncPingReply
*
pMsg
);
...
...
source/dnode/mnode/impl/src/mndMain.c
浏览文件 @
24f31b0f
...
...
@@ -538,12 +538,12 @@ int32_t mndProcessSyncMsg(SRpcMsg *pMsg) {
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_PING
)
{
SyncPing
*
pSyncMsg
=
syncPingFromRpcMsg2
(
pMsg
);
code
=
syncNodeOnPing
Cb
(
pSyncNode
,
pSyncMsg
);
code
=
syncNodeOnPing
(
pSyncNode
,
pSyncMsg
);
syncPingDestroy
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_PING_REPLY
)
{
SyncPingReply
*
pSyncMsg
=
syncPingReplyFromRpcMsg2
(
pMsg
);
code
=
syncNodeOnPingReply
Cb
(
pSyncNode
,
pSyncMsg
);
code
=
syncNodeOnPingReply
(
pSyncNode
,
pSyncMsg
);
syncPingReplyDestroy
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_CLIENT_REQUEST
)
{
...
...
source/dnode/vnode/src/vnd/vnodeSync.c
浏览文件 @
24f31b0f
...
...
@@ -301,13 +301,13 @@ int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_PING
)
{
SyncPing
*
pSyncMsg
=
syncPingFromRpcMsg2
(
pMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
code
=
syncNodeOnPing
Cb
(
pSyncNode
,
pSyncMsg
);
code
=
syncNodeOnPing
(
pSyncNode
,
pSyncMsg
);
syncPingDestroy
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_PING_REPLY
)
{
SyncPingReply
*
pSyncMsg
=
syncPingReplyFromRpcMsg2
(
pMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
code
=
syncNodeOnPingReply
Cb
(
pSyncNode
,
pSyncMsg
);
code
=
syncNodeOnPingReply
(
pSyncNode
,
pSyncMsg
);
syncPingReplyDestroy
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_CLIENT_REQUEST
)
{
...
...
source/libs/sync/inc/syncEnv.h
浏览文件 @
24f31b0f
...
...
@@ -28,13 +28,13 @@ extern "C" {
#include "trpc.h"
#include "ttimer.h"
#define TIMER_MAX_MS 0x7FFFFFFF
#define ENV_TICK_TIMER_MS 1000
#define PING_TIMER_MS 5000
#define ELECT_TIMER_MS_MIN
50
00
#define ELECT_TIMER_MS_MAX (ELECT_TIMER_MS_MIN * 2)
#define TIMER_MAX_MS
0x7FFFFFFF
#define ENV_TICK_TIMER_MS
1000
#define PING_TIMER_MS
5000
#define ELECT_TIMER_MS_MIN
25
00
#define ELECT_TIMER_MS_MAX
(ELECT_TIMER_MS_MIN * 2)
#define ELECT_TIMER_MS_RANGE (ELECT_TIMER_MS_MAX - ELECT_TIMER_MS_MIN)
#define HEARTBEAT_TIMER_MS
9
00
#define HEARTBEAT_TIMER_MS
10
00
#define EMPTY_RAFT_ID ((SRaftId){.addr = 0, .vgId = 0})
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
24f31b0f
...
...
@@ -49,8 +49,8 @@ static int32_t syncNodeAppendNoop(SSyncNode* ths);
static
void
syncNodeEqPeerHeartbeatTimer
(
void
*
param
,
void
*
tmrId
);
// process message ----
int32_t
syncNodeOnPing
Cb
(
SSyncNode
*
ths
,
SyncPing
*
pMsg
);
int32_t
syncNodeOnPingReply
Cb
(
SSyncNode
*
ths
,
SyncPingReply
*
pMsg
);
int32_t
syncNodeOnPing
(
SSyncNode
*
ths
,
SyncPing
*
pMsg
);
int32_t
syncNodeOnPingReply
(
SSyncNode
*
ths
,
SyncPingReply
*
pMsg
);
// ---------------------------------
static
void
syncNodeFreeCb
(
void
*
param
)
{
...
...
@@ -1327,8 +1327,8 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) {
}
// init callback
pSyncNode
->
FpOnPing
=
syncNodeOnPing
Cb
;
pSyncNode
->
FpOnPingReply
=
syncNodeOnPingReply
Cb
;
pSyncNode
->
FpOnPing
=
syncNodeOnPing
;
pSyncNode
->
FpOnPingReply
=
syncNodeOnPingReply
;
pSyncNode
->
FpOnClientRequest
=
syncNodeOnClientRequest
;
pSyncNode
->
FpOnTimeout
=
syncNodeOnTimer
;
pSyncNode
->
FpOnSnapshot
=
syncNodeOnSnapshot
;
...
...
@@ -3003,18 +3003,19 @@ static int32_t syncNodeAppendNoop(SSyncNode* ths) {
}
// on message ----
int32_t
syncNodeOnPingCb
(
SSyncNode
*
ths
,
SyncPing
*
pMsg
)
{
// log state
int32_t
syncNodeOnPing
(
SSyncNode
*
ths
,
SyncPing
*
pMsg
)
{
sTrace
(
"vgId:%d, recv sync-ping"
,
ths
->
vgId
);
SyncPingReply
*
pMsgReply
=
syncPingReplyBuild3
(
&
ths
->
myRaftId
,
&
pMsg
->
srcId
,
ths
->
vgId
);
SRpcMsg
rpcMsg
;
syncPingReply2RpcMsg
(
pMsgReply
,
&
rpcMsg
);
/*
// htonl
SMsgHead* pHead = rpcMsg.pCont;
pHead->contLen = htonl(pHead->contLen);
pHead->vgId = htonl(pHead->vgId);
*/
// htonl
SMsgHead* pHead = rpcMsg.pCont;
pHead->contLen = htonl(pHead->contLen);
pHead->vgId = htonl(pHead->vgId);
*/
syncNodeSendMsgById
(
&
pMsgReply
->
destId
,
ths
,
&
rpcMsg
);
syncPingReplyDestroy
(
pMsgReply
);
...
...
@@ -3022,9 +3023,9 @@ int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg) {
return
0
;
}
int32_t
syncNodeOnPingReply
Cb
(
SSyncNode
*
ths
,
SyncPingReply
*
pMsg
)
{
int32_t
syncNodeOnPingReply
(
SSyncNode
*
ths
,
SyncPingReply
*
pMsg
)
{
int32_t
ret
=
0
;
s
yncPingReplyLog2
(
"==syncNodeOnPingReplyCb=="
,
pMsg
);
s
Trace
(
"vgId:%d, recv sync-ping-reply"
,
ths
->
vgId
);
return
ret
;
}
...
...
source/libs/sync/src/syncMessage.c
浏览文件 @
24f31b0f
...
...
@@ -3095,3 +3095,153 @@ void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg) {
taosMemoryFree
(
serialized
);
}
}
// ---------------------------------------------
SyncLocalCmd
*
syncLocalCmdBuild
(
int32_t
vgId
)
{
uint32_t
bytes
=
sizeof
(
SyncLocalCmd
);
SyncLocalCmd
*
pMsg
=
taosMemoryMalloc
(
bytes
);
memset
(
pMsg
,
0
,
bytes
);
pMsg
->
bytes
=
bytes
;
pMsg
->
vgId
=
vgId
;
pMsg
->
msgType
=
TDMT_SYNC_LOCAL_CMD
;
return
pMsg
;
}
void
syncLocalCmdDestroy
(
SyncLocalCmd
*
pMsg
)
{
if
(
pMsg
!=
NULL
)
{
taosMemoryFree
(
pMsg
);
}
}
void
syncLocalCmdSerialize
(
const
SyncLocalCmd
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
)
{
ASSERT
(
pMsg
->
bytes
<=
bufLen
);
memcpy
(
buf
,
pMsg
,
pMsg
->
bytes
);
}
void
syncLocalCmdDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncLocalCmd
*
pMsg
)
{
memcpy
(
pMsg
,
buf
,
len
);
ASSERT
(
len
==
pMsg
->
bytes
);
}
char
*
syncLocalCmdSerialize2
(
const
SyncLocalCmd
*
pMsg
,
uint32_t
*
len
)
{
char
*
buf
=
taosMemoryMalloc
(
pMsg
->
bytes
);
ASSERT
(
buf
!=
NULL
);
syncLocalCmdSerialize
(
pMsg
,
buf
,
pMsg
->
bytes
);
if
(
len
!=
NULL
)
{
*
len
=
pMsg
->
bytes
;
}
return
buf
;
}
SyncLocalCmd
*
syncLocalCmdDeserialize2
(
const
char
*
buf
,
uint32_t
len
)
{
uint32_t
bytes
=
*
((
uint32_t
*
)
buf
);
SyncLocalCmd
*
pMsg
=
taosMemoryMalloc
(
bytes
);
ASSERT
(
pMsg
!=
NULL
);
syncLocalCmdDeserialize
(
buf
,
len
,
pMsg
);
ASSERT
(
len
==
pMsg
->
bytes
);
return
pMsg
;
}
void
syncLocalCmd2RpcMsg
(
const
SyncLocalCmd
*
pMsg
,
SRpcMsg
*
pRpcMsg
)
{
memset
(
pRpcMsg
,
0
,
sizeof
(
*
pRpcMsg
));
pRpcMsg
->
msgType
=
pMsg
->
msgType
;
pRpcMsg
->
contLen
=
pMsg
->
bytes
;
pRpcMsg
->
pCont
=
rpcMallocCont
(
pRpcMsg
->
contLen
);
syncLocalCmdSerialize
(
pMsg
,
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
}
void
syncLocalCmdFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncLocalCmd
*
pMsg
)
{
syncLocalCmdDeserialize
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
,
pMsg
);
}
SyncLocalCmd
*
syncLocalCmdFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
)
{
SyncLocalCmd
*
pMsg
=
syncLocalCmdDeserialize2
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
ASSERT
(
pMsg
!=
NULL
);
return
pMsg
;
}
cJSON
*
syncLocalCmd2Json
(
const
SyncLocalCmd
*
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
*
pSrcId
=
cJSON_CreateObject
();
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
srcId
.
addr
);
cJSON_AddStringToObject
(
pSrcId
,
"addr"
,
u64buf
);
{
uint64_t
u64
=
pMsg
->
srcId
.
addr
;
cJSON
*
pTmp
=
pSrcId
;
char
host
[
128
];
uint16_t
port
;
syncUtilU642Addr
(
u64
,
host
,
sizeof
(
host
),
&
port
);
cJSON_AddStringToObject
(
pTmp
,
"addr_host"
,
host
);
cJSON_AddNumberToObject
(
pTmp
,
"addr_port"
,
port
);
}
cJSON_AddNumberToObject
(
pSrcId
,
"vgId"
,
pMsg
->
srcId
.
vgId
);
cJSON_AddItemToObject
(
pRoot
,
"srcId"
,
pSrcId
);
cJSON
*
pDestId
=
cJSON_CreateObject
();
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
destId
.
addr
);
cJSON_AddStringToObject
(
pDestId
,
"addr"
,
u64buf
);
{
uint64_t
u64
=
pMsg
->
destId
.
addr
;
cJSON
*
pTmp
=
pDestId
;
char
host
[
128
];
uint16_t
port
;
syncUtilU642Addr
(
u64
,
host
,
sizeof
(
host
),
&
port
);
cJSON_AddStringToObject
(
pTmp
,
"addr_host"
,
host
);
cJSON_AddNumberToObject
(
pTmp
,
"addr_port"
,
port
);
}
cJSON_AddNumberToObject
(
pDestId
,
"vgId"
,
pMsg
->
destId
.
vgId
);
cJSON_AddItemToObject
(
pRoot
,
"destId"
,
pDestId
);
cJSON_AddNumberToObject
(
pRoot
,
"cmd"
,
pMsg
->
cmd
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
sdNewTerm
);
cJSON_AddStringToObject
(
pRoot
,
"sd-new-term"
,
u64buf
);
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SyncLocalCmd2Json"
,
pRoot
);
return
pJson
;
}
char
*
syncLocalCmd2Str
(
const
SyncLocalCmd
*
pMsg
)
{
cJSON
*
pJson
=
syncLocalCmd2Json
(
pMsg
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
// for debug ----------------------
void
syncLocalCmdPrint
(
const
SyncLocalCmd
*
pMsg
)
{
char
*
serialized
=
syncLocalCmd2Str
(
pMsg
);
printf
(
"syncLocalCmdPrint | len:%d | %s
\n
"
,
(
int32_t
)
strlen
(
serialized
),
serialized
);
fflush
(
NULL
);
taosMemoryFree
(
serialized
);
}
void
syncLocalCmdPrint2
(
char
*
s
,
const
SyncLocalCmd
*
pMsg
)
{
char
*
serialized
=
syncLocalCmd2Str
(
pMsg
);
printf
(
"syncLocalCmdPrint2 | len:%d | %s | %s
\n
"
,
(
int32_t
)
strlen
(
serialized
),
s
,
serialized
);
fflush
(
NULL
);
taosMemoryFree
(
serialized
);
}
void
syncLocalCmdLog
(
const
SyncLocalCmd
*
pMsg
)
{
char
*
serialized
=
syncLocalCmd2Str
(
pMsg
);
sTrace
(
"syncLocalCmdLog | len:%d | %s"
,
(
int32_t
)
strlen
(
serialized
),
serialized
);
taosMemoryFree
(
serialized
);
}
void
syncLocalCmdLog2
(
char
*
s
,
const
SyncLocalCmd
*
pMsg
)
{
if
(
gRaftDetailLog
)
{
char
*
serialized
=
syncLocalCmd2Str
(
pMsg
);
sTrace
(
"syncLocalCmdLog2 | len:%d | %s | %s"
,
(
int32_t
)
strlen
(
serialized
),
s
,
serialized
);
taosMemoryFree
(
serialized
);
}
}
\ No newline at end of file
source/libs/sync/src/syncReplication.c
浏览文件 @
24f31b0f
...
...
@@ -57,7 +57,7 @@ int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId) {
SyncIndex
logEndIndex
=
pSyncNode
->
pLogStore
->
syncLogEndIndex
(
pSyncNode
->
pLogStore
);
if
(
nextIndex
<
logStartIndex
||
nextIndex
-
1
>
logEndIndex
)
{
char
logBuf
[
128
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"start snapshot for next-index:%"
PRId64
", start:%"
PRId64
", end:%"
PRId64
,
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"
maybe
start snapshot for next-index:%"
PRId64
", start:%"
PRId64
", end:%"
PRId64
,
nextIndex
,
logStartIndex
,
logEndIndex
);
syncNodeEventLog
(
pSyncNode
,
logBuf
);
...
...
source/libs/sync/test/CMakeLists.txt
浏览文件 @
24f31b0f
...
...
@@ -59,6 +59,7 @@ add_executable(syncRestoreFromSnapshot "")
add_executable
(
syncRaftCfgIndexTest
""
)
add_executable
(
syncHeartbeatTest
""
)
add_executable
(
syncHeartbeatReplyTest
""
)
add_executable
(
syncLocalCmdTest
""
)
target_sources
(
syncTest
...
...
@@ -305,6 +306,10 @@ target_sources(syncHeartbeatReplyTest
PRIVATE
"syncHeartbeatReplyTest.cpp"
)
target_sources
(
syncLocalCmdTest
PRIVATE
"syncLocalCmdTest.cpp"
)
target_include_directories
(
syncTest
...
...
@@ -612,6 +617,11 @@ target_include_directories(syncHeartbeatReplyTest
"
${
TD_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncLocalCmdTest
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_link_libraries
(
syncTest
...
...
@@ -858,6 +868,10 @@ target_link_libraries(syncHeartbeatReplyTest
sync
gtest_main
)
target_link_libraries
(
syncLocalCmdTest
sync
gtest_main
)
enable_testing
()
...
...
source/libs/sync/test/syncConfigChangeSnapshotTest.cpp
浏览文件 @
24f31b0f
...
...
@@ -270,7 +270,7 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) {
pMsg
->
msgType
=
9999
;
pMsg
->
contLen
=
256
;
pMsg
->
pCont
=
rpcMallocCont
(
pMsg
->
contLen
);
snprintf
((
char
*
)(
pMsg
->
pCont
),
pMsg
->
contLen
,
"value-myIndex:%u-%d-%d-"
PRId64
,
myIndex
,
i
,
count
,
snprintf
((
char
*
)(
pMsg
->
pCont
),
pMsg
->
contLen
,
"value-myIndex:%u-%d-%d-
%
"
PRId64
,
myIndex
,
i
,
count
,
taosGetTimestampMs
());
return
pMsg
;
}
...
...
source/libs/sync/test/syncConfigChangeTest.cpp
浏览文件 @
24f31b0f
...
...
@@ -191,7 +191,7 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) {
pMsg
->
msgType
=
9999
;
pMsg
->
contLen
=
256
;
pMsg
->
pCont
=
rpcMallocCont
(
pMsg
->
contLen
);
snprintf
((
char
*
)(
pMsg
->
pCont
),
pMsg
->
contLen
,
"value-myIndex:%u-%d-%d-"
PRId64
,
myIndex
,
i
,
count
,
snprintf
((
char
*
)(
pMsg
->
pCont
),
pMsg
->
contLen
,
"value-myIndex:%u-%d-%d-
%
"
PRId64
,
myIndex
,
i
,
count
,
taosGetTimestampMs
());
return
pMsg
;
}
...
...
source/libs/sync/test/syncEncodeTest.cpp
浏览文件 @
24f31b0f
...
...
@@ -186,7 +186,7 @@ int main(int argc, char **argv) {
int32_t
code
=
pSyncNode
->
pLogStore
->
syncLogGetEntry
(
pSyncNode
->
pLogStore
,
pEntry
->
index
,
&
pEntry
);
ASSERT
(
code
==
0
);
syncEntryLog2
((
char
*
)
"==pEntry
2=="
,
pEntry2
);
syncEntryLog2
((
char
*
)
"==pEntry
=="
,
pEntry
);
// step5
uint32_t
len
;
...
...
source/libs/sync/test/syncIndexTest.cpp
浏览文件 @
24f31b0f
...
...
@@ -13,7 +13,7 @@ void print(SHashObj *pNextIndex) {
SRaftId
*
pRaftId
=
(
SRaftId
*
)
key
;
printf
(
"key:<"
PRIu64
", %d>, value:%"
PRIu64
"
\n
"
,
pRaftId
->
addr
,
pRaftId
->
vgId
,
*
p
);
printf
(
"key:<
%
"
PRIu64
", %d>, value:%"
PRIu64
"
\n
"
,
pRaftId
->
addr
,
pRaftId
->
vgId
,
*
p
);
p
=
(
uint64_t
*
)
taosHashIterate
(
pNextIndex
,
p
);
}
}
...
...
source/libs/sync/test/syncLocalCmdTest.cpp
0 → 100644
浏览文件 @
24f31b0f
#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"
);
}
SyncLocalCmd
*
createMsg
()
{
SyncLocalCmd
*
pMsg
=
syncLocalCmdBuild
(
1000
);
pMsg
->
srcId
.
addr
=
syncUtilAddr2U64
(
"127.0.0.1"
,
1234
);
pMsg
->
srcId
.
vgId
=
100
;
pMsg
->
destId
.
addr
=
syncUtilAddr2U64
(
"127.0.0.1"
,
5678
);
pMsg
->
destId
.
vgId
=
100
;
pMsg
->
sdNewTerm
=
123
;
pMsg
->
cmd
=
SYNC_LOCAL_CMD_STEP_DOWN
;
return
pMsg
;
}
void
test1
()
{
SyncLocalCmd
*
pMsg
=
createMsg
();
syncLocalCmdLog2
((
char
*
)
"test1:"
,
pMsg
);
syncLocalCmdDestroy
(
pMsg
);
}
void
test2
()
{
SyncLocalCmd
*
pMsg
=
createMsg
();
uint32_t
len
=
pMsg
->
bytes
;
char
*
serialized
=
(
char
*
)
taosMemoryMalloc
(
len
);
syncLocalCmdSerialize
(
pMsg
,
serialized
,
len
);
SyncLocalCmd
*
pMsg2
=
syncLocalCmdBuild
(
1000
);
syncLocalCmdDeserialize
(
serialized
,
len
,
pMsg2
);
syncLocalCmdLog2
((
char
*
)
"test2: syncLocalCmdSerialize -> syncLocalCmdDeserialize "
,
pMsg2
);
taosMemoryFree
(
serialized
);
syncLocalCmdDestroy
(
pMsg
);
syncLocalCmdDestroy
(
pMsg2
);
}
void
test3
()
{
SyncLocalCmd
*
pMsg
=
createMsg
();
uint32_t
len
;
char
*
serialized
=
syncLocalCmdSerialize2
(
pMsg
,
&
len
);
SyncLocalCmd
*
pMsg2
=
syncLocalCmdDeserialize2
(
serialized
,
len
);
syncLocalCmdLog2
((
char
*
)
"test3: syncLocalCmdSerialize3 -> syncLocalCmdDeserialize2 "
,
pMsg2
);
taosMemoryFree
(
serialized
);
syncLocalCmdDestroy
(
pMsg
);
syncLocalCmdDestroy
(
pMsg2
);
}
void
test4
()
{
SyncLocalCmd
*
pMsg
=
createMsg
();
SRpcMsg
rpcMsg
;
syncLocalCmd2RpcMsg
(
pMsg
,
&
rpcMsg
);
SyncLocalCmd
*
pMsg2
=
(
SyncLocalCmd
*
)
taosMemoryMalloc
(
rpcMsg
.
contLen
);
syncLocalCmdFromRpcMsg
(
&
rpcMsg
,
pMsg2
);
syncLocalCmdLog2
((
char
*
)
"test4: syncLocalCmd2RpcMsg -> syncLocalCmdFromRpcMsg "
,
pMsg2
);
rpcFreeCont
(
rpcMsg
.
pCont
);
syncLocalCmdDestroy
(
pMsg
);
syncLocalCmdDestroy
(
pMsg2
);
}
void
test5
()
{
SyncLocalCmd
*
pMsg
=
createMsg
();
SRpcMsg
rpcMsg
;
syncLocalCmd2RpcMsg
(
pMsg
,
&
rpcMsg
);
SyncLocalCmd
*
pMsg2
=
syncLocalCmdFromRpcMsg2
(
&
rpcMsg
);
syncLocalCmdLog2
((
char
*
)
"test5: syncLocalCmd2RpcMsg -> syncLocalCmdFromRpcMsg2 "
,
pMsg2
);
rpcFreeCont
(
rpcMsg
.
pCont
);
syncLocalCmdDestroy
(
pMsg
);
syncLocalCmdDestroy
(
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/syncRaftIdCheck.cpp
浏览文件 @
24f31b0f
...
...
@@ -15,7 +15,7 @@ int main(int argc, char** argv) {
char
host
[
128
];
uint16_t
port
;
syncUtilU642Addr
(
u64
,
host
,
sizeof
(
host
),
&
port
);
printf
(
""
PRIu64
" -> %s:%d
\n
"
,
u64
,
host
,
port
);
printf
(
"
%
"
PRIu64
" -> %s:%d
\n
"
,
u64
,
host
,
port
);
}
else
if
(
argc
==
3
)
{
uint64_t
u64
;
...
...
source/libs/sync/test/syncRaftLogTest3.cpp
浏览文件 @
24f31b0f
...
...
@@ -97,8 +97,8 @@ void test1() {
sTrace
(
"lastIndex: %"
PRId64
,
lastIndex
);
sTrace
(
"lastTerm: %"
PRIu64
,
lastTerm
);
sTrace
(
"syncStartIndex: %"
PRId64
,
syncStartIndex
);
sTrace
(
"
"
PRId64
"'s
preIndex: %"
PRId64
,
testIndex
,
preIndex
);
sTrace
(
"
"
PRId64
"'s
preTerm: %"
PRIu64
,
testIndex
,
preTerm
);
sTrace
(
"
testIndex: %"
PRId64
"
preIndex: %"
PRId64
,
testIndex
,
preIndex
);
sTrace
(
"
testIndex: %"
PRId64
"
preTerm: %"
PRIu64
,
testIndex
,
preTerm
);
if
(
gAssert
)
{
assert
(
lastIndex
==
-
1
);
...
...
@@ -170,8 +170,8 @@ void test2() {
SyncIndex
preIndex
=
syncNodeGetPreIndex
(
pSyncNode
,
i
);
SyncTerm
preTerm
=
syncNodeGetPreTerm
(
pSyncNode
,
i
);
sTrace
(
"
"
PRId64
"'s
preIndex: %"
PRId64
,
i
,
preIndex
);
sTrace
(
"
"
PRId64
"'s
preTerm: %"
PRIu64
,
i
,
preTerm
);
sTrace
(
"
i: %"
PRId64
"
preIndex: %"
PRId64
,
i
,
preIndex
);
sTrace
(
"
i: %"
PRId64
"
preTerm: %"
PRIu64
,
i
,
preTerm
);
if
(
gAssert
)
{
SyncIndex
preIndexArr
[
12
]
=
{
-
1
,
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
};
...
...
@@ -292,8 +292,8 @@ void test4() {
SyncIndex
preIndex
=
syncNodeGetPreIndex
(
pSyncNode
,
i
);
SyncTerm
preTerm
=
syncNodeGetPreTerm
(
pSyncNode
,
i
);
sTrace
(
"
"
PRId64
"'s
preIndex: %"
PRId64
,
i
,
preIndex
);
sTrace
(
"
"
PRId64
"'s
preTerm: %"
PRIu64
,
i
,
preTerm
);
sTrace
(
"
i: %"
PRId64
"
preIndex: %"
PRId64
,
i
,
preIndex
);
sTrace
(
"
i: %"
PRId64
"
preTerm: %"
PRIu64
,
i
,
preTerm
);
}
logStoreDestory
(
pLogStore
);
...
...
@@ -354,8 +354,8 @@ void test5() {
SyncIndex
preIndex
=
syncNodeGetPreIndex
(
pSyncNode
,
i
);
SyncTerm
preTerm
=
syncNodeGetPreTerm
(
pSyncNode
,
i
);
sTrace
(
"
"
PRId64
"'s
preIndex: %"
PRId64
,
i
,
preIndex
);
sTrace
(
"
"
PRId64
"'s
preTerm: %"
PRIu64
,
i
,
preTerm
);
sTrace
(
"
i: %"
PRId64
"
preIndex: %"
PRId64
,
i
,
preIndex
);
sTrace
(
"
i: %"
PRId64
"
preTerm: %"
PRIu64
,
i
,
preTerm
);
if
(
gAssert
)
{
SyncIndex
preIndexArr
[
12
]
=
{
9999
,
9999
,
9999
,
9999
,
9999
,
9999
,
5
,
6
,
7
,
8
,
9
,
10
};
...
...
source/libs/sync/test/syncReplicateTest.cpp
浏览文件 @
24f31b0f
...
...
@@ -145,7 +145,7 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) {
pMsg
->
msgType
=
9999
;
pMsg
->
contLen
=
256
;
pMsg
->
pCont
=
rpcMallocCont
(
pMsg
->
contLen
);
snprintf
((
char
*
)(
pMsg
->
pCont
),
pMsg
->
contLen
,
"value-myIndex:%u-%d-%d-"
PRId64
,
myIndex
,
i
,
count
,
snprintf
((
char
*
)(
pMsg
->
pCont
),
pMsg
->
contLen
,
"value-myIndex:%u-%d-%d-
%
"
PRId64
,
myIndex
,
i
,
count
,
taosGetTimestampMs
());
return
pMsg
;
}
...
...
source/libs/sync/test/syncRespMgrTest.cpp
浏览文件 @
24f31b0f
...
...
@@ -58,18 +58,18 @@ void syncRespMgrGetTest(uint64_t i) {
if
(
ret
==
1
)
{
printStub
(
&
stub
);
}
else
if
(
ret
==
0
)
{
printf
(
""
PRId64
" notFound
\n
"
,
i
);
printf
(
"
%
"
PRId64
" notFound
\n
"
,
i
);
}
}
void
syncRespMgrGetAndDelTest
(
uint64_t
i
)
{
printf
(
"------syncRespMgrGetAndDelTest-------"
PRIu64
"--
\n
"
,
i
);
printf
(
"------syncRespMgrGetAndDelTest-------
%
"
PRIu64
"--
\n
"
,
i
);
SRespStub
stub
;
int32_t
ret
=
syncRespMgrGetAndDel
(
pMgr
,
i
,
&
stub
);
if
(
ret
==
1
)
{
printStub
(
&
stub
);
}
else
if
(
ret
==
0
)
{
printf
(
""
PRId64
" notFound
\n
"
,
i
);
printf
(
"
%
"
PRId64
" notFound
\n
"
,
i
);
}
}
...
...
source/libs/sync/test/syncTestTool.cpp
浏览文件 @
24f31b0f
...
...
@@ -154,7 +154,7 @@ int32_t SnapshotDoWrite(struct SSyncFSM* pFsm, void* pWriter, void* pBuf, int32_
void
RestoreFinishCb
(
struct
SSyncFSM
*
pFsm
)
{
sTrace
(
"==callback== ==RestoreFinishCb== pFsm:%p"
,
pFsm
);
}
void
ReConfigCb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SReConfigCbMeta
*
cbMeta
)
{
char
*
s
=
syncCfg2Str
(
&
(
cbMeta
.
newCfg
));
char
*
s
=
syncCfg2Str
(
&
(
cbMeta
->
newCfg
));
sTrace
(
"==callback== ==ReConfigCb== flag:0x%lX, index:%"
PRId64
", code:%d, currentTerm:%"
PRIu64
", term:%"
PRIu64
", newCfg:%s"
,
cbMeta
->
flag
,
cbMeta
->
index
,
cbMeta
->
code
,
cbMeta
->
currentTerm
,
cbMeta
->
term
,
s
);
...
...
@@ -308,7 +308,7 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) {
pMsg
->
msgType
=
TDMT_VND_SUBMIT
;
pMsg
->
contLen
=
256
;
pMsg
->
pCont
=
rpcMallocCont
(
pMsg
->
contLen
);
snprintf
((
char
*
)(
pMsg
->
pCont
),
pMsg
->
contLen
,
"value-myIndex:%u-%d-%d-"
PRId64
,
myIndex
,
i
,
count
,
snprintf
((
char
*
)(
pMsg
->
pCont
),
pMsg
->
contLen
,
"value-myIndex:%u-%d-%d-
%
"
PRId64
,
myIndex
,
i
,
count
,
taosGetTimestampMs
());
return
pMsg
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录