Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
loser646
TDengine
提交
b2e18917
T
TDengine
项目概览
loser646
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b2e18917
编写于
3月 02, 2020
作者:
H
hzcheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more
上级
a4ee9d7c
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
89 addition
and
30 deletion
+89
-30
src/vnode/tsdb/inc/tsdb.h
src/vnode/tsdb/inc/tsdb.h
+1
-1
src/vnode/tsdb/inc/tsdbMeta.h
src/vnode/tsdb/inc/tsdbMeta.h
+4
-4
src/vnode/tsdb/src/tsdbMain.c
src/vnode/tsdb/src/tsdbMain.c
+80
-19
src/vnode/tsdb/src/tsdbMeta.c
src/vnode/tsdb/src/tsdbMeta.c
+4
-6
未找到文件。
src/vnode/tsdb/inc/tsdb.h
浏览文件 @
b2e18917
...
...
@@ -121,7 +121,7 @@ int32_t tsdbCloseRepo(tsdb_repo_t *repo);
*
* @return 0 for success, -1 for failure and the error number is set
*/
int32_t
tsdbConfigRepo
(
tsdb_repo_t
repo
,
STsdbCfg
*
pCfg
);
int32_t
tsdbConfigRepo
(
tsdb_repo_t
*
repo
,
STsdbCfg
*
pCfg
);
/**
* Get the TSDB repository information, including some statistics
...
...
src/vnode/tsdb/inc/tsdbMeta.h
浏览文件 @
b2e18917
...
...
@@ -84,10 +84,10 @@ SSchema *tsdbGetTableSchema(STable *pTable);
#define TSDB_GET_TABLE_OF_NAME(pHandle, name)
/* TODO */
// Create a new meta handle with configuration
S
MetaHandle
*
tsdbCreateMeta
(
int32_t
numOf
Tables
);
int32_t
tsdbFreeMeta
Handle
(
SMetaHandle
*
pMetaHandle
);
S
TsdbMeta
*
tsdbCreateMeta
(
int32_t
max
Tables
);
int32_t
tsdbFreeMeta
(
STsdbMeta
*
pMeta
);
// Recover the meta handle from the file
S
MetaHandle
*
tsdbOpenMetaHandle
(
char
*
tsdbDir
);
S
TsdbMeta
*
tsdbOpenMetaHandle
(
char
*
tsdbDir
);
int32_t
tsdbCreateTableImpl
(
S
MetaHandle
*
pHandle
,
STableCfg
*
pCfg
);
int32_t
tsdbCreateTableImpl
(
S
TsdbMeta
*
pHandle
,
STableCfg
*
pCfg
);
src/vnode/tsdb/src/tsdbMain.c
浏览文件 @
b2e18917
#include <stdio.h>
#include <fcntl.h>
#include <pthread.h>
#include <stdint.h>
...
...
@@ -5,6 +6,8 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <dirent.h>
// #include "taosdef.h"
// #include "disk.h"
...
...
@@ -16,11 +19,12 @@
enum
{
TSDB_REPO_STATE_ACTIVE
,
TSDB_REPO_STATE_CLOSED
,
TSDB_REPO_STATE_CONFIGURING
};
typedef
struct
_tsdb_repo
{
char
*
rootDir
;
// TSDB configuration
STsdbCfg
config
;
// The meter meta handle of this TSDB repository
S
MetaHandle
*
tsdbMeta
;
S
TsdbMeta
*
tsdbMeta
;
// The cache Handle
SCacheHandle
*
tsdbCache
;
...
...
@@ -41,7 +45,8 @@ typedef struct _tsdb_repo {
}
STsdbRepo
;
static
int32_t
tsdbCheckAndSetDefaultCfg
(
STsdbCfg
*
pCfg
);
static
int32_t
tsdbCreateRepoFiles
(
STsdbRepo
*
pRepo
);
static
int32_t
tsdbSetRepoEnv
(
STsdbRepo
*
pRepo
);
static
int32_t
tsdbDestroyRepoEnv
(
STsdbRepo
*
pRepo
);
#define TSDB_GET_TABLE_BY_ID(pRepo, sid) (((STSDBRepo *)pRepo)->pTableList)[sid]
#define TSDB_GET_TABLE_BY_NAME(pRepo, name)
...
...
@@ -63,29 +68,30 @@ tsdb_repo_t *tsdbCreateRepo(char *rootDir, STsdbCfg *pCfg, void *limiter) {
return
NULL
;
}
pRepo
->
rootDir
=
strdup
(
rootDir
);
pRepo
->
config
=
*
pCfg
;
pRepo
->
limiter
=
limiter
;
pRepo
->
tsdbMeta
=
tsdbCreateMeta
(
pCfg
->
maxTables
);
if
(
pRepo
->
tsdbMeta
==
NULL
)
{
// TODO: deal with error
free
(
pRepo
->
rootDir
);
free
(
pRepo
);
return
NULL
;
}
// TODO: Initialize cache handle
pRepo
->
tsdbCache
=
tsdbCreateCache
(
5
);
if
(
pRepo
->
tsdbCache
==
NULL
)
{
// TODO: free the object and return error
tsdbFreeMeta
Handle
(
pRepo
->
tsdbCache
);
free
(
pRepo
->
rootDir
);
tsdbFreeMeta
(
pRepo
->
tsdbMeta
);
free
(
pRepo
);
return
NULL
;
}
// Create the Meta data file and data directory
if
(
tsdbCreateRepoFiles
(
pRepo
)
<
0
)
{
// Failed to create and save files
tsdbFreeMetaHandle
(
pRepo
->
tsdbCache
);
if
(
tsdbSetRepoEnv
(
pRepo
)
<
0
)
{
free
(
pRepo
->
rootDir
);
tsdbFreeMeta
(
pRepo
->
tsdbMeta
);
tsdbFreeCache
(
pRepo
->
tsdbCache
);
free
(
pRepo
);
return
NULL
;
}
...
...
@@ -101,12 +107,16 @@ int32_t tsdbDropRepo(tsdb_repo_t *repo) {
pRepo
->
state
=
TSDB_REPO_STATE_CLOSED
;
// Free the metaHandle
tsdbFreeMeta
Handle
(
pRepo
->
tsdbMeta
);
tsdbFreeMeta
(
pRepo
->
tsdbMeta
);
// Free the cache
tsdbFreeCache
(
pRepo
->
tsdbCache
);
tsdbClearFiles
(
pRepo
);
// Destroy the repository info
tsdbDestroyRepoEnv
(
pRepo
);
free
(
pRepo
->
rootDir
);
free
(
pRepo
);
return
0
;
}
...
...
@@ -122,7 +132,7 @@ tsdb_repo_t *tsdbOpenRepo(char *tsdbDir) {
}
// TODO: Initialize configuration from the file
pRepo
->
tsdbMeta
=
tsdb
OpenMetaHandle
(
);
pRepo
->
tsdbMeta
=
tsdb
CreateMeta
(
pRepo
->
config
.
maxTables
);
if
(
pRepo
->
tsdbMeta
==
NULL
)
{
free
(
pRepo
);
return
NULL
;
...
...
@@ -150,9 +160,9 @@ int32_t tsdbCloseRepo(tsdb_repo_t *repo) {
pRepo
->
state
=
TSDB_REPO_STATE_CLOSED
;
tsdbFreeMeta
Handle
(
pRepo
->
tsdbMeta
);
tsdbFreeMeta
(
pRepo
->
tsdbMeta
);
tsdbFreeCache
(
pRepo
->
tsdb
Meta
);
tsdbFreeCache
(
pRepo
->
tsdb
Cache
);
return
0
;
}
...
...
@@ -160,7 +170,7 @@ int32_t tsdbCloseRepo(tsdb_repo_t *repo) {
int32_t
tsdbConfigRepo
(
tsdb_repo_t
*
repo
,
STsdbCfg
*
pCfg
)
{
STsdbRepo
*
pRepo
=
(
STsdbRepo
*
)
repo
;
pRepo
->
config
=
pCfg
;
pRepo
->
config
=
*
pCfg
;
// TODO
return
0
;
}
...
...
@@ -192,10 +202,61 @@ static int32_t tsdbCheckAndSetDefaultCfg(STsdbCfg *pCfg) {
return
0
;
}
static
int32_t
tsdbCreateRepoFiles
(
STsdbRepo
*
pRepo
)
{
// TODO
static
int32_t
tsdbSetRepoEnv
(
STsdbRepo
*
pRepo
)
{
char
*
metaFname
=
tsdbGetFileName
(
pRepo
->
rootDir
,
"tsdb"
,
TSDB_FILE_TYPE_META
);
int
fd
=
open
(
metaFname
,
O_WRONLY
|
O_CREAT
);
if
(
fd
<
0
)
{
return
-
1
;
}
if
(
write
(
fd
,
(
void
*
)(
&
(
pRepo
->
config
)),
sizeof
(
STsdbCfg
))
<
0
)
{
return
-
1
;
}
// Create the data file
char
*
dirName
=
calloc
(
1
,
strlen
(
pRepo
->
rootDir
)
+
strlen
(
"tsdb"
)
+
2
);
if
(
dirName
==
NULL
)
{
return
-
1
;
}
sprintf
(
dirName
,
"%s/%s"
,
pRepo
->
rootDir
,
dirName
);
if
(
mkdir
(
dirName
,
0755
)
<
0
)
{
free
(
dirName
);
return
-
1
;
}
free
(
dirName
);
return
0
;
}
static
int32_t
tsdbClearFiles
(
STsdbRepo
*
pRepo
)
{
// TODO
static
int32_t
tsdbDestroyRepoEnv
(
STsdbRepo
*
pRepo
)
{
char
fname
[
128
];
if
(
pRepo
==
NULL
)
return
0
;
char
*
dirName
=
calloc
(
1
,
strlen
(
pRepo
->
rootDir
)
+
strlen
(
"tsdb"
)
+
2
);
if
(
dirName
==
NULL
)
{
return
-
1
;
}
sprintf
(
dirName
,
"%s/%s"
,
pRepo
->
rootDir
,
"tsdb"
);
DIR
*
dir
=
opendir
(
dirName
);
if
(
dir
==
NULL
)
return
-
1
;
struct
dirent
*
dp
;
while
((
dp
=
readdir
(
dir
))
!=
NULL
)
{
if
((
strcmp
(
dp
->
d_name
,
"."
)
==
0
)
||
(
strcmp
(
dp
->
d_name
,
".."
)
==
0
))
continue
;
sprintf
(
fname
,
"%s/%s"
,
pRepo
->
rootDir
,
dp
->
d_name
);
remove
(
fname
);
}
closedir
(
dir
);
rmdir
(
dirName
);
char
*
metaFname
=
tsdbGetFileName
(
pRepo
->
rootDir
,
"tsdb"
,
TSDB_FILE_TYPE_META
);
remove
(
metaFname
);
return
0
;
}
\ No newline at end of file
src/vnode/tsdb/src/tsdbMeta.c
浏览文件 @
b2e18917
...
...
@@ -4,7 +4,7 @@
#include "tsdb.h"
#include "tsdbMeta.h"
STsdbMeta
*
tsdbCreateMeta
(
int32_t
max
NumOf
Tables
)
{
STsdbMeta
*
tsdbCreateMeta
(
int32_t
maxTables
)
{
STsdbMeta
*
pMeta
=
(
STsdbMeta
*
)
malloc
(
sizeof
(
STsdbMeta
));
if
(
pMeta
==
NULL
)
{
return
NULL
;
...
...
@@ -12,7 +12,7 @@ STsdbMeta *tsdbCreateMeta(int32_t maxNumOfTables) {
pMeta
->
numOfTables
=
0
;
pMeta
->
numOfSuperTables
=
0
;
pMeta
->
pTables
=
calloc
(
sizeof
(
STable
*
),
numOf
Tables
);
pMeta
->
pTables
=
calloc
(
sizeof
(
STable
*
),
max
Tables
);
if
(
pMeta
->
pTables
==
NULL
)
{
free
(
pMeta
);
return
NULL
;
...
...
@@ -29,9 +29,7 @@ STsdbMeta *tsdbCreateMeta(int32_t maxNumOfTables) {
return
pMeta
;
}
int32_t
tsdbFreeMetaHandle
(
STsdbMeta
*
pMetaHandle
)
{
// TODO
int32_t
tsdbFreeMeta
(
STsdbMeta
*
pMeta
)
{
}
static
int32_t
tsdbCheckTableCfg
(
STableCfg
*
pCfg
)
{
return
0
;
}
...
...
@@ -47,7 +45,7 @@ int32_t tsdbCreateTableImpl(STsdbMeta *pHandle, STableCfg *pCfg) {
return
-
1
;
}
pHandle
->
pTables
[
pCfg
->
tableId
]
=
pTable
;
pHandle
->
pTables
[
pCfg
->
tableId
.
tid
]
=
pTable
;
// TODO: add name to it
return
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录