Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
b2e18917
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看板
提交
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);
...
@@ -121,7 +121,7 @@ int32_t tsdbCloseRepo(tsdb_repo_t *repo);
*
*
* @return 0 for success, -1 for failure and the error number is set
* @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
* Get the TSDB repository information, including some statistics
...
...
src/vnode/tsdb/inc/tsdbMeta.h
浏览文件 @
b2e18917
...
@@ -84,10 +84,10 @@ SSchema *tsdbGetTableSchema(STable *pTable);
...
@@ -84,10 +84,10 @@ SSchema *tsdbGetTableSchema(STable *pTable);
#define TSDB_GET_TABLE_OF_NAME(pHandle, name)
/* TODO */
#define TSDB_GET_TABLE_OF_NAME(pHandle, name)
/* TODO */
// Create a new meta handle with configuration
// Create a new meta handle with configuration
S
MetaHandle
*
tsdbCreateMeta
(
int32_t
numOf
Tables
);
S
TsdbMeta
*
tsdbCreateMeta
(
int32_t
max
Tables
);
int32_t
tsdbFreeMeta
Handle
(
SMetaHandle
*
pMetaHandle
);
int32_t
tsdbFreeMeta
(
STsdbMeta
*
pMeta
);
// Recover the meta handle from the file
// 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 <fcntl.h>
#include <pthread.h>
#include <pthread.h>
#include <stdint.h>
#include <stdint.h>
...
@@ -5,6 +6,8 @@
...
@@ -5,6 +6,8 @@
#include <sys/stat.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/types.h>
#include <unistd.h>
#include <unistd.h>
#include <string.h>
#include <dirent.h>
// #include "taosdef.h"
// #include "taosdef.h"
// #include "disk.h"
// #include "disk.h"
...
@@ -16,11 +19,12 @@
...
@@ -16,11 +19,12 @@
enum
{
TSDB_REPO_STATE_ACTIVE
,
TSDB_REPO_STATE_CLOSED
,
TSDB_REPO_STATE_CONFIGURING
};
enum
{
TSDB_REPO_STATE_ACTIVE
,
TSDB_REPO_STATE_CLOSED
,
TSDB_REPO_STATE_CONFIGURING
};
typedef
struct
_tsdb_repo
{
typedef
struct
_tsdb_repo
{
char
*
rootDir
;
// TSDB configuration
// TSDB configuration
STsdbCfg
config
;
STsdbCfg
config
;
// The meter meta handle of this TSDB repository
// The meter meta handle of this TSDB repository
S
MetaHandle
*
tsdbMeta
;
S
TsdbMeta
*
tsdbMeta
;
// The cache Handle
// The cache Handle
SCacheHandle
*
tsdbCache
;
SCacheHandle
*
tsdbCache
;
...
@@ -41,7 +45,8 @@ typedef struct _tsdb_repo {
...
@@ -41,7 +45,8 @@ typedef struct _tsdb_repo {
}
STsdbRepo
;
}
STsdbRepo
;
static
int32_t
tsdbCheckAndSetDefaultCfg
(
STsdbCfg
*
pCfg
);
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_ID(pRepo, sid) (((STSDBRepo *)pRepo)->pTableList)[sid]
#define TSDB_GET_TABLE_BY_NAME(pRepo, name)
#define TSDB_GET_TABLE_BY_NAME(pRepo, name)
...
@@ -63,29 +68,30 @@ tsdb_repo_t *tsdbCreateRepo(char *rootDir, STsdbCfg *pCfg, void *limiter) {
...
@@ -63,29 +68,30 @@ tsdb_repo_t *tsdbCreateRepo(char *rootDir, STsdbCfg *pCfg, void *limiter) {
return
NULL
;
return
NULL
;
}
}
pRepo
->
rootDir
=
strdup
(
rootDir
);
pRepo
->
config
=
*
pCfg
;
pRepo
->
config
=
*
pCfg
;
pRepo
->
limiter
=
limiter
;
pRepo
->
limiter
=
limiter
;
pRepo
->
tsdbMeta
=
tsdbCreateMeta
(
pCfg
->
maxTables
);
pRepo
->
tsdbMeta
=
tsdbCreateMeta
(
pCfg
->
maxTables
);
if
(
pRepo
->
tsdbMeta
==
NULL
)
{
if
(
pRepo
->
tsdbMeta
==
NULL
)
{
// TODO: deal with error
free
(
pRepo
->
rootDir
);
free
(
pRepo
);
free
(
pRepo
);
return
NULL
;
return
NULL
;
}
}
// TODO: Initialize cache handle
pRepo
->
tsdbCache
=
tsdbCreateCache
(
5
);
pRepo
->
tsdbCache
=
tsdbCreateCache
(
5
);
if
(
pRepo
->
tsdbCache
==
NULL
)
{
if
(
pRepo
->
tsdbCache
==
NULL
)
{
// TODO: free the object and return error
free
(
pRepo
->
rootDir
);
tsdbFreeMeta
Handle
(
pRepo
->
tsdbCache
);
tsdbFreeMeta
(
pRepo
->
tsdbMeta
);
free
(
pRepo
);
free
(
pRepo
);
return
NULL
;
return
NULL
;
}
}
// Create the Meta data file and data directory
// Create the Meta data file and data directory
if
(
tsdbCreateRepoFiles
(
pRepo
)
<
0
)
{
if
(
tsdbSetRepoEnv
(
pRepo
)
<
0
)
{
// Failed to create and save files
free
(
pRepo
->
rootDir
);
tsdbFreeMetaHandle
(
pRepo
->
tsdbCache
);
tsdbFreeMeta
(
pRepo
->
tsdbMeta
);
tsdbFreeCache
(
pRepo
->
tsdbCache
);
free
(
pRepo
);
free
(
pRepo
);
return
NULL
;
return
NULL
;
}
}
...
@@ -101,12 +107,16 @@ int32_t tsdbDropRepo(tsdb_repo_t *repo) {
...
@@ -101,12 +107,16 @@ int32_t tsdbDropRepo(tsdb_repo_t *repo) {
pRepo
->
state
=
TSDB_REPO_STATE_CLOSED
;
pRepo
->
state
=
TSDB_REPO_STATE_CLOSED
;
// Free the metaHandle
// Free the metaHandle
tsdbFreeMeta
Handle
(
pRepo
->
tsdbMeta
);
tsdbFreeMeta
(
pRepo
->
tsdbMeta
);
// Free the cache
// Free the cache
tsdbFreeCache
(
pRepo
->
tsdbCache
);
tsdbFreeCache
(
pRepo
->
tsdbCache
);
tsdbClearFiles
(
pRepo
);
// Destroy the repository info
tsdbDestroyRepoEnv
(
pRepo
);
free
(
pRepo
->
rootDir
);
free
(
pRepo
);
return
0
;
return
0
;
}
}
...
@@ -122,7 +132,7 @@ tsdb_repo_t *tsdbOpenRepo(char *tsdbDir) {
...
@@ -122,7 +132,7 @@ tsdb_repo_t *tsdbOpenRepo(char *tsdbDir) {
}
}
// TODO: Initialize configuration from the file
// TODO: Initialize configuration from the file
pRepo
->
tsdbMeta
=
tsdb
OpenMetaHandle
(
);
pRepo
->
tsdbMeta
=
tsdb
CreateMeta
(
pRepo
->
config
.
maxTables
);
if
(
pRepo
->
tsdbMeta
==
NULL
)
{
if
(
pRepo
->
tsdbMeta
==
NULL
)
{
free
(
pRepo
);
free
(
pRepo
);
return
NULL
;
return
NULL
;
...
@@ -150,9 +160,9 @@ int32_t tsdbCloseRepo(tsdb_repo_t *repo) {
...
@@ -150,9 +160,9 @@ int32_t tsdbCloseRepo(tsdb_repo_t *repo) {
pRepo
->
state
=
TSDB_REPO_STATE_CLOSED
;
pRepo
->
state
=
TSDB_REPO_STATE_CLOSED
;
tsdbFreeMeta
Handle
(
pRepo
->
tsdbMeta
);
tsdbFreeMeta
(
pRepo
->
tsdbMeta
);
tsdbFreeCache
(
pRepo
->
tsdb
Meta
);
tsdbFreeCache
(
pRepo
->
tsdb
Cache
);
return
0
;
return
0
;
}
}
...
@@ -160,7 +170,7 @@ int32_t tsdbCloseRepo(tsdb_repo_t *repo) {
...
@@ -160,7 +170,7 @@ int32_t tsdbCloseRepo(tsdb_repo_t *repo) {
int32_t
tsdbConfigRepo
(
tsdb_repo_t
*
repo
,
STsdbCfg
*
pCfg
)
{
int32_t
tsdbConfigRepo
(
tsdb_repo_t
*
repo
,
STsdbCfg
*
pCfg
)
{
STsdbRepo
*
pRepo
=
(
STsdbRepo
*
)
repo
;
STsdbRepo
*
pRepo
=
(
STsdbRepo
*
)
repo
;
pRepo
->
config
=
pCfg
;
pRepo
->
config
=
*
pCfg
;
// TODO
// TODO
return
0
;
return
0
;
}
}
...
@@ -192,10 +202,61 @@ static int32_t tsdbCheckAndSetDefaultCfg(STsdbCfg *pCfg) {
...
@@ -192,10 +202,61 @@ static int32_t tsdbCheckAndSetDefaultCfg(STsdbCfg *pCfg) {
return
0
;
return
0
;
}
}
static
int32_t
tsdbCreateRepoFiles
(
STsdbRepo
*
pRepo
)
{
static
int32_t
tsdbSetRepoEnv
(
STsdbRepo
*
pRepo
)
{
// TODO
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
)
{
static
int32_t
tsdbDestroyRepoEnv
(
STsdbRepo
*
pRepo
)
{
// TODO
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 @@
...
@@ -4,7 +4,7 @@
#include "tsdb.h"
#include "tsdb.h"
#include "tsdbMeta.h"
#include "tsdbMeta.h"
STsdbMeta
*
tsdbCreateMeta
(
int32_t
max
NumOf
Tables
)
{
STsdbMeta
*
tsdbCreateMeta
(
int32_t
maxTables
)
{
STsdbMeta
*
pMeta
=
(
STsdbMeta
*
)
malloc
(
sizeof
(
STsdbMeta
));
STsdbMeta
*
pMeta
=
(
STsdbMeta
*
)
malloc
(
sizeof
(
STsdbMeta
));
if
(
pMeta
==
NULL
)
{
if
(
pMeta
==
NULL
)
{
return
NULL
;
return
NULL
;
...
@@ -12,7 +12,7 @@ STsdbMeta *tsdbCreateMeta(int32_t maxNumOfTables) {
...
@@ -12,7 +12,7 @@ STsdbMeta *tsdbCreateMeta(int32_t maxNumOfTables) {
pMeta
->
numOfTables
=
0
;
pMeta
->
numOfTables
=
0
;
pMeta
->
numOfSuperTables
=
0
;
pMeta
->
numOfSuperTables
=
0
;
pMeta
->
pTables
=
calloc
(
sizeof
(
STable
*
),
numOf
Tables
);
pMeta
->
pTables
=
calloc
(
sizeof
(
STable
*
),
max
Tables
);
if
(
pMeta
->
pTables
==
NULL
)
{
if
(
pMeta
->
pTables
==
NULL
)
{
free
(
pMeta
);
free
(
pMeta
);
return
NULL
;
return
NULL
;
...
@@ -29,9 +29,7 @@ STsdbMeta *tsdbCreateMeta(int32_t maxNumOfTables) {
...
@@ -29,9 +29,7 @@ STsdbMeta *tsdbCreateMeta(int32_t maxNumOfTables) {
return
pMeta
;
return
pMeta
;
}
}
int32_t
tsdbFreeMetaHandle
(
STsdbMeta
*
pMetaHandle
)
{
int32_t
tsdbFreeMeta
(
STsdbMeta
*
pMeta
)
{
// TODO
}
}
static
int32_t
tsdbCheckTableCfg
(
STableCfg
*
pCfg
)
{
return
0
;
}
static
int32_t
tsdbCheckTableCfg
(
STableCfg
*
pCfg
)
{
return
0
;
}
...
@@ -47,7 +45,7 @@ int32_t tsdbCreateTableImpl(STsdbMeta *pHandle, STableCfg *pCfg) {
...
@@ -47,7 +45,7 @@ int32_t tsdbCreateTableImpl(STsdbMeta *pHandle, STableCfg *pCfg) {
return
-
1
;
return
-
1
;
}
}
pHandle
->
pTables
[
pCfg
->
tableId
]
=
pTable
;
pHandle
->
pTables
[
pCfg
->
tableId
.
tid
]
=
pTable
;
// TODO: add name to it
// TODO: add name to it
return
0
;
return
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录