Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
94076e59
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
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看板
提交
94076e59
编写于
11月 12, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refact: adjust sync append entry
上级
152b1ea9
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
32 addition
and
35 deletion
+32
-35
source/libs/sync/inc/syncMessage.h
source/libs/sync/inc/syncMessage.h
+3
-5
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+5
-5
source/libs/sync/src/syncMessage.c
source/libs/sync/src/syncMessage.c
+22
-23
source/libs/sync/test/syncRpcMsgTest.cpp
source/libs/sync/test/syncRpcMsgTest.cpp
+1
-1
source/libs/sync/test/syncSnapshotTest.cpp
source/libs/sync/test/syncSnapshotTest.cpp
+1
-1
未找到文件。
source/libs/sync/inc/syncMessage.h
浏览文件 @
94076e59
...
...
@@ -434,11 +434,9 @@ ESyncStrategy syncNodeStrategy(SSyncNode* pSyncNode);
const
char
*
syncTimerTypeStr
(
enum
ESyncTimeoutType
timerType
);
int32_t
syncTimeoutBuild
(
SRpcMsg
*
pTimeoutRpcMsg
,
ESyncTimeoutType
timeoutType
,
uint64_t
logicClock
,
int32_t
timerMS
,
SSyncNode
*
pNode
);
int32_t
syncClientRequestBuildFromRpcMsg
(
SRpcMsg
*
pClientRequestRpcMsg
,
const
SRpcMsg
*
pOriginalRpcMsg
,
uint64_t
seqNum
,
bool
isWeak
,
int32_t
vgId
);
int32_t
syncClientRequestBuildFromNoopEntry
(
SRpcMsg
*
pClientRequestRpcMsg
,
const
SSyncRaftEntry
*
pEntry
,
int32_t
vgId
);
int32_t
syncBuildTimeout
(
SRpcMsg
*
pMsg
,
ESyncTimeoutType
ttype
,
uint64_t
logicClock
,
int32_t
ms
,
SSyncNode
*
pNode
);
int32_t
syncBuildClientRequest
(
SRpcMsg
*
pMsg
,
const
SRpcMsg
*
pOriginalRpc
,
uint64_t
seq
,
bool
isWeak
,
int32_t
vgId
);
int32_t
syncBuildClientRequestFromNoopEntry
(
SRpcMsg
*
pMsg
,
const
SSyncRaftEntry
*
pEntry
,
int32_t
vgId
);
int32_t
syncBuildRequestVote
(
SRpcMsg
*
pMsg
,
int32_t
vgId
);
int32_t
syncBuildRequestVoteReply
(
SRpcMsg
*
pMsg
,
int32_t
vgId
);
int32_t
syncBuildAppendEntries
(
SRpcMsg
*
pMsg
,
int32_t
dataLen
,
int32_t
vgId
);
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
94076e59
...
...
@@ -601,7 +601,7 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak) {
SRespStub
stub
=
{.
createTime
=
taosGetTimestampMs
(),
.
rpcMsg
=
*
pMsg
};
uint64_t
seqNum
=
syncRespMgrAdd
(
pSyncNode
->
pSyncRespMgr
,
&
stub
);
SRpcMsg
rpcMsg
=
{
0
};
int32_t
code
=
sync
ClientRequestBuildFromRpcMsg
(
&
rpcMsg
,
pMsg
,
seqNum
,
isWeak
,
pSyncNode
->
vgId
);
int32_t
code
=
sync
BuildClientRequest
(
&
rpcMsg
,
pMsg
,
seqNum
,
isWeak
,
pSyncNode
->
vgId
);
if
(
code
!=
0
)
{
sError
(
"vgId:%d, failed to propose msg while serialize since %s"
,
pSyncNode
->
vgId
,
terrstr
());
(
void
)
syncRespMgrDel
(
pSyncNode
->
pSyncRespMgr
,
seqNum
);
...
...
@@ -1794,7 +1794,7 @@ static void syncNodeEqPingTimer(void* param, void* tmrId) {
SSyncNode
*
pNode
=
param
;
if
(
atomic_load_64
(
&
pNode
->
pingTimerLogicClockUser
)
<=
atomic_load_64
(
&
pNode
->
pingTimerLogicClock
))
{
SRpcMsg
rpcMsg
=
{
0
};
int32_t
code
=
sync
TimeoutBuild
(
&
rpcMsg
,
SYNC_TIMEOUT_PING
,
atomic_load_64
(
&
pNode
->
pingTimerLogicClock
),
int32_t
code
=
sync
BuildTimeout
(
&
rpcMsg
,
SYNC_TIMEOUT_PING
,
atomic_load_64
(
&
pNode
->
pingTimerLogicClock
),
pNode
->
pingTimerMS
,
pNode
);
if
(
code
!=
0
)
{
sNError
(
pNode
,
"failed to build ping msg"
);
...
...
@@ -1824,7 +1824,7 @@ static void syncNodeEqElectTimer(void* param, void* tmrId) {
SSyncNode
*
pNode
=
pElectTimer
->
pSyncNode
;
SRpcMsg
rpcMsg
=
{
0
};
int32_t
code
=
sync
TimeoutBuild
(
&
rpcMsg
,
SYNC_TIMEOUT_ELECTION
,
pElectTimer
->
logicClock
,
pNode
->
electTimerMS
,
pNode
);
int32_t
code
=
sync
BuildTimeout
(
&
rpcMsg
,
SYNC_TIMEOUT_ELECTION
,
pElectTimer
->
logicClock
,
pNode
->
electTimerMS
,
pNode
);
if
(
code
!=
0
)
{
sNError
(
pNode
,
"failed to build elect msg"
);
...
...
@@ -1863,7 +1863,7 @@ static void syncNodeEqHeartbeatTimer(void* param, void* tmrId) {
if
(
pNode
->
replicaNum
>
1
)
{
if
(
atomic_load_64
(
&
pNode
->
heartbeatTimerLogicClockUser
)
<=
atomic_load_64
(
&
pNode
->
heartbeatTimerLogicClock
))
{
SRpcMsg
rpcMsg
=
{
0
};
int32_t
code
=
sync
TimeoutBuild
(
&
rpcMsg
,
SYNC_TIMEOUT_HEARTBEAT
,
atomic_load_64
(
&
pNode
->
heartbeatTimerLogicClock
),
int32_t
code
=
sync
BuildTimeout
(
&
rpcMsg
,
SYNC_TIMEOUT_HEARTBEAT
,
atomic_load_64
(
&
pNode
->
heartbeatTimerLogicClock
),
pNode
->
heartbeatTimerMS
,
pNode
);
if
(
code
!=
0
)
{
...
...
@@ -1970,7 +1970,7 @@ static int32_t syncNodeEqNoop(SSyncNode* pNode) {
if
(
pEntry
==
NULL
)
return
-
1
;
SRpcMsg
rpcMsg
=
{
0
};
int32_t
code
=
sync
ClientRequestBuild
FromNoopEntry
(
&
rpcMsg
,
pEntry
,
pNode
->
vgId
);
int32_t
code
=
sync
BuildClientRequest
FromNoopEntry
(
&
rpcMsg
,
pEntry
,
pNode
->
vgId
);
syncEntryDestory
(
pEntry
);
sNTrace
(
pNode
,
"propose msg, type:noop"
);
...
...
source/libs/sync/src/syncMessage.c
浏览文件 @
94076e59
...
...
@@ -20,18 +20,18 @@
#include "syncUtil.h"
#include "tcoding.h"
int32_t
sync
TimeoutBuild
(
SRpcMsg
*
pTimeoutRpc
Msg
,
ESyncTimeoutType
timeoutType
,
uint64_t
logicClock
,
int32_t
timerMS
,
int32_t
sync
BuildTimeout
(
SRpcMsg
*
p
Msg
,
ESyncTimeoutType
timeoutType
,
uint64_t
logicClock
,
int32_t
timerMS
,
SSyncNode
*
pNode
)
{
int32_t
bytes
=
sizeof
(
SyncTimeout
);
p
TimeoutRpc
Msg
->
pCont
=
rpcMallocCont
(
bytes
);
p
TimeoutRpc
Msg
->
msgType
=
TDMT_SYNC_TIMEOUT
;
p
TimeoutRpc
Msg
->
contLen
=
bytes
;
if
(
p
TimeoutRpc
Msg
->
pCont
==
NULL
)
{
pMsg
->
pCont
=
rpcMallocCont
(
bytes
);
pMsg
->
msgType
=
TDMT_SYNC_TIMEOUT
;
pMsg
->
contLen
=
bytes
;
if
(
pMsg
->
pCont
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
SyncTimeout
*
pTimeout
=
p
TimeoutRpc
Msg
->
pCont
;
SyncTimeout
*
pTimeout
=
pMsg
->
pCont
;
pTimeout
->
bytes
=
bytes
;
pTimeout
->
msgType
=
TDMT_SYNC_TIMEOUT
;
pTimeout
->
vgId
=
pNode
->
vgId
;
...
...
@@ -42,41 +42,40 @@ int32_t syncTimeoutBuild(SRpcMsg* pTimeoutRpcMsg, ESyncTimeoutType timeoutType,
return
0
;
}
int32_t
syncClientRequestBuildFromRpcMsg
(
SRpcMsg
*
pClientRequestRpcMsg
,
const
SRpcMsg
*
pOriginalRpcMsg
,
uint64_t
seqNum
,
bool
isWeak
,
int32_t
vgId
)
{
int32_t
bytes
=
sizeof
(
SyncClientRequest
)
+
pOriginalRpcMsg
->
contLen
;
pClientRequestRpcMsg
->
pCont
=
rpcMallocCont
(
bytes
);
pClientRequestRpcMsg
->
msgType
=
TDMT_SYNC_CLIENT_REQUEST
;
pClientRequestRpcMsg
->
contLen
=
bytes
;
if
(
pClientRequestRpcMsg
->
pCont
==
NULL
)
{
int32_t
syncBuildClientRequest
(
SRpcMsg
*
pMsg
,
const
SRpcMsg
*
pOriginal
,
uint64_t
seqNum
,
bool
isWeak
,
int32_t
vgId
)
{
int32_t
bytes
=
sizeof
(
SyncClientRequest
)
+
pOriginal
->
contLen
;
pMsg
->
pCont
=
rpcMallocCont
(
bytes
);
pMsg
->
msgType
=
TDMT_SYNC_CLIENT_REQUEST
;
pMsg
->
contLen
=
bytes
;
if
(
pMsg
->
pCont
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
SyncClientRequest
*
pClientRequest
=
p
ClientRequestRpc
Msg
->
pCont
;
SyncClientRequest
*
pClientRequest
=
pMsg
->
pCont
;
pClientRequest
->
bytes
=
bytes
;
pClientRequest
->
vgId
=
vgId
;
pClientRequest
->
msgType
=
TDMT_SYNC_CLIENT_REQUEST
;
pClientRequest
->
originalRpcType
=
pOriginal
RpcMsg
->
msgType
;
pClientRequest
->
originalRpcType
=
pOriginal
->
msgType
;
pClientRequest
->
seqNum
=
seqNum
;
pClientRequest
->
isWeak
=
isWeak
;
pClientRequest
->
dataLen
=
pOriginal
RpcMsg
->
contLen
;
memcpy
(
pClientRequest
->
data
,
(
char
*
)
pOriginal
RpcMsg
->
pCont
,
pOriginalRpcMsg
->
contLen
);
pClientRequest
->
dataLen
=
pOriginal
->
contLen
;
memcpy
(
pClientRequest
->
data
,
(
char
*
)
pOriginal
->
pCont
,
pOriginal
->
contLen
);
return
0
;
}
int32_t
sync
ClientRequestBuildFromNoopEntry
(
SRpcMsg
*
pClientRequestRpc
Msg
,
const
SSyncRaftEntry
*
pEntry
,
int32_t
vgId
)
{
int32_t
sync
BuildClientRequestFromNoopEntry
(
SRpcMsg
*
p
Msg
,
const
SSyncRaftEntry
*
pEntry
,
int32_t
vgId
)
{
int32_t
bytes
=
sizeof
(
SyncClientRequest
)
+
pEntry
->
bytes
;
p
ClientRequestRpc
Msg
->
pCont
=
rpcMallocCont
(
bytes
);
p
ClientRequestRpc
Msg
->
msgType
=
TDMT_SYNC_CLIENT_REQUEST
;
p
ClientRequestRpc
Msg
->
contLen
=
bytes
;
if
(
p
ClientRequestRpc
Msg
->
pCont
==
NULL
)
{
pMsg
->
pCont
=
rpcMallocCont
(
bytes
);
pMsg
->
msgType
=
TDMT_SYNC_CLIENT_REQUEST
;
pMsg
->
contLen
=
bytes
;
if
(
pMsg
->
pCont
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
SyncClientRequest
*
pClientRequest
=
p
ClientRequestRpc
Msg
->
pCont
;
SyncClientRequest
*
pClientRequest
=
pMsg
->
pCont
;
pClientRequest
->
bytes
=
bytes
;
pClientRequest
->
vgId
=
vgId
;
pClientRequest
->
msgType
=
TDMT_SYNC_CLIENT_REQUEST
;
...
...
source/libs/sync/test/syncRpcMsgTest.cpp
浏览文件 @
94076e59
...
...
@@ -45,7 +45,7 @@ SyncClientRequest *createSyncClientRequest() {
strcpy
((
char
*
)
rpcMsg
.
pCont
,
"hello rpc"
);
SRpcMsg
clientRequestMsg
;
sync
ClientRequestBuildFromRpcMsg
(
&
clientRequestMsg
,
&
rpcMsg
,
123
,
true
,
1000
);
sync
BuildClientRequest
(
&
clientRequestMsg
,
&
rpcMsg
,
123
,
true
,
1000
);
SyncClientRequest
*
pMsg
=
(
SyncClientRequest
*
)
taosMemoryMalloc
(
clientRequestMsg
.
contLen
);
memcpy
(
pMsg
->
data
,
clientRequestMsg
.
pCont
,
clientRequestMsg
.
contLen
);
return
pMsg
;
...
...
source/libs/sync/test/syncSnapshotTest.cpp
浏览文件 @
94076e59
...
...
@@ -154,7 +154,7 @@ SRpcMsg *step0() {
SyncClientRequest
*
step1
(
const
SRpcMsg
*
pMsg
)
{
SRpcMsg
clientRequestMsg
;
sync
ClientRequestBuildFromRpcMsg
(
&
clientRequestMsg
,
pMsg
,
123
,
true
,
1000
);
sync
BuildClientRequest
(
&
clientRequestMsg
,
pMsg
,
123
,
true
,
1000
);
SyncClientRequest
*
pMsg2
=
(
SyncClientRequest
*
)
taosMemoryMalloc
(
clientRequestMsg
.
contLen
);
memcpy
(
pMsg2
->
data
,
clientRequestMsg
.
pCont
,
clientRequestMsg
.
contLen
);
return
pMsg2
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录