Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
76865258
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看板
提交
76865258
编写于
9月 30, 2022
作者:
B
Benguang Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh: protect WAL meta by flushing to a tmpfile at first and then renaming
上级
36bf800e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
48 addition
and
10 deletion
+48
-10
source/libs/tdb/src/db/tdbDb.c
source/libs/tdb/src/db/tdbDb.c
+2
-2
source/libs/wal/src/walMeta.c
source/libs/wal/src/walMeta.c
+46
-8
未找到文件。
source/libs/tdb/src/db/tdbDb.c
浏览文件 @
76865258
...
...
@@ -121,7 +121,7 @@ int32_t tdbCommit(TDB *pDb, TXN *pTxn) {
for
(
pPager
=
pDb
->
pgrList
;
pPager
;
pPager
=
pPager
->
pNext
)
{
ret
=
tdbPagerCommit
(
pPager
,
pTxn
);
if
(
ret
<
0
)
{
tdbError
(
"failed to commit pager
. dbName:%s, txnId:%d"
,
pDb
->
dbName
,
pTxn
->
txnId
);
tdbError
(
"failed to commit pager
since %s. dbName:%s, txnId:%d"
,
tstrerror
(
terrno
)
,
pDb
->
dbName
,
pTxn
->
txnId
);
return
-
1
;
}
}
...
...
@@ -136,7 +136,7 @@ int32_t tdbAbort(TDB *pDb, TXN *pTxn) {
for
(
pPager
=
pDb
->
pgrList
;
pPager
;
pPager
=
pPager
->
pNext
)
{
ret
=
tdbPagerAbort
(
pPager
,
pTxn
);
if
(
ret
<
0
)
{
tdbError
(
"failed to abort pager
. dbName:%s, txnId:%d"
,
pDb
->
dbName
,
pTxn
->
txnId
);
tdbError
(
"failed to abort pager
since %s. dbName:%s, txnId:%d"
,
tstrerror
(
terrno
)
,
pDb
->
dbName
,
pTxn
->
txnId
);
return
-
1
;
}
}
...
...
source/libs/wal/src/walMeta.c
浏览文件 @
76865258
...
...
@@ -35,8 +35,12 @@ int64_t FORCE_INLINE walGetCommittedVer(SWal* pWal) { return pWal->vers.commitVe
int64_t
FORCE_INLINE
walGetAppliedVer
(
SWal
*
pWal
)
{
return
pWal
->
vers
.
appliedVer
;
}
static
FORCE_INLINE
void
walBuildMetaName
(
SWal
*
pWal
,
int
metaVer
,
char
*
buf
)
{
sprintf
(
buf
,
"%s/meta-ver%d"
,
pWal
->
path
,
metaVer
);
static
FORCE_INLINE
int
walBuildMetaName
(
SWal
*
pWal
,
int
metaVer
,
char
*
buf
)
{
return
sprintf
(
buf
,
"%s/meta-ver%d"
,
pWal
->
path
,
metaVer
);
}
static
FORCE_INLINE
int
walBuildTmpMetaName
(
SWal
*
pWal
,
char
*
buf
)
{
return
sprintf
(
buf
,
"%s/meta-ver.tmp"
,
pWal
->
path
);
}
static
FORCE_INLINE
int64_t
walScanLogGetLastVer
(
SWal
*
pWal
)
{
...
...
@@ -578,22 +582,51 @@ static int walFindCurMetaVer(SWal* pWal) {
int
walSaveMeta
(
SWal
*
pWal
)
{
int
metaVer
=
walFindCurMetaVer
(
pWal
);
char
fnameStr
[
WAL_FILE_LEN
];
walBuildMetaName
(
pWal
,
metaVer
+
1
,
fnameStr
);
TdFilePtr
pMetaFile
=
taosOpenFile
(
fnameStr
,
TD_FILE_CREATE
|
TD_FILE_WRITE
);
char
tmpFnameStr
[
WAL_FILE_LEN
];
int
n
;
// flush to a tmpfile
n
=
walBuildTmpMetaName
(
pWal
,
tmpFnameStr
);
ASSERT
(
n
<
sizeof
(
tmpFnameStr
)
&&
"Buffer overflow of file name"
);
TdFilePtr
pMetaFile
=
taosOpenFile
(
tmpFnameStr
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_TRUNC
);
if
(
pMetaFile
==
NULL
)
{
wError
(
"failed to open file due to %s. file:%s"
,
strerror
(
errno
),
tmpFnameStr
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
char
*
serialized
=
walMetaSerialize
(
pWal
);
int
len
=
strlen
(
serialized
);
if
(
len
!=
taosWriteFile
(
pMetaFile
,
serialized
,
len
))
{
// TODO:clean file
wError
(
"failed to write file due to %s. file:%s"
,
strerror
(
errno
),
tmpFnameStr
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
taosCloseFile
(
&
pMetaFile
);
taosRemoveFile
(
fnameStr
);
return
-
1
;
if
(
taosFsyncFile
(
pMetaFile
)
<
0
)
{
wError
(
"failed to sync file due to %s. file:%s"
,
strerror
(
errno
),
tmpFnameStr
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
if
(
taosCloseFile
(
&
pMetaFile
)
<
0
)
{
wError
(
"failed to close file due to %s. file:%s"
,
strerror
(
errno
),
tmpFnameStr
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
// rename it
n
=
walBuildMetaName
(
pWal
,
metaVer
+
1
,
fnameStr
);
ASSERT
(
n
<
sizeof
(
fnameStr
)
&&
"Buffer overflow of file name"
);
if
(
taosRenameFile
(
tmpFnameStr
,
fnameStr
)
<
0
)
{
wError
(
"failed to rename file due to %s. dest:%s"
,
strerror
(
errno
),
fnameStr
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
taosCloseFile
(
&
pMetaFile
);
// delete old file
if
(
metaVer
>
-
1
)
{
walBuildMetaName
(
pWal
,
metaVer
,
fnameStr
);
...
...
@@ -601,6 +634,11 @@ int walSaveMeta(SWal* pWal) {
}
taosMemoryFree
(
serialized
);
return
0
;
_err:
taosCloseFile
(
&
pMetaFile
);
taosMemoryFree
(
serialized
);
return
-
1
;
}
int
walLoadMeta
(
SWal
*
pWal
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录