Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
3f1a0cef
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看板
提交
3f1a0cef
编写于
12月 05, 2022
作者:
B
Benguang Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: walSaveMeta ahead of deleting WAL files as gc in walEndSnapshot
delete WAL files in descending order during walRollback
上级
09817b8c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
49 addition
and
34 deletion
+49
-34
include/libs/wal/wal.h
include/libs/wal/wal.h
+2
-0
source/libs/wal/src/walMeta.c
source/libs/wal/src/walMeta.c
+3
-1
source/libs/wal/src/walMgmt.c
source/libs/wal/src/walMgmt.c
+12
-1
source/libs/wal/src/walRead.c
source/libs/wal/src/walRead.c
+1
-1
source/libs/wal/src/walWrite.c
source/libs/wal/src/walWrite.c
+31
-31
未找到文件。
include/libs/wal/wal.h
浏览文件 @
3f1a0cef
...
...
@@ -107,6 +107,8 @@ typedef struct SWal {
TdFilePtr
pIdxFile
;
int32_t
writeCur
;
SArray
*
fileInfoSet
;
// SArray<SWalFileInfo>
// gc
SArray
*
toDeleteFiles
;
// SArray<SWalFileInfo>
// status
int64_t
totSize
;
int64_t
lastRollSeq
;
...
...
source/libs/wal/src/walMeta.c
浏览文件 @
3f1a0cef
...
...
@@ -24,7 +24,9 @@ bool FORCE_INLINE walLogExist(SWal* pWal, int64_t ver) {
return
!
walIsEmpty
(
pWal
)
&&
walGetFirstVer
(
pWal
)
<=
ver
&&
walGetLastVer
(
pWal
)
>=
ver
;
}
bool
FORCE_INLINE
walIsEmpty
(
SWal
*
pWal
)
{
return
pWal
->
vers
.
firstVer
==
-
1
;
}
bool
FORCE_INLINE
walIsEmpty
(
SWal
*
pWal
)
{
return
(
pWal
->
vers
.
firstVer
==
-
1
||
pWal
->
vers
.
lastVer
<
pWal
->
vers
.
firstVer
);
// [firstVer, lastVer + 1)
}
int64_t
FORCE_INLINE
walGetFirstVer
(
SWal
*
pWal
)
{
return
pWal
->
vers
.
firstVer
;
}
...
...
source/libs/wal/src/walMgmt.c
浏览文件 @
3f1a0cef
...
...
@@ -121,7 +121,16 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) {
pWal
->
writeCur
=
-
1
;
pWal
->
fileInfoSet
=
taosArrayInit
(
8
,
sizeof
(
SWalFileInfo
));
if
(
pWal
->
fileInfoSet
==
NULL
)
{
wError
(
"vgId:%d, path:%s, failed to init taosArray %s"
,
pWal
->
cfg
.
vgId
,
pWal
->
path
,
strerror
(
errno
));
wError
(
"vgId:%d, failed to init taosArray of fileInfoSet due to %s. path:%s"
,
pWal
->
cfg
.
vgId
,
strerror
(
errno
),
pWal
->
path
);
goto
_err
;
}
// init gc
pWal
->
toDeleteFiles
=
taosArrayInit
(
8
,
sizeof
(
SWalFileInfo
));
if
(
pWal
->
toDeleteFiles
==
NULL
)
{
wError
(
"vgId:%d, failed to init taosArray of toDeleteFiles due to %s. path:%s"
,
pWal
->
cfg
.
vgId
,
strerror
(
errno
),
pWal
->
path
);
goto
_err
;
}
...
...
@@ -203,6 +212,8 @@ void walClose(SWal *pWal) {
pWal
->
pIdxFile
=
NULL
;
taosArrayDestroy
(
pWal
->
fileInfoSet
);
pWal
->
fileInfoSet
=
NULL
;
taosArrayDestroy
(
pWal
->
toDeleteFiles
);
pWal
->
toDeleteFiles
=
NULL
;
void
*
pIter
=
NULL
;
while
(
1
)
{
...
...
source/libs/wal/src/walRead.c
浏览文件 @
3f1a0cef
...
...
@@ -489,7 +489,7 @@ int32_t walReadVer(SWalReader *pReader, int64_t ver) {
int32_t
code
;
bool
seeked
=
false
;
if
(
pReader
->
pWal
->
vers
.
firstVer
==
-
1
)
{
if
(
walIsEmpty
(
pReader
->
pWal
)
)
{
terrno
=
TSDB_CODE_WAL_LOG_NOT_EXIST
;
return
-
1
;
}
...
...
source/libs/wal/src/walWrite.c
浏览文件 @
3f1a0cef
...
...
@@ -120,9 +120,9 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
return
-
1
;
}
// delete files
// delete files
in descending order
int
fileSetSize
=
taosArrayGetSize
(
pWal
->
fileInfoSet
);
for
(
int
i
=
pWal
->
writeCur
+
1
;
i
<
fileSetSize
;
i
++
)
{
for
(
int
i
=
fileSetSize
-
1
;
i
>=
pWal
->
writeCur
+
1
;
i
--
)
{
walBuildLogName
(
pWal
,
((
SWalFileInfo
*
)
taosArrayGet
(
pWal
->
fileInfoSet
,
i
))
->
firstVer
,
fnameStr
);
wDebug
(
"vgId:%d, wal remove file %s for rollback"
,
pWal
->
cfg
.
vgId
,
fnameStr
);
taosRemoveFile
(
fnameStr
);
...
...
@@ -217,14 +217,9 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
pWal
->
vers
.
lastVer
=
ver
-
1
;
if
(
pWal
->
vers
.
lastVer
<
pWal
->
vers
.
firstVer
)
{
ASSERT
(
pWal
->
vers
.
lastVer
==
pWal
->
vers
.
firstVer
-
1
);
pWal
->
vers
.
firstVer
=
-
1
;
}
((
SWalFileInfo
*
)
taosArrayGetLast
(
pWal
->
fileInfoSet
))
->
lastVer
=
ver
-
1
;
((
SWalFileInfo
*
)
taosArrayGetLast
(
pWal
->
fileInfoSet
))
->
fileSize
=
entry
.
offset
;
if
(((
SWalFileInfo
*
)
taosArrayGetLast
(
pWal
->
fileInfoSet
))
->
lastVer
<
ver
-
1
)
{
ASSERT
(((
SWalFileInfo
*
)
taosArrayGetLast
(
pWal
->
fileInfoSet
))
->
fileSize
==
0
);
((
SWalFileInfo
*
)
taosArrayGetLast
(
pWal
->
fileInfoSet
))
->
firstVer
=
-
1
;
}
taosCloseFile
(
&
pIdxFile
);
taosCloseFile
(
&
pLogFile
);
...
...
@@ -338,6 +333,7 @@ int32_t walEndSnapshot(SWal *pWal) {
}
else
{
wDebug
(
"vgId:%d, wal no remove"
,
pWal
->
cfg
.
vgId
);
}
// iterate files, until the searched result
for
(
SWalFileInfo
*
iter
=
pWal
->
fileInfoSet
->
pData
;
iter
<
pInfo
;
iter
++
)
{
wDebug
(
"vgId:%d, wal check remove file %"
PRId64
"(file size %"
PRId64
" close ts %"
PRId64
...
...
@@ -350,34 +346,17 @@ int32_t walEndSnapshot(SWal *pWal) {
wDebug
(
"vgId:%d, check pass"
,
pWal
->
cfg
.
vgId
);
deleteCnt
++
;
newTotSize
-=
iter
->
fileSize
;
taosArrayPush
(
pWal
->
toDeleteFiles
,
iter
);
}
wDebug
(
"vgId:%d, check not pass"
,
pWal
->
cfg
.
vgId
);
}
wDebug
(
"vgId:%d, wal should delete %d files"
,
pWal
->
cfg
.
vgId
,
deleteCnt
);
int32_t
actualDelete
=
0
;
char
fnameStr
[
WAL_FILE_LEN
];
// remove file
for
(
int
i
=
0
;
i
<
deleteCnt
;
i
++
)
{
pInfo
=
taosArrayGet
(
pWal
->
fileInfoSet
,
i
);
walBuildLogName
(
pWal
,
pInfo
->
firstVer
,
fnameStr
);
wDebug
(
"vgId:%d, wal remove file %s"
,
pWal
->
cfg
.
vgId
,
fnameStr
);
if
(
taosRemoveFile
(
fnameStr
)
<
0
)
{
goto
UPDATE_META
;
}
walBuildIdxName
(
pWal
,
pInfo
->
firstVer
,
fnameStr
);
wDebug
(
"vgId:%d, wal remove file %s"
,
pWal
->
cfg
.
vgId
,
fnameStr
);
if
(
taosRemoveFile
(
fnameStr
)
<
0
)
{
ASSERT
(
0
);
}
actualDelete
++
;
}
UPDATE_META:
// make new array, remove files
taosArrayPopFrontBatch
(
pWal
->
fileInfoSet
,
actualDelete
);
taosArrayPopFrontBatch
(
pWal
->
fileInfoSet
,
deleteCnt
);
if
(
taosArrayGetSize
(
pWal
->
fileInfoSet
)
==
0
)
{
pWal
->
writeCur
=
-
1
;
pWal
->
vers
.
firstVer
=
-
1
;
pWal
->
vers
.
firstVer
=
pWal
->
vers
.
lastVer
+
1
;
}
else
{
pWal
->
vers
.
firstVer
=
((
SWalFileInfo
*
)
taosArrayGet
(
pWal
->
fileInfoSet
,
0
))
->
firstVer
;
}
...
...
@@ -392,6 +371,26 @@ int32_t walEndSnapshot(SWal *pWal) {
goto
END
;
}
// delete files
deleteCnt
=
taosArrayGetSize
(
pWal
->
toDeleteFiles
);
wDebug
(
"vgId:%d, wal should delete %d files"
,
pWal
->
cfg
.
vgId
,
deleteCnt
);
char
fnameStr
[
WAL_FILE_LEN
];
for
(
int
i
=
0
;
i
<
deleteCnt
;
i
++
)
{
pInfo
=
taosArrayGet
(
pWal
->
toDeleteFiles
,
i
);
walBuildLogName
(
pWal
,
pInfo
->
firstVer
,
fnameStr
);
wDebug
(
"vgId:%d, wal remove file %s"
,
pWal
->
cfg
.
vgId
,
fnameStr
);
if
(
taosRemoveFile
(
fnameStr
)
<
0
&&
errno
!=
ENOENT
)
{
wError
(
"vgId:%d, failed to remove log file %s due to %s"
,
pWal
->
cfg
.
vgId
,
fnameStr
,
strerror
(
errno
));
goto
END
;
}
walBuildIdxName
(
pWal
,
pInfo
->
firstVer
,
fnameStr
);
wDebug
(
"vgId:%d, wal remove file %s"
,
pWal
->
cfg
.
vgId
,
fnameStr
);
if
(
taosRemoveFile
(
fnameStr
)
<
0
&&
errno
!=
ENOENT
)
{
ASSERT
(
0
);
}
}
taosArrayClear
(
pWal
->
toDeleteFiles
);
END:
taosThreadMutexUnlock
(
&
pWal
->
mutex
);
return
code
;
...
...
@@ -489,9 +488,7 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy
SWalFileInfo
*
pFileInfo
=
walGetCurFileInfo
(
pWal
);
ASSERT
(
pFileInfo
!=
NULL
);
if
(
pFileInfo
->
firstVer
==
-
1
)
{
pFileInfo
->
firstVer
=
index
;
}
ASSERT
(
pFileInfo
->
firstVer
!=
-
1
);
pWal
->
writeHead
.
head
.
version
=
index
;
pWal
->
writeHead
.
head
.
bodyLen
=
bodyLen
;
pWal
->
writeHead
.
head
.
msgType
=
msgType
;
...
...
@@ -527,7 +524,10 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy
}
// set status
if
(
pWal
->
vers
.
firstVer
==
-
1
)
pWal
->
vers
.
firstVer
=
index
;
if
(
pWal
->
vers
.
firstVer
==
-
1
)
{
ASSERT
(
index
==
0
);
pWal
->
vers
.
firstVer
=
0
;
}
pWal
->
vers
.
lastVer
=
index
;
pWal
->
totSize
+=
sizeof
(
SWalCkHead
)
+
bodyLen
;
pFileInfo
->
lastVer
=
index
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录