Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f556d981
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
f556d981
编写于
3月 08, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sync refactor
上级
c9c48e87
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
22 addition
and
21 deletion
+22
-21
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+3
-3
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+18
-17
source/libs/sync/test/syncEnqTest.cpp
source/libs/sync/test/syncEnqTest.cpp
+1
-1
未找到文件。
source/libs/sync/inc/syncInt.h
浏览文件 @
f556d981
...
@@ -120,11 +120,11 @@ typedef struct SSyncNode {
...
@@ -120,11 +120,11 @@ typedef struct SSyncNode {
int32_t
(
*
FpEqMsg
)(
void
*
queue
,
SRpcMsg
*
pMsg
);
int32_t
(
*
FpEqMsg
)(
void
*
queue
,
SRpcMsg
*
pMsg
);
// init internal
// init internal
SNodeInfo
m
e
;
SNodeInfo
m
yNodeInfo
;
SRaftId
r
aftId
;
SRaftId
myR
aftId
;
int32_t
peersNum
;
int32_t
peersNum
;
SNodeInfo
peers
[
TSDB_MAX_REPLICA
];
SNodeInfo
peers
NodeInfo
[
TSDB_MAX_REPLICA
];
SRaftId
peersId
[
TSDB_MAX_REPLICA
];
SRaftId
peersId
[
TSDB_MAX_REPLICA
];
int32_t
replicaNum
;
int32_t
replicaNum
;
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
f556d981
...
@@ -85,20 +85,20 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) {
...
@@ -85,20 +85,20 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) {
pSyncNode
->
FpEqMsg
=
pSyncInfo
->
FpEqMsg
;
pSyncNode
->
FpEqMsg
=
pSyncInfo
->
FpEqMsg
;
// init internal
// init internal
pSyncNode
->
m
e
=
pSyncInfo
->
syncCfg
.
nodeInfo
[
pSyncInfo
->
syncCfg
.
myIndex
];
pSyncNode
->
m
yNodeInfo
=
pSyncInfo
->
syncCfg
.
nodeInfo
[
pSyncInfo
->
syncCfg
.
myIndex
];
syncUtilnodeInfo2raftId
(
&
pSyncNode
->
m
e
,
pSyncInfo
->
vgId
,
&
pSyncNode
->
r
aftId
);
syncUtilnodeInfo2raftId
(
&
pSyncNode
->
m
yNodeInfo
,
pSyncInfo
->
vgId
,
&
pSyncNode
->
myR
aftId
);
// init peersNum, peers, peersId
// init peersNum, peers, peersId
pSyncNode
->
peersNum
=
pSyncInfo
->
syncCfg
.
replicaNum
-
1
;
pSyncNode
->
peersNum
=
pSyncInfo
->
syncCfg
.
replicaNum
-
1
;
int
j
=
0
;
int
j
=
0
;
for
(
int
i
=
0
;
i
<
pSyncInfo
->
syncCfg
.
replicaNum
;
++
i
)
{
for
(
int
i
=
0
;
i
<
pSyncInfo
->
syncCfg
.
replicaNum
;
++
i
)
{
if
(
i
!=
pSyncInfo
->
syncCfg
.
myIndex
)
{
if
(
i
!=
pSyncInfo
->
syncCfg
.
myIndex
)
{
pSyncNode
->
peers
[
j
]
=
pSyncInfo
->
syncCfg
.
nodeInfo
[
i
];
pSyncNode
->
peers
NodeInfo
[
j
]
=
pSyncInfo
->
syncCfg
.
nodeInfo
[
i
];
j
++
;
j
++
;
}
}
}
}
for
(
int
i
=
0
;
i
<
pSyncNode
->
peersNum
;
++
i
)
{
for
(
int
i
=
0
;
i
<
pSyncNode
->
peersNum
;
++
i
)
{
syncUtilnodeInfo2raftId
(
&
pSyncNode
->
peers
[
i
],
pSyncInfo
->
vgId
,
&
pSyncNode
->
peersId
[
i
]);
syncUtilnodeInfo2raftId
(
&
pSyncNode
->
peers
NodeInfo
[
i
],
pSyncInfo
->
vgId
,
&
pSyncNode
->
peersId
[
i
]);
}
}
// init replicaNum, replicasId
// init replicaNum, replicasId
...
@@ -190,16 +190,16 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
...
@@ -190,16 +190,16 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
cJSON_AddStringToObject
(
pRoot
,
"FpEqMsg"
,
u64buf
);
cJSON_AddStringToObject
(
pRoot
,
"FpEqMsg"
,
u64buf
);
// init internal
// init internal
cJSON
*
pMe
=
syncUtilNodeInfo2Json
(
&
pSyncNode
->
m
e
);
cJSON
*
pMe
=
syncUtilNodeInfo2Json
(
&
pSyncNode
->
m
yNodeInfo
);
cJSON_AddItemToObject
(
pRoot
,
"m
e
"
,
pMe
);
cJSON_AddItemToObject
(
pRoot
,
"m
yNodeInfo
"
,
pMe
);
cJSON
*
pRaftId
=
syncUtilRaftId2Json
(
&
pSyncNode
->
r
aftId
);
cJSON
*
pRaftId
=
syncUtilRaftId2Json
(
&
pSyncNode
->
myR
aftId
);
cJSON_AddItemToObject
(
pRoot
,
"
r
aftId"
,
pRaftId
);
cJSON_AddItemToObject
(
pRoot
,
"
myR
aftId"
,
pRaftId
);
cJSON_AddNumberToObject
(
pRoot
,
"peersNum"
,
pSyncNode
->
peersNum
);
cJSON_AddNumberToObject
(
pRoot
,
"peersNum"
,
pSyncNode
->
peersNum
);
cJSON
*
pPeers
=
cJSON_CreateArray
();
cJSON
*
pPeers
=
cJSON_CreateArray
();
cJSON_AddItemToObject
(
pRoot
,
"peers"
,
pPeers
);
cJSON_AddItemToObject
(
pRoot
,
"peers
NodeInfo
"
,
pPeers
);
for
(
int
i
=
0
;
i
<
pSyncNode
->
peersNum
;
++
i
)
{
for
(
int
i
=
0
;
i
<
pSyncNode
->
peersNum
;
++
i
)
{
cJSON_AddItemToArray
(
pPeers
,
syncUtilNodeInfo2Json
(
&
pSyncNode
->
peers
[
i
]));
cJSON_AddItemToArray
(
pPeers
,
syncUtilNodeInfo2Json
(
&
pSyncNode
->
peers
NodeInfo
[
i
]));
}
}
cJSON
*
pPeersId
=
cJSON_CreateArray
();
cJSON
*
pPeersId
=
cJSON_CreateArray
();
cJSON_AddItemToObject
(
pRoot
,
"peersId"
,
pPeersId
);
cJSON_AddItemToObject
(
pRoot
,
"peersId"
,
pPeersId
);
...
@@ -222,7 +222,8 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
...
@@ -222,7 +222,8 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
cJSON_AddItemToObject
(
pRoot
,
"leaderCache"
,
pLaderCache
);
cJSON_AddItemToObject
(
pRoot
,
"leaderCache"
,
pLaderCache
);
// tla+ server vars
// tla+ server vars
cJSON_AddStringToObject
(
pRoot
,
"state"
,
syncUtilState2String
(
pSyncNode
->
state
));
cJSON_AddNumberToObject
(
pRoot
,
"state"
,
pSyncNode
->
state
);
cJSON_AddStringToObject
(
pRoot
,
"state_str"
,
syncUtilState2String
(
pSyncNode
->
state
));
// tla+ candidate vars
// tla+ candidate vars
...
@@ -283,7 +284,7 @@ int32_t syncNodePingAll(SSyncNode* pSyncNode) {
...
@@ -283,7 +284,7 @@ int32_t syncNodePingAll(SSyncNode* pSyncNode) {
for
(
int
i
=
0
;
i
<
pSyncNode
->
syncCfg
.
replicaNum
;
++
i
)
{
for
(
int
i
=
0
;
i
<
pSyncNode
->
syncCfg
.
replicaNum
;
++
i
)
{
SRaftId
destId
;
SRaftId
destId
;
syncUtilnodeInfo2raftId
(
&
pSyncNode
->
syncCfg
.
nodeInfo
[
i
],
pSyncNode
->
vgId
,
&
destId
);
syncUtilnodeInfo2raftId
(
&
pSyncNode
->
syncCfg
.
nodeInfo
[
i
],
pSyncNode
->
vgId
,
&
destId
);
SyncPing
*
pMsg
=
syncPingBuild3
(
&
pSyncNode
->
r
aftId
,
&
destId
);
SyncPing
*
pMsg
=
syncPingBuild3
(
&
pSyncNode
->
myR
aftId
,
&
destId
);
ret
=
syncNodePing
(
pSyncNode
,
&
destId
,
pMsg
);
ret
=
syncNodePing
(
pSyncNode
,
&
destId
,
pMsg
);
assert
(
ret
==
0
);
assert
(
ret
==
0
);
syncPingDestroy
(
pMsg
);
syncPingDestroy
(
pMsg
);
...
@@ -294,8 +295,8 @@ int32_t syncNodePingPeers(SSyncNode* pSyncNode) {
...
@@ -294,8 +295,8 @@ int32_t syncNodePingPeers(SSyncNode* pSyncNode) {
int32_t
ret
=
0
;
int32_t
ret
=
0
;
for
(
int
i
=
0
;
i
<
pSyncNode
->
peersNum
;
++
i
)
{
for
(
int
i
=
0
;
i
<
pSyncNode
->
peersNum
;
++
i
)
{
SRaftId
destId
;
SRaftId
destId
;
syncUtilnodeInfo2raftId
(
&
pSyncNode
->
peers
[
i
],
pSyncNode
->
vgId
,
&
destId
);
syncUtilnodeInfo2raftId
(
&
pSyncNode
->
peers
NodeInfo
[
i
],
pSyncNode
->
vgId
,
&
destId
);
SyncPing
*
pMsg
=
syncPingBuild3
(
&
pSyncNode
->
r
aftId
,
&
destId
);
SyncPing
*
pMsg
=
syncPingBuild3
(
&
pSyncNode
->
myR
aftId
,
&
destId
);
ret
=
syncNodePing
(
pSyncNode
,
&
destId
,
pMsg
);
ret
=
syncNodePing
(
pSyncNode
,
&
destId
,
pMsg
);
assert
(
ret
==
0
);
assert
(
ret
==
0
);
syncPingDestroy
(
pMsg
);
syncPingDestroy
(
pMsg
);
...
@@ -304,7 +305,7 @@ int32_t syncNodePingPeers(SSyncNode* pSyncNode) {
...
@@ -304,7 +305,7 @@ int32_t syncNodePingPeers(SSyncNode* pSyncNode) {
int32_t
syncNodePingSelf
(
SSyncNode
*
pSyncNode
)
{
int32_t
syncNodePingSelf
(
SSyncNode
*
pSyncNode
)
{
int32_t
ret
;
int32_t
ret
;
SyncPing
*
pMsg
=
syncPingBuild3
(
&
pSyncNode
->
raftId
,
&
pSyncNode
->
r
aftId
);
SyncPing
*
pMsg
=
syncPingBuild3
(
&
pSyncNode
->
myRaftId
,
&
pSyncNode
->
myR
aftId
);
ret
=
syncNodePing
(
pSyncNode
,
&
pMsg
->
destId
,
pMsg
);
ret
=
syncNodePing
(
pSyncNode
,
&
pMsg
->
destId
,
pMsg
);
assert
(
ret
==
0
);
assert
(
ret
==
0
);
syncPingDestroy
(
pMsg
);
syncPingDestroy
(
pMsg
);
...
@@ -385,7 +386,7 @@ static int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg) {
...
@@ -385,7 +386,7 @@ static int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg) {
cJSON_Delete
(
pJson
);
cJSON_Delete
(
pJson
);
}
}
SyncPingReply
*
pMsgReply
=
syncPingReplyBuild3
(
&
ths
->
r
aftId
,
&
pMsg
->
srcId
);
SyncPingReply
*
pMsgReply
=
syncPingReplyBuild3
(
&
ths
->
myR
aftId
,
&
pMsg
->
srcId
);
SRpcMsg
rpcMsg
;
SRpcMsg
rpcMsg
;
syncPingReply2RpcMsg
(
pMsgReply
,
&
rpcMsg
);
syncPingReply2RpcMsg
(
pMsgReply
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
pMsgReply
->
destId
,
ths
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
pMsgReply
->
destId
,
ths
,
&
rpcMsg
);
...
@@ -485,7 +486,7 @@ static void syncNodeBecomeFollower(SSyncNode* pSyncNode) {
...
@@ -485,7 +486,7 @@ static void syncNodeBecomeFollower(SSyncNode* pSyncNode) {
//
//
static
void
syncNodeBecomeLeader
(
SSyncNode
*
pSyncNode
)
{
static
void
syncNodeBecomeLeader
(
SSyncNode
*
pSyncNode
)
{
pSyncNode
->
state
=
TAOS_SYNC_STATE_LEADER
;
pSyncNode
->
state
=
TAOS_SYNC_STATE_LEADER
;
pSyncNode
->
leaderCache
=
pSyncNode
->
r
aftId
;
pSyncNode
->
leaderCache
=
pSyncNode
->
myR
aftId
;
// next Index +=1
// next Index +=1
// match Index = 0;
// match Index = 0;
...
...
source/libs/sync/test/syncEnqTest.cpp
浏览文件 @
f556d981
...
@@ -84,7 +84,7 @@ int main(int argc, char** argv) {
...
@@ -84,7 +84,7 @@ int main(int argc, char** argv) {
gSyncIO
->
FpOnSyncPingReply
=
pSyncNode
->
FpOnPingReply
;
gSyncIO
->
FpOnSyncPingReply
=
pSyncNode
->
FpOnPingReply
;
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
SyncPingReply
*
pSyncMsg
=
syncPingReplyBuild3
(
&
pSyncNode
->
raftId
,
&
pSyncNode
->
r
aftId
);
SyncPingReply
*
pSyncMsg
=
syncPingReplyBuild3
(
&
pSyncNode
->
myRaftId
,
&
pSyncNode
->
myR
aftId
);
SRpcMsg
rpcMsg
;
SRpcMsg
rpcMsg
;
syncPingReply2RpcMsg
(
pSyncMsg
,
&
rpcMsg
);
syncPingReply2RpcMsg
(
pSyncMsg
,
&
rpcMsg
);
pSyncNode
->
FpEqMsg
(
pSyncNode
->
queue
,
&
rpcMsg
);
pSyncNode
->
FpEqMsg
(
pSyncNode
->
queue
,
&
rpcMsg
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录