Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f45d10bb
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看板
提交
f45d10bb
编写于
5月 08, 2023
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more code
上级
ebfd8b03
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
246 addition
and
15 deletion
+246
-15
source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h
source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h
+1
-0
source/dnode/vnode/src/tsdb/dev/inc/tsdbFile.h
source/dnode/vnode/src/tsdb/dev/inc/tsdbFile.h
+1
-1
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
+96
-5
source/dnode/vnode/src/tsdb/dev/tsdbFSet.c
source/dnode/vnode/src/tsdb/dev/tsdbFSet.c
+32
-0
source/dnode/vnode/src/tsdb/dev/tsdbFile.c
source/dnode/vnode/src/tsdb/dev/tsdbFile.c
+116
-9
未找到文件。
source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h
浏览文件 @
f45d10bb
...
...
@@ -34,6 +34,7 @@ typedef enum {
}
tsdb_fop_t
;
int32_t
tsdbFileSetToJson
(
const
STFileSet
*
fset
,
cJSON
*
json
);
int32_t
tsdbFileSetFromJson
(
const
cJSON
*
json
,
STFileSet
*
fset
);
int32_t
tsdbFileSetCreate
(
int32_t
fid
,
STFileSet
**
ppSet
);
int32_t
tsdbFileSetEdit
(
STFileSet
*
pSet
,
SFileOp
*
pOp
);
...
...
source/dnode/vnode/src/tsdb/dev/inc/tsdbFile.h
浏览文件 @
f45d10bb
...
...
@@ -36,6 +36,7 @@ typedef enum {
#define TSDB_FTYPE_MAX (TSDB_FTYPE_TOMB + 1)
int32_t
tsdbTFileToJson
(
const
STFile
*
f
,
cJSON
*
json
);
int32_t
tsdbTFileFromJson
(
const
cJSON
*
json
,
tsdb_ftype_t
ftype
,
STFile
**
f
);
int32_t
tsdbTFileInit
(
STsdb
*
pTsdb
,
STFile
*
pFile
);
int32_t
tsdbTFileClear
(
STFile
*
pFile
);
...
...
@@ -44,7 +45,6 @@ struct STFile {
LISTD
(
STFile
)
listNode
;
char
fname
[
TSDB_FILENAME_LEN
];
int32_t
ref
;
int32_t
state
;
tsdb_ftype_t
type
;
SDiskID
did
;
...
...
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
浏览文件 @
f45d10bb
...
...
@@ -102,7 +102,7 @@ _exit:
}
static
int32_t
save_json
(
const
cJSON
*
json
,
const
char
*
fname
)
{
int32_t
code
;
int32_t
code
=
0
;
char
*
data
=
cJSON_Print
(
json
);
if
(
data
==
NULL
)
return
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -130,6 +130,43 @@ _exit:
return
code
;
}
static
int32_t
load_json
(
const
char
*
fname
,
cJSON
**
json
)
{
int32_t
code
=
0
;
void
*
data
=
NULL
;
TdFilePtr
fp
=
taosOpenFile
(
fname
,
TD_FILE_READ
);
if
(
fp
==
NULL
)
return
TAOS_SYSTEM_ERROR
(
code
);
int64_t
size
;
if
(
taosFStatFile
(
fp
,
&
size
,
NULL
)
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
code
);
goto
_exit
;
}
data
=
taosMemoryMalloc
(
size
);
if
(
data
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
if
(
taosReadFile
(
fp
,
data
,
size
)
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
code
);
goto
_exit
;
}
json
[
0
]
=
cJSON_Parse
(
data
);
if
(
json
[
0
]
==
NULL
)
{
code
=
TSDB_CODE_FILE_CORRUPTED
;
goto
_exit
;
}
_exit:
taosCloseFile
(
&
fp
);
if
(
data
)
taosMemoryFree
(
data
);
if
(
code
)
json
[
0
]
=
NULL
;
return
code
;
}
static
int32_t
save_fs
(
int64_t
eid
,
SArray
*
aTFileSet
,
const
char
*
fname
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
...
...
@@ -181,9 +218,63 @@ _exit:
return
code
;
}
static
int32_t
load_fs
(
const
char
*
fname
,
STFileSystem
*
pFS
)
{
ASSERTS
(
0
,
"TODO: Not implemented yet"
);
return
0
;
static
int32_t
load_fs
(
const
char
*
fname
,
SArray
*
aTFileSet
,
int64_t
*
eid
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
taosArrayClear
(
aTFileSet
);
// load json
cJSON
*
json
=
NULL
;
code
=
load_json
(
fname
,
&
json
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
// parse json
const
cJSON
*
item
;
/* fmtv */
item
=
cJSON_GetObjectItem
(
json
,
"fmtv"
);
if
(
cJSON_IsNumber
(
item
))
{
ASSERT
(
item
->
valuedouble
==
1
);
}
else
{
code
=
TSDB_CODE_FILE_CORRUPTED
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
}
/* eid */
item
=
cJSON_GetObjectItem
(
json
,
"eid"
);
if
(
cJSON_IsNumber
(
item
))
{
eid
[
0
]
=
item
->
valuedouble
;
}
else
{
code
=
TSDB_CODE_FILE_CORRUPTED
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
}
/* fset */
item
=
cJSON_GetObjectItem
(
json
,
"fset"
);
if
(
cJSON_IsArray
(
item
))
{
const
cJSON
*
titem
;
cJSON_ArrayForEach
(
titem
,
item
)
{
STFileSet
*
pFileSet
=
taosArrayReserve
(
aTFileSet
,
1
);
if
(
pFileSet
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
code
=
tsdbFileSetFromJson
(
titem
,
pFileSet
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
}
}
else
{
code
=
TSDB_CODE_FILE_CORRUPTED
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
}
_exit:
if
(
code
)
{
tsdbError
(
"%s failed at line %d since %s, fname:%s"
,
__func__
,
lino
,
tstrerror
(
code
),
fname
);
}
if
(
json
)
cJSON_Delete
(
json
);
return
code
;
}
static
int32_t
commit_edit
(
STFileSystem
*
pFS
,
tsdb_fs_edit_t
etype
)
{
...
...
@@ -249,7 +340,7 @@ static int32_t open_fs(STFileSystem *pFS, int8_t rollback) {
current_fname
(
pTsdb
,
mCurrent
,
TSDB_FCURRENT_M
);
if
(
taosCheckExistFile
(
fCurrent
))
{
// current.json exists
code
=
load_fs
(
fCurrent
,
pFS
);
code
=
load_fs
(
fCurrent
,
pFS
->
cstate
,
&
pFS
->
nextEditId
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
// check current.json.commit existence
...
...
source/dnode/vnode/src/tsdb/dev/tsdbFSet.c
浏览文件 @
f45d10bb
...
...
@@ -38,6 +38,11 @@ static int32_t stt_lvl_to_json(const SSttLvl *lvl, cJSON *json) {
return
0
;
}
static
int32_t
stt_lvl_from_json
(
const
cJSON
*
json
,
SSttLvl
*
lvl
)
{
// TODO
return
0
;
}
int32_t
tsdbFileSetCreate
(
int32_t
fid
,
struct
STFileSet
**
ppSet
)
{
int32_t
code
=
0
;
...
...
@@ -94,6 +99,33 @@ int32_t tsdbFileSetToJson(const STFileSet *fset, cJSON *json) {
return
0
;
}
int32_t
tsdbFileSetFromJson
(
const
cJSON
*
json
,
STFileSet
*
fset
)
{
const
cJSON
*
item
;
/* fid */
item
=
cJSON_GetObjectItem
(
json
,
"fid"
);
if
(
cJSON_IsNumber
(
item
))
{
fset
->
fid
=
item
->
valueint
;
}
else
{
return
TSDB_CODE_FILE_CORRUPTED
;
}
for
(
int32_t
ftype
=
TSDB_FTYPE_MIN
;
ftype
<
TSDB_FTYPE_MAX
;
++
ftype
)
{
int32_t
code
=
tsdbTFileFromJson
(
json
,
ftype
,
&
fset
->
farr
[
ftype
]);
if
(
code
)
return
code
;
}
// each level
item
=
cJSON_GetObjectItem
(
json
,
"stt"
);
if
(
cJSON_IsArray
(
item
))
{
// TODO
}
else
{
return
TSDB_CODE_FILE_CORRUPTED
;
}
return
0
;
}
int32_t
tsdbEditFileSet
(
struct
STFileSet
*
pFileSet
,
const
struct
SFileOp
*
pOp
)
{
int32_t
code
=
0
;
ASSERTS
(
0
,
"TODO: Not implemented yet"
);
...
...
source/dnode/vnode/src/tsdb/dev/tsdbFile.c
浏览文件 @
f45d10bb
...
...
@@ -15,40 +15,54 @@
#include "inc/tsdbFile.h"
// to_json
static
int32_t
head_to_json
(
const
STFile
*
file
,
cJSON
*
json
);
static
int32_t
data_to_json
(
const
STFile
*
file
,
cJSON
*
json
);
static
int32_t
sma_to_json
(
const
STFile
*
file
,
cJSON
*
json
);
static
int32_t
tomb_to_json
(
const
STFile
*
file
,
cJSON
*
json
);
static
int32_t
stt_to_json
(
const
STFile
*
file
,
cJSON
*
json
);
// from_json
static
int32_t
head_from_json
(
const
cJSON
*
json
,
STFile
*
file
);
static
int32_t
data_from_json
(
const
cJSON
*
json
,
STFile
*
file
);
static
int32_t
sma_from_json
(
const
cJSON
*
json
,
STFile
*
file
);
static
int32_t
tomb_from_json
(
const
cJSON
*
json
,
STFile
*
file
);
static
int32_t
stt_from_json
(
const
cJSON
*
json
,
STFile
*
file
);
static
const
struct
{
const
char
*
suffix
;
int32_t
(
*
to_json
)(
const
STFile
*
file
,
cJSON
*
json
);
int32_t
(
*
from_json
)(
const
cJSON
*
json
,
STFile
*
file
);
}
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
},
[
TSDB_FTYPE_HEAD
]
=
{
"head"
,
head_to_json
,
head_from_json
},
[
TSDB_FTYPE_DATA
]
=
{
"data"
,
data_to_json
,
data_from_json
},
[
TSDB_FTYPE_SMA
]
=
{
"sma"
,
sma_to_json
,
sma_from_json
},
[
TSDB_FTYPE_TOMB
]
=
{
"tomb"
,
tomb_to_json
,
tomb_from_json
},
[
TSDB_FTYPE_STT
]
=
{
"stt"
,
stt_to_json
,
stt_from_json
},
};
static
int32_t
tfile_to_json
(
const
STFile
*
file
,
cJSON
*
json
)
{
/* did.level */
if
(
cJSON_AddNumberToObject
(
json
,
"did.level"
,
file
->
did
.
level
)
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
/* did.id */
if
(
cJSON_AddNumberToObject
(
json
,
"did.id"
,
file
->
did
.
id
)
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
/* fid */
if
(
cJSON_AddNumberToObject
(
json
,
"fid"
,
file
->
fid
)
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
/* cid */
if
(
cJSON_AddNumberToObject
(
json
,
"cid"
,
file
->
cid
)
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
/* size */
if
(
cJSON_AddNumberToObject
(
json
,
"size"
,
file
->
size
)
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
...
...
@@ -56,22 +70,66 @@ static int32_t tfile_to_json(const STFile *file, cJSON *json) {
return
0
;
}
static
int32_t
head_to_json
(
const
STFile
*
file
,
cJSON
*
json
)
{
return
tfile_to_json
(
file
,
json
);
}
static
int32_t
tfile_from_json
(
const
cJSON
*
json
,
STFile
*
file
)
{
const
cJSON
*
item
;
static
int32_t
data_to_json
(
const
STFile
*
file
,
cJSON
*
json
)
{
return
tfile_to_json
(
file
,
json
);
}
/* did.level */
item
=
cJSON_GetObjectItem
(
json
,
"did.level"
);
if
(
cJSON_IsNumber
(
item
))
{
file
->
did
.
level
=
item
->
valuedouble
;
}
else
{
return
TSDB_CODE_FILE_CORRUPTED
;
}
static
int32_t
sma_to_json
(
const
STFile
*
file
,
cJSON
*
json
)
{
return
tfile_to_json
(
file
,
json
);
}
/* did.id */
item
=
cJSON_GetObjectItem
(
json
,
"did.id"
);
if
(
cJSON_IsNumber
(
item
))
{
file
->
did
.
id
=
item
->
valuedouble
;
}
else
{
return
TSDB_CODE_FILE_CORRUPTED
;
}
static
int32_t
tomb_to_json
(
const
STFile
*
file
,
cJSON
*
json
)
{
return
tfile_to_json
(
file
,
json
);
}
/* fid */
item
=
cJSON_GetObjectItem
(
json
,
"fid"
);
if
(
cJSON_IsNumber
(
item
))
{
file
->
fid
=
item
->
valuedouble
;
}
else
{
return
TSDB_CODE_FILE_CORRUPTED
;
}
/* cid */
item
=
cJSON_GetObjectItem
(
json
,
"cid"
);
if
(
cJSON_IsNumber
(
item
))
{
file
->
cid
=
item
->
valuedouble
;
}
else
{
return
TSDB_CODE_FILE_CORRUPTED
;
}
/* size */
item
=
cJSON_GetObjectItem
(
json
,
"size"
);
if
(
cJSON_IsNumber
(
item
))
{
file
->
size
=
item
->
valuedouble
;
}
else
{
return
TSDB_CODE_FILE_CORRUPTED
;
}
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
;
/* lvl */
if
(
cJSON_AddNumberToObject
(
json
,
"lvl"
,
file
->
stt
.
lvl
)
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
/* nseg */
if
(
cJSON_AddNumberToObject
(
json
,
"nseg"
,
file
->
stt
.
nseg
)
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
...
...
@@ -79,6 +137,35 @@ static int32_t stt_to_json(const STFile *file, cJSON *json) {
return
0
;
}
static
int32_t
head_from_json
(
const
cJSON
*
json
,
STFile
*
file
)
{
return
tfile_from_json
(
json
,
file
);
}
static
int32_t
data_from_json
(
const
cJSON
*
json
,
STFile
*
file
)
{
return
tfile_from_json
(
json
,
file
);
}
static
int32_t
sma_from_json
(
const
cJSON
*
json
,
STFile
*
file
)
{
return
tfile_from_json
(
json
,
file
);
}
static
int32_t
tomb_from_json
(
const
cJSON
*
json
,
STFile
*
file
)
{
return
tfile_from_json
(
json
,
file
);
}
static
int32_t
stt_from_json
(
const
cJSON
*
json
,
STFile
*
file
)
{
int32_t
code
=
tfile_from_json
(
json
,
file
);
if
(
code
)
return
code
;
const
cJSON
*
item
;
/* lvl */
item
=
cJSON_GetObjectItem
(
json
,
"lvl"
);
if
(
cJSON_IsNumber
(
item
))
{
file
->
stt
.
lvl
=
item
->
valuedouble
;
}
else
{
return
TSDB_CODE_FILE_CORRUPTED
;
}
/* nseg */
item
=
cJSON_GetObjectItem
(
json
,
"nseg"
);
if
(
cJSON_IsNumber
(
item
))
{
file
->
stt
.
nseg
=
item
->
valuedouble
;
}
else
{
return
TSDB_CODE_FILE_CORRUPTED
;
}
return
0
;
}
int32_t
tsdbTFileInit
(
STsdb
*
pTsdb
,
STFile
*
pFile
)
{
SVnode
*
pVnode
=
pTsdb
->
pVnode
;
STfs
*
pTfs
=
pVnode
->
pTfs
;
...
...
@@ -120,4 +207,24 @@ int32_t tsdbTFileToJson(const STFile *file, cJSON *json) {
if
(
tjson
==
NULL
)
return
TSDB_CODE_OUT_OF_MEMORY
;
return
g_tfile_info
[
file
->
type
].
to_json
(
file
,
tjson
);
}
int32_t
tsdbTFileFromJson
(
const
cJSON
*
json
,
tsdb_ftype_t
ftype
,
STFile
**
f
)
{
const
cJSON
*
item
=
cJSON_GetObjectItem
(
json
,
g_tfile_info
[
ftype
].
suffix
);
if
(
cJSON_IsObject
(
item
))
{
f
[
0
]
=
(
STFile
*
)
taosMemoryMalloc
(
sizeof
(
*
f
[
0
]));
if
(
f
[
0
]
==
NULL
)
return
TSDB_CODE_OUT_OF_MEMORY
;
int32_t
code
=
g_tfile_info
[
ftype
].
from_json
(
item
,
f
[
0
]);
if
(
code
)
{
taosMemoryFree
(
f
[
0
]);
f
[
0
]
=
NULL
;
return
code
;
}
tsdbTFileInit
(
NULL
/* TODO */
,
f
[
0
]);
}
else
{
f
[
0
]
=
NULL
;
}
return
0
;
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录