Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8a32c0c1
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看板
提交
8a32c0c1
编写于
8月 18, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(sync): adjust strategy for dynamic quorum
上级
73c3a1eb
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
53 addition
and
12 deletion
+53
-12
include/libs/sync/sync.h
include/libs/sync/sync.h
+1
-0
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+1
-1
source/libs/sync/src/syncCommit.c
source/libs/sync/src/syncCommit.c
+32
-8
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+19
-3
未找到文件。
include/libs/sync/sync.h
浏览文件 @
8a32c0c1
...
...
@@ -34,6 +34,7 @@ extern bool gRaftDetailLog;
#define SYNC_MAX_PROGRESS_WAIT_MS 4000
#define SYNC_MAX_START_TIME_RANGE_MS (1000 * 20)
#define SYNC_MAX_RECV_TIME_RANGE_MS 1000
#define SYNC_ADD_QUORUM_COUNT 3
#define SYNC_MAX_BATCH_SIZE 1
#define SYNC_INDEX_BEGIN 0
...
...
source/libs/sync/inc/syncInt.h
浏览文件 @
8a32c0c1
...
...
@@ -237,7 +237,7 @@ void syncNodeVoteForSelf(SSyncNode* pSyncNode);
bool
syncNodeHasSnapshot
(
SSyncNode
*
pSyncNode
);
void
syncNodeMaybeUpdateCommitBySnapshot
(
SSyncNode
*
pSyncNode
);
SyncIndex
syncNodeGetLastIndex
(
SSyncNode
*
pSyncNode
);
SyncIndex
syncNodeGetLastIndex
(
const
SSyncNode
*
pSyncNode
);
SyncTerm
syncNodeGetLastTerm
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeGetLastIndexTerm
(
SSyncNode
*
pSyncNode
,
SyncIndex
*
pLastIndex
,
SyncTerm
*
pLastTerm
);
...
...
source/libs/sync/src/syncCommit.c
浏览文件 @
8a32c0c1
...
...
@@ -146,23 +146,47 @@ int32_t syncNodeDynamicQuorum(const SSyncNode* pSyncNode) {
int64_t
timeNow
=
taosGetTimestampMs
();
for
(
int
i
=
0
;
i
<
pSyncNode
->
peersNum
;
++
i
)
{
int64_t
peerStartTime
=
syncIndexMgrGetStartTime
(
pSyncNode
->
pNextIndex
,
&
(
pSyncNode
->
peersId
)[
i
]);
int64_t
peerRecvTime
=
syncIndexMgrGetRecvTime
(
pSyncNode
->
pNextIndex
,
&
(
pSyncNode
->
peersId
)[
i
]);
int64_t
peerStartTime
=
syncIndexMgrGetStartTime
(
pSyncNode
->
pNextIndex
,
&
(
pSyncNode
->
peersId
)[
i
]);
int64_t
peerRecvTime
=
syncIndexMgrGetRecvTime
(
pSyncNode
->
pNextIndex
,
&
(
pSyncNode
->
peersId
)[
i
]);
SyncIndex
peerMatchIndex
=
syncIndexMgrGetIndex
(
pSyncNode
->
pMatchIndex
,
&
(
pSyncNode
->
peersId
)[
i
]);
int64_t
recvTimeDiff
=
syncNodeAbs64
(
peerRecvTime
,
timeNow
);
int64_t
startTimeDiff
=
syncNodeAbs64
(
peerStartTime
,
pSyncNode
->
startTime
);
int64_t
recvTimeDiff
=
TABS
(
peerRecvTime
-
timeNow
);
int64_t
startTimeDiff
=
TABS
(
peerStartTime
-
pSyncNode
->
startTime
);
int64_t
logDiff
=
TABS
(
peerMatchIndex
-
syncNodeGetLastIndex
(
pSyncNode
));
/*
int64_t recvTimeDiff = syncNodeAbs64(peerRecvTime, timeNow);
int64_t startTimeDiff = syncNodeAbs64(peerStartTime, pSyncNode->startTime);
int64_t logDiff = syncNodeAbs64(peerMatchIndex, syncNodeGetLastIndex(pSyncNode));
*/
int32_t
addQuorum
=
0
;
if
(
recvTimeDiff
<
SYNC_MAX_RECV_TIME_RANGE_MS
)
{
addQuorum
=
1
;
if
(
startTimeDiff
<
SYNC_MAX_START_TIME_RANGE_MS
)
{
addQuorum
=
1
;
}
else
{
if
(
logDiff
<
SYNC_ADD_QUORUM_COUNT
)
{
addQuorum
=
1
;
}
else
{
addQuorum
=
0
;
}
}
}
else
{
addQuorum
=
0
;
}
if
(
startTimeDiff
>
SYNC_MAX_START_TIME_RANGE_MS
)
{
addQuorum
=
0
;
}
/*
if (recvTimeDiff < SYNC_MAX_RECV_TIME_RANGE_MS) {
addQuorum = 1;
} else {
addQuorum = 0;
}
if (startTimeDiff > SYNC_MAX_START_TIME_RANGE_MS) {
addQuorum = 0;
}
*/
quorum
+=
addQuorum
;
}
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
8a32c0c1
...
...
@@ -2284,7 +2284,7 @@ bool syncNodeHasSnapshot(SSyncNode* pSyncNode) {
// return max(logLastIndex, snapshotLastIndex)
// if no snapshot and log, return -1
SyncIndex
syncNodeGetLastIndex
(
SSyncNode
*
pSyncNode
)
{
SyncIndex
syncNodeGetLastIndex
(
const
SSyncNode
*
pSyncNode
)
{
SSnapshot
snapshot
=
{.
data
=
NULL
,
.
lastApplyIndex
=
-
1
,
.
lastApplyTerm
=
0
,
.
lastConfigIndex
=
-
1
};
if
(
pSyncNode
->
pFsm
->
FpGetSnapshotInfo
!=
NULL
)
{
pSyncNode
->
pFsm
->
FpGetSnapshotInfo
(
pSyncNode
->
pFsm
,
&
snapshot
);
...
...
@@ -2773,11 +2773,27 @@ int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* p
return
0
;
}
if
(
ths
->
vgId
>
1
)
{
syncNodeEventLog
(
ths
,
"I am vnode, can not do leader transfer"
);
if
(
pEntry
->
term
<
ths
->
pRaftStore
->
currentTerm
)
{
char
logBuf
[
128
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"little term:%lu, can not do leader transfer"
,
pEntry
->
term
);
syncNodeEventLog
(
ths
,
logBuf
);
return
0
;
}
if
(
pEntry
->
index
<
syncNodeGetLastIndex
(
ths
))
{
char
logBuf
[
128
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"little index:%ld, can not do leader transfer"
,
pEntry
->
index
);
syncNodeEventLog
(
ths
,
logBuf
);
return
0
;
}
/*
if (ths->vgId > 1) {
syncNodeEventLog(ths, "I am vnode, can not do leader transfer");
return 0;
}
*/
do
{
char
logBuf
[
128
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"do leader transfer, index:%ld"
,
pEntry
->
index
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录