Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d795ff85
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
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看板
提交
d795ff85
编写于
1月 15, 2021
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refact tsdb file
上级
5dcfd2a6
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
57 addition
and
61 deletion
+57
-61
src/tsdb/inc/tsdbFS.h
src/tsdb/inc/tsdbFS.h
+1
-1
src/tsdb/inc/tsdbFile.h
src/tsdb/inc/tsdbFile.h
+16
-26
src/tsdb/src/tsdbFile.c
src/tsdb/src/tsdbFile.c
+40
-34
未找到文件。
src/tsdb/inc/tsdbFS.h
浏览文件 @
d795ff85
...
...
@@ -30,7 +30,7 @@ typedef struct {
// ================== TSDB File System Meta
typedef
struct
{
uint
64
_t
version
;
// Commit version from 0 to increase
uint
32
_t
version
;
// Commit version from 0 to increase
int64_t
totalPoints
;
// total points
int64_t
totalStorage
;
// Uncompressed total storage
}
STsdbFSMeta
;
...
...
src/tsdb/inc/tsdbFile.h
浏览文件 @
d795ff85
...
...
@@ -34,15 +34,9 @@ extern "C" {
#define TSDB_FILE_SET_CLOSED(f) (TSDB_FILE_FD(f) = -1)
#define TSDB_FILE_LEVEL(tf) TFILE_LEVEL(TSDB_FILE_F(tf))
#define TSDB_FILE_ID(tf) TFILE_ID(TSDB_FILE_F(tf))
#define TSDB_FILE_FSYNC(tf) fsync(TSDB_FILE_FD(tf))
typedef
enum
{
TSDB_FILE_HEAD
=
0
,
TSDB_FILE_DATA
,
TSDB_FILE_LAST
,
TSDB_FILE_MAX
,
TSDB_FILE_META
,
TSDB_FILE_MANIFEST
}
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
{
...
...
@@ -63,11 +57,13 @@ void tsdbInitMFile(SMFile* pMFile, SDiskID did, int vid, uint32_t ver);
void
tsdbInitMFileEx
(
SMFile
*
pMFile
,
SMFile
*
pOMFile
);
int
tsdbEncodeSMFile
(
void
**
buf
,
SMFile
*
pMFile
);
void
*
tsdbDecodeSMFile
(
void
*
buf
,
SMFile
*
pMFile
);
int
tsdbApplyMFileChange
(
SMFile
*
from
,
SMFile
*
to
);
int
tsdbApplyMFileChange
(
SMFile
*
from
,
SMFile
*
to
);
int
tsdbCreateMFile
(
SMFile
*
pMFile
);
int
tsdbUpdateMFileHeader
(
SMFile
*
pMFile
);
static
FORCE_INLINE
void
tsdbSetMFileInfo
(
SMFile
*
pMFile
,
SMInfo
*
pInfo
)
{
pMFile
->
info
=
*
pInfo
;
}
static
FORCE_INLINE
int
tsdbOpenMFile
(
SMFile
*
pMFile
,
int
flags
)
{
ASSERT
(
!
TSDB_FILE_OPEN
ED
(
pMFile
));
ASSERT
(
TSDB_FILE_CLOS
ED
(
pMFile
));
pMFile
->
fd
=
open
(
TSDB_FILE_FULL_NAME
(
pMFile
),
flags
);
if
(
pMFile
->
fd
<
0
)
{
...
...
@@ -137,12 +133,8 @@ static FORCE_INLINE int tsdbAppendMFile(SMFile* pMFile, void* buf, int64_t nbyte
return
0
;
}
int
tsdbCreateMFile
(
SMFile
*
pMFile
);
static
FORCE_INLINE
int
tsdbRemoveMFile
(
SMFile
*
pMFile
)
{
return
tfsremove
(
TSDB_FILE_F
(
pMFile
));
}
int
tsdbUpdateMFileHeader
(
SMFile
*
pMFile
);
static
FORCE_INLINE
int64_t
tsdbReadMFile
(
SMFile
*
pMFile
,
void
*
buf
,
int64_t
nbyte
)
{
ASSERT
(
TSDB_FILE_OPENED
(
pMFile
));
...
...
@@ -176,6 +168,10 @@ void tsdbInitDFile(SDFile* pDFile, SDiskID did, int vid, int fid, uint32_t ver,
void
tsdbInitDFileEx
(
SDFile
*
pDFile
,
SDFile
*
pODFile
);
int
tsdbEncodeSDFile
(
void
**
buf
,
SDFile
*
pDFile
);
void
*
tsdbDecodeSDFile
(
void
*
buf
,
SDFile
*
pDFile
);
int
tsdbCreateDFile
(
SDFile
*
pDFile
);
int
tsdbUpdateDFileHeader
(
SDFile
*
pDFile
);
static
FORCE_INLINE
void
tsdbSetDFileInfo
(
SDFile
*
pDFile
,
SDFInfo
*
pInfo
)
{
pDFile
->
info
=
*
pInfo
;
}
static
FORCE_INLINE
int
tsdbOpenDFile
(
SDFile
*
pDFile
,
int
flags
)
{
ASSERT
(
!
TSDB_FILE_OPENED
(
pDFile
));
...
...
@@ -196,7 +192,7 @@ static FORCE_INLINE void tsdbCloseDFile(SDFile* pDFile) {
}
}
static
FORCE_INLINE
int64_t
tsdbSeekDFile
(
SDFile
*
pDFile
,
int64_t
offset
,
int
whence
)
{
static
FORCE_INLINE
int64_t
tsdbSeekDFile
(
SDFile
*
pDFile
,
int64_t
offset
,
int
whence
)
{
ASSERT
(
TSDB_FILE_OPENED
(
pDFile
));
int64_t
loffset
=
taosLSeek
(
TSDB_FILE_FD
(
pDFile
),
offset
,
whence
);
...
...
@@ -248,12 +244,8 @@ static FORCE_INLINE int tsdbAppendDFile(SDFile* pDFile, void* buf, int64_t nbyte
return
0
;
}
int
tsdbCreateDFile
(
SDFile
*
pDFile
);
static
FORCE_INLINE
int
tsdbRemoveDFile
(
SDFile
*
pDFile
)
{
return
tfsremove
(
TSDB_FILE_F
(
pDFile
));
}
int
tsdbUpdateDFileHeader
(
SDFile
*
pDFile
);
static
FORCE_INLINE
int64_t
tsdbReadDFile
(
SDFile
*
pDFile
,
void
*
buf
,
int64_t
nbyte
)
{
ASSERT
(
TSDB_FILE_OPENED
(
pDFile
));
...
...
@@ -272,7 +264,7 @@ static FORCE_INLINE int tsdbCopyDFile(SDFile* pSrc, SDFile* pDest) {
return
-
1
;
}
pDest
->
info
=
pSrc
->
info
;
tsdbSetDFileInfo
(
pDest
,
TSDB_FILE_INFO
(
pSrc
))
;
return
0
;
}
...
...
@@ -294,11 +286,13 @@ typedef struct {
} \
} while (0);
void
tsdbInitDFileSet
(
SDFileSet
*
pSet
,
SDiskID
did
,
int
vid
,
int
fid
,
uint32_t
ver
);
void
tsdbInitDFileSet
(
SDFileSet
*
pSet
,
SDiskID
did
,
int
vid
,
int
fid
,
uint32_t
ver
);
void
tsdbInitDFileSetEx
(
SDFileSet
*
pSet
,
SDFileSet
*
pOSet
);
int
tsdbEncodeDFileSet
(
void
**
buf
,
SDFileSet
*
pSet
);
void
*
tsdbDecodeDFileSet
(
void
*
buf
,
SDFileSet
*
pSet
);
int
tsdbApplyDFileSetChange
(
SDFileSet
*
from
,
SDFileSet
*
to
);
int
tsdbCreateDFileSet
(
SDFileSet
*
pSet
);
int
tsdbUpdateDFileSetHeader
(
SDFileSet
*
pSet
);
static
FORCE_INLINE
void
tsdbCloseDFileSet
(
SDFileSet
*
pSet
)
{
for
(
TSDB_FILE_T
ftype
=
0
;
ftype
<
TSDB_FILE_MAX
;
ftype
++
)
{
...
...
@@ -316,16 +310,12 @@ static FORCE_INLINE int tsdbOpenDFileSet(SDFileSet* pSet, int flags) {
return
0
;
}
int
tsdbCreateDFileSet
(
SDFileSet
*
pSet
);
static
FORCE_INLINE
void
tsdbRemoveDFileSet
(
SDFileSet
*
pSet
)
{
for
(
TSDB_FILE_T
ftype
=
0
;
ftype
<
TSDB_FILE_MAX
;
ftype
++
)
{
tsdbRemoveDFile
(
TSDB_DFILE_IN_SET
(
pSet
,
ftype
));
}
}
int
tsdbUpdateDFileSetHeader
(
SDFileSet
*
pSet
);
static
FORCE_INLINE
int
tsdbCopyDFileSet
(
SDFileSet
*
pSrc
,
SDFileSet
*
pDest
)
{
for
(
TSDB_FILE_T
ftype
=
0
;
ftype
<
TSDB_FILE_MAX
;
ftype
++
)
{
if
(
tsdbCopyDFile
(
TSDB_DFILE_IN_SET
(
pSrc
,
ftype
),
TSDB_DFILE_IN_SET
(
pDest
,
ftype
))
<
0
)
{
...
...
src/tsdb/src/tsdbFile.c
浏览文件 @
d795ff85
...
...
@@ -16,12 +16,11 @@
#include "tsdbint.h"
static
const
char
*
TSDB_FNAME_SUFFIX
[]
=
{
".head"
,
// TSDB_FILE_HEAD
".data"
,
// TSDB_FILE_DATA
".last"
,
// TSDB_FILE_LAST
""
,
// TSDB_FILE_MAX
"meta"
,
// TSDB_FILE_META
"manifest"
// TSDB_FILE_MANIFEST
".head"
,
// TSDB_FILE_HEAD
".data"
,
// TSDB_FILE_DATA
".last"
,
// TSDB_FILE_LAST
""
,
// TSDB_FILE_MAX
"meta"
// TSDB_FILE_META
};
static
void
tsdbGetFilename
(
int
vid
,
int
fid
,
uint32_t
ver
,
TSDB_FILE_T
ftype
,
char
*
fname
);
...
...
@@ -62,6 +61,7 @@ int tsdbEncodeSMFile(void **buf, SMFile *pMFile) {
void
*
tsdbDecodeSMFile
(
void
*
buf
,
SMFile
*
pMFile
)
{
buf
=
tsdbDecodeMFInfo
(
buf
,
&
(
pMFile
->
info
));
buf
=
tfsDecodeFile
(
buf
,
&
(
pMFile
->
f
));
TSDB_FILE_SET_CLOSED
(
pMFile
);
return
buf
;
}
...
...
@@ -71,14 +71,14 @@ int tsdbApplyMFileChange(SMFile *from, SMFile *to) {
if
(
from
!=
NULL
)
{
if
(
to
==
NULL
)
{
tsdbRemoveMFile
(
from
);
return
tsdbRemoveMFile
(
from
);
}
else
{
if
(
tfsIsSameFile
(
TSDB_FILE_F
(
from
),
TSDB_FILE_F
(
to
)))
{
if
(
from
->
info
.
size
>
to
->
info
.
size
)
{
tsdbRollBackMFile
(
to
);
}
}
else
{
tsdbRemoveMFile
(
from
);
return
tsdbRemoveMFile
(
from
);
}
}
}
...
...
@@ -86,28 +86,6 @@ int tsdbApplyMFileChange(SMFile *from, SMFile *to) {
return
0
;
}
static
int
tsdbRollBackMFile
(
SMFile
*
pMFile
)
{
SMFile
mf
=
*
pMFile
;
if
(
tsdbOpenMFile
(
&
mf
,
O_WRONLY
)
<
0
)
{
return
-
1
;
}
if
(
taosFtruncate
(
TSDB_FILE_FD
(
&
mf
),
pMFile
->
info
.
size
)
<
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
tsdbCloseMFile
(
&
mf
);
return
-
1
;
}
if
(
tsdbUpdateMFileHeader
(
&
mf
)
<
0
)
{
tsdbCloseMFile
(
&
mf
);
return
-
1
;
}
tsdbCloseMFile
(
&
mf
);
return
0
;
}
int
tsdbCreateMFile
(
SMFile
*
pMFile
)
{
ASSERT
(
pMFile
->
info
.
size
==
0
&&
pMFile
->
info
.
magic
==
TSDB_FILE_INIT_MAGIC
);
...
...
@@ -139,7 +117,7 @@ int tsdbUpdateMFileHeader(SMFile *pMFile) {
}
void
*
ptr
=
buf
;
tsdbEncodeMFInfo
(
&
ptr
,
&
(
pMFile
->
info
));
tsdbEncodeMFInfo
(
&
ptr
,
TSDB_FILE_INFO
(
pMFile
));
if
(
tsdbWriteMFile
(
pMFile
,
buf
,
TSDB_FILE_HEAD_SIZE
)
<
0
)
{
return
-
1
;
...
...
@@ -170,6 +148,30 @@ static void *tsdbDecodeMFInfo(void *buf, SMFInfo *pInfo) {
return
buf
;
}
static
int
tsdbRollBackMFile
(
SMFile
*
pMFile
)
{
SMFile
mf
=
*
pMFile
;
if
(
tsdbOpenMFile
(
&
mf
,
O_WRONLY
)
<
0
)
{
return
-
1
;
}
if
(
taosFtruncate
(
TSDB_FILE_FD
(
&
mf
),
pMFile
->
info
.
size
)
<
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
tsdbCloseMFile
(
&
mf
);
return
-
1
;
}
if
(
tsdbUpdateMFileHeader
(
&
mf
)
<
0
)
{
tsdbCloseMFile
(
&
mf
);
return
-
1
;
}
TSDB_FILE_FSYNC
(
&
mf
);
tsdbCloseMFile
(
&
mf
);
return
0
;
}
// ============== Operations on SDFile
void
tsdbInitDFile
(
SDFile
*
pDFile
,
SDiskID
did
,
int
vid
,
int
fid
,
uint32_t
ver
,
TSDB_FILE_T
ftype
)
{
char
fname
[
TSDB_FILENAME_LEN
];
...
...
@@ -179,7 +181,7 @@ void tsdbInitDFile(SDFile *pDFile, SDiskID did, int vid, int fid, uint32_t ver,
memset
(
&
(
pDFile
->
info
),
0
,
sizeof
(
pDFile
->
info
));
pDFile
->
info
.
magic
=
TSDB_FILE_INIT_MAGIC
;
tsdbGetFilename
(
vid
,
0
,
ver
,
ftype
,
fname
);
tsdbGetFilename
(
vid
,
fid
,
ver
,
ftype
,
fname
);
tfsInitFile
(
&
(
pDFile
->
f
),
did
.
level
,
did
.
id
,
fname
);
}
...
...
@@ -200,6 +202,7 @@ int tsdbEncodeSDFile(void **buf, SDFile *pDFile) {
void
*
tsdbDecodeSDFile
(
void
*
buf
,
SDFile
*
pDFile
)
{
buf
=
tsdbDecodeDFInfo
(
buf
,
&
(
pDFile
->
info
));
buf
=
tfsDecodeFile
(
buf
,
&
(
pDFile
->
f
));
TSDB_FILE_SET_CLOSED
(
pDFile
);
return
buf
;
}
...
...
@@ -308,6 +311,8 @@ static int tsdbRollBackDFile(SDFile *pDFile) {
return
-
1
;
}
TSDB_FILE_FSYNC
(
&
df
);
tsdbCloseDFile
(
&
df
);
return
0
;
}
...
...
@@ -384,13 +389,14 @@ static void tsdbGetFilename(int vid, int fid, uint32_t ver, TSDB_FILE_T ftype, c
if
(
ver
==
0
)
{
snprintf
(
fname
,
TSDB_FILENAME_LEN
,
"vnode/vnode%d/tsdb/data/v%df%d.%s"
,
vid
,
vid
,
fid
,
TSDB_FNAME_SUFFIX
[
ftype
]);
}
else
{
snprintf
(
fname
,
TSDB_FILENAME_LEN
,
"vnode/vnode%d/tsdb/data/v%df%d.%s-%012"
PRIu32
,
vid
,
vid
,
fid
,
TSDB_FNAME_SUFFIX
[
ftype
],
ver
);
snprintf
(
fname
,
TSDB_FILENAME_LEN
,
"vnode/vnode%d/tsdb/data/v%df%d.%s-ver%"
PRIu32
,
vid
,
vid
,
fid
,
TSDB_FNAME_SUFFIX
[
ftype
],
ver
);
}
}
else
{
if
(
ver
==
0
)
{
snprintf
(
fname
,
TSDB_FILENAME_LEN
,
"vnode/vnode%d/tsdb/%s"
,
vid
,
TSDB_FNAME_SUFFIX
[
ftype
]);
}
else
{
snprintf
(
fname
,
TSDB_FILENAME_LEN
,
"vnode/vnode%d/tsdb/%s-
%012
"
PRIu32
,
vid
,
TSDB_FNAME_SUFFIX
[
ftype
],
ver
);
snprintf
(
fname
,
TSDB_FILENAME_LEN
,
"vnode/vnode%d/tsdb/%s-
ver%
"
PRIu32
,
vid
,
TSDB_FNAME_SUFFIX
[
ftype
],
ver
);
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录