Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
a1ac1c63
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看板
提交
a1ac1c63
编写于
8月 19, 2021
作者:
L
lichuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-4352]<feature>refactor code,use meta-ver instead of tmp file
上级
dc778057
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
47 addition
and
27 deletion
+47
-27
src/tsdb/inc/tsdbFile.h
src/tsdb/inc/tsdbFile.h
+2
-2
src/tsdb/src/tsdbCommit.c
src/tsdb/src/tsdbCommit.c
+41
-20
src/tsdb/src/tsdbFS.c
src/tsdb/src/tsdbFS.c
+1
-1
src/tsdb/src/tsdbFile.c
src/tsdb/src/tsdbFile.c
+2
-3
src/tsdb/src/tsdbSync.c
src/tsdb/src/tsdbSync.c
+1
-1
未找到文件。
src/tsdb/inc/tsdbFile.h
浏览文件 @
a1ac1c63
...
...
@@ -38,7 +38,7 @@
#define TSDB_FILE_IS_OK(tf) (TSDB_FILE_STATE(tf) == TSDB_FILE_STATE_OK)
#define TSDB_FILE_IS_BAD(tf) (TSDB_FILE_STATE(tf) == TSDB_FILE_STATE_BAD)
typedef
enum
{
TSDB_FILE_HEAD
=
0
,
TSDB_FILE_DATA
,
TSDB_FILE_LAST
,
TSDB_FILE_MAX
,
TSDB_FILE_META
,
TSDB_FILE_META_TMP
}
TSDB_FILE_T
;
typedef
enum
{
TSDB_FILE_HEAD
=
0
,
TSDB_FILE_DATA
,
TSDB_FILE_LAST
,
TSDB_FILE_MAX
,
TSDB_FILE_META
}
TSDB_FILE_T
;
// =============== SMFile
typedef
struct
{
...
...
@@ -56,7 +56,7 @@ typedef struct {
uint8_t
state
;
}
SMFile
;
void
tsdbInitMFile
(
SMFile
*
pMFile
,
SDiskID
did
,
int
vid
,
uint32_t
ver
,
bool
tmp
);
void
tsdbInitMFile
(
SMFile
*
pMFile
,
SDiskID
did
,
int
vid
,
uint32_t
ver
);
void
tsdbInitMFileEx
(
SMFile
*
pMFile
,
const
SMFile
*
pOMFile
);
int
tsdbEncodeSMFile
(
void
**
buf
,
SMFile
*
pMFile
);
void
*
tsdbDecodeSMFile
(
void
*
buf
,
SMFile
*
pMFile
);
...
...
src/tsdb/src/tsdbCommit.c
浏览文件 @
a1ac1c63
...
...
@@ -264,6 +264,35 @@ int tsdbWriteBlockIdx(SDFile *pHeadf, SArray *pIdxA, void **ppBuf) {
// =================== Commit Meta Data
static
int
tsdbInitCommitMetaFile
(
STsdbRepo
*
pRepo
,
SMFile
*
pMf
,
bool
open
)
{
STsdbFS
*
pfs
=
REPO_FS
(
pRepo
);
SMFile
*
pOMFile
=
pfs
->
cstatus
->
pmf
;
SDiskID
did
;
// Create/Open a meta file or open the existing file
if
(
pOMFile
==
NULL
)
{
// Create a new meta file
did
.
level
=
TFS_PRIMARY_LEVEL
;
did
.
id
=
TFS_PRIMARY_ID
;
tsdbInitMFile
(
pMf
,
did
,
REPO_ID
(
pRepo
),
FS_TXN_VERSION
(
REPO_FS
(
pRepo
)));
if
(
open
&&
tsdbCreateMFile
(
pMf
,
true
)
<
0
)
{
tsdbError
(
"vgId:%d failed to create META file since %s"
,
REPO_ID
(
pRepo
),
tstrerror
(
terrno
));
return
-
1
;
}
tsdbInfo
(
"vgId:%d meta file %s is created to commit"
,
REPO_ID
(
pRepo
),
TSDB_FILE_FULL_NAME
(
pMf
));
}
else
{
tsdbInitMFileEx
(
pMf
,
pOMFile
);
if
(
open
&&
tsdbOpenMFile
(
pMf
,
O_WRONLY
)
<
0
)
{
tsdbError
(
"vgId:%d failed to open META file since %s"
,
REPO_ID
(
pRepo
),
tstrerror
(
terrno
));
return
-
1
;
}
}
return
0
;
}
static
int
tsdbCommitMeta
(
STsdbRepo
*
pRepo
)
{
STsdbFS
*
pfs
=
REPO_FS
(
pRepo
);
SMemTable
*
pMem
=
pRepo
->
imem
;
...
...
@@ -272,34 +301,25 @@ static int tsdbCommitMeta(STsdbRepo *pRepo) {
SActObj
*
pAct
=
NULL
;
SActCont
*
pCont
=
NULL
;
SListNode
*
pNode
=
NULL
;
SDiskID
did
;
ASSERT
(
pOMFile
!=
NULL
||
listNEles
(
pMem
->
actList
)
>
0
);
if
(
listNEles
(
pMem
->
actList
)
<=
0
)
{
// no meta data to commit, just keep the old meta file
tsdbUpdateMFile
(
pfs
,
pOMFile
);
return
0
;
}
else
{
// Create/Open a meta file or open the existing file
if
(
pOMFile
==
NULL
)
{
// Create a new meta file
did
.
level
=
TFS_PRIMARY_LEVEL
;
did
.
id
=
TFS_PRIMARY_ID
;
tsdbInitMFile
(
&
mf
,
did
,
REPO_ID
(
pRepo
),
FS_TXN_VERSION
(
REPO_FS
(
pRepo
)),
false
);
if
(
tsdbCreateMFile
(
&
mf
,
true
)
<
0
)
{
tsdbError
(
"vgId:%d failed to create META file since %s"
,
REPO_ID
(
pRepo
),
tstrerror
(
terrno
));
if
(
tsTsdbMetaCompactRatio
>
0
)
{
if
(
tsdbInitCommitMetaFile
(
pRepo
,
&
mf
,
false
)
<
0
)
{
return
-
1
;
}
int
ret
=
tsdbCompactMetaFile
(
pRepo
,
pfs
,
&
mf
);
if
(
ret
<
0
)
tsdbError
(
"compact meta file error"
);
tsdbInfo
(
"vgId:%d meta file %s is created to commit"
,
REPO_ID
(
pRepo
),
TSDB_FILE_FULL_NAME
(
&
mf
));
}
else
{
tsdbInitMFileEx
(
&
mf
,
pOMFile
);
if
(
tsdbOpenMFile
(
&
mf
,
O_WRONLY
)
<
0
)
{
tsdbError
(
"vgId:%d failed to open META file since %s"
,
REPO_ID
(
pRepo
),
tstrerror
(
terrno
));
return
-
1
;
}
return
ret
;
}
return
0
;
}
else
{
if
(
tsdbInitCommitMetaFile
(
pRepo
,
&
mf
,
true
)
<
0
)
{
return
-
1
;
}
}
...
...
@@ -477,7 +497,7 @@ static int tsdbCompactMetaFile(STsdbRepo *pRepo, STsdbFS *pfs, SMFile *pMFile) {
// first create tmp meta file
did
.
level
=
TFS_PRIMARY_LEVEL
;
did
.
id
=
TFS_PRIMARY_ID
;
tsdbInitMFile
(
&
mf
,
did
,
REPO_ID
(
pRepo
),
FS_TXN_VERSION
(
REPO_FS
(
pRepo
))
,
true
);
tsdbInitMFile
(
&
mf
,
did
,
REPO_ID
(
pRepo
),
FS_TXN_VERSION
(
REPO_FS
(
pRepo
))
+
1
);
if
(
tsdbCreateMFile
(
&
mf
,
true
)
<
0
)
{
tsdbError
(
"vgId:%d failed to create META file since %s"
,
REPO_ID
(
pRepo
),
tstrerror
(
terrno
));
...
...
@@ -542,6 +562,7 @@ _err:
if
(
code
==
0
)
{
// rename meta.tmp -> meta
tsdbInfo
(
"vgId:%d meta file rename %s -> %s"
,
REPO_ID
(
pRepo
),
TSDB_FILE_FULL_NAME
(
&
mf
),
TSDB_FILE_FULL_NAME
(
pMFile
));
taosRename
(
mf
.
f
.
aname
,
pMFile
->
f
.
aname
);
tstrncpy
(
mf
.
f
.
aname
,
pMFile
->
f
.
aname
,
TSDB_FILENAME_LEN
);
tstrncpy
(
mf
.
f
.
rname
,
pMFile
->
f
.
rname
,
TSDB_FILENAME_LEN
);
...
...
src/tsdb/src/tsdbFS.c
浏览文件 @
a1ac1c63
...
...
@@ -274,7 +274,7 @@ static int tsdbCreateMeta(STsdbRepo *pRepo) {
// Create a new meta file
did
.
level
=
TFS_PRIMARY_LEVEL
;
did
.
id
=
TFS_PRIMARY_ID
;
tsdbInitMFile
(
&
mf
,
did
,
REPO_ID
(
pRepo
),
FS_TXN_VERSION
(
REPO_FS
(
pRepo
))
,
false
);
tsdbInitMFile
(
&
mf
,
did
,
REPO_ID
(
pRepo
),
FS_TXN_VERSION
(
REPO_FS
(
pRepo
)));
if
(
tsdbCreateMFile
(
&
mf
,
true
)
<
0
)
{
tsdbError
(
"vgId:%d failed to create META file since %s"
,
REPO_ID
(
pRepo
),
tstrerror
(
terrno
));
...
...
src/tsdb/src/tsdbFile.c
浏览文件 @
a1ac1c63
...
...
@@ -21,7 +21,6 @@ static const char *TSDB_FNAME_SUFFIX[] = {
"last"
,
// TSDB_FILE_LAST
""
,
// TSDB_FILE_MAX
"meta"
,
// TSDB_FILE_META
"meta.tmp"
,
// TSDB_FILE_META_TMP
};
static
void
tsdbGetFilename
(
int
vid
,
int
fid
,
uint32_t
ver
,
TSDB_FILE_T
ftype
,
char
*
fname
);
...
...
@@ -31,7 +30,7 @@ static void *tsdbDecodeDFInfo(void *buf, SDFInfo *pInfo);
static
int
tsdbRollBackDFile
(
SDFile
*
pDFile
);
// ============== SMFile
void
tsdbInitMFile
(
SMFile
*
pMFile
,
SDiskID
did
,
int
vid
,
uint32_t
ver
,
bool
tmp
)
{
void
tsdbInitMFile
(
SMFile
*
pMFile
,
SDiskID
did
,
int
vid
,
uint32_t
ver
)
{
char
fname
[
TSDB_FILENAME_LEN
];
TSDB_FILE_SET_STATE
(
pMFile
,
TSDB_FILE_STATE_OK
);
...
...
@@ -39,7 +38,7 @@ void tsdbInitMFile(SMFile *pMFile, SDiskID did, int vid, uint32_t ver, bool tmp)
memset
(
&
(
pMFile
->
info
),
0
,
sizeof
(
pMFile
->
info
));
pMFile
->
info
.
magic
=
TSDB_FILE_INIT_MAGIC
;
tsdbGetFilename
(
vid
,
0
,
ver
,
tmp
?
TSDB_FILE_META_TMP
:
TSDB_FILE_META
,
fname
);
tsdbGetFilename
(
vid
,
0
,
ver
,
TSDB_FILE_META
,
fname
);
tfsInitFile
(
TSDB_FILE_F
(
pMFile
),
did
.
level
,
did
.
id
,
fname
);
}
...
...
src/tsdb/src/tsdbSync.c
浏览文件 @
a1ac1c63
...
...
@@ -209,7 +209,7 @@ static int32_t tsdbSyncRecvMeta(SSyncH *pSynch) {
// Recv from remote
SMFile
mf
;
SDiskID
did
=
{.
level
=
TFS_PRIMARY_LEVEL
,
.
id
=
TFS_PRIMARY_ID
};
tsdbInitMFile
(
&
mf
,
did
,
REPO_ID
(
pRepo
),
FS_TXN_VERSION
(
REPO_FS
(
pRepo
))
,
false
);
tsdbInitMFile
(
&
mf
,
did
,
REPO_ID
(
pRepo
),
FS_TXN_VERSION
(
REPO_FS
(
pRepo
)));
if
(
tsdbCreateMFile
(
&
mf
,
false
)
<
0
)
{
tsdbError
(
"vgId:%d, failed to create file while recv metafile since %s"
,
REPO_ID
(
pRepo
),
tstrerror
(
terrno
));
return
-
1
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录