Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
a6303b07
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看板
提交
a6303b07
编写于
1月 11, 2022
作者:
L
Liu Jicong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
force repair
上级
c22de779
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
45 addition
and
23 deletion
+45
-23
source/libs/wal/src/walMeta.c
source/libs/wal/src/walMeta.c
+18
-20
source/libs/wal/src/walMgmt.c
source/libs/wal/src/walMgmt.c
+4
-1
source/libs/wal/test/walMetaTest.cpp
source/libs/wal/test/walMetaTest.cpp
+22
-0
tests/script/sim/db/basic1.sim
tests/script/sim/db/basic1.sim
+1
-2
未找到文件。
source/libs/wal/src/walMeta.c
浏览文件 @
a6303b07
...
...
@@ -65,6 +65,7 @@ static inline int64_t walScanLogGetLastVer(SWal* pWal) {
struct
stat
statbuf
;
stat
(
fnameStr
,
&
statbuf
);
int
readSize
=
MIN
(
WAL_MAX_SIZE
+
2
,
statbuf
.
st_size
);
pLastFileInfo
->
fileSize
=
statbuf
.
st_size
;
FileFd
fd
=
taosOpenFileRead
(
fnameStr
);
if
(
fd
<
0
)
{
...
...
@@ -91,7 +92,7 @@ static inline int64_t walScanLogGetLastVer(SWal* pWal) {
char
*
haystack
=
buf
;
char
*
found
=
NULL
;
char
*
candidate
=
NULL
;
char
*
candidate
;
while
((
candidate
=
tmemmem
(
haystack
,
readSize
-
(
haystack
-
buf
),
(
char
*
)
&
magic
,
sizeof
(
uint64_t
)))
!=
NULL
)
{
// read and validate
SWalHead
*
logContent
=
(
SWalHead
*
)
candidate
;
...
...
@@ -142,7 +143,6 @@ int walCheckAndRepairMeta(SWal* pWal) {
SWalFileInfo
fileInfo
;
memset
(
&
fileInfo
,
-
1
,
sizeof
(
SWalFileInfo
));
sscanf
(
name
,
"%"
PRId64
".log"
,
&
fileInfo
.
firstVer
);
FileFd
fd
=
taosOpenFileRead
(
ent
->
d_name
);
//get lastVer
//get size
taosArrayPush
(
pLogInfoArray
,
&
fileInfo
);
...
...
@@ -159,28 +159,25 @@ int walCheckAndRepairMeta(SWal* pWal) {
}
int
newSz
=
taosArrayGetSize
(
pLogInfoArray
);
// case 1. meta file not exist / cannot be parsed
if
(
pWal
->
fileInfoSet
==
NULL
&&
newSz
!=
0
)
{
// recover fileInfo set
pWal
->
fileInfoSet
=
pLogInfoArray
;
if
(
newSz
!=
0
)
{
// recover meta version
pWal
->
vers
.
firstVer
=
((
SWalFileInfo
*
)
taosArrayGet
(
pLogInfoArray
,
0
))
->
firstVer
;
pWal
->
writeCur
=
newSz
-
1
;
}
// recover file size
}
else
if
(
oldSz
<
newSz
)
{
if
(
oldSz
<
newSz
)
{
for
(
int
i
=
oldSz
;
i
<
newSz
;
i
++
)
{
SWalFileInfo
*
pFileInfo
=
taosArrayGet
(
pLogInfoArray
,
i
);
taosArrayPush
(
pWal
->
fileInfoSet
,
pFileInfo
);
}
pWal
->
writeCur
=
newSz
-
1
;
}
if
(
pWal
->
fileInfoSet
&&
taosArrayGetSize
(
pWal
->
fileInfoSet
)
!=
0
)
{
pWal
->
vers
.
firstVer
=
((
SWalFileInfo
*
)
taosArrayGet
(
pLogInfoArray
,
0
))
->
firstVer
;
pWal
->
vers
.
lastVer
=
walScanLogGetLastVer
(
pWal
);
((
SWalFileInfo
*
)
taosArrayGetLast
(
pWal
->
fileInfoSet
))
->
lastVer
=
pWal
->
vers
.
lastVer
;
ASSERT
(
pWal
->
vers
.
lastVer
!=
-
1
);
}
int
code
=
walSaveMeta
(
pWal
);
if
(
code
<
0
)
{
taosArrayDestroy
(
pLogInfoArray
);
return
-
1
;
}
}
// case 2. versions in meta not match log
// or some log not included in meta
// (e.g. program killed)
...
...
@@ -204,14 +201,11 @@ int walCheckAndRepairMeta(SWal* pWal) {
}
#endif
int
code
=
walSaveMeta
(
pWal
);
if
(
code
<
0
)
{
return
-
1
;
}
// get last version of this file
//
// rebuild meta
taosArrayDestroy
(
pLogInfoArray
);
return
0
;
}
...
...
@@ -419,6 +413,10 @@ int walLoadMeta(SWal* pWal) {
}
memset
(
buf
,
0
,
size
+
5
);
FileFd
fd
=
taosOpenFileRead
(
fnameStr
);
if
(
fd
<
0
)
{
terrno
=
TSDB_CODE_WAL_FILE_CORRUPTED
;
return
-
1
;
}
if
(
taosReadFile
(
fd
,
buf
,
size
)
!=
size
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
taosCloseFile
(
fd
);
...
...
source/libs/wal/src/walMgmt.c
浏览文件 @
a6303b07
...
...
@@ -122,7 +122,9 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) {
return
NULL
;
}
if
(
walLoadMeta
(
pWal
)
<
0
&&
walCheckAndRepairMeta
(
pWal
)
<
0
)
{
walLoadMeta
(
pWal
);
if
(
walCheckAndRepairMeta
(
pWal
)
<
0
)
{
taosRemoveRef
(
tsWal
.
refSetId
,
pWal
->
refId
);
pthread_mutex_destroy
(
&
pWal
->
mutex
);
taosArrayDestroy
(
pWal
->
fileInfoSet
);
...
...
@@ -131,6 +133,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) {
}
if
(
walCheckAndRepairIdx
(
pWal
)
<
0
)
{
}
wDebug
(
"vgId:%d, wal:%p is opened, level:%d fsyncPeriod:%d"
,
pWal
->
cfg
.
vgId
,
pWal
,
pWal
->
cfg
.
level
,
...
...
source/libs/wal/test/walMetaTest.cpp
浏览文件 @
a6303b07
...
...
@@ -380,4 +380,26 @@ TEST_F(WalRetentionEnv, repairMeta1) {
ASSERT_EQ
(
code
,
0
);
}
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
int
ver
=
rand
()
%
200
;
code
=
walReadWithHandle
(
pRead
,
ver
);
ASSERT_EQ
(
code
,
0
);
// printf("rrbody: \n");
// for(int i = 0; i < pRead->pHead->head.len; i++) {
// printf("%d ", pRead->pHead->head.body[i]);
//}
// printf("\n");
ASSERT_EQ
(
pRead
->
pHead
->
head
.
version
,
ver
);
ASSERT_EQ
(
pRead
->
curVersion
,
ver
+
1
);
char
newStr
[
100
];
sprintf
(
newStr
,
"%s-%d"
,
ranStr
,
ver
);
int
len
=
strlen
(
newStr
);
ASSERT_EQ
(
pRead
->
pHead
->
head
.
len
,
len
);
for
(
int
j
=
0
;
j
<
len
;
j
++
)
{
EXPECT_EQ
(
newStr
[
j
],
pRead
->
pHead
->
head
.
body
[
j
]);
}
}
}
tests/script/sim/db/basic1.sim
浏览文件 @
a6303b07
...
...
@@ -85,7 +85,6 @@ if $data02 != 2 then
return -1
endi
return
system sh/exec.sh -n dnode1 -s stop -x SIGKILL
system sh/exec.sh -n dnode1 -s start
...
...
@@ -104,4 +103,4 @@ if $rows != 2 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
\ No newline at end of file
system sh/exec.sh -n dnode1 -s stop -x SIGINT
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录