Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ebfd8b03
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1193
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看板
提交
ebfd8b03
编写于
5月 08, 2023
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more code
上级
198fe289
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
237 addition
and
156 deletion
+237
-156
source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h
source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h
+4
-3
source/dnode/vnode/src/tsdb/dev/inc/tsdbFile.h
source/dnode/vnode/src/tsdb/dev/inc/tsdbFile.h
+8
-5
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
+80
-114
source/dnode/vnode/src/tsdb/dev/tsdbFSet.c
source/dnode/vnode/src/tsdb/dev/tsdbFSet.c
+53
-4
source/dnode/vnode/src/tsdb/dev/tsdbFile.c
source/dnode/vnode/src/tsdb/dev/tsdbFile.c
+89
-27
source/dnode/vnode/src/tsdb/tsdbFS.c
source/dnode/vnode/src/tsdb/tsdbFS.c
+3
-3
未找到文件。
source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h
浏览文件 @
ebfd8b03
...
@@ -33,9 +33,10 @@ typedef enum {
...
@@ -33,9 +33,10 @@ typedef enum {
TSDB_FOP_TRUNCATE
,
TSDB_FOP_TRUNCATE
,
}
tsdb_fop_t
;
}
tsdb_fop_t
;
int32_t
tsdbFileSetToJson
(
const
STFileSet
*
fset
,
cJSON
*
json
);
int32_t
tsdbFileSetCreate
(
int32_t
fid
,
STFileSet
**
ppSet
);
int32_t
tsdbFileSetCreate
(
int32_t
fid
,
STFileSet
**
ppSet
);
int32_t
tsdbFileSetEdit
(
STFileSet
*
pSet
,
SFileOp
*
pOp
);
int32_t
tsdbFileSetEdit
(
STFileSet
*
pSet
,
SFileOp
*
pOp
);
int32_t
tsdbFileSetToJson
(
SJson
*
pJson
,
const
STFileSet
*
pSet
);
int32_t
tsdbEditFileSet
(
STFileSet
*
pFileSet
,
const
SFileOp
*
pOp
);
int32_t
tsdbEditFileSet
(
STFileSet
*
pFileSet
,
const
SFileOp
*
pOp
);
struct
SFileOp
{
struct
SFileOp
{
...
@@ -48,8 +49,8 @@ struct SFileOp {
...
@@ -48,8 +49,8 @@ struct SFileOp {
typedef
struct
SSttLvl
{
typedef
struct
SSttLvl
{
LISTD
(
struct
SSttLvl
)
listNode
;
LISTD
(
struct
SSttLvl
)
listNode
;
int32_t
lvl
;
// level
int32_t
lvl
;
// level
int32_t
n
S
tt
;
// number of .stt files on this level
int32_t
n
s
tt
;
// number of .stt files on this level
STFile
*
f
S
tt
;
// .stt files
STFile
*
f
s
tt
;
// .stt files
}
SSttLvl
;
}
SSttLvl
;
struct
STFileSet
{
struct
STFileSet
{
...
...
source/dnode/vnode/src/tsdb/dev/inc/tsdbFile.h
浏览文件 @
ebfd8b03
...
@@ -32,22 +32,25 @@ typedef enum {
...
@@ -32,22 +32,25 @@ typedef enum {
TSDB_FTYPE_STT
=
TSDB_FTYPE_TOMB
+
2
,
// .stt
TSDB_FTYPE_STT
=
TSDB_FTYPE_TOMB
+
2
,
// .stt
}
tsdb_ftype_t
;
}
tsdb_ftype_t
;
#define TSDB_FTYPE_MIN TSDB_FTYPE_HEAD
#define TSDB_FTYPE_MAX (TSDB_FTYPE_TOMB + 1)
#define TSDB_FTYPE_MAX (TSDB_FTYPE_TOMB + 1)
int32_t
tsdbTFileToJson
(
const
STFile
*
f
,
cJSON
*
json
);
int32_t
tsdbTFileInit
(
STsdb
*
pTsdb
,
STFile
*
pFile
);
int32_t
tsdbTFileInit
(
STsdb
*
pTsdb
,
STFile
*
pFile
);
int32_t
tsdbTFileClear
(
STFile
*
pFile
);
int32_t
tsdbTFileClear
(
STFile
*
pFile
);
struct
STFile
{
struct
STFile
{
LISTD
(
STFile
)
listNode
;
LISTD
(
STFile
)
listNode
;
char
fname
[
TSDB_FILENAME_LEN
];
int32_t
ref
;
int32_t
state
;
char
fname
[
TSDB_FILENAME_LEN
];
int32_t
ref
;
int32_t
state
;
tsdb_ftype_t
type
;
tsdb_ftype_t
type
;
SDiskID
did
;
SDiskID
did
;
int64_t
size
;
int64_t
cid
;
int32_t
fid
;
int32_t
fid
;
int64_t
cid
;
int64_t
size
;
union
{
union
{
struct
{
struct
{
int32_t
lvl
;
int32_t
lvl
;
...
...
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
浏览文件 @
ebfd8b03
...
@@ -27,8 +27,8 @@ enum {
...
@@ -27,8 +27,8 @@ enum {
typedef
enum
{
typedef
enum
{
TSDB_FCURRENT
=
1
,
TSDB_FCURRENT
=
1
,
TSDB_FCURRENT_C
,
TSDB_FCURRENT_C
,
// for commit
TSDB_FCURRENT_M
,
TSDB_FCURRENT_M
,
// for merge
}
EFCurrentT
;
}
EFCurrentT
;
static
const
char
*
gCurrentFname
[]
=
{
static
const
char
*
gCurrentFname
[]
=
{
...
@@ -91,131 +91,97 @@ static int32_t current_fname(STsdb *pTsdb, char *fname, EFCurrentT ftype) {
...
@@ -91,131 +91,97 @@ static int32_t current_fname(STsdb *pTsdb, char *fname, EFCurrentT ftype) {
return
0
;
return
0
;
}
}
static
int32_t
fs_
to_json_str
(
STFileSystem
*
pFS
,
char
**
ppData
)
{
static
int32_t
fs_
from_json_str
(
const
char
*
pData
,
STFileSystem
*
pFS
)
{
int32_t
code
=
0
;
int32_t
code
=
0
;
int32_t
lino
;
int32_t
lino
;
cJSON
*
pJson
=
cJSON_CreateObject
();
ASSERTS
(
0
,
"TODO: Not implemented yet"
);
if
(
pJson
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
/* format version */
_exit:
TSDB_CHECK_NULL
(
//
return
code
;
cJSON_AddNumberToObject
(
pJson
,
//
}
"version"
,
//
1
/* TODO */
),
code
,
//
lino
,
//
_exit
,
//
TSDB_CODE_OUT_OF_MEMORY
);
/* next edit id */
TSDB_CHECK_NULL
(
//
cJSON_AddNumberToObject
(
pJson
,
//
"edit id"
,
//
pFS
->
nextEditId
),
code
,
//
lino
,
//
_exit
,
//
TSDB_CODE_OUT_OF_MEMORY
);
/* file sets */
cJSON
*
aFileSetJson
;
TSDB_CHECK_NULL
(
//
aFileSetJson
=
cJSON_AddArrayToObject
(
pJson
,
"file sets"
),
//
code
,
//
lino
,
//
_exit
,
//
TSDB_CODE_OUT_OF_MEMORY
);
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pFS
->
nstate
);
i
++
)
{
struct
STFileSet
*
pFileSet
=
taosArrayGet
(
pFS
->
nstate
,
i
);
code
=
tsdbFileSetToJson
(
aFileSetJson
,
pFileSet
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
ppData
[
0
]
=
cJSON_Print
(
pJson
);
static
int32_t
save_json
(
const
cJSON
*
json
,
const
char
*
fname
)
{
if
(
ppData
[
0
]
==
NULL
)
{
int32_t
code
;
code
=
TSDB_CODE_OUT_OF_MEMORY
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
char
*
data
=
cJSON_Print
(
json
);
if
(
data
==
NULL
)
return
TSDB_CODE_OUT_OF_MEMORY
;
TdFilePtr
fp
=
taosOpenFile
(
fname
,
TD_FILE_WRITE
|
TD_FILE_CREATE
|
TD_FILE_TRUNC
);
if
(
fp
==
NULL
)
{
code
=
TAOS_SYSTEM_ERROR
(
code
);
goto
_exit
;
}
}
_exit:
if
(
taosWriteFile
(
fp
,
data
,
strlen
(
data
)
+
1
)
<
0
)
{
cJSON_Delete
(
pJson
);
code
=
TAOS_SYSTEM_ERROR
(
code
);
if
(
code
)
{
goto
_exit
;
tsdbError
(
"vgId:%d %s failed at line %d since %s"
,
//
TD_VID
(
pFS
->
pTsdb
->
pVnode
),
//
__func__
,
//
lino
,
//
tstrerror
(
code
));
}
}
return
code
;
}
static
int32_t
fs_from_json_str
(
const
char
*
pData
,
STFileSystem
*
pFS
)
{
if
(
taosFsyncFile
(
fp
)
<
0
)
{
int32_t
code
=
0
;
code
=
TAOS_SYSTEM_ERROR
(
code
);
int32_t
lino
;
goto
_exit
;
}
ASSERTS
(
0
,
"TODO: Not implemented yet"
);
taosCloseFile
(
&
fp
);
_exit:
_exit:
taosMemoryFree
(
data
);
return
code
;
return
code
;
}
}
static
int32_t
save_fs
_to_file
(
STFileSystem
*
pFS
,
const
char
*
fname
)
{
static
int32_t
save_fs
(
int64_t
eid
,
SArray
*
aTFileSet
,
const
char
*
fname
)
{
int32_t
code
=
0
;
int32_t
code
=
0
;
int32_t
lino
;
int32_t
lino
=
0
;
char
*
pData
=
NULL
;
// to json string
cJSON
*
json
=
cJSON_CreateObject
();
code
=
fs_to_json_str
(
pFS
,
&
pData
);
if
(
json
==
NULL
)
return
TSDB_CODE_OUT_OF_MEMORY
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
TdFilePtr
fd
=
taosOpenFile
(
fname
,
//
// fmtv
TD_FILE_WRITE
//
if
(
cJSON_AddNumberToObject
(
json
,
"fmtv"
,
1
)
==
NULL
)
{
|
TD_FILE_CREATE
//
code
=
TSDB_CODE_OUT_OF_MEMORY
;
|
TD_FILE_TRUNC
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
if
(
fd
==
NULL
)
{
code
=
TAOS_SYSTEM_ERROR
(
code
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
}
int64_t
n
=
taosWriteFile
(
fd
,
pData
,
strlen
(
pData
)
+
1
);
// eid
if
(
n
<
0
)
{
if
(
cJSON_AddNumberToObject
(
json
,
"eid"
,
eid
)
==
NULL
)
{
code
=
TAOS_SYSTEM_ERROR
(
code
);
code
=
TSDB_CODE_OUT_OF_MEMORY
;
taosCloseFile
(
&
fd
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
}
if
(
taosFsyncFile
(
fd
)
<
0
)
{
// fset
code
=
TAOS_SYSTEM_ERROR
(
code
);
cJSON
*
ajson
=
cJSON_AddArrayToObject
(
json
,
"fset"
);
taosCloseFile
(
&
fd
);
if
(
ajson
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
}
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
aTFileSet
);
i
++
)
{
STFileSet
*
pFileSet
=
(
STFileSet
*
)
taosArrayGet
(
aTFileSet
,
i
);
cJSON
*
tjson
=
cJSON_CreateObject
();
if
(
tjson
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
}
code
=
tsdbFileSetToJson
(
pFileSet
,
tjson
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
cJSON_AddItemToArray
(
ajson
,
tjson
);
}
}
taosCloseFile
(
&
fd
);
code
=
save_json
(
json
,
fname
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
_exit:
_exit:
if
(
code
)
{
if
(
code
)
{
tsdbError
(
"vgId:%d %s failed at line %d since %s"
,
//
tsdbError
(
"%s failed at line %d since %s"
,
__func__
,
lino
,
tstrerror
(
code
));
TD_VID
(
pFS
->
pTsdb
->
pVnode
),
//
__func__
,
//
lino
,
//
tstrerror
(
code
));
}
else
{
tsdbDebug
(
"vgId:%d %s success"
,
//
TD_VID
(
pFS
->
pTsdb
->
pVnode
),
//
__func__
);
}
if
(
pData
)
{
taosMemoryFree
(
pData
);
}
}
cJSON_Delete
(
json
);
return
code
;
return
code
;
}
}
static
int32_t
load_fs
_from_file
(
const
char
*
fname
,
STFileSystem
*
pFS
)
{
static
int32_t
load_fs
(
const
char
*
fname
,
STFileSystem
*
pFS
)
{
ASSERTS
(
0
,
"TODO: Not implemented yet"
);
ASSERTS
(
0
,
"TODO: Not implemented yet"
);
return
0
;
return
0
;
}
}
...
@@ -280,10 +246,10 @@ static int32_t open_fs(STFileSystem *pFS, int8_t rollback) {
...
@@ -280,10 +246,10 @@ static int32_t open_fs(STFileSystem *pFS, int8_t rollback) {
current_fname
(
pTsdb
,
fCurrent
,
TSDB_FCURRENT
);
current_fname
(
pTsdb
,
fCurrent
,
TSDB_FCURRENT
);
current_fname
(
pTsdb
,
cCurrent
,
TSDB_FCURRENT_C
);
current_fname
(
pTsdb
,
cCurrent
,
TSDB_FCURRENT_C
);
current_fname
(
pTsdb
,
mCurrent
,
TSDB_FCURRENT_
C
);
current_fname
(
pTsdb
,
mCurrent
,
TSDB_FCURRENT_
M
);
if
(
taosCheckExistFile
(
fCurrent
))
{
// current.json exists
if
(
taosCheckExistFile
(
fCurrent
))
{
// current.json exists
code
=
load_fs
_from_file
(
fCurrent
,
pFS
);
code
=
load_fs
(
fCurrent
,
pFS
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
// check current.json.commit existence
// check current.json.commit existence
...
@@ -302,17 +268,17 @@ static int32_t open_fs(STFileSystem *pFS, int8_t rollback) {
...
@@ -302,17 +268,17 @@ static int32_t open_fs(STFileSystem *pFS, int8_t rollback) {
code
=
abort_edit
(
pFS
,
TSDB_FS_EDIT_MERGE
);
code
=
abort_edit
(
pFS
,
TSDB_FS_EDIT_MERGE
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
}
code
=
scan_file_system
(
pFS
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
scan_and_schedule_merge
(
pFS
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
else
{
}
else
{
code
=
save_fs
_to_file
(
pFS
,
fCurrent
);
code
=
save_fs
(
0
,
pFS
->
nstate
,
fCurrent
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
}
code
=
scan_file_system
(
pFS
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
scan_and_schedule_merge
(
pFS
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
_exit:
_exit:
if
(
code
)
{
if
(
code
)
{
tsdbError
(
"vgId:%d %s failed at line %d since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
__func__
,
lino
,
tstrerror
(
code
));
tsdbError
(
"vgId:%d %s failed at line %d since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
__func__
,
lino
,
tstrerror
(
code
));
...
@@ -427,19 +393,19 @@ int32_t tsdbFileSystemEditBegin(STFileSystem *pFS, const SArray *aFileOp, tsdb_f
...
@@ -427,19 +393,19 @@ int32_t tsdbFileSystemEditBegin(STFileSystem *pFS, const SArray *aFileOp, tsdb_f
int32_t
lino
;
int32_t
lino
;
char
fname
[
TSDB_FILENAME_LEN
];
char
fname
[
TSDB_FILENAME_LEN
];
current_fname
(
pFS
->
pTsdb
,
fname
,
etype
==
TSDB_FS_EDIT_COMMIT
?
TSDB_FCURRENT_C
:
TSDB_FCURRENT_M
);
//
current_fname(pFS->pTsdb, fname, etype == TSDB_FS_EDIT_COMMIT ? TSDB_FCURRENT_C : TSDB_FCURRENT_M);
tsem_wait
(
&
pFS
->
canEdit
);
//
tsem_wait(&pFS->canEdit);
TSDB_CHECK_CODE
(
//
//
TSDB_CHECK_CODE( //
code
=
edit_fs
(
pFS
,
aFileOp
),
//
//
code = edit_fs(pFS, aFileOp), //
lino
,
//
//
lino, //
_exit
);
//
_exit);
TSDB_CHECK_CODE
(
//
// TSDB_CHECK_CODE(
//
code
=
save_fs_to_file
(
pFS
,
fname
),
//
// code = save_fs
(pFS, fname), //
lino
,
//
// lino,
//
_exit
);
//
_exit);
_exit:
_exit:
if
(
code
)
{
if
(
code
)
{
...
...
source/dnode/vnode/src/tsdb/dev/tsdbFSet.c
浏览文件 @
ebfd8b03
...
@@ -15,6 +15,29 @@
...
@@ -15,6 +15,29 @@
#include "inc/tsdbFSet.h"
#include "inc/tsdbFSet.h"
static
int32_t
stt_lvl_to_json
(
const
SSttLvl
*
lvl
,
cJSON
*
json
)
{
if
(
cJSON_AddNumberToObject
(
json
,
"lvl"
,
lvl
->
lvl
)
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
cJSON
*
arr
=
cJSON_AddArrayToObject
(
json
,
"stt"
);
if
(
arr
==
NULL
)
return
TSDB_CODE_OUT_OF_MEMORY
;
// TODO: .stt files
// STFile *f;
// LISTD_FOREACH(&lvl->fstt, f, listNode) {
// cJSON *item = cJSON_CreateObject();
// if (item == NULL) return TSDB_CODE_OUT_OF_MEMORY;
// int32_t code = tsdbTFileToJson(f, item);
// if (code) return code;
// cJSON_AddItemToArray(arr, item);
// }
return
0
;
}
int32_t
tsdbFileSetCreate
(
int32_t
fid
,
struct
STFileSet
**
ppSet
)
{
int32_t
tsdbFileSetCreate
(
int32_t
fid
,
struct
STFileSet
**
ppSet
)
{
int32_t
code
=
0
;
int32_t
code
=
0
;
...
@@ -36,13 +59,39 @@ int32_t tsdbFileSetEdit(struct STFileSet *pSet, struct SFileOp *pOp) {
...
@@ -36,13 +59,39 @@ int32_t tsdbFileSetEdit(struct STFileSet *pSet, struct SFileOp *pOp) {
return
code
;
return
code
;
}
}
int32_t
tsdbFileSetToJson
(
SJson
*
pJson
,
const
struct
STFileSet
*
pSet
)
{
int32_t
tsdbFileSetToJson
(
const
STFileSet
*
fset
,
cJSON
*
json
)
{
int32_t
code
=
0
;
int32_t
code
=
0
;
ASSERTS
(
0
,
"TODO: Not implemented yet"
);
// fid
if
(
cJSON_AddNumberToObject
(
json
,
"fid"
,
fset
->
fid
)
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
_exit:
for
(
int32_t
ftype
=
TSDB_FTYPE_MIN
;
ftype
<
TSDB_FTYPE_MAX
;
++
ftype
)
{
return
code
;
if
(
fset
->
farr
[
ftype
]
==
NULL
)
{
continue
;
}
code
=
tsdbTFileToJson
(
fset
->
farr
[
ftype
],
json
);
if
(
code
)
return
code
;
}
// each level
cJSON
*
ajson
=
cJSON_AddArrayToObject
(
json
,
"stt"
);
if
(
ajson
==
NULL
)
return
TSDB_CODE_OUT_OF_MEMORY
;
SSttLvl
*
sttLvl
;
LISTD_FOREACH
(
&
fset
->
lvl0
,
sttLvl
,
listNode
)
{
cJSON
*
ljson
=
cJSON_CreateObject
();
if
(
ljson
==
NULL
)
return
TSDB_CODE_OUT_OF_MEMORY
;
code
=
stt_lvl_to_json
(
sttLvl
,
ljson
);
if
(
code
)
return
code
;
cJSON_AddItemToArray
(
ajson
,
ljson
);
}
return
0
;
}
}
int32_t
tsdbEditFileSet
(
struct
STFileSet
*
pFileSet
,
const
struct
SFileOp
*
pOp
)
{
int32_t
tsdbEditFileSet
(
struct
STFileSet
*
pFileSet
,
const
struct
SFileOp
*
pOp
)
{
...
...
source/dnode/vnode/src/tsdb/dev/tsdbFile.c
浏览文件 @
ebfd8b03
...
@@ -15,41 +15,96 @@
...
@@ -15,41 +15,96 @@
#include "inc/tsdbFile.h"
#include "inc/tsdbFile.h"
const
char
*
tsdb_ftype_suffix
[]
=
{
static
int32_t
head_to_json
(
const
STFile
*
file
,
cJSON
*
json
);
[
TSDB_FTYPE_HEAD
]
=
".head"
,
//
static
int32_t
data_to_json
(
const
STFile
*
file
,
cJSON
*
json
);
[
TSDB_FTYPE_DATA
]
=
".data"
,
//
static
int32_t
sma_to_json
(
const
STFile
*
file
,
cJSON
*
json
);
[
TSDB_FTYPE_SMA
]
=
".sma"
,
//
static
int32_t
tomb_to_json
(
const
STFile
*
file
,
cJSON
*
json
);
[
TSDB_FTYPE_TOMB
]
=
".tomb"
,
//
static
int32_t
stt_to_json
(
const
STFile
*
file
,
cJSON
*
json
);
[
TSDB_FTYPE_MAX
]
=
NULL
,
//
[
TSDB_FTYPE_STT
]
=
".stt"
,
static
const
struct
{
const
char
*
suffix
;
int32_t
(
*
to_json
)(
const
STFile
*
file
,
cJSON
*
json
);
}
g_tfile_info
[]
=
{
[
TSDB_FTYPE_HEAD
]
=
{
"head"
,
head_to_json
},
//
[
TSDB_FTYPE_DATA
]
=
{
"data"
,
data_to_json
},
//
[
TSDB_FTYPE_SMA
]
=
{
"sma"
,
sma_to_json
},
//
[
TSDB_FTYPE_TOMB
]
=
{
"tomb"
,
tomb_to_json
},
//
[
TSDB_FTYPE_STT
]
=
{
"stt"
,
stt_to_json
},
};
};
static
int32_t
tfile_to_json
(
const
STFile
*
file
,
cJSON
*
json
)
{
if
(
cJSON_AddNumberToObject
(
json
,
"did.level"
,
file
->
did
.
level
)
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
if
(
cJSON_AddNumberToObject
(
json
,
"did.id"
,
file
->
did
.
id
)
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
if
(
cJSON_AddNumberToObject
(
json
,
"fid"
,
file
->
fid
)
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
if
(
cJSON_AddNumberToObject
(
json
,
"cid"
,
file
->
cid
)
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
if
(
cJSON_AddNumberToObject
(
json
,
"size"
,
file
->
size
)
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
return
0
;
}
static
int32_t
head_to_json
(
const
STFile
*
file
,
cJSON
*
json
)
{
return
tfile_to_json
(
file
,
json
);
}
static
int32_t
data_to_json
(
const
STFile
*
file
,
cJSON
*
json
)
{
return
tfile_to_json
(
file
,
json
);
}
static
int32_t
sma_to_json
(
const
STFile
*
file
,
cJSON
*
json
)
{
return
tfile_to_json
(
file
,
json
);
}
static
int32_t
tomb_to_json
(
const
STFile
*
file
,
cJSON
*
json
)
{
return
tfile_to_json
(
file
,
json
);
}
static
int32_t
stt_to_json
(
const
STFile
*
file
,
cJSON
*
json
)
{
int32_t
code
=
tfile_to_json
(
file
,
json
);
if
(
code
)
return
code
;
if
(
cJSON_AddNumberToObject
(
json
,
"lvl"
,
file
->
stt
.
lvl
)
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
if
(
cJSON_AddNumberToObject
(
json
,
"nseg"
,
file
->
stt
.
nseg
)
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
return
0
;
}
int32_t
tsdbTFileInit
(
STsdb
*
pTsdb
,
STFile
*
pFile
)
{
int32_t
tsdbTFileInit
(
STsdb
*
pTsdb
,
STFile
*
pFile
)
{
SVnode
*
pVnode
=
pTsdb
->
pVnode
;
SVnode
*
pVnode
=
pTsdb
->
pVnode
;
STfs
*
pTfs
=
pVnode
->
pTfs
;
STfs
*
pTfs
=
pVnode
->
pTfs
;
if
(
pTfs
)
{
if
(
pTfs
)
{
snprintf
(
pFile
->
fname
,
//
snprintf
(
pFile
->
fname
,
//
TSDB_FILENAME_LEN
,
//
TSDB_FILENAME_LEN
,
//
"%s%s%s%sv%df%dver%"
PRId64
"%s"
,
//
"%s%s%s%sv%df%dver%"
PRId64
"
.
%s"
,
//
tfsGetDiskPath
(
pTfs
,
pFile
->
did
),
//
tfsGetDiskPath
(
pTfs
,
pFile
->
did
),
//
TD_DIRSEP
,
//
TD_DIRSEP
,
//
pTsdb
->
path
,
//
pTsdb
->
path
,
//
TD_DIRSEP
,
//
TD_DIRSEP
,
//
TD_VID
(
pVnode
),
//
TD_VID
(
pVnode
),
//
pFile
->
fid
,
//
pFile
->
fid
,
//
pFile
->
cid
,
//
pFile
->
cid
,
//
tsdb_ftype_suffix
[
pFile
->
type
]
);
g_tfile_info
[
pFile
->
type
].
suffix
);
}
else
{
}
else
{
snprintf
(
pFile
->
fname
,
//
snprintf
(
pFile
->
fname
,
//
TSDB_FILENAME_LEN
,
//
TSDB_FILENAME_LEN
,
//
"%s%sv%df%dver%"
PRId64
"%s"
,
//
"%s%sv%df%dver%"
PRId64
"
.
%s"
,
//
pTsdb
->
path
,
//
pTsdb
->
path
,
//
TD_DIRSEP
,
//
TD_DIRSEP
,
//
TD_VID
(
pVnode
),
//
TD_VID
(
pVnode
),
//
pFile
->
fid
,
//
pFile
->
fid
,
//
pFile
->
cid
,
//
pFile
->
cid
,
//
tsdb_ftype_suffix
[
pFile
->
type
]
);
g_tfile_info
[
pFile
->
type
].
suffix
);
}
}
pFile
->
ref
=
1
;
pFile
->
ref
=
1
;
return
0
;
return
0
;
...
@@ -58,4 +113,11 @@ int32_t tsdbTFileInit(STsdb *pTsdb, STFile *pFile) {
...
@@ -58,4 +113,11 @@ int32_t tsdbTFileInit(STsdb *pTsdb, STFile *pFile) {
int32_t
tsdbTFileClear
(
STFile
*
pFile
)
{
int32_t
tsdbTFileClear
(
STFile
*
pFile
)
{
// TODO
// TODO
return
0
;
return
0
;
}
int32_t
tsdbTFileToJson
(
const
STFile
*
file
,
cJSON
*
json
)
{
cJSON
*
tjson
=
cJSON_AddObjectToObject
(
json
,
g_tfile_info
[
file
->
type
].
suffix
);
if
(
tjson
==
NULL
)
return
TSDB_CODE_OUT_OF_MEMORY
;
return
g_tfile_info
[
file
->
type
].
to_json
(
file
,
tjson
);
}
}
\ No newline at end of file
source/dnode/vnode/src/tsdb/tsdbFS.c
浏览文件 @
ebfd8b03
...
@@ -290,7 +290,7 @@ static void tsdbGetCurrentFName(STsdb *pTsdb, char *current, char *current_t) {
...
@@ -290,7 +290,7 @@ static void tsdbGetCurrentFName(STsdb *pTsdb, char *current, char *current_t) {
}
}
}
}
static
int32_t
load_fs
_from_file
(
const
char
*
fname
,
STsdbFS
*
pFS
)
{
static
int32_t
load_fs
(
const
char
*
fname
,
STsdbFS
*
pFS
)
{
int32_t
code
=
0
;
int32_t
code
=
0
;
int32_t
lino
=
0
;
int32_t
lino
=
0
;
uint8_t
*
pData
=
NULL
;
uint8_t
*
pData
=
NULL
;
...
@@ -724,7 +724,7 @@ int32_t tsdbFSCommit(STsdb *pTsdb) {
...
@@ -724,7 +724,7 @@ int32_t tsdbFSCommit(STsdb *pTsdb) {
code
=
tsdbFSCreate
(
&
fs
);
code
=
tsdbFSCreate
(
&
fs
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
load_fs
_from_file
(
current
,
&
fs
);
code
=
load_fs
(
current
,
&
fs
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
// apply file change
// apply file change
...
@@ -769,7 +769,7 @@ int32_t tsdbFSOpen(STsdb *pTsdb, int8_t rollback) {
...
@@ -769,7 +769,7 @@ int32_t tsdbFSOpen(STsdb *pTsdb, int8_t rollback) {
tsdbGetCurrentFName
(
pTsdb
,
current
,
current_t
);
tsdbGetCurrentFName
(
pTsdb
,
current
,
current_t
);
if
(
taosCheckExistFile
(
current
))
{
if
(
taosCheckExistFile
(
current
))
{
code
=
load_fs
_from_file
(
current
,
&
pTsdb
->
fs
);
code
=
load_fs
(
current
,
&
pTsdb
->
fs
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
if
(
taosCheckExistFile
(
current_t
))
{
if
(
taosCheckExistFile
(
current_t
))
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录