Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
6b329f79
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
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看板
提交
6b329f79
编写于
6月 06, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh(sync): update raft core functions
上级
af27303a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
27 addition
and
35 deletion
+27
-35
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+0
-2
source/libs/sync/src/syncAppendEntriesReply.c
source/libs/sync/src/syncAppendEntriesReply.c
+22
-1
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+1
-17
source/libs/sync/src/syncSnapshot.c
source/libs/sync/src/syncSnapshot.c
+4
-15
未找到文件。
source/libs/sync/inc/syncInt.h
浏览文件 @
6b329f79
...
...
@@ -152,11 +152,9 @@ typedef struct SSyncNode {
SSyncRespMgr
*
pSyncRespMgr
;
// restore state
// sem_t restoreSem;
bool
restoreFinish
;
// SSnapshot* pSnapshot;
SSyncSnapshotSender
*
senders
[
TSDB_MAX_REPLICA
];
SSyncSnapshotReceiver
*
receivers
[
TSDB_MAX_REPLICA
];
SSyncSnapshotReceiver
*
pNewNodeReceiver
;
}
SSyncNode
;
...
...
source/libs/sync/src/syncAppendEntriesReply.c
浏览文件 @
6b329f79
...
...
@@ -19,6 +19,7 @@
#include "syncInt.h"
#include "syncRaftLog.h"
#include "syncRaftStore.h"
#include "syncSnapshot.h"
#include "syncUtil.h"
#include "syncVoteMgr.h"
...
...
@@ -137,7 +138,9 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries
syncIndexMgrSetIndex
(
ths
->
pMatchIndex
,
&
(
pMsg
->
srcId
),
pMsg
->
matchIndex
);
// maybe commit
syncMaybeAdvanceCommitIndex
(
ths
);
if
(
ths
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
syncMaybeAdvanceCommitIndex
(
ths
);
}
}
else
{
SyncIndex
nextIndex
=
syncIndexMgrGetIndex
(
ths
->
pNextIndex
,
&
(
pMsg
->
srcId
));
...
...
@@ -151,8 +154,26 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries
SSnapshot
snapshot
;
ths
->
pFsm
->
FpGetSnapshot
(
ths
->
pFsm
,
&
snapshot
);
if
(
nextIndex
<=
snapshot
.
lastApplyIndex
)
{
ASSERT
(
nextIndex
==
snapshot
.
lastApplyIndex
);
nextIndex
=
snapshot
.
lastApplyIndex
+
1
;
sInfo
(
"reset new nextIndex %ld, snapshot.lastApplyIndex:%ld"
,
nextIndex
,
snapshot
.
lastApplyIndex
);
// start send snapshot
// get sender
SSyncSnapshotSender
*
pSender
=
NULL
;
for
(
int
i
=
0
;
i
<
ths
->
replicaNum
;
++
i
)
{
if
(
syncUtilSameId
(
&
(
pMsg
->
srcId
),
&
((
ths
->
replicasId
)[
i
])))
{
pSender
=
(
ths
->
senders
)[
i
];
}
}
ASSERT
(
pSender
!=
NULL
);
if
(
!
(
pSender
->
term
==
ths
->
pRaftStore
->
currentTerm
&&
pSender
->
finish
==
true
))
{
snapshotSenderStart
(
pSender
);
}
else
{
sInfo
(
"snapshot send finish, send_term:%lu, current_term:%lu"
,
pSender
->
term
,
ths
->
pRaftStore
->
currentTerm
);
}
}
}
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
6b329f79
...
...
@@ -598,12 +598,6 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) {
}
// snapshot receivers
for
(
int
i
=
0
;
i
<
TSDB_MAX_REPLICA
;
++
i
)
{
SSyncSnapshotReceiver
*
pReceiver
=
snapshotReceiverCreate
(
pSyncNode
,
i
);
// ASSERT(pReceiver != NULL);
(
pSyncNode
->
receivers
)[
i
]
=
pReceiver
;
}
pSyncNode
->
pNewNodeReceiver
=
snapshotReceiverCreate
(
pSyncNode
,
100
);
// start in syncNodeStart
...
...
@@ -705,13 +699,6 @@ void syncNodeClose(SSyncNode* pSyncNode) {
}
}
for
(
int
i
=
0
;
i
<
TSDB_MAX_REPLICA
;
++
i
)
{
if
((
pSyncNode
->
receivers
)[
i
]
!=
NULL
)
{
snapshotReceiverDestroy
((
pSyncNode
->
receivers
)[
i
]);
(
pSyncNode
->
receivers
)[
i
]
=
NULL
;
}
}
if
(
pSyncNode
->
pNewNodeReceiver
!=
NULL
)
{
snapshotReceiverDestroy
(
pSyncNode
->
pNewNodeReceiver
);
pSyncNode
->
pNewNodeReceiver
=
NULL
;
...
...
@@ -1025,10 +1012,7 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
// snapshot receivers
cJSON
*
pReceivers
=
cJSON_CreateArray
();
cJSON_AddItemToObject
(
pRoot
,
"receivers"
,
pReceivers
);
for
(
int
i
=
0
;
i
<
TSDB_MAX_REPLICA
;
++
i
)
{
cJSON_AddItemToArray
(
pReceivers
,
snapshotReceiver2Json
((
pSyncNode
->
receivers
)[
i
]));
}
cJSON_AddItemToObject
(
pRoot
,
"receiver"
,
snapshotReceiver2Json
(
pSyncNode
->
pNewNodeReceiver
));
}
cJSON
*
pJson
=
cJSON_CreateObject
();
...
...
source/libs/sync/src/syncSnapshot.c
浏览文件 @
6b329f79
...
...
@@ -284,7 +284,7 @@ cJSON *snapshotSender2Json(SSyncSnapshotSender *pSender) {
char
*
snapshotSender2Str
(
SSyncSnapshotSender
*
pSender
)
{
cJSON
*
pJson
=
snapshotSender2Json
(
pSender
);
char
*
serialized
=
cJSON_Print
(
pJson
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
...
...
@@ -398,7 +398,7 @@ cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver) {
char
*
snapshotReceiver2Str
(
SSyncSnapshotReceiver
*
pReceiver
)
{
cJSON
*
pJson
=
snapshotReceiver2Json
(
pReceiver
);
char
*
serialized
=
cJSON_Print
(
pJson
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
...
...
@@ -406,19 +406,8 @@ char *snapshotReceiver2Str(SSyncSnapshotReceiver *pReceiver) {
// receiver do something
int32_t
syncNodeOnSnapshotSendCb
(
SSyncNode
*
pSyncNode
,
SyncSnapshotSend
*
pMsg
)
{
// get receiver
SSyncSnapshotReceiver
*
pReceiver
=
NULL
;
for
(
int
i
=
0
;
i
<
pSyncNode
->
replicaNum
;
++
i
)
{
if
(
syncUtilSameId
(
&
(
pMsg
->
srcId
),
&
((
pSyncNode
->
replicasId
)[
i
])))
{
pReceiver
=
(
pSyncNode
->
receivers
)[
i
];
}
}
// add new replica
if
(
pReceiver
==
NULL
)
{
pReceiver
=
pSyncNode
->
pNewNodeReceiver
;
}
bool
needRsp
=
false
;
SSyncSnapshotReceiver
*
pReceiver
=
pSyncNode
->
pNewNodeReceiver
;
bool
needRsp
=
false
;
// state, term, seq/ack
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_FOLLOWER
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录