Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e2478705
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看板
提交
e2478705
编写于
5月 19, 2023
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more code
上级
66ea1075
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
219 addition
and
170 deletion
+219
-170
include/util/tarray2.h
include/util/tarray2.h
+36
-26
source/dnode/vnode/src/tsdb/dev/inc/tsdbFS.h
source/dnode/vnode/src/tsdb/dev/inc/tsdbFS.h
+8
-8
source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h
source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h
+10
-7
source/dnode/vnode/src/tsdb/dev/inc/tsdbFile.h
source/dnode/vnode/src/tsdb/dev/inc/tsdbFile.h
+3
-3
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
+16
-17
source/dnode/vnode/src/tsdb/dev/tsdbFSet.c
source/dnode/vnode/src/tsdb/dev/tsdbFSet.c
+145
-108
source/dnode/vnode/src/tsdb/dev/tsdbFile.c
source/dnode/vnode/src/tsdb/dev/tsdbFile.c
+1
-1
未找到文件。
include/util/tarray2.h
浏览文件 @
e2478705
...
...
@@ -77,45 +77,55 @@ static FORCE_INLINE int32_t tarray2_make_room(void *arg, // array
#define TARRAY2_CLEAR(a, cb) \
do { \
if (cb) { \
void (*cb_)(void *) = (cb); \
for (int32_t i = 0; i < (a)->size; ++i) { \
cb
((a)->data + i);
\
cb
_((a)->data + i);
\
} \
} \
(a)->size = 0; \
} while (0)
#define TARRAY2_CLEAR_FREE(a, cb) \
do { \
TARRAY2_CLEAR(a, cb); \
TARRAY2_FREE(a); \
} while (0)
#define TARRAY2_SEARCH(a, ep, cmp, flag) \
(((a)->size == 0) ? NULL : taosbsearch(ep, (a)->data, (a)->size, sizeof(
(a)->data[0]
), cmp, flag))
#define TARRAY2_INSERT(a, idx, e) \
({ \
int32_t __ret = 0; \
if ((a)->size >= (a)->capacity) { \
__ret = tarray2_make_room(&(a), (a)->size + 1, sizeof(
*(a)->data
)); \
} \
if (!__ret) { \
if ((a)->size > (idx)) { \
memmove((a)->data + (idx) + 1, (a)->data + (idx), sizeof(
*(a)->data
) * ((a)->size - (idx))); \
} \
(a)->data[(idx)] = e; \
(a)->size++; \
} \
__ret; \
(((a)->size == 0) ? NULL : taosbsearch(ep, (a)->data, (a)->size, sizeof(
typeof((a)->data[0])
), cmp, flag))
#define TARRAY2_INSERT(a, idx, e)
\
({
\
int32_t __ret = 0;
\
if ((a)->size >= (a)->capacity) {
\
__ret = tarray2_make_room(&(a), (a)->size + 1, sizeof(
typeof((a)->data[0])
)); \
}
\
if (!__ret) {
\
if ((a)->size > (idx)) {
\
memmove((a)->data + (idx) + 1, (a)->data + (idx), sizeof(
typeof((a)->data[0])
) * ((a)->size - (idx))); \
}
\
(a)->data[(idx)] = e;
\
(a)->size++;
\
}
\
__ret;
\
})
#define TARRAY2_INSERT_P(a, idx, ep) TARRAY2_INSERT(a, idx, *(ep))
#define TARRAY2_APPEND(a, e) TARRAY2_INSERT(a, (a)->size, e)
#define TARRAY2_APPEND_P(a, ep) TARRAY2_APPEND(a, *(ep))
#define TARRAY2_REMOVE(a, idx, cb) \
do { \
if ((idx) < (a)->size) { \
if (cb) cb((a)->data + (idx)); \
if ((idx) < (a)->size - 1) { \
memmove((a)->data + (idx), (a)->data + (idx) + 1, sizeof(*(a)->data) * ((a)->size - (idx)-1)); \
} \
(a)->size--; \
} \
#define TARRAY2_REMOVE(a, idx, cb) \
do { \
if ((idx) < (a)->size) { \
if (cb) { \
void (*cb_)(void *) = cb; \
cb_((a)->data + (idx)); \
} \
if ((idx) < (a)->size - 1) { \
memmove((a)->data + (idx), (a)->data + (idx) + 1, sizeof(typeof(*(a)->data)) * ((a)->size - (idx)-1)); \
} \
(a)->size--; \
} \
} while (0)
#define TARRAY2_FOREACH(a, e) for (int32_t __i = 0; __i < (a)->size && ((e) = (a)->data[__i], 1); __i++)
...
...
source/dnode/vnode/src/tsdb/dev/inc/tsdbFS.h
浏览文件 @
e2478705
...
...
@@ -44,14 +44,14 @@ int32_t tsdbFSGetFSet(STFileSystem *fs, int32_t fid, const STFileSet **ppFSet);
/* Exposed Structs */
struct
STFileSystem
{
STsdb
*
pTsdb
;
tsem_t
canEdit
;
int32_t
state
;
int64_t
neid
;
EFEditT
etype
;
int64_t
eid
;
T
ARRAY2
(
STFileSet
*
)
cstate
;
T
ARRAY2
(
STFileSet
*
)
nstate
;
STsdb
*
pTsdb
;
tsem_t
canEdit
;
int32_t
state
;
int64_t
neid
;
EFEditT
etype
;
int64_t
eid
;
T
FileSetArray
cstate
;
T
FileSetArray
nstate
;
};
#ifdef __cplusplus
...
...
source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h
浏览文件 @
e2478705
...
...
@@ -25,6 +25,8 @@ extern "C" {
typedef
struct
STFileSet
STFileSet
;
typedef
struct
STFileOp
STFileOp
;
typedef
struct
SSttLvl
SSttLvl
;
typedef
TARRAY2
(
STFileSet
*
)
TFileSetArray
;
typedef
TARRAY2
(
SSttLvl
*
)
TSttLvlArray
;
typedef
enum
{
TSDB_FOP_NONE
=
0
,
...
...
@@ -34,11 +36,12 @@ 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
tsdbFileSetToJson
(
const
STFileSet
*
fset
,
cJSON
*
json
);
int32_t
tsdbJsonToFileSet
(
const
cJSON
*
json
,
STFileSet
*
fset
);
int32_t
tsdbFileSetInit
(
STFileSet
*
pSet
,
int32_t
fid
);
int32_t
tsdbFileSetInitEx
(
const
STFileSet
*
fset1
,
STFileSet
*
fset2
);
int32_t
tsdbFileSetClear
(
STFileSet
*
pSet
);
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
);
...
...
@@ -59,9 +62,9 @@ struct SSttLvl {
};
struct
STFileSet
{
int32_t
fid
;
STFileObj
*
farr
[
TSDB_FTYPE_MAX
];
// file array
SRBTree
lvlTree
;
// SRBTree<SSttLvl>, level tree of .stt
int32_t
fid
;
STFileObj
*
farr
[
TSDB_FTYPE_MAX
];
// file array
TSttLvlArray
lvlArr
;
// level array
};
#ifdef __cplusplus
...
...
source/dnode/vnode/src/tsdb/dev/inc/tsdbFile.h
浏览文件 @
e2478705
...
...
@@ -37,13 +37,13 @@ typedef enum {
#define TSDB_FTYPE_MAX (TSDB_FTYPE_TOMB + 1)
// STFile
int32_t
tsdbTFileToJson
(
const
STFile
*
f
,
cJSON
*
json
);
int32_t
tsdbJsonToTFile
(
const
cJSON
*
json
,
tsdb_ftype_t
ftype
,
STFile
*
f
);
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
(
STFileObj
**
fobj
);
int32_t
tsdbTFileObjCreate
(
const
STFile
*
f
,
STFileObj
**
fobj
);
int32_t
tsdbTFileObjDestroy
(
STFileObj
*
fobj
);
struct
STFile
{
...
...
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
浏览文件 @
e2478705
...
...
@@ -85,7 +85,7 @@ static int32_t current_fname(STsdb *pTsdb, char *fname, EFCurrentT ftype) {
static
int32_t
save_json
(
const
cJSON
*
json
,
const
char
*
fname
)
{
int32_t
code
=
0
;
char
*
data
=
cJSON_Print
(
json
);
char
*
data
=
cJSON_Print
Unformatted
(
json
);
if
(
data
==
NULL
)
return
TSDB_CODE_OUT_OF_MEMORY
;
TdFilePtr
fp
=
taosOpenFile
(
fname
,
TD_FILE_WRITE
|
TD_FILE_CREATE
|
TD_FILE_TRUNC
);
...
...
@@ -149,7 +149,7 @@ _exit:
return
code
;
}
static
int32_t
save_fs
(
SArray
*
aTFileSet
,
const
char
*
fname
)
{
static
int32_t
save_fs
(
const
TFileSetArray
*
arr
,
const
char
*
fname
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
...
...
@@ -165,15 +165,13 @@ static int32_t save_fs(SArray *aTFileSet, const char *fname) {
// fset
cJSON
*
ajson
=
cJSON_AddArrayToObject
(
json
,
"fset"
);
if
(
!
ajson
)
TSDB_CHECK_CODE
(
code
=
TSDB_CODE_OUT_OF_MEMORY
,
lino
,
_exit
);
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
aTFileSet
);
i
++
)
{
STFileSet
*
pFileSet
=
(
STFileSet
*
)
taosArrayGet
(
aTFileSet
,
i
);
cJSON
*
item
;
item
=
cJSON_CreateObject
();
const
STFileSet
*
fset
;
TARRAY2_FOREACH
(
arr
,
fset
)
{
cJSON
*
item
=
cJSON_CreateObject
();
if
(
!
item
)
TSDB_CHECK_CODE
(
code
=
TSDB_CODE_OUT_OF_MEMORY
,
lino
,
_exit
);
cJSON_AddItemToArray
(
ajson
,
item
);
code
=
tsdbFileSetToJson
(
pFileS
et
,
item
);
code
=
tsdbFileSetToJson
(
fs
et
,
item
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
...
...
@@ -188,11 +186,11 @@ _exit:
return
code
;
}
static
int32_t
load_fs
(
const
char
*
fname
,
SArray
*
aTFileSet
)
{
static
int32_t
load_fs
(
const
char
*
fname
,
TFileSetArray
*
arr
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
taosArrayClear
(
aTFileSet
);
TARRAY2_CLEAR
(
arr
,
NULL
);
// load json
cJSON
*
json
=
NULL
;
...
...
@@ -215,10 +213,11 @@ static int32_t load_fs(const char *fname, SArray *aTFileSet) {
if
(
cJSON_IsArray
(
item
))
{
const
cJSON
*
titem
;
cJSON_ArrayForEach
(
titem
,
item
)
{
STFileSet
*
fset
=
taosArrayReserve
(
aTFileSet
,
1
);
if
(
!
fset
)
TSDB_CHECK_CODE
(
code
=
TSDB_CODE_OUT_OF_MEMORY
,
lino
,
_exit
);
STFileSet
*
fset
;
code
=
tsdbJsonToFileSet
(
titem
,
&
fset
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
tsdbJsonToFileSet
(
titem
,
fset
);
code
=
TARRAY2_APPEND
(
arr
,
fset
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
}
else
{
...
...
@@ -420,8 +419,8 @@ static int32_t open_fs(STFileSystem *fs, int8_t rollback) {
current_fname
(
pTsdb
,
mCurrent
,
TSDB_FCURRENT_M
);
if
(
taosCheckExistFile
(
fCurrent
))
{
// current.json exists
// code = load_fs(fCurrent,
fs->cstate);
//
TSDB_CHECK_CODE(code, lino, _exit);
code
=
load_fs
(
fCurrent
,
&
fs
->
cstate
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
if
(
taosCheckExistFile
(
cCurrent
))
{
// current.c.json exists
...
...
@@ -447,8 +446,8 @@ static int32_t open_fs(STFileSystem *fs, int8_t rollback) {
code
=
scan_and_fix_fs
(
fs
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
else
{
// code = save_fs(
fs->cstate, fCurrent);
//
TSDB_CHECK_CODE(code, lino, _exit);
code
=
save_fs
(
&
fs
->
cstate
,
fCurrent
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
_exit:
...
...
source/dnode/vnode/src/tsdb/dev/tsdbFSet.c
浏览文件 @
e2478705
...
...
@@ -79,11 +79,11 @@ static int32_t json_to_stt_lvl(const cJSON *json, SSttLvl *lvl) {
cJSON_ArrayForEach
(
item2
,
item1
)
{
STFileObj
*
fobj
;
int32_t
code
=
tsdbTFileObjCreate
(
&
fobj
);
if
(
code
)
return
code
;
//
int32_t code = tsdbTFileObjCreate(&fobj);
//
if (code) return code;
code
=
tsdbJsonToTFile
(
item2
,
TSDB_FTYPE_STT
,
&
fobj
->
f
);
if
(
code
)
return
code
;
//
code = tsdbJsonToTFile(item2, TSDB_FTYPE_STT, &fobj->f);
//
if (code) return code;
add_file_to_stt_lvl
(
lvl
,
fobj
);
}
...
...
@@ -95,29 +95,29 @@ static int32_t json_to_stt_lvl(const cJSON *json, SSttLvl *lvl) {
}
static
int32_t
add_stt_lvl
(
STFileSet
*
fset
,
SSttLvl
*
lvl
)
{
tRBTreePut
(
&
fset
->
lvlTree
,
&
lvl
->
rbtn
);
//
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
;
}
//
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
;
}
...
...
@@ -134,14 +134,14 @@ static int32_t stt_lvl_cmpr(const SRBTreeNode *n1, const SRBTreeNode *n2) {
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_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
...
...
@@ -167,64 +167,64 @@ int32_t tsdbFileSetToJson(const STFileSet *fset, cJSON *json) {
// each level
item1
=
cJSON_AddArrayToObject
(
json
,
"stt levels"
);
if
(
item1
==
NULL
)
return
TSDB_CODE_OUT_OF_MEMORY
;
SRBTreeIter
iter
=
tRBTreeIterCreate
(
&
fset
->
lvlTree
,
1
)
;
for
(
SRBTreeNode
*
node
=
tRBTreeIterNext
(
&
iter
);
node
;
node
=
tRBTreeIterNext
(
&
iter
)
)
{
const
SSttLvl
*
lvl
;
TARRAY2_FOREACH
(
&
fset
->
lvlArr
,
lvl
)
{
item2
=
cJSON_CreateObject
();
if
(
!
item2
)
return
TSDB_CODE_OUT_OF_MEMORY
;
cJSON_AddItemToArray
(
item1
,
item2
);
code
=
stt_lvl_to_json
(
TCONTAINER_OF
(
node
,
SSttLvl
,
rbtn
)
,
item2
);
code
=
stt_lvl_to_json
(
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
;
/* fid */
item1
=
cJSON_GetObjectItem
(
json
,
"fid"
);
if
(
cJSON_IsNumber
(
item1
))
{
fset
->
fid
=
item1
->
valueint
;
}
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
;
}
}
// 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
;
}
int32_t
tsdbJsonToFileSet
(
const
cJSON
*
json
,
STFileSet
*
*
fset
)
{
//
const cJSON *item1, *item2;
//
int32_t code;
//
STFile tf;
/
/ /
* fid */
//
item1 = cJSON_GetObjectItem(json, "fid");
//
if (cJSON_IsNumber(item1)) {
//
fset->fid = item1->valueint;
//
} 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;
//
}
//
}
//
//
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;
//
}
return
0
;
}
...
...
@@ -242,7 +242,7 @@ int32_t tsdbFileSetEdit(STFileSet *fset, const STFileOp *op) {
||
0
/* TODO*/
)
{
STFileObj
*
fobj
;
code
=
tsdbTFileObjCreate
(
&
fobj
);
//
code = tsdbTFileObjCreate(&fobj);
if
(
code
)
return
code
;
fobj
->
f
=
op
->
nState
;
add_file_to_fset
(
fset
,
fobj
);
...
...
@@ -256,48 +256,85 @@ int32_t tsdbFileSetEdit(STFileSet *fset, const STFileOp *op) {
return
0
;
}
int32_t
tsdbFileSetInit
(
STFileSet
*
pSet
,
int32_t
fid
)
{
return
fset_init
(
pSet
,
fid
);
}
int32_t
tsdbFileSetInit
(
int32_t
fid
,
STFileSet
**
fset
)
{
fset
[
0
]
=
taosMemoryCalloc
(
1
,
sizeof
(
STFileSet
));
if
(
fset
[
0
]
==
NULL
)
return
TSDB_CODE_OUT_OF_MEMORY
;
fset
[
0
]
->
fid
=
fid
;
TARRAY2_INIT
(
&
fset
[
0
]
->
lvlArr
);
return
0
;
}
int32_t
tsdbFileSetInitEx
(
const
STFileSet
*
fset1
,
STFileSet
*
fset2
)
{
int32_t
code
;
int32_t
tsdbFileSetInitEx
(
const
STFileSet
*
fset1
,
STFileSet
**
fset
)
{
int32_t
code
=
tsdbFileSetInit
(
fset1
->
fid
,
fset
);
if
(
code
)
return
code
;
fset_init
(
fset2
,
fset1
->
fid
);
for
(
int32_t
ftype
=
TSDB_FTYPE_MIN
;
ftype
<
TSDB_FTYPE_MAX
;
++
ftype
)
{
if
(
fset1
->
farr
[
ftype
]
==
NULL
)
continue
;
code
=
tsdbTFileObjCreate
(
&
fset2
->
farr
[
ftype
]);
if
(
code
)
return
code
;
fset2
->
farr
[
ftype
]
->
f
=
fset1
->
farr
[
ftype
]
->
f
;
code
=
tsdbTFileObjCreate
(
&
fset1
->
farr
[
ftype
]
->
f
,
&
fset
[
0
]
->
farr
[
ftype
]);
if
(
code
)
{
tsdbFileSetClear
(
fset
);
return
code
;
}
}
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
);
const
SSttLvl
*
lvl1
;
TARRAY2_FOREACH
(
&
fset1
->
lvlArr
,
lvl1
)
{
SSttLvl
*
lvl
;
// code = stt_lvl_init_ex(lvl1, &lvl);
if
(
code
)
{
tsdbFileSetClear
(
fset
);
return
code
;
}
}
// 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
*
pSet
)
{
// TODO
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);
// }
taosMemoryFree
(
fset
[
0
]);
fset
[
0
]
=
NULL
;
}
return
0
;
}
const
SSttLvl
*
tsdbFileSetGetLvl
(
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
;
// SSttLvl tlvl = {.level = level};
// SRBTreeNode *node = tRBTreeGet(&fset->lvlTree, &tlvl.rbtn);
// return node ? TCONTAINER_OF(node, SSttLvl, rbtn) : NULL;
// TODO
return
NULL
;
}
\ No newline at end of file
source/dnode/vnode/src/tsdb/dev/tsdbFile.c
浏览文件 @
e2478705
...
...
@@ -232,7 +232,7 @@ int32_t tsdbJsonToTFile(const cJSON *json, tsdb_ftype_t ftype, STFile *f) {
return
0
;
}
int32_t
tsdbTFileObjCreate
(
STFileObj
**
fobj
)
{
int32_t
tsdbTFileObjCreate
(
const
STFile
*
f
,
STFileObj
**
fobj
)
{
fobj
[
0
]
=
taosMemoryMalloc
(
sizeof
(
STFileObj
));
if
(
!
fobj
[
0
])
return
TSDB_CODE_OUT_OF_MEMORY
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录