Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f4959b03
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看板
提交
f4959b03
编写于
2月 19, 2020
作者:
H
hzcheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more
上级
f3f657a6
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
125 addition
and
61 deletion
+125
-61
src/vnode/tests/tsdb/tsdbTests.cpp
src/vnode/tests/tsdb/tsdbTests.cpp
+2
-5
src/vnode/tsdb/inc/tsdb.h
src/vnode/tsdb/inc/tsdb.h
+12
-17
src/vnode/tsdb/inc/tsdbCache.h
src/vnode/tsdb/inc/tsdbCache.h
+1
-0
src/vnode/tsdb/inc/tsdbFile.h
src/vnode/tsdb/inc/tsdbFile.h
+6
-6
src/vnode/tsdb/inc/tsdbMeta.h
src/vnode/tsdb/inc/tsdbMeta.h
+4
-3
src/vnode/tsdb/src/tsdb.c
src/vnode/tsdb/src/tsdb.c
+80
-29
src/vnode/tsdb/src/tsdbCache.c
src/vnode/tsdb/src/tsdbCache.c
+3
-0
src/vnode/tsdb/src/tsdbMeta.c
src/vnode/tsdb/src/tsdbMeta.c
+17
-1
未找到文件。
src/vnode/tests/tsdb/tsdbTests.cpp
浏览文件 @
f4959b03
...
...
@@ -6,10 +6,7 @@
TEST
(
TsdbTest
,
createTsdbRepo
)
{
STSDBCfg
*
pCfg
=
(
STSDBCfg
*
)
malloc
(
sizeof
(
STSDBCfg
));
pCfg
->
rootDir
=
"/var/lib/taos/"
;
free
(
pCfg
)
;
int32_t
err_num
=
0
;
tsdb_repo_t
*
pRepo
=
tsdbCreateRepo
(
pCfg
,
&
err_num
);
ASSERT_EQ
(
pRepo
,
NULL
);
ASSERT_EQ
(
1
,
2
/
2
);
}
\ No newline at end of file
src/vnode/tsdb/inc/tsdb.h
浏览文件 @
f4959b03
...
...
@@ -21,6 +21,7 @@ typedef int16_t tsdb_id_t; // TSDB repository ID
// Submit message
typedef
struct
{
int32_t
numOfTables
;
int32_t
compressed
;
char
data
[];
}
SSubmitMsg
;
...
...
@@ -111,49 +112,44 @@ typedef struct {
/**
* Create a new TSDB repository
* @param pCfg the TSDB repository configuration, upper layer to free the pointer
* @param error the error number to set when failure occurs
*
* @return a TSDB repository handle on success, NULL for failure and the error number is set
*/
tsdb_repo_t
*
tsdbCreateRepo
(
STSDBCfg
*
pCfg
,
int32_t
*
error
);
tsdb_repo_t
*
tsdbCreateRepo
(
STSDBCfg
*
pCfg
);
/**
* Close and free all resources taken by the repository
* @param
pR
epo the TSDB repository handle. The interface will free the handle too, so upper
* @param
r
epo the TSDB repository handle. The interface will free the handle too, so upper
* layer do NOT need to free the repo handle again.
* @param error the error number to set when failure occurs
*
* @return 0 for success, -1 for failure and the error number is set
*/
int32_t
tsdbDropRepo
(
tsdb_repo_t
*
pRepo
,
int32_t
*
error
);
int32_t
tsdbDropRepo
(
tsdb_repo_t
*
repo
);
/**
* Open an existing TSDB storage repository
* @param tsdbDir the existing TSDB root directory
* @param error the error number to set when failure occurs
*
* @return a TSDB repository handle on success, NULL for failure and the error number is set
*/
tsdb_repo_t
*
tsdbOpenRepo
(
char
*
tsdbDir
,
int32_t
*
error
);
tsdb_repo_t
*
tsdbOpenRepo
(
char
*
tsdbDir
);
/**
* Close a TSDB repository. Only free memory resources, and keep the files.
* @param
pR
epo the opened TSDB repository handle. The interface will free the handle too, so upper
* @param
r
epo the opened TSDB repository handle. The interface will free the handle too, so upper
* layer do NOT need to free the repo handle again.
* @param error the error number to set when failure occurs
*
* @return 0 for success, -1 for failure and the error number is set
*/
int32_t
tsdbCloseRepo
(
tsdb_repo_t
*
pRepo
,
int32_t
*
error
);
int32_t
tsdbCloseRepo
(
tsdb_repo_t
*
repo
);
/**
* Change the configuration of a repository
* @param pCfg the repository configuration, the upper layer should free the pointer
* @param error the error number to set when failure occurs
*
* @return 0 for success, -1 for failure and the error number is set
*/
int32_t
tsdbConfigRepo
(
STSDBCfg
*
pCfg
,
int32_t
*
error
);
int32_t
tsdbConfigRepo
(
tsdb_repo_t
repo
,
STSDBCfg
*
pCfg
);
/**
* Get the TSDB repository information, including some statistics
...
...
@@ -163,20 +159,19 @@ int32_t tsdbConfigRepo(STSDBCfg *pCfg, int32_t *error);
* @return a info struct handle on success, NULL for failure and the error number is set. The upper
* layers should free the info handle themselves or memory leak will occur
*/
STSDBRepoInfo
*
tsdbGetStatus
(
tsdb_repo_t
*
pRepo
,
int32_t
*
error
);
STSDBRepoInfo
*
tsdbGetStatus
(
tsdb_repo_t
*
pRepo
);
// -- For table manipulation
/**
* Create/Alter a table in a TSDB repository handle
* @param
pR
epo the TSDB repository handle
* @param
r
epo the TSDB repository handle
* @param pCfg the table configurations, the upper layer should free the pointer
* @param error the error number to set when failure occurs
*
* @return 0 for success, -1 for failure and the error number is set
*/
int32_t
tsdbCreateTable
(
tsdb_repo_t
*
pRepo
,
STableCfg
*
pCfg
,
int32_t
*
error
);
int32_t
tsdbAlterTable
(
tsdb_repo_t
*
pRepo
,
STableCfg
*
pCfg
,
int32_t
*
error
);
int32_t
tsdbCreateTable
(
tsdb_repo_t
*
repo
,
STableCfg
*
pCfg
);
int32_t
tsdbAlterTable
(
tsdb_repo_t
*
repo
,
STableCfg
*
pCfg
);
/**
* Drop a table in a repository and free all the resources it takes
...
...
src/vnode/tsdb/inc/tsdbCache.h
浏览文件 @
f4959b03
...
...
@@ -36,5 +36,6 @@ typedef struct STSDBCache {
#define TSDB_PREV_CACHE_BLOCK(pBlock) ((pBlock)->prev)
SCacheHandle
*
tsdbCreateCache
(
int32_t
numOfBlocks
);
int32_t
tsdbFreeCache
(
SCacheHandle
*
pHandle
);
#endif // _TD_TSDBCACHE_H_
src/vnode/tsdb/inc/tsdbFile.h
浏览文件 @
f4959b03
...
...
@@ -29,12 +29,12 @@ typedef struct {
SFileInfo
fInfo
;
}
SFILE
;
typedef
struct
{
int64_t
offset
;
int64_t
skey
;
int64_t
ekey
;
int16_t
numOfBlocks
;
}
SDataBlock
;
//
typedef struct {
//
int64_t offset;
//
int64_t skey;
//
int64_t ekey;
//
int16_t numOfBlocks;
//
} SDataBlock;
char
*
tsdbGetFileName
(
char
*
dirName
,
char
*
fname
,
TSDB_FILE_TYPE
type
);
...
...
src/vnode/tsdb/inc/tsdbMeta.h
浏览文件 @
f4959b03
...
...
@@ -84,9 +84,10 @@ SSchema *tsdbGetTableSchema(STable *pTable);
#define TSDB_GET_TABLE_OF_NAME(pHandle, name)
/* TODO */
// Create a new meta handle with configuration
SMetaHandle
*
tsdbCreateMetaHandle
(
int32_t
numOfTables
);
SMetaHandle
*
tsdbCreateMetaHandle
(
int32_t
numOfTables
);
int32_t
tsdbFreeMetaHandle
(
SMetaHandle
*
pMetaHandle
);
// Recover the meta handle from the file
SMetaHandle
*
tsdbOpenMetaHandle
(
int
fd
);
SMetaHandle
*
tsdbOpenMetaHandle
(
char
*
tsdbDir
);
int32_t
tsdbCreate
Meter
Impl
(
SMetaHandle
*
pHandle
,
STableCfg
*
pCfg
);
int32_t
tsdbCreate
Table
Impl
(
SMetaHandle
*
pHandle
,
STableCfg
*
pCfg
);
src/vnode/tsdb/src/tsdb.c
浏览文件 @
f4959b03
...
...
@@ -13,7 +13,13 @@
#include "tsdbCache.h"
#include "tsdbMeta.h"
typedef
struct
STSDBRepo
{
enum
{
TSDB_REPO_STATE_ACTIVE
,
TSDB_REPO_STATE_CLOSED
,
TSDB_REPO_STATE_CONFIGURING
};
typedef
struct
_tsdb_repo
{
// TSDB configuration
STSDBCfg
*
pCfg
;
...
...
@@ -31,10 +37,14 @@ typedef struct STSDBRepo {
pthread_mutex_t
tsdbMutex
;
int8_t
state
;
}
STSDBRepo
;
#define TSDB_GET_TABLE_BY_ID(pRepo, sid) (((STSDBRepo *)pRepo)->pTableList)[sid]
#define TSDB_GET_TABLE_BY_NAME(pRepo, name)
#define TSDB_IS_REPO_ACTIVE(pRepo) ((pRepo)->state == TSDB_REPO_STATE_ACTIVE)
#define TSDB_IS_REPO_CLOSED(pRepo) ((pRepo)->state == TSDB_REPO_STATE_CLOSED)
// Check the correctness of the TSDB configuration
static
int32_t
tsdbCheckCfg
(
STSDBCfg
*
pCfg
)
{
...
...
@@ -47,11 +57,18 @@ static int32_t tsdbCheckCfg(STSDBCfg *pCfg) {
return
0
;
}
tsdb_repo_t
*
tsdbCreateRepo
(
STSDBCfg
*
pCfg
,
int32_t
*
error
)
{
int32_t
err
=
0
;
err
=
tsdbCheckCfg
(
pCfg
);
if
(
err
!=
0
)
{
// TODO: deal with the error here
static
int32_t
tsdbCreateFiles
(
STSDBRepo
*
pRepo
)
{
// TODO
}
static
int32_t
tsdbClearFiles
(
STSDBRepo
*
pRepo
)
{
// TODO
}
tsdb_repo_t
*
tsdbCreateRepo
(
STSDBCfg
*
pCfg
)
{
// Check the configuration
if
(
tsdbCheckCfg
(
pCfg
)
<
0
)
{
return
NULL
;
}
...
...
@@ -73,74 +90,108 @@ tsdb_repo_t *tsdbCreateRepo(STSDBCfg *pCfg, int32_t *error) {
pRepo
->
pCacheHandle
=
tsdbCreateCache
(
5
);
if
(
pRepo
->
pCacheHandle
==
NULL
)
{
// TODO: free the object and return error
tsdbFreeMetaHandle
(
pRepo
->
pCacheHandle
);
free
(
pRepo
);
return
NULL
;
}
// Create the Meta data file and data directory
// Set configuration
pRepo
->
pCfg
=
pCfg
;
char
*
pTsdbMetaFName
=
tsdbGetFileName
(
pCfg
->
rootDir
,
"tsdb"
,
TSDB_FILE_TYPE_META
);
// int fd = open(pTsdbMetaFName, )
// if (open)
// Create the Meta data file and data directory
if
(
tsdbCreateFiles
(
pRepo
)
<
0
)
{
// Failed to create and save files
tsdbFreeMetaHandle
(
pRepo
->
pCacheHandle
);
free
(
pRepo
);
return
NULL
;
}
pRepo
->
state
=
TSDB_REPO_STATE_ACTIVE
;
return
(
tsdb_repo_t
*
)
pRepo
;
}
int32_t
tsdbDropRepo
(
tsdb_repo_t
*
pRepo
,
int32_t
*
error
)
{
STSDBRepo
*
pTRepo
=
(
STSDBRepo
*
)
pRepo
;
int32_t
tsdbDropRepo
(
tsdb_repo_t
*
repo
)
{
STSDBRepo
*
pRepo
=
(
STSDBRepo
*
)
repo
;
pRepo
->
state
=
TSDB_REPO_STATE_CLOSED
;
// TODO: Close the metaHandle
// Free the metaHandle
tsdbFreeMetaHandle
(
pRepo
->
pMetaHandle
);
// TODO: Close the cache
// Free the cache
tsdbFreeCache
(
pRepo
->
pCacheHandle
);
tsdbClearFiles
(
pRepo
);
return
0
;
}
tsdb_repo_t
*
tsdbOpenRepo
(
char
*
tsdbDir
,
int32_t
*
error
)
{
tsdb_repo_t
*
tsdbOpenRepo
(
char
*
tsdbDir
)
{
if
(
access
(
tsdbDir
,
F_OK
|
W_OK
|
R_OK
)
<
0
)
{
return
NULL
;
}
STSDBRepo
*
pRepo
=
(
STSDBRepo
*
)
malloc
(
sizeof
(
STSDBRepo
));
if
(
pRepo
==
NULL
)
{
return
NULL
;
}
// TODO: Initialize configuration from the file
{
// TODO: Initialize the pMetaHandle
}
pRepo
->
pMetaHandle
=
tsdbOpenMetaHandle
();
if
(
pRepo
->
pMetaHandle
==
NULL
)
{
free
(
pRepo
);
return
NULL
;
}
{
// TODO: initialize the pCacheHandle
}
pRepo
->
pCacheHandle
=
tsdbCreateCache
(
5
);
if
(
pRepo
->
pCacheHandle
==
NULL
)
{
// TODO: deal with error
return
NULL
;
}
pRepo
->
state
=
TSDB_REPO_STATE_ACTIVE
;
return
(
tsdb_repo_t
*
)
pRepo
;
}
int32_t
tsdbCloseRepo
(
tsdb_repo_t
*
pRepo
,
int32_t
*
error
)
{
STSDBRepo
*
pTRepo
=
(
STSDBRepo
*
)
pRepo
;
static
int32_t
tsdbFlushCache
(
STSDBRepo
*
pRepo
)
{
// TODO
}
int32_t
tsdbCloseRepo
(
tsdb_repo_t
*
repo
)
{
STSDBRepo
*
pRepo
=
(
STSDBRepo
*
)
repo
;
tsdbFlushCache
(
pRepo
);
pRepo
->
state
=
TSDB_REPO_STATE_CLOSED
;
tsdbFreeMetaHandle
(
pRepo
->
pMetaHandle
);
tsdbFreeCache
(
pRepo
->
pMetaHandle
);
return
0
;
}
int32_t
tsdbConfigRepo
(
STSDBCfg
*
pCfg
,
int32_t
*
error
)
{
int32_t
tsdbConfigRepo
(
tsdb_repo_t
*
repo
,
STSDBCfg
*
pCfg
)
{
STSDBRepo
*
pRepo
=
(
STSDBRepo
*
)
repo
;
pRepo
->
pCfg
=
pCfg
;
// TODO
return
0
;
}
STSDBRepoInfo
*
tsdbGetStatus
(
tsdb_repo_t
*
pRepo
,
int32_t
*
error
)
{
STSDBRepoInfo
*
tsdbGetStatus
(
tsdb_repo_t
*
pRepo
)
{
// TODO
}
int32_t
tsdbCreateTable
(
tsdb_repo_t
*
pRepo
,
STableCfg
*
pCfg
,
int32_t
*
error
)
{
// TODO
int32_t
tsdbCreateTable
(
tsdb_repo_t
*
repo
,
STableCfg
*
pCfg
)
{
STSDBRepo
*
pRepo
=
(
STSDBRepo
*
)
repo
;
return
tsdbCreateTableImpl
(
pRepo
->
pMetaHandle
,
pCfg
);
}
int32_t
tsdbAlterTable
(
tsdb_repo_t
*
pRepo
,
STableCfg
*
pCfg
,
int32_t
*
error
)
{
int32_t
tsdbAlterTable
(
tsdb_repo_t
*
pRepo
,
STableCfg
*
pCfg
)
{
// TODO
}
...
...
src/vnode/tsdb/src/tsdbCache.c
浏览文件 @
f4959b03
...
...
@@ -12,4 +12,7 @@ SCacheHandle *tsdbCreateCache(int32_t numOfBlocks) {
return
pCacheHandle
;
}
int32_t
tsdbFreeCache
(
SCacheHandle
*
pHandle
)
{
}
\ No newline at end of file
src/vnode/tsdb/src/tsdbMeta.c
浏览文件 @
f4959b03
...
...
@@ -29,9 +29,14 @@ SMetaHandle *tsdbCreateMetaHandle(int32_t numOfTables) {
return
pMetahandle
;
}
int32_t
tsdbFreeMetaHandle
(
SMetaHandle
*
pMetaHandle
)
{
// TODO
}
static
int32_t
tsdbCheckTableCfg
(
STableCfg
*
pCfg
)
{
return
0
;
}
int32_t
tsdbCreate
Meter
Impl
(
SMetaHandle
*
pHandle
,
STableCfg
*
pCfg
)
{
int32_t
tsdbCreate
Table
Impl
(
SMetaHandle
*
pHandle
,
STableCfg
*
pCfg
)
{
if
(
tsdbCheckTableCfg
(
pCfg
)
<
0
)
{
return
-
1
;
}
...
...
@@ -46,4 +51,15 @@ int32_t tsdbCreateMeterImpl(SMetaHandle *pHandle, STableCfg *pCfg) {
// TODO: add name to it
return
0
;
}
SMetaHandle
*
tsdbOpenMetaHandle
(
char
*
tsdbDir
)
{
// Open meta file for reading
SMetaHandle
*
pHandle
=
(
SMetaHandle
*
)
malloc
(
sizeof
(
SMetaHandle
));
if
(
pHandle
==
NULL
)
{
return
NULL
;
}
return
pHandle
;
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录