Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
94b648eb
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看板
未验证
提交
94b648eb
编写于
11月 22, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
11月 22, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #18331 from taosdata/feature/sync-del-wal
refactor(sync): del wal in multi-replicas
上级
af31e510
1d48426e
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
66 addition
and
33 deletion
+66
-33
include/libs/sync/sync.h
include/libs/sync/sync.h
+1
-1
source/libs/sync/src/syncAppendEntriesReply.c
source/libs/sync/src/syncAppendEntriesReply.c
+3
-0
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+34
-17
source/libs/sync/src/syncRaftLog.c
source/libs/sync/src/syncRaftLog.c
+11
-1
source/libs/sync/src/syncTimeout.c
source/libs/sync/src/syncTimeout.c
+13
-11
source/libs/sync/src/syncUtil.c
source/libs/sync/src/syncUtil.c
+2
-2
source/libs/wal/src/walWrite.c
source/libs/wal/src/walWrite.c
+2
-1
未找到文件。
include/libs/sync/sync.h
浏览文件 @
94b648eb
...
...
@@ -36,7 +36,7 @@ extern "C" {
#define SYNC_DEL_WAL_MS (1000 * 60)
#define SYNC_ADD_QUORUM_COUNT 3
#define SYNC_MNODE_LOG_RETENTION 10000
#define SYNC_VNODE_LOG_RETENTION
10
0
#define SYNC_VNODE_LOG_RETENTION
2
0
#define SNAPSHOT_MAX_CLOCK_SKEW_MS 1000 * 10
#define SNAPSHOT_WAIT_MS 1000 * 30
...
...
source/libs/sync/src/syncAppendEntriesReply.c
浏览文件 @
94b648eb
...
...
@@ -67,6 +67,9 @@ int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
if
(
pMsg
->
matchIndex
>
oldMatchIndex
)
{
syncIndexMgrSetIndex
(
ths
->
pMatchIndex
,
&
(
pMsg
->
srcId
),
pMsg
->
matchIndex
);
syncMaybeAdvanceCommitIndex
(
ths
);
// maybe update minMatchIndex
ths
->
minMatchIndex
=
syncMinMatchIndex
(
ths
);
}
syncIndexMgrSetIndex
(
ths
->
pNextIndex
,
&
(
pMsg
->
srcId
),
pMsg
->
matchIndex
+
1
);
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
94b648eb
...
...
@@ -243,6 +243,18 @@ int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) {
goto
_DEL_WAL
;
}
else
{
lastApplyIndex
-=
SYNC_VNODE_LOG_RETENTION
;
SyncIndex
beginIndex
=
pSyncNode
->
pLogStore
->
syncLogBeginIndex
(
pSyncNode
->
pLogStore
);
SyncIndex
endIndex
=
pSyncNode
->
pLogStore
->
syncLogEndIndex
(
pSyncNode
->
pLogStore
);
bool
isEmpty
=
pSyncNode
->
pLogStore
->
syncLogIsEmpty
(
pSyncNode
->
pLogStore
);
if
(
isEmpty
||
!
(
lastApplyIndex
>=
beginIndex
&&
lastApplyIndex
<=
endIndex
))
{
sNTrace
(
pSyncNode
,
"new-snapshot-index:%"
PRId64
", empty:%d, do not delete wal"
,
lastApplyIndex
,
isEmpty
);
syncNodeRelease
(
pSyncNode
);
return
0
;
}
// vnode
if
(
pSyncNode
->
replicaNum
>
1
)
{
// multi replicas
...
...
@@ -300,13 +312,17 @@ int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) {
_DEL_WAL:
do
{
SSyncLogStoreData
*
pData
=
pSyncNode
->
pLogStore
->
data
;
SyncIndex
snapshotVer
=
walGetSnapshotVer
(
pData
->
pWal
);
SyncIndex
walCommitVer
=
walGetCommittedVer
(
pData
->
pWal
);
SyncIndex
wallastVer
=
walGetLastVer
(
pData
->
pWal
);
if
(
lastApplyIndex
<=
walCommitVer
)
{
SyncIndex
snapshottingIndex
=
atomic_load_64
(
&
pSyncNode
->
snapshottingIndex
);
if
(
snapshottingIndex
==
SYNC_INDEX_INVALID
)
{
atomic_store_64
(
&
pSyncNode
->
snapshottingIndex
,
lastApplyIndex
);
pSyncNode
->
snapshottingTime
=
taosGetTimestampMs
();
SSyncLogStoreData
*
pData
=
pSyncNode
->
pLogStore
->
data
;
code
=
walBeginSnapshot
(
pData
->
pWal
,
lastApplyIndex
);
if
(
code
==
0
)
{
sNTrace
(
pSyncNode
,
"wal snapshot begin, index:%"
PRId64
", last apply index:%"
PRId64
,
...
...
@@ -321,6 +337,7 @@ _DEL_WAL:
sNTrace
(
pSyncNode
,
"snapshotting for %"
PRId64
", do not delete wal for new-snapshot-index:%"
PRId64
,
snapshottingIndex
,
lastApplyIndex
);
}
}
}
while
(
0
);
syncNodeRelease
(
pSyncNode
);
...
...
source/libs/sync/src/syncRaftLog.c
浏览文件 @
94b648eb
...
...
@@ -375,7 +375,17 @@ static int32_t raftLogGetLastEntry(SSyncLogStore* pLogStore, SSyncRaftEntry** pp
int32_t
raftLogUpdateCommitIndex
(
SSyncLogStore
*
pLogStore
,
SyncIndex
index
)
{
SSyncLogStoreData
*
pData
=
pLogStore
->
data
;
SWal
*
pWal
=
pData
->
pWal
;
// ASSERT(walCommit(pWal, index) == 0);
// need not update
SyncIndex
snapshotVer
=
walGetSnapshotVer
(
pWal
);
SyncIndex
walCommitVer
=
walGetCommittedVer
(
pWal
);
SyncIndex
wallastVer
=
walGetLastVer
(
pWal
);
if
(
index
<
snapshotVer
||
index
>
wallastVer
)
{
// ignore
return
0
;
}
int32_t
code
=
walCommit
(
pWal
,
index
);
if
(
code
!=
0
)
{
int32_t
err
=
terrno
;
...
...
source/libs/sync/src/syncTimeout.c
浏览文件 @
94b648eb
...
...
@@ -62,9 +62,10 @@ static int32_t syncNodeTimerRoutine(SSyncNode* ths) {
syncNodeCleanConfigIndex
(
ths
);
}
// end timeout wal snapshot
int64_t
timeNow
=
taosGetTimestampMs
();
if
(
timeNow
-
ths
->
snapshottingIndex
>
SYNC_DEL_WAL_MS
&&
if
(
atomic_load_64
(
&
ths
->
snapshottingIndex
)
!=
SYNC_INDEX_INVALID
)
{
// end timeout wal snapshot
if
(
timeNow
-
ths
->
snapshottingTime
>
SYNC_DEL_WAL_MS
&&
atomic_load_64
(
&
ths
->
snapshottingIndex
)
!=
SYNC_INDEX_INVALID
)
{
SSyncLogStoreData
*
pData
=
ths
->
pLogStore
->
data
;
int32_t
code
=
walEndSnapshot
(
pData
->
pWal
);
...
...
@@ -76,6 +77,7 @@ static int32_t syncNodeTimerRoutine(SSyncNode* ths) {
atomic_store_64
(
&
ths
->
snapshottingIndex
,
SYNC_INDEX_INVALID
);
}
}
}
#if 0
if (!syncNodeIsMnode(ths)) {
...
...
source/libs/sync/src/syncUtil.c
浏览文件 @
94b648eb
...
...
@@ -239,11 +239,11 @@ void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNo
"vgId:%d, sync %s "
"%s"
", tm:%"
PRIu64
", cmt:%"
PRId64
", fst:%"
PRId64
", lst:%"
PRId64
", min:%"
PRId64
", snap:%"
PRId64
", snap-tm:%"
PRIu64
", sby:%d, aq:%d,
bch:%d
, r-num:%d, lcfg:%"
PRId64
", snap-tm:%"
PRIu64
", sby:%d, aq:%d,
snaping:%"
PRId64
"
, r-num:%d, lcfg:%"
PRId64
", chging:%d, rsto:%d, dquorum:%d, elt:%"
PRId64
", hb:%"
PRId64
", %s, %s"
,
pNode
->
vgId
,
syncStr
(
pNode
->
state
),
eventLog
,
currentTerm
,
pNode
->
commitIndex
,
logBeginIndex
,
logLastIndex
,
pNode
->
minMatchIndex
,
snapshot
.
lastApplyIndex
,
snapshot
.
lastApplyTerm
,
pNode
->
pRaftCfg
->
isStandBy
,
aqItems
,
pNode
->
pRaftCfg
->
batchSize
,
pNode
->
replicaNum
,
pNode
->
pRaftCfg
->
isStandBy
,
aqItems
,
pNode
->
snapshottingIndex
,
pNode
->
replicaNum
,
pNode
->
pRaftCfg
->
lastConfigIndex
,
pNode
->
changing
,
pNode
->
restoreFinish
,
quorum
,
pNode
->
electTimerLogicClock
,
pNode
->
heartbeatTimerLogicClockUser
,
peerStr
,
cfgStr
);
}
...
...
source/libs/wal/src/walWrite.c
浏览文件 @
94b648eb
...
...
@@ -325,7 +325,8 @@ int32_t walEndSnapshot(SWal *pWal) {
SWalFileInfo
*
pInfo
=
taosArraySearch
(
pWal
->
fileInfoSet
,
&
tmp
,
compareWalFileInfo
,
TD_LE
);
if
(
pInfo
)
{
if
(
ver
>=
pInfo
->
lastVer
)
{
pInfo
--
;
//pInfo--;
pInfo
++
;
}
if
(
POINTER_DISTANCE
(
pInfo
,
pWal
->
fileInfoSet
->
pData
)
>
0
)
{
wDebug
(
"vgId:%d, wal end remove for %"
PRId64
,
pWal
->
cfg
.
vgId
,
pInfo
->
firstVer
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录