Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
b69a2667
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
b69a2667
编写于
5月 12, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh(sync): raft config change
上级
7c41d529
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
107 addition
and
7 deletion
+107
-7
include/common/tmsgdef.h
include/common/tmsgdef.h
+1
-0
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+1
-0
source/libs/sync/inc/syncUtil.h
source/libs/sync/inc/syncUtil.h
+5
-0
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+18
-4
source/libs/sync/src/syncCommit.c
source/libs/sync/src/syncCommit.c
+12
-1
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+42
-2
source/libs/sync/src/syncUtil.c
source/libs/sync/src/syncUtil.c
+28
-0
未找到文件。
include/common/tmsgdef.h
浏览文件 @
b69a2667
...
...
@@ -217,6 +217,7 @@ enum {
TD_DEF_MSG_TYPE
(
TDMT_VND_SYNC_UNKNOWN
,
"vnode-sync-unknown"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_VND_SYNC_COMMON_RESPONSE
,
"vnode-sync-common-response"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_VND_SYNC_APPLY_MSG
,
"vnode-sync-apply-msg"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_VND_SYNC_CONFIG_CHANGE
,
"vnode-sync-config-change"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_VND_SYNC_VNODE
,
"vnode-sync-vnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_VND_ALTER_VNODE
,
"vnode-alter-vnode"
,
NULL
,
NULL
)
...
...
source/libs/sync/inc/syncInt.h
浏览文件 @
b69a2667
...
...
@@ -271,6 +271,7 @@ int32_t syncNodeSendMsgByInfo(const SNodeInfo* nodeInfo, SSyncNode* pSyncNode, S
cJSON
*
syncNode2Json
(
const
SSyncNode
*
pSyncNode
);
char
*
syncNode2Str
(
const
SSyncNode
*
pSyncNode
);
char
*
syncNode2SimpleStr
(
const
SSyncNode
*
pSyncNode
);
void
syncNodeUpdateConfig
(
SSyncNode
*
pSyncNode
,
SSyncCfg
*
newConfig
);
SSyncNode
*
syncNodeAcquire
(
int64_t
rid
);
void
syncNodeRelease
(
SSyncNode
*
pNode
);
...
...
source/libs/sync/inc/syncUtil.h
浏览文件 @
b69a2667
...
...
@@ -57,6 +57,11 @@ SyncIndex syncUtilMinIndex(SyncIndex a, SyncIndex b);
SyncIndex
syncUtilMaxIndex
(
SyncIndex
a
,
SyncIndex
b
);
void
syncUtilMsgHtoN
(
void
*
msg
);
void
syncUtilMsgNtoH
(
void
*
msg
);
bool
syncUtilIsData
(
tmsg_t
msgType
);
bool
syncUtilUserPreCommit
(
tmsg_t
msgType
);
bool
syncUtilUserCommit
(
tmsg_t
msgType
);
bool
syncUtilUserRollback
(
tmsg_t
msgType
);
#ifdef __cplusplus
}
...
...
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
b69a2667
...
...
@@ -19,6 +19,7 @@
#include "syncRaftStore.h"
#include "syncUtil.h"
#include "syncVoteMgr.h"
#include "syncRaftCfg.h"
// TLA+ Spec
// HandleAppendEntriesRequest(i, j, m) ==
...
...
@@ -199,7 +200,8 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
SSyncRaftEntry
*
pRollBackEntry
=
logStoreGetEntry
(
ths
->
pLogStore
,
index
);
assert
(
pRollBackEntry
!=
NULL
);
if
(
pRollBackEntry
->
msgType
!=
TDMT_VND_SYNC_NOOP
)
{
//if (pRollBackEntry->msgType != TDMT_VND_SYNC_NOOP) {
if
(
syncUtilUserRollback
(
pRollBackEntry
->
msgType
))
{
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pRollBackEntry
,
&
rpcMsg
);
...
...
@@ -227,7 +229,8 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pAppendEntry
,
&
rpcMsg
);
if
(
ths
->
pFsm
!=
NULL
)
{
if
(
ths
->
pFsm
->
FpPreCommitCb
!=
NULL
&&
pAppendEntry
->
originalRpcType
!=
TDMT_VND_SYNC_NOOP
)
{
//if (ths->pFsm->FpPreCommitCb != NULL && pAppendEntry->originalRpcType != TDMT_VND_SYNC_NOOP) {
if
(
ths
->
pFsm
->
FpPreCommitCb
!=
NULL
&&
syncUtilUserPreCommit
(
pAppendEntry
->
originalRpcType
))
{
SFsmCbMeta
cbMeta
;
cbMeta
.
index
=
pAppendEntry
->
index
;
cbMeta
.
isWeak
=
pAppendEntry
->
isWeak
;
...
...
@@ -258,7 +261,8 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pAppendEntry
,
&
rpcMsg
);
if
(
ths
->
pFsm
!=
NULL
)
{
if
(
ths
->
pFsm
->
FpPreCommitCb
!=
NULL
&&
pAppendEntry
->
originalRpcType
!=
TDMT_VND_SYNC_NOOP
)
{
//if (ths->pFsm->FpPreCommitCb != NULL && pAppendEntry->originalRpcType != TDMT_VND_SYNC_NOOP) {
if
(
ths
->
pFsm
->
FpPreCommitCb
!=
NULL
&&
syncUtilUserPreCommit
(
pAppendEntry
->
originalRpcType
))
{
SFsmCbMeta
cbMeta
;
cbMeta
.
index
=
pAppendEntry
->
index
;
cbMeta
.
isWeak
=
pAppendEntry
->
isWeak
;
...
...
@@ -320,7 +324,8 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pEntry
,
&
rpcMsg
);
if
(
ths
->
pFsm
->
FpCommitCb
!=
NULL
&&
pEntry
->
originalRpcType
!=
TDMT_VND_SYNC_NOOP
)
{
//if (ths->pFsm->FpCommitCb != NULL && pEntry->originalRpcType != TDMT_VND_SYNC_NOOP) {
if
(
ths
->
pFsm
->
FpCommitCb
!=
NULL
&&
syncUtilUserCommit
(
pEntry
->
originalRpcType
))
{
SFsmCbMeta
cbMeta
;
cbMeta
.
index
=
pEntry
->
index
;
cbMeta
.
isWeak
=
pEntry
->
isWeak
;
...
...
@@ -330,6 +335,15 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
ths
->
pFsm
->
FpCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
cbMeta
);
}
// config change
if
(
pEntry
->
originalRpcType
==
TDMT_VND_SYNC_CONFIG_CHANGE
)
{
SSyncCfg
newSyncCfg
;
int32_t
ret
=
syncCfgFromStr
(
rpcMsg
.
pCont
,
&
newSyncCfg
);
ASSERT
(
ret
==
0
);
syncNodeUpdateConfig
(
ths
,
&
newSyncCfg
);
}
rpcFreeCont
(
rpcMsg
.
pCont
);
syncEntryDestory
(
pEntry
);
}
...
...
source/libs/sync/src/syncCommit.c
浏览文件 @
b69a2667
...
...
@@ -19,6 +19,7 @@
#include "syncRaftLog.h"
#include "syncRaftStore.h"
#include "syncUtil.h"
#include "syncRaftCfg.h"
// \* Leader i advances its commitIndex.
// \* This is done as a separate step from handling AppendEntries responses,
...
...
@@ -101,7 +102,8 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pEntry
,
&
rpcMsg
);
if
(
pSyncNode
->
pFsm
->
FpCommitCb
!=
NULL
&&
pEntry
->
originalRpcType
!=
TDMT_VND_SYNC_NOOP
)
{
//if (pSyncNode->pFsm->FpCommitCb != NULL && pEntry->originalRpcType != TDMT_VND_SYNC_NOOP) {
if
(
pSyncNode
->
pFsm
->
FpCommitCb
!=
NULL
&&
syncUtilUserCommit
(
pEntry
->
originalRpcType
))
{
SFsmCbMeta
cbMeta
;
cbMeta
.
index
=
pEntry
->
index
;
cbMeta
.
isWeak
=
pEntry
->
isWeak
;
...
...
@@ -111,6 +113,15 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
pSyncNode
->
pFsm
->
FpCommitCb
(
pSyncNode
->
pFsm
,
&
rpcMsg
,
cbMeta
);
}
// config change
if
(
pEntry
->
originalRpcType
==
TDMT_VND_SYNC_CONFIG_CHANGE
)
{
SSyncCfg
newSyncCfg
;
int32_t
ret
=
syncCfgFromStr
(
rpcMsg
.
pCont
,
&
newSyncCfg
);
ASSERT
(
ret
==
0
);
syncNodeUpdateConfig
(
pSyncNode
,
&
newSyncCfg
);
}
rpcFreeCont
(
rpcMsg
.
pCont
);
syncEntryDestory
(
pEntry
);
}
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
b69a2667
...
...
@@ -116,6 +116,15 @@ void syncStop(int64_t rid) {
int32_t
syncReconfig
(
int64_t
rid
,
const
SSyncCfg
*
pSyncCfg
)
{
int32_t
ret
=
0
;
char
*
configChange
=
syncCfg2Str
((
SSyncCfg
*
)
pSyncCfg
);
SRpcMsg
rpcMsg
=
{
0
};
rpcMsg
.
msgType
=
TDMT_VND_SYNC_CONFIG_CHANGE
;
rpcMsg
.
noResp
=
1
;
rpcMsg
.
contLen
=
strlen
(
configChange
)
+
1
;
rpcMsg
.
pCont
=
rpcMallocCont
(
rpcMsg
.
contLen
);
snprintf
(
rpcMsg
.
pCont
,
rpcMsg
.
contLen
,
"%s"
,
configChange
);
taosMemoryFree
(
configChange
);
ret
=
syncPropose
(
rid
,
&
rpcMsg
,
false
);
return
ret
;
}
...
...
@@ -849,6 +858,35 @@ char* syncNode2SimpleStr(const SSyncNode* pSyncNode) {
return
s
;
}
void
syncNodeUpdateConfig
(
SSyncNode
*
pSyncNode
,
SSyncCfg
*
newConfig
)
{
pSyncNode
->
pRaftCfg
->
cfg
=
*
newConfig
;
int32_t
ret
=
raftCfgPersist
(
pSyncNode
->
pRaftCfg
);
ASSERT
(
ret
==
0
);
// init internal
pSyncNode
->
myNodeInfo
=
pSyncNode
->
pRaftCfg
->
cfg
.
nodeInfo
[
pSyncNode
->
pRaftCfg
->
cfg
.
myIndex
];
syncUtilnodeInfo2raftId
(
&
pSyncNode
->
myNodeInfo
,
pSyncNode
->
vgId
,
&
pSyncNode
->
myRaftId
);
// init peersNum, peers, peersId
pSyncNode
->
peersNum
=
pSyncNode
->
pRaftCfg
->
cfg
.
replicaNum
-
1
;
int
j
=
0
;
for
(
int
i
=
0
;
i
<
pSyncNode
->
pRaftCfg
->
cfg
.
replicaNum
;
++
i
)
{
if
(
i
!=
pSyncNode
->
pRaftCfg
->
cfg
.
myIndex
)
{
pSyncNode
->
peersNodeInfo
[
j
]
=
pSyncNode
->
pRaftCfg
->
cfg
.
nodeInfo
[
i
];
j
++
;
}
}
for
(
int
i
=
0
;
i
<
pSyncNode
->
peersNum
;
++
i
)
{
syncUtilnodeInfo2raftId
(
&
pSyncNode
->
peersNodeInfo
[
i
],
pSyncNode
->
vgId
,
&
pSyncNode
->
peersId
[
i
]);
}
// init replicaNum, replicasId
pSyncNode
->
replicaNum
=
pSyncNode
->
pRaftCfg
->
cfg
.
replicaNum
;
for
(
int
i
=
0
;
i
<
pSyncNode
->
pRaftCfg
->
cfg
.
replicaNum
;
++
i
)
{
syncUtilnodeInfo2raftId
(
&
pSyncNode
->
pRaftCfg
->
cfg
.
nodeInfo
[
i
],
pSyncNode
->
vgId
,
&
pSyncNode
->
replicasId
[
i
]);
}
}
SSyncNode
*
syncNodeAcquire
(
int64_t
rid
)
{
SSyncNode
*
pNode
=
taosAcquireRef
(
tsNodeRefId
,
rid
);
if
(
pNode
==
NULL
)
{
...
...
@@ -1207,7 +1245,8 @@ int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg) {
syncEntry2OriginalRpc
(
pEntry
,
&
rpcMsg
);
if
(
ths
->
pFsm
!=
NULL
)
{
if
(
ths
->
pFsm
->
FpPreCommitCb
!=
NULL
&&
pEntry
->
originalRpcType
!=
TDMT_VND_SYNC_NOOP
)
{
//if (ths->pFsm->FpPreCommitCb != NULL && pEntry->originalRpcType != TDMT_VND_SYNC_NOOP) {
if
(
ths
->
pFsm
->
FpPreCommitCb
!=
NULL
&&
syncUtilUserPreCommit
(
pEntry
->
originalRpcType
))
{
SFsmCbMeta
cbMeta
;
cbMeta
.
index
=
pEntry
->
index
;
cbMeta
.
isWeak
=
pEntry
->
isWeak
;
...
...
@@ -1228,7 +1267,8 @@ int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg) {
syncEntry2OriginalRpc
(
pEntry
,
&
rpcMsg
);
if
(
ths
->
pFsm
!=
NULL
)
{
if
(
ths
->
pFsm
->
FpPreCommitCb
!=
NULL
&&
pEntry
->
originalRpcType
!=
TDMT_VND_SYNC_NOOP
)
{
//if (ths->pFsm->FpPreCommitCb != NULL && pEntry->originalRpcType != TDMT_VND_SYNC_NOOP) {
if
(
ths
->
pFsm
->
FpPreCommitCb
!=
NULL
&&
syncUtilUserPreCommit
(
pEntry
->
originalRpcType
))
{
SFsmCbMeta
cbMeta
;
cbMeta
.
index
=
pEntry
->
index
;
cbMeta
.
isWeak
=
pEntry
->
isWeak
;
...
...
source/libs/sync/src/syncUtil.c
浏览文件 @
b69a2667
...
...
@@ -212,4 +212,32 @@ void syncUtilMsgNtoH(void* msg) {
SMsgHead
*
pHead
=
msg
;
pHead
->
contLen
=
ntohl
(
pHead
->
contLen
);
pHead
->
vgId
=
ntohl
(
pHead
->
vgId
);
}
bool
syncUtilIsData
(
tmsg_t
msgType
)
{
if
(
msgType
==
TDMT_VND_SYNC_NOOP
||
msgType
==
TDMT_VND_SYNC_CONFIG_CHANGE
)
{
return
false
;
}
return
true
;
}
bool
syncUtilUserPreCommit
(
tmsg_t
msgType
)
{
if
(
msgType
!=
TDMT_VND_SYNC_NOOP
&&
msgType
!=
TDMT_VND_SYNC_CONFIG_CHANGE
)
{
return
true
;
}
return
false
;
}
bool
syncUtilUserCommit
(
tmsg_t
msgType
)
{
if
(
msgType
!=
TDMT_VND_SYNC_NOOP
&&
msgType
!=
TDMT_VND_SYNC_CONFIG_CHANGE
)
{
return
true
;
}
return
false
;
}
bool
syncUtilUserRollback
(
tmsg_t
msgType
)
{
if
(
msgType
!=
TDMT_VND_SYNC_NOOP
&&
msgType
!=
TDMT_VND_SYNC_CONFIG_CHANGE
)
{
return
true
;
}
return
false
;
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录