Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f0427c93
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看板
提交
f0427c93
编写于
10月 18, 2022
作者:
B
Benguang Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: ftrunc on appending WAL log failure for recovery in walWriteImpl
上级
23e18bff
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
29 addition
and
12 deletion
+29
-12
source/libs/wal/src/walWrite.c
source/libs/wal/src/walWrite.c
+29
-12
未找到文件。
source/libs/wal/src/walWrite.c
浏览文件 @
f0427c93
...
@@ -408,25 +408,33 @@ END:
...
@@ -408,25 +408,33 @@ END:
static
int32_t
walWriteIndex
(
SWal
*
pWal
,
int64_t
ver
,
int64_t
offset
)
{
static
int32_t
walWriteIndex
(
SWal
*
pWal
,
int64_t
ver
,
int64_t
offset
)
{
SWalIdxEntry
entry
=
{.
ver
=
ver
,
.
offset
=
offset
};
SWalIdxEntry
entry
=
{.
ver
=
ver
,
.
offset
=
offset
};
int64_t
idxOffset
=
taosLSeekFile
(
pWal
->
pIdxFile
,
0
,
SEEK_END
);
SWalFileInfo
*
pFileInfo
=
walGetCurFileInfo
(
pWal
);
ASSERT
(
pFileInfo
!=
NULL
);
ASSERT
(
pFileInfo
->
firstVer
>=
0
);
int64_t
idxOffset
=
(
entry
.
ver
-
pFileInfo
->
firstVer
)
*
sizeof
(
SWalIdxEntry
);
wDebug
(
"vgId:%d, write index, index:%"
PRId64
", offset:%"
PRId64
", at %"
PRId64
,
pWal
->
cfg
.
vgId
,
ver
,
offset
,
wDebug
(
"vgId:%d, write index, index:%"
PRId64
", offset:%"
PRId64
", at %"
PRId64
,
pWal
->
cfg
.
vgId
,
ver
,
offset
,
idxOffset
);
idxOffset
);
int64_t
size
=
taosWriteFile
(
pWal
->
pIdxFile
,
&
entry
,
sizeof
(
SWalIdxEntry
));
int64_t
size
=
taosWriteFile
(
pWal
->
pIdxFile
,
&
entry
,
sizeof
(
SWalIdxEntry
));
if
(
size
!=
sizeof
(
SWalIdxEntry
))
{
if
(
size
!=
sizeof
(
SWalIdxEntry
))
{
wError
(
"vgId:%d, failed to write idx entry due to %s. ver:%lld"
,
pWal
->
cfg
.
vgId
,
strerror
(
errno
),
ver
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
// TODO truncate
return
-
1
;
return
-
1
;
}
}
return
0
;
return
0
;
}
}
// TODO gurantee atomicity by truncate failed writing
static
FORCE_INLINE
int32_t
walWriteImpl
(
SWal
*
pWal
,
int64_t
index
,
tmsg_t
msgType
,
SWalSyncInfo
syncMeta
,
static
FORCE_INLINE
int32_t
walWriteImpl
(
SWal
*
pWal
,
int64_t
index
,
tmsg_t
msgType
,
SWalSyncInfo
syncMeta
,
const
void
*
body
,
int32_t
bodyLen
)
{
const
void
*
body
,
int32_t
bodyLen
)
{
int64_t
code
=
0
;
int64_t
code
=
0
;
int64_t
offset
=
walGetCurFileOffset
(
pWal
);
int64_t
offset
=
walGetCurFileOffset
(
pWal
);
SWalFileInfo
*
pFileInfo
=
walGetCurFileInfo
(
pWal
);
ASSERT
(
pFileInfo
!=
NULL
);
if
(
pFileInfo
->
firstVer
==
-
1
)
{
pFileInfo
->
firstVer
=
index
;
}
pWal
->
writeHead
.
head
.
version
=
index
;
pWal
->
writeHead
.
head
.
version
=
index
;
pWal
->
writeHead
.
head
.
bodyLen
=
bodyLen
;
pWal
->
writeHead
.
head
.
bodyLen
=
bodyLen
;
pWal
->
writeHead
.
head
.
msgType
=
msgType
;
pWal
->
writeHead
.
head
.
msgType
=
msgType
;
...
@@ -437,11 +445,9 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy
...
@@ -437,11 +445,9 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy
pWal
->
writeHead
.
cksumHead
=
walCalcHeadCksum
(
&
pWal
->
writeHead
);
pWal
->
writeHead
.
cksumHead
=
walCalcHeadCksum
(
&
pWal
->
writeHead
);
pWal
->
writeHead
.
cksumBody
=
walCalcBodyCksum
(
body
,
bodyLen
);
pWal
->
writeHead
.
cksumBody
=
walCalcBodyCksum
(
body
,
bodyLen
);
wDebug
(
"vgId:%d, wal write log %ld, msgType: %s"
,
pWal
->
cfg
.
vgId
,
index
,
TMSG_INFO
(
msgType
));
wDebug
(
"vgId:%d, wal write log %ld, msgType: %s"
,
pWal
->
cfg
.
vgId
,
index
,
TMSG_INFO
(
msgType
));
if
(
taosWriteFile
(
pWal
->
pLogFile
,
&
pWal
->
writeHead
,
sizeof
(
SWalCkHead
))
!=
sizeof
(
SWalCkHead
))
{
if
(
taosWriteFile
(
pWal
->
pLogFile
,
&
pWal
->
writeHead
,
sizeof
(
SWalCkHead
))
!=
sizeof
(
SWalCkHead
))
{
// TODO ftruncate
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
wError
(
"vgId:%d, file:%"
PRId64
".log, failed to write since %s"
,
pWal
->
cfg
.
vgId
,
walGetLastFileFirstVer
(
pWal
),
wError
(
"vgId:%d, file:%"
PRId64
".log, failed to write since %s"
,
pWal
->
cfg
.
vgId
,
walGetLastFileFirstVer
(
pWal
),
strerror
(
errno
));
strerror
(
errno
));
...
@@ -450,7 +456,6 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy
...
@@ -450,7 +456,6 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy
}
}
if
(
taosWriteFile
(
pWal
->
pLogFile
,
(
char
*
)
body
,
bodyLen
)
!=
bodyLen
)
{
if
(
taosWriteFile
(
pWal
->
pLogFile
,
(
char
*
)
body
,
bodyLen
)
!=
bodyLen
)
{
// TODO ftruncate
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
wError
(
"vgId:%d, file:%"
PRId64
".log, failed to write since %s"
,
pWal
->
cfg
.
vgId
,
walGetLastFileFirstVer
(
pWal
),
wError
(
"vgId:%d, file:%"
PRId64
".log, failed to write since %s"
,
pWal
->
cfg
.
vgId
,
walGetLastFileFirstVer
(
pWal
),
strerror
(
errno
));
strerror
(
errno
));
...
@@ -460,7 +465,6 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy
...
@@ -460,7 +465,6 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy
code
=
walWriteIndex
(
pWal
,
index
,
offset
);
code
=
walWriteIndex
(
pWal
,
index
,
offset
);
if
(
code
<
0
)
{
if
(
code
<
0
)
{
// TODO ftruncate
goto
END
;
goto
END
;
}
}
...
@@ -468,14 +472,27 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy
...
@@ -468,14 +472,27 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy
if
(
pWal
->
vers
.
firstVer
==
-
1
)
pWal
->
vers
.
firstVer
=
index
;
if
(
pWal
->
vers
.
firstVer
==
-
1
)
pWal
->
vers
.
firstVer
=
index
;
pWal
->
vers
.
lastVer
=
index
;
pWal
->
vers
.
lastVer
=
index
;
pWal
->
totSize
+=
sizeof
(
SWalCkHead
)
+
bodyLen
;
pWal
->
totSize
+=
sizeof
(
SWalCkHead
)
+
bodyLen
;
if
(
walGetCurFileInfo
(
pWal
)
->
firstVer
==
-
1
)
{
pFileInfo
->
lastVer
=
index
;
walGetCurFileInfo
(
pWal
)
->
firstVer
=
index
;
pFileInfo
->
fileSize
+=
sizeof
(
SWalCkHead
)
+
bodyLen
;
}
walGetCurFileInfo
(
pWal
)
->
lastVer
=
index
;
walGetCurFileInfo
(
pWal
)
->
fileSize
+=
sizeof
(
SWalCkHead
)
+
bodyLen
;
return
0
;
return
0
;
END:
END:
// recover in a reverse order
if
(
taosFtruncateFile
(
pWal
->
pLogFile
,
offset
)
<
0
)
{
wFatal
(
"vgId:%d, failed to ftruncate logfile to offset:%lld during recovery due to %s"
,
pWal
->
cfg
.
vgId
,
offset
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
ASSERT
(
0
&&
"failed to recover from error"
);
}
int64_t
idxOffset
=
(
index
-
pFileInfo
->
firstVer
)
*
sizeof
(
SWalIdxEntry
);
if
(
taosFtruncateFile
(
pWal
->
pIdxFile
,
idxOffset
)
<
0
)
{
wFatal
(
"vgId:%d, failed to ftruncate idxfile to offset:%lld during recovery due to %s"
,
pWal
->
cfg
.
vgId
,
idxOffset
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
ASSERT
(
0
&&
"failed to recover from error"
);
}
return
-
1
;
return
-
1
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录