Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
1c4abc62
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
1c4abc62
编写于
5月 19, 2023
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more code
上级
e2478705
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
217 addition
and
283 deletion
+217
-283
include/util/tarray2.h
include/util/tarray2.h
+5
-3
source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h
source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h
+10
-12
source/dnode/vnode/src/tsdb/dev/inc/tsdbFile.h
source/dnode/vnode/src/tsdb/dev/inc/tsdbFile.h
+6
-7
source/dnode/vnode/src/tsdb/dev/tsdbCommit.c
source/dnode/vnode/src/tsdb/dev/tsdbCommit.c
+10
-9
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
+3
-3
source/dnode/vnode/src/tsdb/dev/tsdbFSet.c
source/dnode/vnode/src/tsdb/dev/tsdbFSet.c
+136
-205
source/dnode/vnode/src/tsdb/dev/tsdbFile.c
source/dnode/vnode/src/tsdb/dev/tsdbFile.c
+45
-42
source/dnode/vnode/src/tsdb/dev/tsdbSttFReaderWriter.c
source/dnode/vnode/src/tsdb/dev/tsdbSttFReaderWriter.c
+2
-2
未找到文件。
include/util/tarray2.h
浏览文件 @
1c4abc62
...
...
@@ -36,6 +36,8 @@ extern "C" {
TYPE *data; \
}
typedef
void
(
*
TArray2Cb
)(
void
*
);
#define TARRAY2_MIN_SIZE 16
#define TARRAY2_INITIALIZER \
...
...
@@ -77,7 +79,7 @@ static FORCE_INLINE int32_t tarray2_make_room(void *arg, // array
#define TARRAY2_CLEAR(a, cb) \
do { \
if (cb) { \
void (*cb_)(void *) = (cb);
\
TArray2Cb cb_ = (TArray2Cb)(cb);
\
for (int32_t i = 0; i < (a)->size; ++i) { \
cb_((a)->data + i); \
} \
...
...
@@ -98,7 +100,7 @@ static FORCE_INLINE int32_t tarray2_make_room(void *arg, // array
({ \
int32_t __ret = 0; \
if ((a)->size >= (a)->capacity) { \
__ret = tarray2_make_room(
&(a), (a)->size + 1, sizeof(typeof((a)->data[0])));
\
__ret = tarray2_make_room(
(a), (a)->size + 1, sizeof(typeof((a)->data[0])));
\
} \
if (!__ret) { \
if ((a)->size > (idx)) { \
...
...
@@ -118,7 +120,7 @@ static FORCE_INLINE int32_t tarray2_make_room(void *arg, // array
do { \
if ((idx) < (a)->size) { \
if (cb) { \
void (*cb_)(void *) = cb;
\
TArray2Cb cb_ = (TArray2Cb)(cb);
\
cb_((a)->data + (idx)); \
} \
if ((idx) < (a)->size - 1) { \
...
...
source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h
浏览文件 @
1c4abc62
...
...
@@ -36,16 +36,16 @@ typedef enum {
TSDB_FOP_TRUNCATE
,
}
tsdb_fop_t
;
int32_t
tsdbFileSetInit
(
int32_t
fid
,
STFileSet
**
fset
);
int32_t
tsdbFileSetInitEx
(
const
STFileSet
*
fset1
,
STFileSet
**
fset2
);
int32_t
tsdbFileSetClear
(
STFileSet
**
fset
);
int32_t
tsdb
T
FileSetInit
(
int32_t
fid
,
STFileSet
**
fset
);
int32_t
tsdb
T
FileSetInitEx
(
const
STFileSet
*
fset1
,
STFileSet
**
fset2
);
int32_t
tsdb
T
FileSetClear
(
STFileSet
**
fset
);
int32_t
tsdbFileSetToJson
(
const
STFileSet
*
fset
,
cJSON
*
json
);
int32_t
tsdbJsonToFileSet
(
const
cJSON
*
json
,
STFileSet
**
fset
);
int32_t
tsdbFileSetEdit
(
STFileSet
*
fset
,
const
STFileOp
*
op
);
int32_t
tsdbFSetCmprFn
(
const
STFileSet
*
pSet1
,
const
STFileSet
*
pSet2
);
int32_t
tsdbTFileSetToJson
(
const
STFileSet
*
fset
,
cJSON
*
json
);
int32_t
tsdbJsonToTFileSet
(
const
cJSON
*
json
,
STFileSet
**
fset
);
const
SSttLvl
*
tsdbFileSetGetLvl
(
const
STFileSet
*
fset
,
int32_t
level
);
int32_t
tsdbTFileSetEdit
(
STFileSet
*
fset
,
const
STFileOp
*
op
);
const
SSttLvl
*
tsdbTFileSetGetLvl
(
const
STFileSet
*
fset
,
int32_t
level
);
struct
STFileOp
{
tsdb_fop_t
op
;
...
...
@@ -55,10 +55,8 @@ struct STFileOp {
};
struct
SSttLvl
{
int32_t
level
;
// level
int32_t
nstt
;
// number of .stt files on this level
SRBTree
sttTree
;
// .stt file tree, sorted by cid
SRBTreeNode
rbtn
;
int32_t
level
;
TFileObjArray
farr
;
};
struct
STFileSet
{
...
...
source/dnode/vnode/src/tsdb/dev/inc/tsdbFile.h
浏览文件 @
1c4abc62
...
...
@@ -24,6 +24,7 @@ extern "C" {
typedef
struct
STFile
STFile
;
typedef
struct
STFileObj
STFileObj
;
typedef
TARRAY2
(
STFileObj
*
)
TFileObjArray
;
typedef
enum
{
TSDB_FTYPE_HEAD
=
0
,
// .head
...
...
@@ -37,17 +38,15 @@ typedef enum {
#define TSDB_FTYPE_MAX (TSDB_FTYPE_TOMB + 1)
// STFile
int32_t
tsdbTFileInit
(
STsdb
*
pTsdb
,
STFile
*
pFile
);
int32_t
tsdbTFileClear
(
STFile
*
pFile
);
int32_t
tsdbTFileToJson
(
const
STFile
*
f
,
cJSON
*
json
);
int32_t
tsdbJsonToTFile
(
const
cJSON
*
json
,
tsdb_ftype_t
ftype
,
STFile
*
f
);
// STFileObj
int32_t
tsdbTFileObjCreate
(
const
STFile
*
f
,
STFileObj
**
fobj
);
int32_t
tsdbTFileObjDestroy
(
STFileObj
*
fobj
);
int32_t
tsdbTFileObjInit
(
const
STFile
*
f
,
STFileObj
**
fobj
);
int32_t
tsdbTFileObjRef
(
STFileObj
*
fobj
);
int32_t
tsdbTFileObjUnref
(
STFileObj
*
fobj
);
struct
STFile
{
char
fname
[
TSDB_FILENAME_LEN
];
tsdb_ftype_t
type
;
SDiskID
did
;
// disk id
int32_t
fid
;
// file id
...
...
@@ -62,9 +61,9 @@ struct STFile {
};
struct
STFileObj
{
SRBTreeNode
rbtn
;
volatile
int32_t
ref
;
STFile
f
;
volatile
int32_t
ref
;
char
fname
[
TSDB_FILENAME_LEN
];
};
#ifdef __cplusplus
...
...
source/dnode/vnode/src/tsdb/dev/tsdbCommit.c
浏览文件 @
1c4abc62
...
...
@@ -72,7 +72,7 @@ static int32_t open_writer_with_new_stt(SCommitter *pCommitter) {
config
.
file
.
size
=
0
;
config
.
file
.
stt
.
level
=
0
;
config
.
file
.
stt
.
nseg
=
0
;
tsdbTFileInit
(
pTsdb
,
&
config
.
file
);
//
tsdbTFileInit(pTsdb, &config.file);
code
=
tsdbSttFWriterOpen
(
&
config
,
&
pCommitter
->
pWriter
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
...
...
@@ -120,21 +120,22 @@ static int32_t open_committer_writer(SCommitter *pCommitter) {
return
open_writer_with_new_stt
(
pCommitter
);
}
const
SSttLvl
*
lvl0
=
tsdbFileSetGetLvl
(
pCommitter
->
fset
,
0
);
const
SSttLvl
*
lvl0
=
tsdb
T
FileSetGetLvl
(
pCommitter
->
fset
,
0
);
if
(
lvl0
==
NULL
)
{
return
open_writer_with_new_stt
(
pCommitter
);
}
SRBTreeNode
*
node
=
tRBTreeMax
(
&
lvl0
->
sttTree
);
SRBTreeNode
*
node
=
NULL
;
//
tRBTreeMax(&lvl0->sttTree);
if
(
node
==
NULL
)
{
return
open_writer_with_new_stt
(
pCommitter
);
}
else
{
STFileObj
*
fobj
=
TCONTAINER_OF
(
node
,
STFileObj
,
rbtn
);
if
(
fobj
->
f
.
stt
.
nseg
>=
pCommitter
->
sttTrigger
)
{
return
open_writer_with_new_stt
(
pCommitter
);
}
else
{
return
open_writer_with_exist_stt
(
pCommitter
,
&
fobj
->
f
);
}
// STFileObj *fobj = TCONTAINER_OF(node, STFileObj, rbtn);
// if (fobj->f.stt.nseg >= pCommitter->sttTrigger) {
// return open_writer_with_new_stt(pCommitter);
// } else {
// return open_writer_with_exist_stt(pCommitter, &fobj->f);
// }
return
0
;
}
}
...
...
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
浏览文件 @
1c4abc62
...
...
@@ -171,7 +171,7 @@ static int32_t save_fs(const TFileSetArray *arr, const char *fname) {
if
(
!
item
)
TSDB_CHECK_CODE
(
code
=
TSDB_CODE_OUT_OF_MEMORY
,
lino
,
_exit
);
cJSON_AddItemToArray
(
ajson
,
item
);
code
=
tsdbFileSetToJson
(
fset
,
item
);
code
=
tsdb
T
FileSetToJson
(
fset
,
item
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
...
...
@@ -214,7 +214,7 @@ static int32_t load_fs(const char *fname, TFileSetArray *arr) {
const
cJSON
*
titem
;
cJSON_ArrayForEach
(
titem
,
item
)
{
STFileSet
*
fset
;
code
=
tsdbJsonToFileSet
(
titem
,
&
fset
);
code
=
tsdbJsonTo
T
FileSet
(
titem
,
&
fset
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
TARRAY2_APPEND
(
arr
,
fset
);
...
...
@@ -506,7 +506,7 @@ static int32_t edit_fs(STFileSystem *pFS, const SArray *aFileOp) {
// }
}
code
=
tsdbFileSetEdit
(
pSet
,
op
);
code
=
tsdb
T
FileSetEdit
(
pSet
,
op
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
...
...
source/dnode/vnode/src/tsdb/dev/tsdbFSet.c
浏览文件 @
1c4abc62
...
...
@@ -15,18 +15,48 @@
#include "inc/tsdbFSet.h"
static
int32_t
stt_lvl_to_json
(
const
SSttLvl
*
lvl
,
cJSON
*
json
)
{
static
int32_t
tsdbSttLvlInit
(
int32_t
level
,
SSttLvl
**
lvl
)
{
lvl
[
0
]
=
taosMemoryMalloc
(
sizeof
(
SSttLvl
));
if
(
lvl
[
0
]
==
NULL
)
return
TSDB_CODE_OUT_OF_MEMORY
;
lvl
[
0
]
->
level
=
level
;
TARRAY2_INIT
(
&
lvl
[
0
]
->
farr
);
return
0
;
}
static
void
tsdbSttLvlClearFObj
(
void
*
data
)
{
tsdbTFileObjUnref
(
*
(
STFileObj
**
)
data
);
}
static
int32_t
tsdbSttLvlClear
(
SSttLvl
**
lvl
)
{
TARRAY2_CLEAR_FREE
(
&
lvl
[
0
]
->
farr
,
tsdbSttLvlClearFObj
);
taosMemoryFree
(
lvl
[
0
]);
lvl
[
0
]
=
NULL
;
return
0
;
}
static
int32_t
tsdbSttLvlInitEx
(
const
SSttLvl
*
lvl1
,
SSttLvl
**
lvl
)
{
int32_t
code
=
tsdbSttLvlInit
(
lvl1
->
level
,
lvl
);
if
(
code
)
return
code
;
const
STFileObj
*
fobj1
;
TARRAY2_FOREACH
(
&
lvl1
->
farr
,
fobj1
)
{
STFileObj
*
fobj
;
code
=
tsdbTFileObjInit
(
&
fobj1
->
f
,
&
fobj
);
if
(
code
)
{
tsdbSttLvlClear
(
lvl
);
return
code
;
}
TARRAY2_APPEND
(
&
lvl
[
0
]
->
farr
,
fobj
);
}
return
0
;
}
static
int32_t
tsdbSttLvlToJson
(
const
SSttLvl
*
lvl
,
cJSON
*
json
)
{
if
(
cJSON_AddNumberToObject
(
json
,
"level"
,
lvl
->
level
)
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
cJSON
*
ajson
=
cJSON_AddArrayToObject
(
json
,
"files"
);
if
(
ajson
==
NULL
)
return
TSDB_CODE_OUT_OF_MEMORY
;
SRBTreeIter
iter
=
tRBTreeIterCreate
(
&
lvl
->
sttTree
,
1
);
for
(
SRBTreeNode
*
node
=
tRBTreeIterNext
(
&
iter
);
node
;
node
=
tRBTreeIterNext
(
&
iter
))
{
STFileObj
*
fobj
=
TCONTAINER_OF
(
node
,
STFileObj
,
rbtn
);
const
STFileObj
*
fobj
;
TARRAY2_FOREACH
(
&
lvl
->
farr
,
fobj
)
{
cJSON
*
item
=
cJSON_CreateObject
();
if
(
item
==
NULL
)
return
TSDB_CODE_OUT_OF_MEMORY
;
cJSON_AddItemToArray
(
ajson
,
item
);
...
...
@@ -38,117 +68,47 @@ static int32_t stt_lvl_to_json(const SSttLvl *lvl, cJSON *json) {
return
0
;
}
static
int32_t
stt_file_cmpr
(
const
SRBTreeNode
*
n1
,
const
SRBTreeNode
*
n2
)
{
STFileObj
*
f1
=
TCONTAINER_OF
(
n1
,
STFileObj
,
rbtn
);
STFileObj
*
f2
=
TCONTAINER_OF
(
n2
,
STFileObj
,
rbtn
);
if
(
f1
->
f
.
cid
<
f2
->
f
.
cid
)
{
return
-
1
;
}
else
if
(
f1
->
f
.
cid
>
f2
->
f
.
cid
)
{
return
1
;
}
return
0
;
}
static
int32_t
stt_lvl_init
(
SSttLvl
*
lvl
,
int32_t
level
)
{
lvl
->
level
=
level
;
lvl
->
nstt
=
0
;
tRBTreeCreate
(
&
lvl
->
sttTree
,
stt_file_cmpr
);
return
0
;
}
static
int32_t
add_file_to_stt_lvl
(
SSttLvl
*
lvl
,
STFileObj
*
fobj
)
{
lvl
->
nstt
++
;
tRBTreePut
(
&
lvl
->
sttTree
,
&
fobj
->
rbtn
);
return
0
;
}
static
int32_t
json_to_stt_lvl
(
const
cJSON
*
json
,
SSttLvl
*
lvl
)
{
static
int32_t
tsdbJsonToSttLvl
(
const
cJSON
*
json
,
SSttLvl
**
lvl
)
{
const
cJSON
*
item1
,
*
item2
;
int32_t
level
;
item1
=
cJSON_GetObjectItem
(
json
,
"level"
);
if
(
cJSON_IsNumber
(
item1
))
{
l
vl
->
l
evel
=
item1
->
valuedouble
;
level
=
item1
->
valuedouble
;
}
else
{
return
TSDB_CODE_FILE_CORRUPTED
;
}
stt_lvl_init
(
lvl
,
lvl
->
level
);
int32_t
code
=
tsdbSttLvlInit
(
level
,
lvl
);
if
(
code
)
return
code
;
item1
=
cJSON_GetObjectItem
(
json
,
"files"
);
if
(
cJSON_IsArray
(
item1
))
{
cJSON_ArrayForEach
(
item2
,
item1
)
{
STFileObj
*
fobj
;
// int32_t code = tsdbTFileObjCreate(&fobj);
// if (code) return code;
// code = tsdbJsonToTFile(item2, TSDB_FTYPE_STT, &fobj->f);
// if (code) return code;
add_file_to_stt_lvl
(
lvl
,
fobj
);
}
}
else
{
if
(
!
cJSON_IsArray
(
item1
))
{
tsdbSttLvlClear
(
lvl
);
return
TSDB_CODE_FILE_CORRUPTED
;
}
return
0
;
}
static
int32_t
add_stt_lvl
(
STFileSet
*
fset
,
SSttLvl
*
lvl
)
{
// tRBTreePut(&fset->lvlTree, &lvl->rbtn);
return
0
;
}
static
int32_t
add_file_to_fset
(
STFileSet
*
fset
,
STFileObj
*
fobj
)
{
// if (fobj->f.type == TSDB_FTYPE_STT) {
// SSttLvl *lvl;
// SSttLvl tlvl = {.level = fobj->f.stt.level};
// SRBTreeNode *node = tRBTreeGet(&fset->lvlTree, &tlvl.rbtn);
// if (node) {
// lvl = TCONTAINER_OF(node, SSttLvl, rbtn);
// } else {
// lvl = taosMemoryMalloc(sizeof(*lvl));
// if (!lvl) return TSDB_CODE_OUT_OF_MEMORY;
// stt_lvl_init(lvl, fobj->f.stt.level);
// add_stt_lvl(fset, lvl);
// }
// add_file_to_stt_lvl(lvl, fobj);
// } else {
// fset->farr[fobj->f.type] = fobj;
// }
return
0
;
}
cJSON_ArrayForEach
(
item2
,
item1
)
{
STFile
tf
;
code
=
tsdbJsonToTFile
(
item2
,
TSDB_FTYPE_STT
,
&
tf
);
if
(
code
)
{
tsdbSttLvlClear
(
lvl
);
return
code
;
}
static
int32_t
stt_lvl_cmpr
(
const
SRBTreeNode
*
n1
,
const
SRBTreeNode
*
n2
)
{
SSttLvl
*
lvl1
=
TCONTAINER_OF
(
n1
,
SSttLvl
,
rbtn
);
SSttLvl
*
lvl2
=
TCONTAINER_OF
(
n2
,
SSttLvl
,
rbtn
);
STFileObj
*
fobj
;
code
=
tsdbTFileObjInit
(
&
tf
,
&
fobj
);
if
(
code
)
{
tsdbSttLvlClear
(
lvl
);
return
code
;
}
if
(
lvl1
->
level
<
lvl2
->
level
)
{
return
-
1
;
}
else
if
(
lvl1
->
level
>
lvl2
->
level
)
{
return
1
;
TARRAY2_APPEND
(
&
lvl
[
0
]
->
farr
,
fobj
);
}
return
0
;
}
// static int32_t fset_init(STFileSet *fset, int32_t fid) {
// fset->fid = fid;
// for (int32_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) {
// fset->farr[ftype] = NULL;
// }
// tRBTreeCreate(&fset->lvlTree, stt_lvl_cmpr);
// return 0;
// }
static
int32_t
fset_clear
(
STFileSet
*
fset
)
{
// TODO
return
0
;
}
int32_t
tsdbFileSetToJson
(
const
STFileSet
*
fset
,
cJSON
*
json
)
{
int32_t
tsdbTFileSetToJson
(
const
STFileSet
*
fset
,
cJSON
*
json
)
{
int32_t
code
=
0
;
cJSON
*
item1
,
*
item2
;
...
...
@@ -165,7 +125,7 @@ int32_t tsdbFileSetToJson(const STFileSet *fset, cJSON *json) {
}
// each level
item1
=
cJSON_AddArrayToObject
(
json
,
"stt l
evels
"
);
item1
=
cJSON_AddArrayToObject
(
json
,
"stt l
vl
"
);
if
(
item1
==
NULL
)
return
TSDB_CODE_OUT_OF_MEMORY
;
const
SSttLvl
*
lvl
;
TARRAY2_FOREACH
(
&
fset
->
lvlArr
,
lvl
)
{
...
...
@@ -173,90 +133,82 @@ int32_t tsdbFileSetToJson(const STFileSet *fset, cJSON *json) {
if
(
!
item2
)
return
TSDB_CODE_OUT_OF_MEMORY
;
cJSON_AddItemToArray
(
item1
,
item2
);
code
=
stt_lvl_to_j
son
(
lvl
,
item2
);
code
=
tsdbSttLvlToJ
son
(
lvl
,
item2
);
if
(
code
)
return
code
;
}
return
0
;
}
int32_t
tsdbJsonToFileSet
(
const
cJSON
*
json
,
STFileSet
**
fset
)
{
// const cJSON *item1, *item2;
// int32_t code;
// STFile tf;
int32_t
tsdbJsonToTFileSet
(
const
cJSON
*
json
,
STFileSet
**
fset
)
{
int32_t
code
;
const
cJSON
*
item1
,
*
item2
;
int32_t
fid
;
STFile
tf
;
//
/* fid */
//
item1 = cJSON_GetObjectItem(json, "fid");
//
if (cJSON_IsNumber(item1)) {
// fset->fid = item1->valueint
;
//
} else {
//
return TSDB_CODE_FILE_CORRUPTED;
//
}
//
fid
item1
=
cJSON_GetObjectItem
(
json
,
"fid"
);
if
(
cJSON_IsNumber
(
item1
))
{
fid
=
item1
->
valuedouble
;
}
else
{
return
TSDB_CODE_FILE_CORRUPTED
;
}
// fset_init(fset, fset->fid);
// for (int32_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) {
// code = tsdbJsonToTFile(json, ftype, &tf);
// if (code == TSDB_CODE_NOT_FOUND) {
// continue;
// } else if (code) {
// return code;
// } else {
// code = tsdbTFileObjCreate(&fset->farr[ftype]);
// if (code) return code;
// fset->farr[ftype]->f = tf;
// }
// }
code
=
tsdbTFileSetInit
(
fid
,
fset
);
if
(
code
)
return
code
;
// // each level
// item1 = cJSON_GetObjectItem(json, "stt");
// if (cJSON_IsArray(item1)) {
// cJSON_ArrayForEach(item2, item1) {
// SSttLvl *lvl = taosMemoryCalloc(1, sizeof(*lvl));
// if (lvl == NULL) return TSDB_CODE_OUT_OF_MEMORY;
// code = json_to_stt_lvl(item2, lvl);
// if (code) {
// taosMemoryFree(lvl);
// return code;
// }
// add_stt_lvl(fset, lvl);
// }
// } else {
// return TSDB_CODE_FILE_CORRUPTED;
// }
for
(
tsdb_ftype_t
ftype
=
TSDB_FTYPE_MIN
;
ftype
<
TSDB_FTYPE_MAX
;
++
ftype
)
{
code
=
tsdbJsonToTFile
(
json
,
ftype
,
&
tf
);
if
(
code
==
TSDB_CODE_NOT_FOUND
)
{
continue
;
}
else
if
(
code
)
{
tsdbTFileSetClear
(
fset
);
return
code
;
}
}
return
0
;
}
// each level
item1
=
cJSON_GetObjectItem
(
json
,
"stt lvl"
);
if
(
cJSON_IsArray
(
item1
))
{
cJSON_ArrayForEach
(
item2
,
item1
)
{
SSttLvl
*
lvl
;
code
=
tsdbJsonToSttLvl
(
item2
,
&
lvl
);
if
(
code
)
{
tsdbTFileSetClear
(
fset
);
return
code
;
}
TARRAY2_APPEND
(
&
(
*
fset
)
->
lvlArr
,
lvl
);
}
}
else
{
return
TSDB_CODE_FILE_CORRUPTED
;
}
int32_t
tsdbFSetCmprFn
(
const
STFileSet
*
pSet1
,
const
STFileSet
*
pSet2
)
{
if
(
pSet1
->
fid
<
pSet2
->
fid
)
return
-
1
;
if
(
pSet1
->
fid
>
pSet2
->
fid
)
return
1
;
return
0
;
}
int32_t
tsdbFileSetEdit
(
STFileSet
*
fset
,
const
STFileOp
*
op
)
{
int32_t
tsdb
T
FileSetEdit
(
STFileSet
*
fset
,
const
STFileOp
*
op
)
{
int32_t
code
=
0
;
if
(
op
->
oState
.
size
==
0
//
||
0
/* TODO*/
)
{
STFileObj
*
fobj
;
// code = tsdbTFileObjCreate(&fobj);
if
(
code
)
return
code
;
fobj
->
f
=
op
->
nState
;
add_file_to_fset
(
fset
,
fobj
);
}
else
if
(
op
->
nState
.
size
==
0
)
{
// delete
ASSERT
(
0
);
}
else
{
// modify
ASSERT
(
0
);
}
//
if (op->oState.size == 0 //
//
|| 0 /* TODO*/
//
) {
//
STFileObj *fobj;
//
// code = tsdbTFileObjCreate(&fobj);
//
if (code) return code;
//
fobj->f = op->nState;
//
add_file_to_fset(fset, fobj);
//
} else if (op->nState.size == 0) {
//
// delete
//
ASSERT(0);
//
} else {
//
// modify
//
ASSERT(0);
//
}
return
0
;
}
int32_t
tsdbFileSetInit
(
int32_t
fid
,
STFileSet
**
fset
)
{
int32_t
tsdb
T
FileSetInit
(
int32_t
fid
,
STFileSet
**
fset
)
{
fset
[
0
]
=
taosMemoryCalloc
(
1
,
sizeof
(
STFileSet
));
if
(
fset
[
0
]
==
NULL
)
return
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -265,16 +217,16 @@ int32_t tsdbFileSetInit(int32_t fid, STFileSet **fset) {
return
0
;
}
int32_t
tsdbFileSetInitEx
(
const
STFileSet
*
fset1
,
STFileSet
**
fset
)
{
int32_t
code
=
tsdbFileSetInit
(
fset1
->
fid
,
fset
);
int32_t
tsdb
T
FileSetInitEx
(
const
STFileSet
*
fset1
,
STFileSet
**
fset
)
{
int32_t
code
=
tsdb
T
FileSetInit
(
fset1
->
fid
,
fset
);
if
(
code
)
return
code
;
for
(
int32_t
ftype
=
TSDB_FTYPE_MIN
;
ftype
<
TSDB_FTYPE_MAX
;
++
ftype
)
{
if
(
fset1
->
farr
[
ftype
]
==
NULL
)
continue
;
code
=
tsdbTFileObj
Create
(
&
fset1
->
farr
[
ftype
]
->
f
,
&
fset
[
0
]
->
farr
[
ftype
]);
code
=
tsdbTFileObj
Init
(
&
fset1
->
farr
[
ftype
]
->
f
,
&
fset
[
0
]
->
farr
[
ftype
]);
if
(
code
)
{
tsdbFileSetClear
(
fset
);
tsdb
T
FileSetClear
(
fset
);
return
code
;
}
}
...
...
@@ -282,56 +234,35 @@ int32_t tsdbFileSetInitEx(const STFileSet *fset1, STFileSet **fset) {
const
SSttLvl
*
lvl1
;
TARRAY2_FOREACH
(
&
fset1
->
lvlArr
,
lvl1
)
{
SSttLvl
*
lvl
;
// code = stt_lvl_init_e
x(lvl1, &lvl);
code
=
tsdbSttLvlInitE
x
(
lvl1
,
&
lvl
);
if
(
code
)
{
tsdbFileSetClear
(
fset
);
tsdb
T
FileSetClear
(
fset
);
return
code
;
}
TARRAY2_APPEND
(
&
fset
[
0
]
->
lvlArr
,
lvl
);
}
// SRBTreeIter iter = tRBTreeIterCreate(&fset1->lvlTree, 1);
// for (SRBTreeNode *node = tRBTreeIterNext(&iter); node; node = tRBTreeIterNext(&iter)) {
// SSttLvl *lvl1 = TCONTAINER_OF(node, SSttLvl, rbtn);
// SSttLvl *lvl2 = taosMemoryCalloc(1, sizeof(*lvl2));
// if (lvl2 == NULL) return TSDB_CODE_OUT_OF_MEMORY;
// stt_lvl_init(lvl2, lvl1->level);
// add_stt_lvl(fset2, lvl2);
// SRBTreeIter iter2 = tRBTreeIterCreate(&lvl1->sttTree, 1);
// for (SRBTreeNode *node2 = tRBTreeIterNext(&iter2); node2; node2 = tRBTreeIterNext(&iter2)) {
// STFileObj *fobj1 = TCONTAINER_OF(node2, STFileObj, rbtn);
// STFileObj *fobj2;
// code = tsdbTFileObjCreate(&fobj2);
// if (code) return code;
// fobj2->f = fobj1->f;
// add_file_to_stt_lvl(lvl2, fobj2);
// }
// }
return
0
;
}
int32_t
tsdbFileSetClear
(
STFileSet
**
fset
)
{
if
(
fset
[
0
])
{
for
(
tsdb_ftype_t
ftype
=
TSDB_FTYPE_MIN
;
ftype
<
TSDB_FTYPE_MAX
;
++
ftype
)
{
// if (fset[0]->farr[ftype]) {
// tsdbTFileObjDestroy(&fset[0]->farr[ftype]);
// fset[0]->farr[ftype] = NULL;
// }
}
// TODO
// SSttLvl *lvl;
// TARRAY2_FOREACH(&fset[0]->lvlArr, lvl) {
// // stt_lvl_clear(&lvl);
// }
int32_t
tsdbTFileSetClear
(
STFileSet
**
fset
)
{
if
(
!
fset
[
0
])
return
0
;
taosMemoryFree
(
fset
[
0
]);
fset
[
0
]
=
NULL
;
for
(
tsdb_ftype_t
ftype
=
TSDB_FTYPE_MIN
;
ftype
<
TSDB_FTYPE_MAX
;
++
ftype
)
{
if
(
fset
[
0
]
->
farr
[
ftype
]
==
NULL
)
continue
;
tsdbTFileObjUnref
(
fset
[
0
]
->
farr
[
ftype
]);
}
TARRAY2_CLEAR_FREE
(
&
fset
[
0
]
->
lvlArr
,
tsdbSttLvlClear
);
taosMemoryFree
(
fset
[
0
]);
fset
[
0
]
=
NULL
;
return
0
;
}
const
SSttLvl
*
tsdbFileSetGetLvl
(
const
STFileSet
*
fset
,
int32_t
level
)
{
const
SSttLvl
*
tsdb
T
FileSetGetLvl
(
const
STFileSet
*
fset
,
int32_t
level
)
{
// SSttLvl tlvl = {.level = level};
// SRBTreeNode *node = tRBTreeGet(&fset->lvlTree, &tlvl.rbtn);
// return node ? TCONTAINER_OF(node, SSttLvl, rbtn) : NULL;
...
...
source/dnode/vnode/src/tsdb/dev/tsdbFile.c
浏览文件 @
1c4abc62
...
...
@@ -166,41 +166,35 @@ static int32_t stt_from_json(const cJSON *json, STFile *file) {
return
0
;
}
int32_t
tsdbTFileInit
(
STsdb
*
pTsdb
,
STFile
*
pFile
)
{
SVnode
*
pVnode
=
pTsdb
->
pVnode
;
STfs
*
pTfs
=
pVnode
->
pTfs
;
if
(
pTfs
)
{
snprintf
(
pFile
->
fname
,
//
TSDB_FILENAME_LEN
,
//
"%s%s%s%sv%df%dver%"
PRId64
".%s"
,
//
tfsGetDiskPath
(
pTfs
,
pFile
->
did
),
//
TD_DIRSEP
,
//
pTsdb
->
path
,
//
TD_DIRSEP
,
//
TD_VID
(
pVnode
),
//
pFile
->
fid
,
//
pFile
->
cid
,
//
g_tfile_info
[
pFile
->
type
].
suffix
);
}
else
{
snprintf
(
pFile
->
fname
,
//
TSDB_FILENAME_LEN
,
//
"%s%sv%df%dver%"
PRId64
".%s"
,
//
pTsdb
->
path
,
//
TD_DIRSEP
,
//
TD_VID
(
pVnode
),
//
pFile
->
fid
,
//
pFile
->
cid
,
//
g_tfile_info
[
pFile
->
type
].
suffix
);
}
// pFile->ref = 1;
return
0
;
}
int32_t
tsdbTFileClear
(
STFile
*
pFile
)
{
// TODO
return
0
;
}
// int32_t tsdbTFileInit(STsdb *pTsdb, STFile *pFile) {
// SVnode *pVnode = pTsdb->pVnode;
// STfs *pTfs = pVnode->pTfs;
// if (pTfs) {
// // snprintf(pFile->fname, //
// // TSDB_FILENAME_LEN, //
// // "%s%s%s%sv%df%dver%" PRId64 ".%s", //
// // tfsGetDiskPath(pTfs, pFile->did), //
// // TD_DIRSEP, //
// // pTsdb->path, //
// // TD_DIRSEP, //
// // TD_VID(pVnode), //
// // pFile->fid, //
// // pFile->cid, //
// // g_tfile_info[pFile->type].suffix);
// } else {
// // snprintf(pFile->fname, //
// // TSDB_FILENAME_LEN, //
// // "%s%sv%df%dver%" PRId64 ".%s", //
// // pTsdb->path, //
// // TD_DIRSEP, //
// // TD_VID(pVnode), //
// // pFile->fid, //
// // pFile->cid, //
// // g_tfile_info[pFile->type].suffix);
// }
// return 0;
// }
int32_t
tsdbTFileToJson
(
const
STFile
*
file
,
cJSON
*
json
)
{
if
(
file
->
type
==
TSDB_FTYPE_STT
)
{
...
...
@@ -228,21 +222,30 @@ int32_t tsdbJsonToTFile(const cJSON *json, tsdb_ftype_t ftype, STFile *f) {
}
}
// TODO: tsdbTFileInit(NULL, f);
return
0
;
}
int32_t
tsdbTFileObj
Create
(
const
STFile
*
f
,
STFileObj
**
fobj
)
{
fobj
[
0
]
=
taosMemoryMalloc
(
sizeof
(
STFileObj
));
int32_t
tsdbTFileObj
Init
(
const
STFile
*
f
,
STFileObj
**
fobj
)
{
fobj
[
0
]
=
taosMemoryMalloc
(
sizeof
(
*
fobj
[
0
]
));
if
(
!
fobj
[
0
])
return
TSDB_CODE_OUT_OF_MEMORY
;
fobj
[
0
]
->
f
=
*
f
;
fobj
[
0
]
->
ref
=
1
;
// TODO
// TODO
: generate the file name
return
0
;
}
int32_t
tsdbTFileObjDestroy
(
STFileObj
*
fobj
)
{
// TODO
taosMemoryFree
(
fobj
);
int32_t
tsdbTFileObjRef
(
STFileObj
*
fobj
)
{
int32_t
nRef
=
atomic_fetch_add_32
(
&
fobj
->
ref
,
1
);
ASSERT
(
nRef
>
0
);
return
0
;
}
int32_t
tsdbTFileObjUnref
(
STFileObj
*
fobj
)
{
int32_t
nRef
=
atomic_sub_fetch_32
(
&
fobj
->
ref
,
1
);
ASSERT
(
nRef
>=
0
);
if
(
nRef
==
0
)
{
taosMemoryFree
(
fobj
);
}
return
0
;
}
source/dnode/vnode/src/tsdb/dev/tsdbSttFReaderWriter.c
浏览文件 @
1c4abc62
...
...
@@ -479,7 +479,7 @@ static int32_t open_stt_fwriter(SSttFileWriter *pWriter) {
flag
|=
(
TD_FILE_CREATE
|
TD_FILE_TRUNC
);
}
code
=
tsdbOpenFile
(
pWriter
->
config
.
file
.
fname
,
pWriter
->
config
.
szPage
,
flag
,
&
pWriter
->
pFd
);
code
=
tsdbOpenFile
(
NULL
/*pWriter->config.file.fname*/
,
pWriter
->
config
.
szPage
,
flag
,
&
pWriter
->
pFd
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
if
(
pWriter
->
tFile
.
size
==
0
)
{
...
...
@@ -494,7 +494,7 @@ _exit:
if
(
pWriter
->
pFd
)
tsdbCloseFile
(
&
pWriter
->
pFd
);
tsdbError
(
"vgId:%d %s failed at line %d since %s"
,
vid
,
__func__
,
lino
,
tstrerror
(
code
));
}
else
{
tsdbDebug
(
"vgId:%d %s done, fname:%s size:%"
PRId64
,
vid
,
__func__
,
pWriter
->
config
.
file
.
fname
,
tsdbDebug
(
"vgId:%d %s done, fname:%s size:%"
PRId64
,
vid
,
__func__
,
""
/*pWriter->config.file.fname*/
,
pWriter
->
config
.
file
.
size
);
}
return
code
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录