Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c80686b9
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看板
提交
c80686b9
编写于
3月 12, 2020
作者:
H
hzcheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add more and refactor
上级
a3f5bec0
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
53 addition
and
51 deletion
+53
-51
src/vnode/tsdb/inc/tsdbMeta.h
src/vnode/tsdb/inc/tsdbMeta.h
+16
-12
src/vnode/tsdb/inc/tsdbMetaFile.h
src/vnode/tsdb/inc/tsdbMetaFile.h
+1
-2
src/vnode/tsdb/src/tsdbMain.c
src/vnode/tsdb/src/tsdbMain.c
+8
-10
src/vnode/tsdb/src/tsdbMeta.c
src/vnode/tsdb/src/tsdbMeta.c
+27
-26
src/vnode/tsdb/src/tsdbMetaFile.c
src/vnode/tsdb/src/tsdbMetaFile.c
+1
-1
未找到文件。
src/vnode/tsdb/inc/tsdbMeta.h
浏览文件 @
c80686b9
...
...
@@ -20,6 +20,7 @@
#include "tsdb.h"
#include "dataformat.h"
#include "tskiplist.h"
#include "tsdbMetaFile.h"
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -78,14 +79,24 @@ typedef struct STable {
}
STable
;
// ---------- TSDB META HANDLE DEFINITION
typedef
struct
{
int32_t
maxTables
;
int32_t
nTables
;
STable
**
tables
;
// array of normal tables
STable
*
stables
;
// linked list of super tables // TODO use container to implement this
void
*
tableMap
;
// hash map of uid ==> STable *
int32_t
maxTables
;
// Max number of tables
int32_t
nTables
;
// Tables created
STable
**
tables
;
// table array
STable
*
superList
;
// super table list TODO: change it to list container
void
*
map
;
// table map of (uid ===> table)
SMetaFile
*
mfh
;
// meta file handle
}
STsdbMeta
;
STsdbMeta
*
tsdbInitMeta
(
const
char
*
rootDir
,
int32_t
maxTables
);
int32_t
tsdbFreeMeta
(
STsdbMeta
*
pMeta
);
// ---- Operation on STable
#define TSDB_TABLE_ID(pTable) ((pTable)->tableId)
#define TSDB_TABLE_UID(pTable) ((pTable)->uid)
...
...
@@ -105,13 +116,6 @@ STSchema *tsdbGetTableSchema(STable *pTable);
#define TSDB_TABLE_OF_ID(pHandle, id) ((pHandle)->pTables)[id]
#define TSDB_GET_TABLE_OF_NAME(pHandle, name)
/* TODO */
// Create a new meta handle with configuration
STsdbMeta
*
tsdbInitMeta
(
int32_t
maxTables
);
int32_t
tsdbFreeMeta
(
STsdbMeta
*
pMeta
);
// Recover the meta handle from the file
STsdbMeta
*
tsdbOpenMeta
(
char
*
tsdbDir
);
int32_t
tsdbCreateTableImpl
(
STsdbMeta
*
pMeta
,
STableCfg
*
pCfg
);
int32_t
tsdbDropTableImpl
(
STsdbMeta
*
pMeta
,
STableId
tableId
);
STable
*
tsdbIsValidTableToInsert
(
STsdbMeta
*
pMeta
,
STableId
tableId
);
...
...
src/vnode/tsdb/inc/tsdbMetaFile.h
浏览文件 @
c80686b9
...
...
@@ -18,13 +18,12 @@
#include <stdint.h>
#include "tsdbMeta.h"
#ifdef __cplusplus
extern
"C"
{
#endif
#define TSDB_META_FILE_NAME "META"
#define TSDB_META_HASH_FRACTION 1.1
typedef
struct
{
int
fd
;
// File descriptor
...
...
src/vnode/tsdb/src/tsdbMain.c
浏览文件 @
c80686b9
...
...
@@ -145,8 +145,15 @@ tsdb_repo_t *tsdbCreateRepo(char *rootDir, STsdbCfg *pCfg, void *limiter /* TODO
pRepo
->
config
=
*
pCfg
;
pRepo
->
limiter
=
limiter
;
// Create the environment files and directories
if
(
tsdbSetRepoEnv
(
pRepo
)
<
0
)
{
free
(
pRepo
->
rootDir
);
free
(
pRepo
);
return
NULL
;
}
// Initialize meta
STsdbMeta
*
pMeta
=
tsdbInitMeta
(
pCfg
->
maxTables
);
STsdbMeta
*
pMeta
=
tsdbInitMeta
(
rootDir
,
pCfg
->
maxTables
);
if
(
pMeta
==
NULL
)
{
free
(
pRepo
->
rootDir
);
free
(
pRepo
);
...
...
@@ -164,15 +171,6 @@ tsdb_repo_t *tsdbCreateRepo(char *rootDir, STsdbCfg *pCfg, void *limiter /* TODO
}
pRepo
->
tsdbCache
=
pCache
;
// Create the environment files and directories
if
(
tsdbSetRepoEnv
(
pRepo
)
<
0
)
{
free
(
pRepo
->
rootDir
);
tsdbFreeMeta
(
pRepo
->
tsdbMeta
);
tsdbFreeCache
(
pRepo
->
tsdbCache
);
free
(
pRepo
);
return
NULL
;
}
pRepo
->
state
=
TSDB_REPO_STATE_ACTIVE
;
return
(
tsdb_repo_t
*
)
pRepo
;
...
...
src/vnode/tsdb/src/tsdbMeta.c
浏览文件 @
c80686b9
...
...
@@ -18,23 +18,33 @@ static int tsdbAddTableIntoMap(STsdbMeta *pMeta, STable *pTable);
static
int
tsdbAddTableIntoIndex
(
STsdbMeta
*
pMeta
,
STable
*
pTable
);
static
int
tsdbRemoveTableFromIndex
(
STsdbMeta
*
pMeta
,
STable
*
pTable
);
STsdbMeta
*
tsdbInitMeta
(
int32_t
maxTables
)
{
/**
* Initialize the meta handle
* ASSUMPTIONS: VALID PARAMETER
*/
STsdbMeta
*
tsdbInitMeta
(
const
char
*
rootDir
,
int32_t
maxTables
)
{
STsdbMeta
*
pMeta
=
(
STsdbMeta
*
)
malloc
(
sizeof
(
STsdbMeta
));
if
(
pMeta
==
NULL
)
{
return
NULL
;
}
if
(
pMeta
==
NULL
)
return
NULL
;
pMeta
->
maxTables
=
maxTables
;
pMeta
->
nTables
=
0
;
pMeta
->
s
tables
=
NULL
;
pMeta
->
s
uperList
=
NULL
;
pMeta
->
tables
=
(
STable
**
)
calloc
(
maxTables
,
sizeof
(
STable
*
));
if
(
pMeta
->
tables
==
NULL
)
{
free
(
pMeta
);
return
NULL
;
}
pMeta
->
tableMap
=
taosInitHashTable
(
maxTables
+
maxTables
/
10
,
taosGetDefaultHashFunction
,
false
);
if
(
pMeta
->
tableMap
==
NULL
)
{
pMeta
->
map
=
taosInitHashTable
(
maxTables
*
TSDB_META_HASH_FRACTION
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
false
);
if
(
pMeta
->
map
==
NULL
)
{
free
(
pMeta
->
tables
);
free
(
pMeta
);
return
NULL
;
}
pMeta
->
mfh
=
tsdbInitMetaFile
(
rootDir
,
maxTables
);
if
(
pMeta
->
mfh
==
NULL
)
{
taosCleanUpHashTable
(
pMeta
->
map
);
free
(
pMeta
->
tables
);
free
(
pMeta
);
return
NULL
;
...
...
@@ -46,6 +56,8 @@ STsdbMeta *tsdbInitMeta(int32_t maxTables) {
int32_t
tsdbFreeMeta
(
STsdbMeta
*
pMeta
)
{
if
(
pMeta
==
NULL
)
return
0
;
tsdbCloseMetaFile
(
pMeta
->
mfh
);
for
(
int
i
=
0
;
i
<
pMeta
->
maxTables
;
i
++
)
{
if
(
pMeta
->
tables
[
i
]
!=
NULL
)
{
tsdbFreeTable
(
pMeta
->
tables
[
i
]);
...
...
@@ -54,14 +66,14 @@ int32_t tsdbFreeMeta(STsdbMeta *pMeta) {
free
(
pMeta
->
tables
);
STable
*
pTable
=
pMeta
->
s
tables
;
STable
*
pTable
=
pMeta
->
s
uperList
;
while
(
pTable
!=
NULL
)
{
STable
*
pTemp
=
pTable
;
pTable
=
pTemp
->
next
;
tsdbFreeTable
(
pTemp
);
}
taosCleanUpHashTable
(
pMeta
->
tableM
ap
);
taosCleanUpHashTable
(
pMeta
->
m
ap
);
free
(
pMeta
);
...
...
@@ -126,17 +138,6 @@ int32_t tsdbCreateTableImpl(STsdbMeta *pMeta, STableCfg *pCfg) {
return
0
;
}
STsdbMeta
*
tsdbOpenMeta
(
char
*
tsdbDir
)
{
// TODO : Open meta file for reading
STsdbMeta
*
pMeta
=
(
STsdbMeta
*
)
malloc
(
sizeof
(
STsdbMeta
));
if
(
pMeta
==
NULL
)
{
return
NULL
;
}
return
pMeta
;
}
/**
* Check if a table is valid to insert.
* @return NULL for invalid and the pointer to the table if valid
...
...
@@ -206,7 +207,7 @@ static int32_t tsdbCheckTableCfg(STableCfg *pCfg) {
}
STable
*
tsdbGetTableByUid
(
STsdbMeta
*
pMeta
,
int64_t
uid
)
{
void
*
ptr
=
taosGetDataFromHashTable
(
pMeta
->
tableM
ap
,
(
char
*
)(
&
uid
),
sizeof
(
uid
));
void
*
ptr
=
taosGetDataFromHashTable
(
pMeta
->
m
ap
,
(
char
*
)(
&
uid
),
sizeof
(
uid
));
if
(
ptr
==
NULL
)
return
NULL
;
...
...
@@ -216,12 +217,12 @@ STable *tsdbGetTableByUid(STsdbMeta *pMeta, int64_t uid) {
static
int
tsdbAddTableToMeta
(
STsdbMeta
*
pMeta
,
STable
*
pTable
)
{
if
(
pTable
->
type
==
TSDB_SUPER_TABLE
)
{
// add super table to the linked list
if
(
pMeta
->
s
tables
==
NULL
)
{
pMeta
->
s
tables
=
pTable
;
if
(
pMeta
->
s
uperList
==
NULL
)
{
pMeta
->
s
uperList
=
pTable
;
pTable
->
next
=
NULL
;
}
else
{
STable
*
pTemp
=
pMeta
->
s
tables
;
pMeta
->
s
tables
=
pTable
;
STable
*
pTemp
=
pMeta
->
s
uperList
;
pMeta
->
s
uperList
=
pTable
;
pTable
->
next
=
pTemp
;
}
}
else
{
...
...
@@ -245,7 +246,7 @@ static int tsdbRemoveTableFromMeta(STsdbMeta *pMeta, STable *pTable) {
static
int
tsdbAddTableIntoMap
(
STsdbMeta
*
pMeta
,
STable
*
pTable
)
{
// TODO: add the table to the map
int64_t
uid
=
pTable
->
tableId
.
uid
;
if
(
taosAddToHashTable
(
pMeta
->
tableM
ap
,
(
char
*
)(
&
uid
),
sizeof
(
uid
),
(
void
*
)(
&
pTable
),
sizeof
(
pTable
))
<
0
)
{
if
(
taosAddToHashTable
(
pMeta
->
m
ap
,
(
char
*
)(
&
uid
),
sizeof
(
uid
),
(
void
*
)(
&
pTable
),
sizeof
(
pTable
))
<
0
)
{
return
-
1
;
}
return
0
;
...
...
src/vnode/tsdb/src/tsdbMetaFile.c
浏览文件 @
c80686b9
...
...
@@ -15,11 +15,11 @@
#include <stdlib.h>
#include <unistd.h>
#include "taosdef.h"
#include "hash.h"
#include "tsdbMetaFile.h"
#define TSDB_META_FILE_HEADER_SIZE 512
#define TSDB_META_HASH_FRACTION 1.1
typedef
struct
{
int32_t
offset
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录