Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f81120e3
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看板
提交
f81120e3
编写于
6月 03, 2020
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-90
上级
4de11d83
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
51 addition
and
23 deletion
+51
-23
src/tsdb/inc/tsdbMain.h
src/tsdb/inc/tsdbMain.h
+3
-1
src/tsdb/src/tsdbMeta.c
src/tsdb/src/tsdbMeta.c
+48
-22
未找到文件。
src/tsdb/inc/tsdbMain.h
浏览文件 @
f81120e3
...
...
@@ -69,11 +69,13 @@ typedef struct {
}
SMemTable
;
// ---------- TSDB TABLE DEFINITION
#define TSDB_MAX_TABLE_SCHEMAS 16
typedef
struct
STable
{
int8_t
type
;
STableId
tableId
;
uint64_t
superUid
;
// Super table UID
STSchema
*
schema
;
int16_t
numOfSchemas
;
STSchema
**
schema
;
STSchema
*
tagSchema
;
SKVRow
tagVal
;
SMemTable
*
mem
;
...
...
src/tsdb/src/tsdbMeta.c
浏览文件 @
f81120e3
...
...
@@ -37,18 +37,24 @@ void tsdbEncodeTable(STable *pTable, char *buf, int *contLen) {
ptr
=
(
char
*
)
ptr
+
sizeof
(
int
);
memcpy
(
ptr
,
varDataVal
(
pTable
->
name
),
varDataLen
(
pTable
->
name
));
ptr
=
(
char
*
)
ptr
+
varDataLen
(
pTable
->
name
);
T_APPEND_MEMBER
(
ptr
,
&
(
pTable
->
tableId
),
STableId
,
uid
);
T_APPEND_MEMBER
(
ptr
,
&
(
pTable
->
tableId
),
STableId
,
tid
);
T_APPEND_MEMBER
(
ptr
,
pTable
,
STable
,
superUid
);
if
(
pTable
->
type
==
TSDB_SUPER_TABLE
)
{
ptr
=
tdEncodeSchema
(
ptr
,
pTable
->
schema
);
T_APPEND_MEMBER
(
ptr
,
pTable
,
STable
,
numOfSchemas
);
for
(
int
i
=
0
;
i
<
pTable
->
numOfSchemas
;
i
++
)
{
ptr
=
tdEncodeSchema
(
ptr
,
pTable
->
schema
[
i
]);
}
ptr
=
tdEncodeSchema
(
ptr
,
pTable
->
tagSchema
);
}
else
if
(
pTable
->
type
==
TSDB_CHILD_TABLE
)
{
ptr
=
tdEncodeKVRow
(
ptr
,
pTable
->
tagVal
);
}
else
{
ptr
=
tdEncodeSchema
(
ptr
,
pTable
->
schema
);
T_APPEND_MEMBER
(
ptr
,
pTable
,
STable
,
numOfSchemas
);
for
(
int
i
=
0
;
i
<
pTable
->
numOfSchemas
;
i
++
)
{
ptr
=
tdEncodeSchema
(
ptr
,
pTable
->
schema
[
i
]);
}
}
if
(
pTable
->
type
==
TSDB_STREAM_TABLE
)
{
...
...
@@ -71,6 +77,11 @@ void tsdbEncodeTable(STable *pTable, char *buf, int *contLen) {
STable
*
tsdbDecodeTable
(
void
*
cont
,
int
contLen
)
{
STable
*
pTable
=
(
STable
*
)
calloc
(
1
,
sizeof
(
STable
));
if
(
pTable
==
NULL
)
return
NULL
;
pTable
->
schema
=
(
STSchema
**
)
malloc
(
sizeof
(
STSchema
*
)
*
TSDB_MAX_TABLE_SCHEMAS
);
if
(
pTable
->
schema
==
NULL
)
{
free
(
pTable
);
return
NULL
;
}
void
*
ptr
=
cont
;
T_READ_MEMBER
(
ptr
,
int8_t
,
pTable
->
type
);
...
...
@@ -78,28 +89,34 @@ STable *tsdbDecodeTable(void *cont, int contLen) {
ptr
=
(
char
*
)
ptr
+
sizeof
(
int
);
pTable
->
name
=
calloc
(
1
,
len
+
VARSTR_HEADER_SIZE
+
1
);
if
(
pTable
->
name
==
NULL
)
return
NULL
;
varDataSetLen
(
pTable
->
name
,
len
);
memcpy
(
pTable
->
name
->
data
,
ptr
,
len
);
ptr
=
(
char
*
)
ptr
+
len
;
T_READ_MEMBER
(
ptr
,
uint64_t
,
pTable
->
tableId
.
uid
);
T_READ_MEMBER
(
ptr
,
int32_t
,
pTable
->
tableId
.
tid
);
T_READ_MEMBER
(
ptr
,
uint64_t
,
pTable
->
superUid
);
if
(
pTable
->
type
==
TSDB_SUPER_TABLE
)
{
pTable
->
schema
=
tdDecodeSchema
(
&
ptr
);
T_READ_MEMBER
(
ptr
,
int16_t
,
pTable
->
numOfSchemas
);
for
(
int
i
=
0
;
i
<
pTable
->
numOfSchemas
;
i
++
)
{
pTable
->
schema
[
i
]
=
tdDecodeSchema
(
&
ptr
);
}
pTable
->
tagSchema
=
tdDecodeSchema
(
&
ptr
);
}
else
if
(
pTable
->
type
==
TSDB_CHILD_TABLE
)
{
ptr
=
tdDecodeKVRow
(
ptr
,
&
pTable
->
tagVal
);
}
else
{
pTable
->
schema
=
tdDecodeSchema
(
&
ptr
);
T_READ_MEMBER
(
ptr
,
int16_t
,
pTable
->
numOfSchemas
);
for
(
int
i
=
0
;
i
<
pTable
->
numOfSchemas
;
i
++
)
{
pTable
->
schema
[
i
]
=
tdDecodeSchema
(
&
ptr
);
}
}
if
(
pTable
->
type
==
TSDB_STREAM_TABLE
)
{
ptr
=
taosDecodeString
(
ptr
,
&
(
pTable
->
sql
));
}
pTable
->
lastKey
=
TSKEY_INITIAL_VAL
;
return
pTable
;
}
...
...
@@ -221,13 +238,14 @@ int32_t tsdbFreeMeta(STsdbMeta *pMeta) {
return
0
;
}
// Get the newest table schema
STSchema
*
tsdbGetTableSchema
(
STsdbMeta
*
pMeta
,
STable
*
pTable
)
{
if
(
pTable
->
type
==
TSDB_NORMAL_TABLE
||
pTable
->
type
==
TSDB_SUPER_TABLE
||
pTable
->
type
==
TSDB_STREAM_TABLE
)
{
return
pTable
->
schema
;
return
pTable
->
schema
[
pTable
->
numOfSchemas
-
1
]
;
}
else
if
(
pTable
->
type
==
TSDB_CHILD_TABLE
)
{
STable
*
pSuper
=
tsdbGetTableByUid
(
pMeta
,
pTable
->
superUid
);
if
(
pSuper
==
NULL
)
return
NULL
;
return
pSuper
->
schema
;
return
pSuper
->
schema
[
pSuper
->
numOfSchemas
-
1
]
;
}
else
{
return
NULL
;
}
...
...
@@ -299,13 +317,16 @@ static STable *tsdbNewTable(STableCfg *pCfg, bool isSuper) {
}
pTable
->
type
=
pCfg
->
type
;
pTable
->
numOfSchemas
=
0
;
if
(
isSuper
)
{
pTable
->
type
=
TSDB_SUPER_TABLE
;
pTable
->
tableId
.
uid
=
pCfg
->
superUid
;
pTable
->
tableId
.
tid
=
-
1
;
pTable
->
superUid
=
TSDB_INVALID_SUPER_TABLE_ID
;
pTable
->
schema
=
tdDupSchema
(
pCfg
->
schema
);
pTable
->
schema
=
(
STSchema
**
)
malloc
(
sizeof
(
STSchema
*
)
*
TSDB_MAX_TABLE_SCHEMAS
);
pTable
->
numOfSchemas
=
1
;
pTable
->
schema
[
0
]
=
tdDupSchema
(
pCfg
->
schema
);
pTable
->
tagSchema
=
tdDupSchema
(
pCfg
->
tagSchema
);
tsize
=
strnlen
(
pCfg
->
sname
,
TSDB_TABLE_NAME_LEN
);
...
...
@@ -340,14 +361,18 @@ static STable *tsdbNewTable(STableCfg *pCfg, bool isSuper) {
if
(
pCfg
->
type
==
TSDB_CHILD_TABLE
)
{
pTable
->
superUid
=
pCfg
->
superUid
;
pTable
->
tagVal
=
tdKVRowDup
(
pCfg
->
tagValues
);
}
else
if
(
pCfg
->
type
==
TSDB_NORMAL_TABLE
)
{
pTable
->
superUid
=
-
1
;
pTable
->
schema
=
tdDupSchema
(
pCfg
->
schema
);
}
else
{
ASSERT
(
pCfg
->
type
==
TSDB_STREAM_TABLE
);
pTable
->
superUid
=
-
1
;
pTable
->
schema
=
tdDupSchema
(
pCfg
->
schema
);
pTable
->
sql
=
strdup
(
pCfg
->
sql
);
pTable
->
schema
=
(
STSchema
**
)
malloc
(
sizeof
(
STSchema
*
)
*
TSDB_MAX_TABLE_SCHEMAS
);
pTable
->
numOfSchemas
=
1
;
pTable
->
schema
[
0
]
=
tdDupSchema
(
pCfg
->
schema
);
if
(
pCfg
->
type
==
TSDB_NORMAL_TABLE
)
{
pTable
->
superUid
=
-
1
;
}
else
{
ASSERT
(
pCfg
->
type
==
TSDB_STREAM_TABLE
);
pTable
->
superUid
=
-
1
;
pTable
->
sql
=
strdup
(
pCfg
->
sql
);
}
}
}
...
...
@@ -580,7 +605,7 @@ static int tsdbFreeTable(STable *pTable) {
if
(
pTable
->
type
==
TSDB_CHILD_TABLE
)
{
kvRowFree
(
pTable
->
tagVal
);
}
else
{
tdFreeSchema
(
pTable
->
schema
);
for
(
int
i
=
0
;
i
<
pTable
->
numOfSchemas
;
i
++
)
tdFreeSchema
(
pTable
->
schema
[
i
]
);
}
if
(
pTable
->
type
==
TSDB_STREAM_TABLE
)
{
...
...
@@ -642,9 +667,10 @@ static int tsdbAddTableToMeta(STsdbMeta *pMeta, STable *pTable, bool addIdx) {
}
// Update the pMeta->maxCols and pMeta->maxRowBytes
if
(
pTable
->
type
==
TSDB_SUPER_TABLE
||
pTable
->
type
==
TSDB_NORMAL_TABLE
)
{
if
(
schemaNCols
(
pTable
->
schema
)
>
pMeta
->
maxCols
)
pMeta
->
maxCols
=
schemaNCols
(
pTable
->
schema
);
int
bytes
=
dataRowMaxBytesFromSchema
(
pTable
->
schema
);
if
(
pTable
->
type
==
TSDB_SUPER_TABLE
||
pTable
->
type
==
TSDB_NORMAL_TABLE
||
pTable
->
type
==
TSDB_STREAM_TABLE
)
{
if
(
schemaNCols
(
pTable
->
schema
[
pTable
->
numOfSchemas
-
1
])
>
pMeta
->
maxCols
)
pMeta
->
maxCols
=
schemaNCols
(
pTable
->
schema
[
pTable
->
numOfSchemas
-
1
]);
int
bytes
=
dataRowMaxBytesFromSchema
(
pTable
->
schema
[
pTable
->
numOfSchemas
-
1
]);
if
(
bytes
>
pMeta
->
maxRowBytes
)
pMeta
->
maxRowBytes
=
bytes
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录