Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
0c942e62
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
0c942e62
编写于
7月 28, 2022
作者:
L
Liu Jicong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh(wal): remove file failure handling
上级
904ec81b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
54 addition
and
43 deletion
+54
-43
include/libs/wal/wal.h
include/libs/wal/wal.h
+3
-3
source/libs/wal/src/walMeta.c
source/libs/wal/src/walMeta.c
+7
-7
source/libs/wal/src/walRead.c
source/libs/wal/src/walRead.c
+33
-29
source/libs/wal/src/walWrite.c
source/libs/wal/src/walWrite.c
+11
-4
未找到文件。
include/libs/wal/wal.h
浏览文件 @
0c942e62
...
@@ -77,11 +77,11 @@ typedef struct {
...
@@ -77,11 +77,11 @@ typedef struct {
}
SWalSyncInfo
;
}
SWalSyncInfo
;
typedef
struct
{
typedef
struct
{
int8_t
protoVer
;
int64_t
version
;
int64_t
version
;
int
16_t
msgType
;
int
64_t
ingestTs
;
int32_t
bodyLen
;
int32_t
bodyLen
;
int64_t
ingestTs
;
// not implemented
int16_t
msgType
;
int8_t
protoVer
;
// sync meta
// sync meta
SWalSyncInfo
syncMeta
;
SWalSyncInfo
syncMeta
;
...
...
source/libs/wal/src/walMeta.c
浏览文件 @
0c942e62
...
@@ -139,7 +139,7 @@ int walCheckAndRepairMeta(SWal* pWal) {
...
@@ -139,7 +139,7 @@ int walCheckAndRepairMeta(SWal* pWal) {
const
char
*
idxPattern
=
"^[0-9]+.idx$"
;
const
char
*
idxPattern
=
"^[0-9]+.idx$"
;
regex_t
logRegPattern
;
regex_t
logRegPattern
;
regex_t
idxRegPattern
;
regex_t
idxRegPattern
;
SArray
*
pLogInfoArray
=
taosArrayInit
(
8
,
sizeof
(
SWalFileInfo
));
SArray
*
actualLog
=
taosArrayInit
(
8
,
sizeof
(
SWalFileInfo
));
regcomp
(
&
logRegPattern
,
logPattern
,
REG_EXTENDED
);
regcomp
(
&
logRegPattern
,
logPattern
,
REG_EXTENDED
);
regcomp
(
&
idxRegPattern
,
idxPattern
,
REG_EXTENDED
);
regcomp
(
&
idxRegPattern
,
idxPattern
,
REG_EXTENDED
);
...
@@ -159,7 +159,7 @@ int walCheckAndRepairMeta(SWal* pWal) {
...
@@ -159,7 +159,7 @@ int walCheckAndRepairMeta(SWal* pWal) {
SWalFileInfo
fileInfo
;
SWalFileInfo
fileInfo
;
memset
(
&
fileInfo
,
-
1
,
sizeof
(
SWalFileInfo
));
memset
(
&
fileInfo
,
-
1
,
sizeof
(
SWalFileInfo
));
sscanf
(
name
,
"%"
PRId64
".log"
,
&
fileInfo
.
firstVer
);
sscanf
(
name
,
"%"
PRId64
".log"
,
&
fileInfo
.
firstVer
);
taosArrayPush
(
pLogInfoArray
,
&
fileInfo
);
taosArrayPush
(
actualLog
,
&
fileInfo
);
}
}
}
}
...
@@ -167,10 +167,10 @@ int walCheckAndRepairMeta(SWal* pWal) {
...
@@ -167,10 +167,10 @@ int walCheckAndRepairMeta(SWal* pWal) {
regfree
(
&
logRegPattern
);
regfree
(
&
logRegPattern
);
regfree
(
&
idxRegPattern
);
regfree
(
&
idxRegPattern
);
taosArraySort
(
pLogInfoArray
,
compareWalFileInfo
);
taosArraySort
(
actualLog
,
compareWalFileInfo
);
int
metaFileNum
=
taosArrayGetSize
(
pWal
->
fileInfoSet
);
int
metaFileNum
=
taosArrayGetSize
(
pWal
->
fileInfoSet
);
int
actualFileNum
=
taosArrayGetSize
(
pLogInfoArray
);
int
actualFileNum
=
taosArrayGetSize
(
actualLog
);
#if 0
#if 0
for (int32_t fileNo = actualFileNum - 1; fileNo >= 0; fileNo--) {
for (int32_t fileNo = actualFileNum - 1; fileNo >= 0; fileNo--) {
...
@@ -196,11 +196,11 @@ int walCheckAndRepairMeta(SWal* pWal) {
...
@@ -196,11 +196,11 @@ int walCheckAndRepairMeta(SWal* pWal) {
taosArrayPopFrontBatch
(
pWal
->
fileInfoSet
,
metaFileNum
-
actualFileNum
);
taosArrayPopFrontBatch
(
pWal
->
fileInfoSet
,
metaFileNum
-
actualFileNum
);
}
else
if
(
metaFileNum
<
actualFileNum
)
{
}
else
if
(
metaFileNum
<
actualFileNum
)
{
for
(
int
i
=
metaFileNum
;
i
<
actualFileNum
;
i
++
)
{
for
(
int
i
=
metaFileNum
;
i
<
actualFileNum
;
i
++
)
{
SWalFileInfo
*
pFileInfo
=
taosArrayGet
(
pLogInfoArray
,
i
);
SWalFileInfo
*
pFileInfo
=
taosArrayGet
(
actualLog
,
i
);
taosArrayPush
(
pWal
->
fileInfoSet
,
pFileInfo
);
taosArrayPush
(
pWal
->
fileInfoSet
,
pFileInfo
);
}
}
}
}
taosArrayDestroy
(
pLogInfoArray
);
taosArrayDestroy
(
actualLog
);
pWal
->
writeCur
=
actualFileNum
-
1
;
pWal
->
writeCur
=
actualFileNum
-
1
;
if
(
actualFileNum
>
0
)
{
if
(
actualFileNum
>
0
)
{
...
@@ -221,7 +221,7 @@ int walCheckAndRepairMeta(SWal* pWal) {
...
@@ -221,7 +221,7 @@ int walCheckAndRepairMeta(SWal* pWal) {
int
code
=
walSaveMeta
(
pWal
);
int
code
=
walSaveMeta
(
pWal
);
if
(
code
<
0
)
{
if
(
code
<
0
)
{
taosArrayDestroy
(
pLogInfoArray
);
taosArrayDestroy
(
actualLog
);
return
-
1
;
return
-
1
;
}
}
}
}
...
...
source/libs/wal/src/walRead.c
浏览文件 @
0c942e62
...
@@ -423,37 +423,38 @@ int32_t walFetchBody(SWalReader *pRead, SWalCkHead **ppHead) {
...
@@ -423,37 +423,38 @@ int32_t walFetchBody(SWalReader *pRead, SWalCkHead **ppHead) {
return
0
;
return
0
;
}
}
int32_t
walReadVer
(
SWalReader
*
pRead
,
int64_t
ver
)
{
int32_t
walReadVer
(
SWalReader
*
pRead
er
,
int64_t
ver
)
{
wDebug
(
"vgId:%d wal start to read ver %ld"
,
pRead
->
pWal
->
cfg
.
vgId
,
ver
);
wDebug
(
"vgId:%d wal start to read ver %ld"
,
pRead
er
->
pWal
->
cfg
.
vgId
,
ver
);
int64_t
contLen
;
int64_t
contLen
;
int32_t
code
;
bool
seeked
=
false
;
bool
seeked
=
false
;
if
(
pRead
->
pWal
->
vers
.
firstVer
==
-
1
)
{
if
(
pRead
er
->
pWal
->
vers
.
firstVer
==
-
1
)
{
terrno
=
TSDB_CODE_WAL_LOG_NOT_EXIST
;
terrno
=
TSDB_CODE_WAL_LOG_NOT_EXIST
;
return
-
1
;
return
-
1
;
}
}
if
(
ver
>
pRead
->
pWal
->
vers
.
lastVer
||
ver
<
pRead
->
pWal
->
vers
.
firstVer
)
{
if
(
ver
>
pRead
er
->
pWal
->
vers
.
lastVer
||
ver
<
pReader
->
pWal
->
vers
.
firstVer
)
{
wDebug
(
"vgId:%d, invalid index:%"
PRId64
", first index:%"
PRId64
", last index:%"
PRId64
,
pRead
->
pWal
->
cfg
.
vgId
,
wDebug
(
"vgId:%d, invalid index:%"
PRId64
", first index:%"
PRId64
", last index:%"
PRId64
,
pRead
er
->
pWal
->
cfg
.
vgId
,
ver
,
pRead
->
pWal
->
vers
.
firstVer
,
pRead
->
pWal
->
vers
.
lastVer
);
ver
,
pRead
er
->
pWal
->
vers
.
firstVer
,
pReader
->
pWal
->
vers
.
lastVer
);
terrno
=
TSDB_CODE_WAL_LOG_NOT_EXIST
;
terrno
=
TSDB_CODE_WAL_LOG_NOT_EXIST
;
return
-
1
;
return
-
1
;
}
}
if
(
pRead
->
curInvalid
||
pRead
->
curVersion
!=
ver
)
{
if
(
pRead
er
->
curInvalid
||
pReader
->
curVersion
!=
ver
)
{
if
(
walReadSeekVer
(
pRead
,
ver
)
<
0
)
{
if
(
walReadSeekVer
(
pRead
er
,
ver
)
<
0
)
{
wError
(
"vgId:%d, unexpected wal log, index:%"
PRId64
", since %s"
,
pRead
->
pWal
->
cfg
.
vgId
,
ver
,
terrstr
());
wError
(
"vgId:%d, unexpected wal log, index:%"
PRId64
", since %s"
,
pRead
er
->
pWal
->
cfg
.
vgId
,
ver
,
terrstr
());
return
-
1
;
return
-
1
;
}
}
seeked
=
true
;
seeked
=
true
;
}
}
while
(
1
)
{
while
(
1
)
{
contLen
=
taosReadFile
(
pRead
->
pLogFile
,
pRead
->
pHead
,
sizeof
(
SWalCkHead
));
contLen
=
taosReadFile
(
pRead
er
->
pLogFile
,
pReader
->
pHead
,
sizeof
(
SWalCkHead
));
if
(
contLen
==
sizeof
(
SWalCkHead
))
{
if
(
contLen
==
sizeof
(
SWalCkHead
))
{
break
;
break
;
}
else
if
(
contLen
==
0
&&
!
seeked
)
{
}
else
if
(
contLen
==
0
&&
!
seeked
)
{
walReadSeekVerImpl
(
pRead
,
ver
);
walReadSeekVerImpl
(
pRead
er
,
ver
);
seeked
=
true
;
seeked
=
true
;
continue
;
continue
;
}
else
{
}
else
{
...
@@ -467,26 +468,26 @@ int32_t walReadVer(SWalReader *pRead, int64_t ver) {
...
@@ -467,26 +468,26 @@ int32_t walReadVer(SWalReader *pRead, int64_t ver) {
}
}
}
}
co
ntLen
=
walValidHeadCksum
(
pRead
->
pHead
);
co
de
=
walValidHeadCksum
(
pReader
->
pHead
);
if
(
co
ntLen
!=
0
)
{
if
(
co
de
!=
0
)
{
wError
(
"vgId:%d, unexpected wal log, index:%"
PRId64
", since head checksum not passed"
,
pRead
->
pWal
->
cfg
.
vgId
,
wError
(
"vgId:%d, unexpected wal log, index:%"
PRId64
", since head checksum not passed"
,
pRead
er
->
pWal
->
cfg
.
vgId
,
ver
);
ver
);
terrno
=
TSDB_CODE_WAL_FILE_CORRUPTED
;
terrno
=
TSDB_CODE_WAL_FILE_CORRUPTED
;
return
-
1
;
return
-
1
;
}
}
if
(
pRead
->
capacity
<
pRead
->
pHead
->
head
.
bodyLen
)
{
if
(
pRead
er
->
capacity
<
pReader
->
pHead
->
head
.
bodyLen
)
{
void
*
ptr
=
taosMemoryRealloc
(
pRead
->
pHead
,
sizeof
(
SWalCkHead
)
+
pRead
->
pHead
->
head
.
bodyLen
);
void
*
ptr
=
taosMemoryRealloc
(
pRead
er
->
pHead
,
sizeof
(
SWalCkHead
)
+
pReader
->
pHead
->
head
.
bodyLen
);
if
(
ptr
==
NULL
)
{
if
(
ptr
==
NULL
)
{
terrno
=
TSDB_CODE_WAL_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_WAL_OUT_OF_MEMORY
;
return
-
1
;
return
-
1
;
}
}
pRead
->
pHead
=
ptr
;
pRead
er
->
pHead
=
ptr
;
pRead
->
capacity
=
pRead
->
pHead
->
head
.
bodyLen
;
pRead
er
->
capacity
=
pReader
->
pHead
->
head
.
bodyLen
;
}
}
if
((
contLen
=
taosReadFile
(
pRead
->
pLogFile
,
pRead
->
pHead
->
head
.
body
,
pRead
->
pHead
->
head
.
bodyLen
))
!=
if
((
contLen
=
taosReadFile
(
pRead
er
->
pLogFile
,
pReader
->
pHead
->
head
.
body
,
pReader
->
pHead
->
head
.
bodyLen
))
!=
pRead
->
pHead
->
head
.
bodyLen
)
{
pRead
er
->
pHead
->
head
.
bodyLen
)
{
if
(
contLen
<
0
)
if
(
contLen
<
0
)
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
else
{
else
{
...
@@ -496,25 +497,28 @@ int32_t walReadVer(SWalReader *pRead, int64_t ver) {
...
@@ -496,25 +497,28 @@ int32_t walReadVer(SWalReader *pRead, int64_t ver) {
return
-
1
;
return
-
1
;
}
}
if
(
pRead
->
pHead
->
head
.
version
!=
ver
)
{
if
(
pRead
er
->
pHead
->
head
.
version
!=
ver
)
{
wError
(
"vgId:%d, unexpected wal log, index:%"
PRId64
", read request index:%"
PRId64
,
pRead
->
pWal
->
cfg
.
vgId
,
wError
(
"vgId:%d, unexpected wal log, index:%"
PRId64
", read request index:%"
PRId64
,
pRead
er
->
pWal
->
cfg
.
vgId
,
pRead
->
pHead
->
head
.
version
,
ver
);
pRead
er
->
pHead
->
head
.
version
,
ver
);
pRead
->
curInvalid
=
1
;
pRead
er
->
curInvalid
=
1
;
terrno
=
TSDB_CODE_WAL_FILE_CORRUPTED
;
terrno
=
TSDB_CODE_WAL_FILE_CORRUPTED
;
ASSERT
(
0
);
ASSERT
(
0
);
return
-
1
;
return
-
1
;
}
}
co
ntLen
=
walValidBodyCksum
(
pRead
->
pHead
);
co
de
=
walValidBodyCksum
(
pReader
->
pHead
);
if
(
co
ntLen
!=
0
)
{
if
(
co
de
!=
0
)
{
wError
(
"vgId:%d, unexpected wal log, index:%"
PRId64
", since body checksum not passed"
,
pRead
->
pWal
->
cfg
.
vgId
,
wError
(
"vgId:%d, unexpected wal log, index:%"
PRId64
", since body checksum not passed"
,
pRead
er
->
pWal
->
cfg
.
vgId
,
ver
);
ver
);
pRead
->
curInvalid
=
1
;
uint32_t
readCkSum
=
walCalcBodyCksum
(
pReader
->
pHead
->
head
.
body
,
pReader
->
pHead
->
head
.
bodyLen
);
uint32_t
logCkSum
=
pReader
->
pHead
->
cksumBody
;
wError
(
"checksum written into log: %u, checksum calculated: %u"
,
logCkSum
,
readCkSum
);
pReader
->
curInvalid
=
1
;
terrno
=
TSDB_CODE_WAL_FILE_CORRUPTED
;
terrno
=
TSDB_CODE_WAL_FILE_CORRUPTED
;
ASSERT
(
0
);
ASSERT
(
0
);
return
-
1
;
return
-
1
;
}
}
pRead
->
curVersion
++
;
pRead
er
->
curVersion
++
;
return
0
;
return
0
;
}
}
source/libs/wal/src/walWrite.c
浏览文件 @
0c942e62
...
@@ -289,18 +289,25 @@ int32_t walEndSnapshot(SWal *pWal) {
...
@@ -289,18 +289,25 @@ int32_t walEndSnapshot(SWal *pWal) {
newTotSize
-=
iter
->
fileSize
;
newTotSize
-=
iter
->
fileSize
;
}
}
}
}
char
fnameStr
[
WAL_FILE_LEN
];
int32_t
actualDelete
=
0
;
char
fnameStr
[
WAL_FILE_LEN
];
// remove file
// remove file
for
(
int
i
=
0
;
i
<
deleteCnt
;
i
++
)
{
for
(
int
i
=
0
;
i
<
deleteCnt
;
i
++
)
{
pInfo
=
taosArrayGet
(
pWal
->
fileInfoSet
,
i
);
pInfo
=
taosArrayGet
(
pWal
->
fileInfoSet
,
i
);
walBuildLogName
(
pWal
,
pInfo
->
firstVer
,
fnameStr
);
walBuildLogName
(
pWal
,
pInfo
->
firstVer
,
fnameStr
);
taosRemoveFile
(
fnameStr
);
if
(
taosRemoveFile
(
fnameStr
)
<
0
)
{
goto
UPDATE_META
;
}
walBuildIdxName
(
pWal
,
pInfo
->
firstVer
,
fnameStr
);
walBuildIdxName
(
pWal
,
pInfo
->
firstVer
,
fnameStr
);
taosRemoveFile
(
fnameStr
);
if
(
taosRemoveFile
(
fnameStr
)
<
0
)
{
ASSERT
(
0
);
}
actualDelete
++
;
}
}
UPDATE_META:
// make new array, remove files
// make new array, remove files
taosArrayPopFrontBatch
(
pWal
->
fileInfoSet
,
deleteCnt
);
taosArrayPopFrontBatch
(
pWal
->
fileInfoSet
,
actualDelete
);
if
(
taosArrayGetSize
(
pWal
->
fileInfoSet
)
==
0
)
{
if
(
taosArrayGetSize
(
pWal
->
fileInfoSet
)
==
0
)
{
pWal
->
writeCur
=
-
1
;
pWal
->
writeCur
=
-
1
;
pWal
->
vers
.
firstVer
=
-
1
;
pWal
->
vers
.
firstVer
=
-
1
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录