Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
73d4733c
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
73d4733c
编写于
1月 12, 2021
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refact tsdbFile.c
上级
924f88dc
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
268 addition
and
103 deletion
+268
-103
src/inc/tfs.h
src/inc/tfs.h
+6
-4
src/os/src/detail/osFile.c
src/os/src/detail/osFile.c
+2
-1
src/tfs/inc/tfsint.h
src/tfs/inc/tfsint.h
+1
-0
src/tfs/src/tfs.c
src/tfs/src/tfs.c
+24
-0
src/tsdb/inc/tsdbFile.h
src/tsdb/inc/tsdbFile.h
+123
-41
src/tsdb/src/tsdbFile.c
src/tsdb/src/tsdbFile.c
+112
-57
未找到文件。
src/inc/tfs.h
浏览文件 @
73d4733c
...
@@ -68,6 +68,8 @@ typedef struct {
...
@@ -68,6 +68,8 @@ typedef struct {
void
tfsInitFile
(
TFILE
*
pf
,
int
level
,
int
id
,
const
char
*
bname
);
void
tfsInitFile
(
TFILE
*
pf
,
int
level
,
int
id
,
const
char
*
bname
);
bool
tfsIsSameFile
(
TFILE
*
pf1
,
TFILE
*
pf2
);
bool
tfsIsSameFile
(
TFILE
*
pf1
,
TFILE
*
pf2
);
int
tfsEncodeFile
(
void
**
buf
,
TFILE
*
pf
);
void
*
tfsDecodeFile
(
void
*
buf
,
TFILE
*
pf
);
void
tfsbasename
(
const
TFILE
*
pf
,
char
*
dest
);
void
tfsbasename
(
const
TFILE
*
pf
,
char
*
dest
);
void
tfsdirname
(
const
TFILE
*
pf
,
char
*
dest
);
void
tfsdirname
(
const
TFILE
*
pf
,
char
*
dest
);
...
...
src/os/src/detail/osFile.c
浏览文件 @
73d4733c
...
@@ -128,7 +128,7 @@ int64_t taosCopy(char *from, char *to) {
...
@@ -128,7 +128,7 @@ int64_t taosCopy(char *from, char *to) {
fidfrom
=
open
(
from
,
O_RDONLY
);
fidfrom
=
open
(
from
,
O_RDONLY
);
if
(
fidfrom
<
0
)
goto
_err
;
if
(
fidfrom
<
0
)
goto
_err
;
fidto
=
open
(
to
,
O_WRONLY
|
O_CREAT
,
0755
);
fidto
=
open
(
to
,
O_WRONLY
|
O_CREAT
|
O_EXCL
,
0755
);
if
(
fidto
<
0
)
goto
_err
;
if
(
fidto
<
0
)
goto
_err
;
while
(
true
)
{
while
(
true
)
{
...
@@ -149,6 +149,7 @@ int64_t taosCopy(char *from, char *to) {
...
@@ -149,6 +149,7 @@ int64_t taosCopy(char *from, char *to) {
_err:
_err:
if
(
fidfrom
>=
0
)
close
(
fidfrom
);
if
(
fidfrom
>=
0
)
close
(
fidfrom
);
if
(
fidto
>=
0
)
close
(
fidto
);
if
(
fidto
>=
0
)
close
(
fidto
);
remove
(
to
);
return
-
1
;
return
-
1
;
}
}
...
...
src/tfs/inc/tfsint.h
浏览文件 @
73d4733c
...
@@ -19,6 +19,7 @@
...
@@ -19,6 +19,7 @@
#include "tlog.h"
#include "tlog.h"
#include "tglobal.h"
#include "tglobal.h"
#include "tfs.h"
#include "tfs.h"
#include "tcoding.h"
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
...
...
src/tfs/src/tfs.c
浏览文件 @
73d4733c
...
@@ -196,6 +196,30 @@ bool tfsIsSameFile(TFILE *pf1, TFILE *pf2) {
...
@@ -196,6 +196,30 @@ bool tfsIsSameFile(TFILE *pf1, TFILE *pf2) {
return
true
;
return
true
;
}
}
int
tfsEncodeFile
(
void
**
buf
,
TFILE
*
pf
)
{
int
tlen
=
0
;
tlen
+=
taosEncodeVariantI32
(
buf
,
pf
->
level
);
tlen
+=
taosEncodeVariantI32
(
buf
,
pf
->
id
);
tlen
+=
taosEncodeString
(
buf
,
pf
->
rname
);
return
tlen
;
}
void
*
tfsDecodeFile
(
void
*
buf
,
TFILE
*
pf
)
{
int32_t
level
,
id
;
char
*
rname
;
buf
=
taosDecodeVariantI32
(
buf
,
&
(
level
));
buf
=
taosDecodeVariantI32
(
buf
,
&
(
id
));
buf
=
taosDecodeString
(
buf
,
&
rname
);
tfsInitFile
(
pf
,
level
,
id
,
rname
);
tfree
(
rname
);
return
buf
;
}
void
tfsbasename
(
const
TFILE
*
pf
,
char
*
dest
)
{
void
tfsbasename
(
const
TFILE
*
pf
,
char
*
dest
)
{
char
tname
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
char
tname
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
...
...
src/tsdb/inc/tsdbFile.h
浏览文件 @
73d4733c
...
@@ -27,8 +27,8 @@ extern "C" {
...
@@ -27,8 +27,8 @@ extern "C" {
#define TSDB_FILE_INFO(tf) (&((tf)->info))
#define TSDB_FILE_INFO(tf) (&((tf)->info))
#define TSDB_FILE_F(tf) (&((tf)->f))
#define TSDB_FILE_F(tf) (&((tf)->f))
#define TSDB_FILE_FD(tf) ((tf)->fd)
#define TSDB_FILE_FD(tf) ((tf)->fd)
#define TSDB_FILE_FULL_NAME(
f) TFILE_NAME(TSDB_FILE_F(
f))
#define TSDB_FILE_FULL_NAME(
tf) TFILE_NAME(TSDB_FILE_F(t
f))
#define TSDB_FILE_OPENED(
f) (TSDB_FILE_FD(
f) >= 0)
#define TSDB_FILE_OPENED(
tf) (TSDB_FILE_FD(t
f) >= 0)
#define TSDB_FILE_SET_CLOSED(f) (TSDB_FILE_FD(f) = -1)
#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_LEVEL(tf) TFILE_LEVEL(TSDB_FILE_F(tf))
#define TSDB_FILE_ID(tf) TFILE_ID(TSDB_FILE_F(tf))
#define TSDB_FILE_ID(tf) TFILE_ID(TSDB_FILE_F(tf))
...
@@ -57,7 +57,8 @@ typedef struct {
...
@@ -57,7 +57,8 @@ typedef struct {
int
fd
;
int
fd
;
}
SMFile
;
}
SMFile
;
void
tsdbInitMFile
(
SMFile
*
pMFile
,
int
vid
,
int
ver
,
SMFInfo
*
pInfo
);
void
tsdbInitMFile
(
SMFile
*
pMFile
,
SDiskID
did
,
int
vid
,
int
ver
);
void
tsdbInitMFileEx
(
SMFile
*
pMFile
,
SMFile
*
pOMFile
);
int
tsdbEncodeSMFile
(
void
**
buf
,
SMFile
*
pMFile
);
int
tsdbEncodeSMFile
(
void
**
buf
,
SMFile
*
pMFile
);
void
*
tsdbDecodeSMFile
(
void
*
buf
,
SMFile
*
pMFile
);
void
*
tsdbDecodeSMFile
(
void
*
buf
,
SMFile
*
pMFile
);
...
@@ -108,7 +109,47 @@ static FORCE_INLINE void tsdbUpdateMFileMagic(SMFile* pMFile, void* pCksum) {
...
@@ -108,7 +109,47 @@ static FORCE_INLINE void tsdbUpdateMFileMagic(SMFile* pMFile, void* pCksum) {
pMFile
->
info
.
magic
=
taosCalcChecksum
(
pMFile
->
info
.
magic
,
(
uint8_t
*
)(
pCksum
),
sizeof
(
TSCKSUM
));
pMFile
->
info
.
magic
=
taosCalcChecksum
(
pMFile
->
info
.
magic
,
(
uint8_t
*
)(
pCksum
),
sizeof
(
TSCKSUM
));
}
}
static
FORCE_INLINE
int64_t
tsdbTellMFile
(
SMFile
*
pMFile
)
{
return
tsdbSeekMFile
(
pMFile
,
0
,
SEEK_CUR
);
}
static
FORCE_INLINE
int
tsdbAppendMFile
(
SMFile
*
pMFile
,
void
*
buf
,
int64_t
nbyte
,
int64_t
*
offset
)
{
ASSERT
(
TSDB_FILE_OPENED
(
pMFile
));
int64_t
toffset
;
if
((
toffset
=
tsdbSeekMFile
(
pMFile
,
0
,
SEEK_END
))
<
0
)
{
return
-
1
;
}
ASSERT
(
pMFile
->
info
.
size
==
toffset
);
if
(
offset
)
{
*
offset
=
toffset
;
}
if
(
tsdbWriteMFile
(
pMFile
,
buf
,
nbyte
)
<
0
)
{
return
-
1
;
}
pMFile
->
info
.
size
+=
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
));
int64_t
nread
=
taosRead
(
pMFile
->
fd
,
buf
,
nbyte
);
if
(
nread
<
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
return
nread
;
}
// =============== SDFile
// =============== SDFile
typedef
struct
{
typedef
struct
{
...
@@ -127,17 +168,15 @@ typedef struct {
...
@@ -127,17 +168,15 @@ typedef struct {
int
fd
;
int
fd
;
}
SDFile
;
}
SDFile
;
void
tsdbInitDFile
(
SDFile
*
pDFile
,
int
vid
,
int
fid
,
int
ver
,
int
level
,
int
id
,
const
SDFInfo
*
pInfo
,
void
tsdbInitDFile
(
SDFile
*
pDFile
,
SDiskID
did
,
int
vid
,
int
fid
,
uint32_t
ver
,
TSDB_FILE_T
ftype
);
TSDB_FILE_T
ftype
);
void
tsdbInitDFileEx
(
SDFile
*
pDFile
,
SDFile
*
pODFile
);
void
tsdbInitDFileWithOld
(
SDFile
*
pDFile
,
SDFile
*
pOldDFile
);
int
tsdbEncodeSDFile
(
void
**
buf
,
SDFile
*
pDFile
);
int
tsdbEncodeSDFile
(
void
**
buf
,
SDFile
*
pDFile
);
void
*
tsdbDecodeSDFile
(
void
*
buf
,
SDFile
*
pDFile
);
void
*
tsdbDecodeSDFile
(
void
*
buf
,
SDFile
*
pDFile
);
int
tsdbUpdateDFileHeader
(
SDFile
*
pDFile
);
static
FORCE_INLINE
int
tsdbOpenDFile
(
SDFile
*
pDFile
,
int
flags
)
{
static
FORCE_INLINE
int
tsdbOpenDFile
(
SDFile
*
pDFile
,
int
flags
)
{
ASSERT
(
!
TSDB_FILE_OPENED
(
pDFile
));
ASSERT
(
!
TSDB_FILE_OPENED
(
pDFile
));
pDFile
->
fd
=
open
(
pDFile
->
f
.
aname
,
flags
);
pDFile
->
fd
=
open
(
TSDB_FILE_FULL_NAME
(
pDFile
)
,
flags
);
if
(
pDFile
->
fd
<
0
)
{
if
(
pDFile
->
fd
<
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
return
-
1
;
...
@@ -156,7 +195,7 @@ static FORCE_INLINE void tsdbCloseDFile(SDFile* pDFile) {
...
@@ -156,7 +195,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
));
ASSERT
(
TSDB_FILE_OPENED
(
pDFile
));
int64_t
loffset
=
taosLSeek
(
pDFile
->
fd
,
offset
,
whence
);
int64_t
loffset
=
taosLSeek
(
TSDB_FILE_FD
(
pDFile
)
,
offset
,
whence
);
if
(
loffset
<
0
)
{
if
(
loffset
<
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
return
-
1
;
...
@@ -177,19 +216,40 @@ static FORCE_INLINE int64_t tsdbWriteDFile(SDFile* pDFile, void* buf, int64_t nb
...
@@ -177,19 +216,40 @@ static FORCE_INLINE int64_t tsdbWriteDFile(SDFile* pDFile, void* buf, int64_t nb
return
nwrite
;
return
nwrite
;
}
}
static
FORCE_INLINE
int64_t
tsdbAppendDFile
(
SDFile
*
pDFile
,
void
*
buf
,
int64_t
nbyte
,
int64_t
*
offset
)
{
static
FORCE_INLINE
void
tsdbUpdateDFileMagic
(
SDFile
*
pDFile
,
void
*
pCksm
)
{
pDFile
->
info
.
magic
=
taosCalcChecksum
(
pDFile
->
info
.
magic
,
(
uint8_t
*
)(
pCksm
),
sizeof
(
TSCKSUM
));
}
static
FORCE_INLINE
int
tsdbAppendDFile
(
SDFile
*
pDFile
,
void
*
buf
,
int64_t
nbyte
,
int64_t
*
offset
)
{
ASSERT
(
TSDB_FILE_OPENED
(
pDFile
));
ASSERT
(
TSDB_FILE_OPENED
(
pDFile
));
int64_t
nwrite
;
*
offset
=
tsdbSeekDFile
(
pDFile
,
0
,
SEEK_SET
);
int64_t
toffset
;
if
(
*
offset
<
0
)
return
-
1
;
nwrite
=
tsdbWriteDFile
(
pDFile
,
buf
,
nbyte
);
if
((
toffset
=
tsdbSeekDFile
(
pDFile
,
0
,
SEEK_END
))
<
0
)
{
if
(
nwrite
<
0
)
return
nwrite
;
return
-
1
;
}
return
nwrite
;
ASSERT
(
pDFile
->
info
.
size
==
toffset
);
if
(
offset
)
{
*
offset
=
toffset
;
}
if
(
tsdbWriteDFile
(
pDFile
,
buf
,
nbyte
)
<
0
)
{
return
-
1
;
}
pDFile
->
info
.
size
+=
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
)
{
static
FORCE_INLINE
int64_t
tsdbReadDFile
(
SDFile
*
pDFile
,
void
*
buf
,
int64_t
nbyte
)
{
ASSERT
(
TSDB_FILE_OPENED
(
pDFile
));
ASSERT
(
TSDB_FILE_OPENED
(
pDFile
));
...
@@ -202,25 +262,13 @@ static FORCE_INLINE int64_t tsdbReadDFile(SDFile* pDFile, void* buf, int64_t nby
...
@@ -202,25 +262,13 @@ static FORCE_INLINE int64_t tsdbReadDFile(SDFile* pDFile, void* buf, int64_t nby
return
nread
;
return
nread
;
}
}
static
FORCE_INLINE
int64_t
tsdbTellDFile
(
SDFile
*
pDFile
)
{
return
tsdbSeekDFile
(
pDFile
,
0
,
SEEK_CUR
);
}
static
FORCE_INLINE
int
tsdbCopyDFile
(
SDFile
*
pSrc
,
SDFile
*
pDest
)
{
if
(
tfscopy
(
TSDB_FILE_F
(
pSrc
),
TSDB_FILE_F
(
pDest
))
<
0
)
{
static
FORCE_INLINE
void
tsdbUpdateDFileMagic
(
SDFile
*
pDFile
,
void
*
pCksm
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
pDFile
->
info
.
magic
=
taosCalcChecksum
(
pDFile
->
info
.
magic
,
(
uint8_t
*
)(
pCksm
),
sizeof
(
TSCKSUM
));
}
static
FORCE_INLINE
int
tsdbCreateAndOpenDFile
(
SDFile
*
pDFile
)
{
if
(
tsdbOpenDFile
(
pDFile
,
O_WRONLY
|
O_CREAT
|
O_EXCL
)
<
0
)
{
return
-
1
;
}
pDFile
->
info
.
size
+=
TSDB_FILE_HEAD_SIZE
;
if
(
tsdbUpdateDFileHeader
(
pDFile
)
<
0
)
{
tsdbCloseDFile
(
pDFile
);
remove
(
TSDB_FILE_FULL_NAME
(
pDFile
));
return
-
1
;
return
-
1
;
}
}
pDest
->
info
=
pSrc
->
info
;
return
0
;
return
0
;
}
}
...
@@ -236,13 +284,47 @@ typedef struct {
...
@@ -236,13 +284,47 @@ typedef struct {
#define TSDB_FSET_LEVEL(s) TSDB_FILE_LEVEL(TSDB_DFILE_IN_SET(s, 0))
#define TSDB_FSET_LEVEL(s) TSDB_FILE_LEVEL(TSDB_DFILE_IN_SET(s, 0))
#define TSDB_FSET_ID(s) TSDB_FILE_ID(TSDB_DFILE_IN_SET(s, 0))
#define TSDB_FSET_ID(s) TSDB_FILE_ID(TSDB_DFILE_IN_SET(s, 0))
void
tsdbInitDFileSet
(
SDFileSet
*
pSet
,
int
vid
,
int
fid
,
int
ver
,
int
level
,
int
id
);
void
tsdbInitDFileSet
(
SDFileSet
*
pSet
,
SDiskID
did
,
int
vid
,
int
fid
,
int
ver
);
void
tsdbInitDFileSetWithOld
(
SDFileSet
*
pSet
,
SDFileSet
*
pOldSet
);
void
tsdbInitDFileSetEx
(
SDFileSet
*
pSet
,
SDFileSet
*
pOSet
);
int
tsdbOpenDFileSet
(
SDFileSet
*
pSet
,
int
flags
);
int
tsdbEncodeDFileSet
(
void
**
buf
,
SDFileSet
*
pSet
);
void
tsdbCloseDFileSet
(
SDFileSet
*
pSet
);
void
*
tsdbDecodeDFileSet
(
void
*
buf
,
SDFileSet
*
pSet
);
static
FORCE_INLINE
void
tsdbCloseDFileSet
(
SDFileSet
*
pSet
)
{
for
(
TSDB_FILE_T
ftype
=
0
;
ftype
<
TSDB_FILE_MAX
;
ftype
++
)
{
tsdbCloseDFile
(
TSDB_DFILE_IN_SET
(
pSet
,
ftype
));
}
}
static
FORCE_INLINE
int
tsdbOpenDFileSet
(
SDFileSet
*
pSet
,
int
flags
)
{
for
(
TSDB_FILE_T
ftype
=
0
;
ftype
<
TSDB_FILE_MAX
;
ftype
++
)
{
if
(
tsdbOpenDFile
(
TSDB_DFILE_IN_SET
(
pSet
,
ftype
),
flags
)
<
0
)
{
tsdbCloseDFileSet
(
pSet
);
return
-
1
;
}
}
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
);
int
tsdbUpdateDFileSetHeader
(
SDFileSet
*
pSet
);
int
tsdbCopyDFileSet
(
SDFileSet
src
,
int
tolevel
,
int
toid
,
SDFileSet
*
pDest
);
int
tsdbCopyDFileSet
(
SDFileSet
src
,
int
tolevel
,
int
toid
,
SDFileSet
*
pDest
);
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
)
{
tsdbRemoveDFileSet
(
pDest
);
return
-
1
;
}
}
return
0
;
}
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
src/tsdb/src/tsdbFile.c
浏览文件 @
73d4733c
...
@@ -24,23 +24,22 @@ static const char *TSDB_FNAME_SUFFIX[] = {
...
@@ -24,23 +24,22 @@ static const char *TSDB_FNAME_SUFFIX[] = {
"manifest"
// TSDB_FILE_MANIFEST
"manifest"
// TSDB_FILE_MANIFEST
};
};
#define tsdbOpenFile(T, f) tsdbOpenT
// ============== SMFile
// ============== SMFile
void
tsdbInitMFile
(
SMFile
*
pMFile
,
int
vid
,
int
ver
,
SMFInfo
*
pInfo
)
{
void
tsdbInitMFile
(
SMFile
*
pMFile
,
SDiskID
did
,
int
vid
,
uint32_t
ver
)
{
char
fname
[
TSDB_FILENAME_LEN
];
char
fname
[
TSDB_FILENAME_LEN
];
TSDB_FILE_SET_CLOSED
(
pMFile
);
TSDB_FILE_SET_CLOSED
(
pMFile
);
if
(
pInfo
==
NULL
)
{
memset
(
&
(
pMFile
->
info
),
0
,
sizeof
(
pMFile
->
info
));
memset
(
&
(
pMFile
->
info
),
0
,
sizeof
(
pMFile
->
info
));
pMFile
->
info
.
magic
=
TSDB_FILE_INIT_MAGIC
;
pMFile
->
info
.
magic
=
TSDB_FILE_INIT_MAGIC
;
}
else
{
pMFile
->
info
=
*
pInfo
;
}
tsdbGetFilename
(
vid
,
0
,
ver
,
TSDB_FILE_META
,
fname
);
tsdbGetFilename
(
vid
,
0
,
ver
,
TSDB_FILE_META
,
fname
);
tfsInitFile
(
TSDB_FILE_F
(
pMFile
),
TFS_PRIMARY_LEVEL
,
TFS_PRIMARY_ID
,
fname
);
tfsInitFile
(
TSDB_FILE_F
(
pMFile
),
did
.
level
,
did
.
id
,
fname
);
}
void
tsdbInitMFileEx
(
SMFile
*
pMFile
,
SMFile
*
pOMFile
)
{
*
pMFile
=
*
pOMFile
;
TSDB_FILE_SET_CLOSED
(
pMFile
);
}
}
int
tsdbEncodeSMFile
(
void
**
buf
,
SMFile
*
pMFile
)
{
int
tsdbEncodeSMFile
(
void
**
buf
,
SMFile
*
pMFile
)
{
...
@@ -59,6 +58,46 @@ void *tsdbDecodeSMFile(void *buf, SMFile *pMFile) {
...
@@ -59,6 +58,46 @@ void *tsdbDecodeSMFile(void *buf, SMFile *pMFile) {
return
buf
;
return
buf
;
}
}
int
tsdbCreateMFile
(
SMFile
*
pMFile
)
{
ASSERT
(
pMFile
->
info
.
size
==
0
&&
pMFile
->
info
.
magic
==
TSDB_FILE_INIT_MAGIC
);
char
buf
[
TSDB_FILE_HEAD_SIZE
]
=
"
\0
"
;
if
(
tsdbOpenMFile
(
pMFile
,
O_WRONLY
|
O_CREAT
|
O_EXCL
)
<
0
)
{
return
-
1
;
}
void
*
ptr
=
buf
;
tsdbEncodeMFInfo
(
&
ptr
,
&
(
pMFile
->
info
));
if
(
tsdbWriteMFile
(
pMFile
,
buf
,
TSDB_FILE_HEAD_SIZE
)
<
0
)
{
tsdbCloseMFile
(
pMFile
);
tsdbRemoveMFile
(
pMFile
);
return
-
1
;
}
pMFile
->
info
.
size
+=
TSDB_FILE_HEAD_SIZE
;
return
0
;
}
int
tsdbUpdateMFileHeader
(
SMFile
*
pMFile
)
{
char
buf
[
TSDB_FILE_HEAD_SIZE
]
=
"
\0
"
;
if
(
tsdbSeekMFile
(
pMFile
,
0
,
SEEK_SET
)
<
0
)
{
return
-
1
;
}
void
*
ptr
=
buf
;
tsdbEncodeMFInfo
(
&
ptr
,
&
(
pMFile
->
info
));
if
(
tsdbWriteMFile
(
pMFile
,
buf
,
TSDB_FILE_HEAD_SIZE
)
<
0
)
{
return
-
1
;
}
return
0
;
}
static
int
tsdbEncodeMFInfo
(
void
**
buf
,
SMFInfo
*
pInfo
)
{
static
int
tsdbEncodeMFInfo
(
void
**
buf
,
SMFInfo
*
pInfo
)
{
int
tlen
=
0
;
int
tlen
=
0
;
...
@@ -82,24 +121,20 @@ static void *tsdbDecodeMFInfo(void *buf, SMFInfo *pInfo) {
...
@@ -82,24 +121,20 @@ static void *tsdbDecodeMFInfo(void *buf, SMFInfo *pInfo) {
}
}
// ============== Operations on SDFile
// ============== Operations on SDFile
void
tsdbInitDFile
(
SDFile
*
pDFile
,
int
vid
,
int
fid
,
uint32_t
ver
,
int
level
,
int
id
,
const
SDFInfo
*
pInfo
,
void
tsdbInitDFile
(
SDFile
*
pDFile
,
SDiskID
did
,
int
vid
,
int
fid
,
uint32_t
ver
,
TSDB_FILE_T
ftype
)
{
TSDB_FILE_T
ftype
)
{
char
fname
[
TSDB_FILENAME_LEN
];
char
fname
[
TSDB_FILENAME_LEN
];
TSDB_FILE_SET_CLOSED
(
pDFile
);
TSDB_FILE_SET_CLOSED
(
pDFile
);
if
(
pInfo
==
NULL
)
{
memset
(
&
(
pDFile
->
info
),
0
,
sizeof
(
pDFile
->
info
));
memset
(
&
(
pDFile
->
info
),
0
,
sizeof
(
pDFile
->
info
));
pDFile
->
info
.
magic
=
TSDB_FILE_INIT_MAGIC
;
pDFile
->
info
.
magic
=
TSDB_FILE_INIT_MAGIC
;
}
else
{
pDFile
->
info
=
*
pInfo
;
}
tfsInitFile
(
&
(
pDFile
->
f
),
level
,
id
,
NULL
/*TODO*/
);
tsdbGetFilename
(
vid
,
0
,
ver
,
ftype
,
fname
);
tfsInitFile
(
&
(
pDFile
->
f
),
level
,
id
,
fname
);
}
}
void
tsdbInitDFile
WithOld
(
SDFile
*
pDFile
,
SDFile
*
pOld
DFile
)
{
void
tsdbInitDFile
Ex
(
SDFile
*
pDFile
,
SDFile
*
pO
DFile
)
{
*
pDFile
=
*
pO
ld
DFile
;
*
pDFile
=
*
pODFile
;
TSDB_FILE_SET_CLOSED
(
pDFile
);
TSDB_FILE_SET_CLOSED
(
pDFile
);
}
}
...
@@ -119,22 +154,44 @@ void *tsdbDecodeSDFile(void *buf, SDFile *pDFile) {
...
@@ -119,22 +154,44 @@ void *tsdbDecodeSDFile(void *buf, SDFile *pDFile) {
return
buf
;
return
buf
;
}
}
int
tsdbUpdateDFileHeader
(
SDFile
*
pDFile
)
{
int
tsdbCreateDFile
(
SDFile
*
pDFile
)
{
// TODO
ASSERT
(
pDFile
->
info
.
size
==
0
&&
pDFile
->
info
.
magic
==
TSDB_FILE_INIT_MAGIC
);
char
buf
[
TSDB_FILE_HEAD_SIZE
]
=
"
\0
"
;
if
(
tsdbOpenDFile
(
pDFile
,
O_WRONLY
|
O_CREAT
|
O_EXCL
)
<
0
)
{
return
-
1
;
}
void
*
ptr
=
buf
;
tsdbEncodeDFInfo
(
&
ptr
,
&
(
pDFile
->
info
));
if
(
tsdbWriteDFile
(
pDFile
,
buf
,
TSDB_FILE_HEAD_SIZE
)
<
0
)
{
tsdbCloseDFile
(
pDFile
);
tsdbRemoveDFile
(
pDFile
);
return
-
1
;
}
pDFile
->
info
.
size
+=
TSDB_FILE_HEAD_SIZE
;
return
0
;
return
0
;
}
}
static
int
tsdbCopyDFile
(
SDFile
*
pSrc
,
int
tolevel
,
int
toid
,
SDFile
*
pDest
)
{
int
tsdbUpdateDFileHeader
(
SDFile
*
pDFile
)
{
TSDB_FILE_SET_CLOSED
(
pDest
);
char
buf
[
TSDB_FILE_HEAD_SIZE
]
=
"
\0
"
;
pDest
->
info
=
pSrc
->
info
;
tfsInitFile
(
TSDB_FILE_F
(
pDest
),
tolevel
,
toid
,
TFILE_REL_NAME
(
TSDB_FILE_F
(
pSrc
)));
if
(
taosCopy
(
TSDB_FILE_FULL_NAME
(
pSrc
),
TSDB_FILE_FULL_NAME
(
pDest
))
<
0
)
{
if
(
tsdbSeekDFile
(
pDFile
,
0
,
SEEK_SET
)
<
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
return
-
1
;
}
}
void
*
ptr
=
buf
;
tsdbEncodeDFInfo
(
&
ptr
,
&
(
pDFile
->
info
));
if
(
tsdbWriteDFile
(
pDFile
,
buf
,
TSDB_FILE_HEAD_SIZE
)
<
0
)
{
return
-
1
;
return
-
1
;
}
return
0
;
}
}
static
int
tsdbEncodeDFInfo
(
void
**
buf
,
SDFInfo
*
pInfo
)
{
static
int
tsdbEncodeDFInfo
(
void
**
buf
,
SDFInfo
*
pInfo
)
{
...
@@ -164,60 +221,58 @@ static void *tsdbDecodeDFInfo(void *buf, SDFInfo *pInfo) {
...
@@ -164,60 +221,58 @@ static void *tsdbDecodeDFInfo(void *buf, SDFInfo *pInfo) {
}
}
// ============== Operations on SDFileSet
// ============== Operations on SDFileSet
void
tsdbInitDFileSet
(
SDFileSet
*
pSet
,
int
vid
,
int
fid
,
uint32_t
ver
,
int
level
,
int
id
)
{
void
tsdbInitDFileSet
(
SDFileSet
*
pSet
,
SDiskID
did
,
int
vid
,
int
fid
,
uint32_t
ver
)
{
pSet
->
fid
=
fid
;
pSet
->
fid
=
fid
;
pSet
->
state
=
0
;
pSet
->
state
=
0
;
for
(
TSDB_FILE_T
ftype
=
0
;
ftype
<
TSDB_FILE_MAX
;
ftype
++
)
{
for
(
TSDB_FILE_T
ftype
=
0
;
ftype
<
TSDB_FILE_MAX
;
ftype
++
)
{
SDFile
*
pDFile
=
TSDB_DFILE_IN_SET
(
pSet
,
ftype
);
SDFile
*
pDFile
=
TSDB_DFILE_IN_SET
(
pSet
,
ftype
);
tsdbInitDFile
(
pDFile
,
vid
,
fid
,
ver
,
level
,
id
,
NULL
,
ftype
);
tsdbInitDFile
(
pDFile
,
did
,
vid
,
fid
,
ver
,
ftype
);
}
}
}
}
void
tsdbInitDFileSet
WithOld
(
SDFileSet
*
pSet
,
SDFileSet
*
pOld
Set
)
{
void
tsdbInitDFileSet
Ex
(
SDFileSet
*
pSet
,
SDFileSet
*
pO
Set
)
{
for
(
TSDB_FILE_T
ftype
=
0
;
ftype
<
TSDB_FILE_MAX
;
ftype
++
)
{
for
(
TSDB_FILE_T
ftype
=
0
;
ftype
<
TSDB_FILE_MAX
;
ftype
++
)
{
tsdbInitDFile
WithOld
(
TSDB_DFILE_IN_SET
(
pSet
,
ftype
),
TSDB_DFILE_IN_SET
(
pOld
Set
,
ftype
));
tsdbInitDFile
Ex
(
TSDB_DFILE_IN_SET
(
pSet
,
ftype
),
TSDB_DFILE_IN_SET
(
pO
Set
,
ftype
));
}
}
}
}
int
tsdbOpenDFileSet
(
SDFileSet
*
pSet
,
int
flags
)
{
int
tsdbEncodeDFileSet
(
void
**
buf
,
SDFileSet
*
pSet
)
{
for
(
TSDB_FILE_T
ftype
=
0
;
ftype
<
TSDB_FILE_MAX
;
ftype
++
)
{
int
tlen
=
0
;
SDFile
*
pDFile
=
TSDB_DFILE_IN_SET
(
pSet
,
ftype
);
if
(
tsdbOpenDFile
(
pDFile
,
flags
)
<
0
)
{
for
(
TSDB_FILE_T
ftype
=
0
;
ftype
<
TSDB_FILE_MAX
;
ftype
++
)
{
tsdbCloseDFileSet
(
pSet
);
tlen
+=
tsdbEncodeSDFile
(
buf
,
TSDB_DFILE_IN_SET
(
pSet
,
ftype
));
return
-
1
;
}
}
}
return
tlen
}
}
void
tsdbCloseDFileSet
(
SDFileSet
*
pSet
)
{
void
*
tsdbDecodeDFileSet
(
void
*
buf
,
SDFileSet
*
pSet
)
{
for
(
TSDB_FILE_T
ftype
=
0
;
ftype
<
TSDB_FILE_MAX
;
ftype
++
)
{
for
(
TSDB_FILE_T
ftype
=
0
;
ftype
<
TSDB_FILE_MAX
;
ftype
++
)
{
SDFile
*
pDFile
=
TSDB_DFILE_IN_SET
(
pSet
,
ftype
);
buf
=
tsdbDecodeSDFile
(
buf
,
TSDB_DFILE_IN_SET
(
pSet
,
ftype
));
tsdbCloseDFile
(
pDFile
);
}
}
return
buf
;
}
}
int
tsdbUpdateDFileSetHeader
(
SDFileSet
*
pSet
)
{
int
tsdbCreateDFileSet
(
SDFileSet
*
pSet
)
{
// TODO
for
(
TSDB_FILE_T
ftype
=
0
;
ftype
<
TSDB_FILE_MAX
;
ftype
++
)
{
if
(
tsdbCreateDFile
(
TSDB_DFILE_IN_SET
(
pSet
,
ftype
))
<
0
)
{
tsdbCloseDFileSet
(
pSet
);
tsdbRemoveDFileSet
(
pSet
);
return
-
1
;
}
}
return
0
;
return
0
;
}
}
int
tsdbCopyDFileSet
(
SDFileSet
src
,
int
tolevel
,
int
toid
,
SDFileSet
*
pDest
)
{
int
tsdbUpdateDFileSetHeader
(
SDFileSet
*
pSet
)
{
ASSERT
(
tolevel
>
TSDB_FSET_LEVEL
(
&
src
));
for
(
TSDB_FILE_T
ftype
=
0
;
ftype
<
TSDB_FILE_MAX
;
ftype
++
)
{
for
(
TSDB_FILE_T
ftype
=
0
;
ftype
<
TSDB_FILE_MAX
;
ftype
++
)
{
if
(
tsdbCopyDFile
(
TSDB_DFILE_IN_SET
(
&
src
,
ftype
),
tolevel
,
toid
,
TSDB_DFILE_IN_SET
(
pDest
,
ftype
))
<
0
)
{
if
(
tsdbUpdateDFileHeader
(
TSDB_DFILE_IN_SET
(
pSet
,
ftype
))
<
0
)
{
while
(
ftype
>=
0
)
{
remove
(
TSDB_FILE_FULL_NAME
(
TSDB_DFILE_IN_SET
(
pDest
,
ftype
)));
ftype
--
;
}
return
-
1
;
return
-
1
;
}
}
}
}
return
0
return
0
;
}
}
static
void
tsdbGetFilename
(
int
vid
,
int
fid
,
uint32_t
ver
,
TSDB_FILE_T
ftype
,
char
*
fname
)
{
static
void
tsdbGetFilename
(
int
vid
,
int
fid
,
uint32_t
ver
,
TSDB_FILE_T
ftype
,
char
*
fname
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录