Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
83b639ae
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看板
提交
83b639ae
编写于
7月 06, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(sync): persist batch size
上级
6ec47a7a
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
39 addition
and
14 deletion
+39
-14
source/libs/sync/inc/syncRaftCfg.h
source/libs/sync/inc/syncRaftCfg.h
+2
-0
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+8
-6
source/libs/sync/src/syncAppendEntriesReply.c
source/libs/sync/src/syncAppendEntriesReply.c
+20
-8
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+1
-0
source/libs/sync/src/syncRaftCfg.c
source/libs/sync/src/syncRaftCfg.c
+5
-0
source/libs/sync/test/syncRaftCfgTest.cpp
source/libs/sync/test/syncRaftCfgTest.cpp
+3
-0
未找到文件。
source/libs/sync/inc/syncRaftCfg.h
浏览文件 @
83b639ae
...
...
@@ -36,6 +36,7 @@ typedef struct SRaftCfg {
TdFilePtr
pFile
;
char
path
[
TSDB_FILENAME_LEN
*
2
];
int8_t
isStandBy
;
int32_t
batchSize
;
int8_t
snapshotStrategy
;
SyncIndex
lastConfigIndex
;
...
...
@@ -62,6 +63,7 @@ int32_t raftCfgFromStr(const char *s, SRaftCfg *pRaftCfg);
typedef
struct
SRaftCfgMeta
{
int8_t
isStandBy
;
int32_t
batchSize
;
int8_t
snapshotStrategy
;
SyncIndex
lastConfigIndex
;
}
SRaftCfgMeta
;
...
...
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
83b639ae
...
...
@@ -834,7 +834,7 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc
//
// operation:
// if hasAppendEntries && pMsg->prevLogIndex == ths->commitIndex, append entry
// match my-commit-index or my-commit-index +
1
// match my-commit-index or my-commit-index +
batchSize
do
{
bool
condition
=
(
pMsg
->
term
==
ths
->
pRaftStore
->
currentTerm
)
&&
(
ths
->
state
==
TAOS_SYNC_STATE_FOLLOWER
)
&&
(
pMsg
->
prevLogIndex
<=
ths
->
commitIndex
);
...
...
@@ -928,11 +928,13 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc
bool
condition
=
condition1
||
condition2
;
if
(
condition
)
{
char
logBuf
[
128
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"recv sync-append-entries-batch, not match, pre-index:%ld, pre-term:%lu, datalen:%d"
,
pMsg
->
prevLogIndex
,
pMsg
->
prevLogTerm
,
pMsg
->
dataLen
);
syncNodeEventLog
(
ths
,
logBuf
);
do
{
char
logBuf
[
128
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"recv sync-append-entries-batch, not match, pre-index:%ld, pre-term:%lu, datalen:%d"
,
pMsg
->
prevLogIndex
,
pMsg
->
prevLogTerm
,
pMsg
->
dataLen
);
syncNodeEventLog
(
ths
,
logBuf
);
}
while
(
0
);
// prepare response msg
SyncAppendEntriesReply
*
pReply
=
syncAppendEntriesReplyBuild
(
ths
->
vgId
);
...
...
source/libs/sync/src/syncAppendEntriesReply.c
浏览文件 @
83b639ae
...
...
@@ -109,19 +109,30 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p
}
// only start once
static
void
syncNodeStartSnapshot
(
SSyncNode
*
ths
,
SyncIndex
beginIndex
,
SyncIndex
endIndex
,
SyncTerm
lastApplyTerm
,
SyncAppendEntriesReply
*
pMsg
)
{
static
void
syncNodeStartSnapshot
Once
(
SSyncNode
*
ths
,
SyncIndex
beginIndex
,
SyncIndex
endIndex
,
SyncTerm
lastApplyTerm
,
SyncAppendEntriesReply
*
pMsg
)
{
// get sender
SSyncSnapshotSender
*
pSender
=
syncNodeGetSnapshotSender
(
ths
,
&
(
pMsg
->
srcId
));
ASSERT
(
pSender
!=
NULL
);
if
(
snapshotSenderIsStart
(
pSender
))
{
do
{
char
*
eventLog
=
snapshotSender2SimpleStr
(
pSender
,
"snapshot sender already start"
);
syncNodeErrorLog
(
ths
,
eventLog
);
taosMemoryFree
(
eventLog
);
}
while
(
0
);
return
;
}
SSnapshot
snapshot
=
{
.
data
=
NULL
,
.
lastApplyIndex
=
endIndex
,
.
lastApplyTerm
=
lastApplyTerm
,
.
lastConfigIndex
=
SYNC_INDEX_INVALID
};
void
*
pReader
=
NULL
;
SSnapshotParam
readerParam
=
{.
start
=
beginIndex
,
.
end
=
endIndex
};
ths
->
pFsm
->
FpSnapshotStartRead
(
ths
->
pFsm
,
&
readerParam
,
&
pReader
);
if
(
!
snapshotSenderIsStart
(
pSender
)
&&
pMsg
->
privateTerm
<
pSender
->
privateTerm
)
{
int32_t
code
=
ths
->
pFsm
->
FpSnapshotStartRead
(
ths
->
pFsm
,
&
readerParam
,
&
pReader
);
ASSERT
(
code
==
0
);
if
(
pMsg
->
privateTerm
<
pSender
->
privateTerm
)
{
ASSERT
(
pReader
!=
NULL
);
snapshotSenderStart
(
pSender
,
readerParam
,
snapshot
,
pReader
);
...
...
@@ -178,7 +189,9 @@ int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntrie
// start snapshot <match+1, old snapshot.end>
SSnapshot
oldSnapshot
;
ths
->
pFsm
->
FpGetSnapshotInfo
(
ths
->
pFsm
,
&
oldSnapshot
);
syncNodeStartSnapshot
(
ths
,
newMatchIndex
+
1
,
oldSnapshot
.
lastApplyIndex
,
oldSnapshot
.
lastApplyTerm
,
pMsg
);
ASSERT
(
oldSnapshot
.
lastApplyIndex
>=
newMatchIndex
+
1
);
syncNodeStartSnapshotOnce
(
ths
,
newMatchIndex
+
1
,
oldSnapshot
.
lastApplyIndex
,
oldSnapshot
.
lastApplyTerm
,
pMsg
);
// term maybe not ok?
syncIndexMgrSetIndex
(
ths
->
pNextIndex
,
&
(
pMsg
->
srcId
),
oldSnapshot
.
lastApplyIndex
+
1
);
syncIndexMgrSetIndex
(
ths
->
pMatchIndex
,
&
(
pMsg
->
srcId
),
newMatchIndex
);
...
...
@@ -187,7 +200,6 @@ int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntrie
}
else
{
SyncIndex
nextIndex
=
syncIndexMgrGetIndex
(
ths
->
pNextIndex
,
&
(
pMsg
->
srcId
));
// notice! int64, uint64
if
(
nextIndex
>
SYNC_INDEX_BEGIN
)
{
--
nextIndex
;
...
...
@@ -198,7 +210,7 @@ int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntrie
SSyncRaftEntry
*
pEntry
;
int32_t
code
=
ths
->
pLogStore
->
syncLogGetEntry
(
ths
->
pLogStore
,
nextIndex
,
&
pEntry
);
ASSERT
(
code
==
0
);
syncNodeStartSnapshot
(
ths
,
SYNC_INDEX_BEGIN
,
nextIndex
,
pEntry
->
term
,
pMsg
);
syncNodeStartSnapshot
Once
(
ths
,
SYNC_INDEX_BEGIN
,
nextIndex
,
pEntry
->
term
,
pMsg
);
// get sender
SSyncSnapshotSender
*
pSender
=
syncNodeGetSnapshotSender
(
ths
,
&
(
pMsg
->
srcId
));
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
83b639ae
...
...
@@ -846,6 +846,7 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) {
meta
.
isStandBy
=
pSyncInfo
->
isStandBy
;
meta
.
snapshotStrategy
=
pSyncInfo
->
snapshotStrategy
;
meta
.
lastConfigIndex
=
SYNC_INDEX_INVALID
;
meta
.
batchSize
=
pSyncInfo
->
batchSize
;
ret
=
raftCfgCreateFile
((
SSyncCfg
*
)
&
(
pSyncInfo
->
syncCfg
),
meta
,
pSyncNode
->
configPath
);
ASSERT
(
ret
==
0
);
...
...
source/libs/sync/src/syncRaftCfg.c
浏览文件 @
83b639ae
...
...
@@ -183,6 +183,7 @@ cJSON *raftCfg2Json(SRaftCfg *pRaftCfg) {
cJSON_AddItemToObject
(
pRoot
,
"SSyncCfg"
,
syncCfg2Json
(
&
(
pRaftCfg
->
cfg
)));
cJSON_AddNumberToObject
(
pRoot
,
"isStandBy"
,
pRaftCfg
->
isStandBy
);
cJSON_AddNumberToObject
(
pRoot
,
"snapshotStrategy"
,
pRaftCfg
->
snapshotStrategy
);
cJSON_AddNumberToObject
(
pRoot
,
"batchSize"
,
pRaftCfg
->
batchSize
);
char
buf64
[
128
];
snprintf
(
buf64
,
sizeof
(
buf64
),
"%ld"
,
pRaftCfg
->
lastConfigIndex
);
...
...
@@ -228,6 +229,7 @@ int32_t raftCfgCreateFile(SSyncCfg *pCfg, SRaftCfgMeta meta, const char *path) {
SRaftCfg
raftCfg
;
raftCfg
.
cfg
=
*
pCfg
;
raftCfg
.
isStandBy
=
meta
.
isStandBy
;
raftCfg
.
batchSize
=
meta
.
batchSize
;
raftCfg
.
snapshotStrategy
=
meta
.
snapshotStrategy
;
raftCfg
.
lastConfigIndex
=
meta
.
lastConfigIndex
;
raftCfg
.
configIndexCount
=
1
;
...
...
@@ -257,6 +259,9 @@ int32_t raftCfgFromJson(const cJSON *pRoot, SRaftCfg *pRaftCfg) {
cJSON
*
pJsonIsStandBy
=
cJSON_GetObjectItem
(
pJson
,
"isStandBy"
);
pRaftCfg
->
isStandBy
=
cJSON_GetNumberValue
(
pJsonIsStandBy
);
cJSON
*
pJsonBatchSize
=
cJSON_GetObjectItem
(
pJson
,
"batchSize"
);
pRaftCfg
->
batchSize
=
cJSON_GetNumberValue
(
pJsonBatchSize
);
cJSON
*
pJsonSnapshotStrategy
=
cJSON_GetObjectItem
(
pJson
,
"snapshotStrategy"
);
pRaftCfg
->
snapshotStrategy
=
cJSON_GetNumberValue
(
pJsonSnapshotStrategy
);
...
...
source/libs/sync/test/syncRaftCfgTest.cpp
浏览文件 @
83b639ae
...
...
@@ -26,6 +26,7 @@ SRaftCfg* createRaftCfg() {
snprintf
(((
pCfg
->
cfg
.
nodeInfo
)[
i
]).
nodeFqdn
,
sizeof
(((
pCfg
->
cfg
.
nodeInfo
)[
i
]).
nodeFqdn
),
"100.200.300.%d"
,
i
);
}
pCfg
->
isStandBy
=
taosGetTimestampSec
()
%
100
;
pCfg
->
batchSize
=
taosGetTimestampSec
()
%
100
;
pCfg
->
configIndexCount
=
5
;
for
(
int
i
=
0
;
i
<
MAX_CONFIG_INDEX_COUNT
;
++
i
)
{
...
...
@@ -84,6 +85,7 @@ void test3() {
SRaftCfgMeta
meta
;
meta
.
isStandBy
=
7
;
meta
.
snapshotStrategy
=
9
;
meta
.
batchSize
=
10
;
meta
.
lastConfigIndex
=
789
;
raftCfgCreateFile
(
pCfg
,
meta
,
s
);
printf
(
"%s create json file: %s
\n
"
,
(
char
*
)
__FUNCTION__
,
s
);
...
...
@@ -109,6 +111,7 @@ void test5() {
pCfg
->
cfg
.
myIndex
=
taosGetTimestampSec
();
pCfg
->
isStandBy
+=
2
;
pCfg
->
snapshotStrategy
+=
3
;
pCfg
->
batchSize
+=
4
;
pCfg
->
lastConfigIndex
+=
1000
;
pCfg
->
configIndexCount
=
5
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录