Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
268c6dd2
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
268c6dd2
编写于
6月 02, 2020
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-90
上级
caa9cb42
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
46 addition
and
11 deletion
+46
-11
src/tsdb/src/tsdbMeta.c
src/tsdb/src/tsdbMeta.c
+46
-11
未找到文件。
src/tsdb/src/tsdbMeta.c
浏览文件 @
268c6dd2
...
...
@@ -41,7 +41,6 @@ void tsdbEncodeTable(STable *pTable, char *buf, int *contLen) {
T_APPEND_MEMBER
(
ptr
,
&
(
pTable
->
tableId
),
STableId
,
uid
);
T_APPEND_MEMBER
(
ptr
,
&
(
pTable
->
tableId
),
STableId
,
tid
);
T_APPEND_MEMBER
(
ptr
,
pTable
,
STable
,
superUid
);
// T_APPEND_MEMBER(ptr, pTable, STable, sversion);
if
(
pTable
->
type
==
TSDB_SUPER_TABLE
)
{
ptr
=
tdEncodeSchema
(
ptr
,
pTable
->
schema
);
...
...
@@ -87,7 +86,6 @@ STable *tsdbDecodeTable(void *cont, int contLen) {
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
);
// T_READ_MEMBER(ptr, int32_t, pTable->sversion);
if
(
pTable
->
type
==
TSDB_SUPER_TABLE
)
{
pTable
->
schema
=
tdDecodeSchema
(
&
ptr
);
...
...
@@ -360,6 +358,34 @@ _err:
return
NULL
;
}
static
int
tsdbUpdateTableTagSchema
(
STable
*
pTable
,
STSchema
*
newSchema
)
{
ASSERT
(
pTable
->
type
==
TSDB_SUPER_TABLE
);
ASSERT
(
schemaVersion
(
pTable
->
tagSchema
)
<
schemaVersion
(
newSchema
));
STSchema
*
pOldSchema
=
pTable
->
tagSchema
;
STSchema
*
pNewSchema
=
tdDupSchema
(
newSchema
);
if
(
pNewSchema
==
NULL
)
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
pTable
->
tagSchema
=
pNewSchema
;
tdFreeSchema
(
pOldSchema
);
return
TSDB_CODE_SUCCESS
;
}
static
int
tsdbCheckAndUpdateTable
(
STable
*
pTable
,
STableCfg
*
pCfg
)
{
ASSERT
(
pTable
->
type
!=
TSDB_CHILD_TABLE
);
if
(
pTable
->
type
==
TSDB_SUPER_TABLE
)
{
if
(
schemaVersion
(
pTable
->
tagSchema
)
<
schemaVersion
(
pCfg
->
tagSchema
))
{
int32_t
code
=
tsdbUpdateTableTagSchema
(
pTable
,
pCfg
->
tagSchema
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
return
code
;
}
}
{
// TODO: try to update the data schema
}
return
TSDB_CODE_SUCCESS
;
}
int
tsdbCreateTable
(
TsdbRepoT
*
repo
,
STableCfg
*
pCfg
)
{
STsdbRepo
*
pRepo
=
(
STsdbRepo
*
)
repo
;
STsdbMeta
*
pMeta
=
pRepo
->
tsdbMeta
;
...
...
@@ -384,6 +410,8 @@ int tsdbCreateTable(TsdbRepoT *repo, STableCfg *pCfg) {
if
(
super
==
NULL
)
return
-
1
;
}
else
{
if
(
super
->
type
!=
TSDB_SUPER_TABLE
)
return
-
1
;
if
(
super
->
tableId
.
uid
!=
pCfg
->
superUid
)
return
-
1
;
tsdbCheckAndUpdateTable
(
super
,
pCfg
);
}
}
...
...
@@ -458,23 +486,30 @@ STableCfg *tsdbCreateTableCfgFromMsg(SMDCreateTableMsg *pMsg) {
if
(
tsdbTableSetName
(
pCfg
,
pMsg
->
tableId
,
true
)
<
0
)
goto
_err
;
if
(
numOfTags
>
0
)
{
int
accBytes
=
0
;
char
*
pTagData
=
pMsg
->
data
+
(
numOfCols
+
numOfTags
)
*
sizeof
(
SSchema
);
SKVRowBuilder
kvRowBuilder
=
{
0
};
// Decode tag schema
tdResetTSchemaBuilder
(
&
schemaBuilder
,
htonl
(
pMsg
->
tversion
));
if
(
tdInitKVRowBuilder
(
&
kvRowBuilder
)
<
0
)
goto
_err
;
for
(
int
i
=
numOfCols
;
i
<
numOfCols
+
numOfTags
;
i
++
)
{
tdAddColToSchema
(
&
schemaBuilder
,
pSchema
[
i
].
type
,
htons
(
pSchema
[
i
].
colId
),
htons
(
pSchema
[
i
].
bytes
));
tdAddColToKVRow
(
&
kvRowBuilder
,
htons
(
pSchema
[
i
].
colId
),
pSchema
[
i
].
type
,
pTagData
+
accBytes
);
accBytes
+=
htons
(
pSchema
[
i
].
bytes
);
}
if
(
tsdbTableSetTagSchema
(
pCfg
,
tdGetSchemaFromBuilder
(
&
schemaBuilder
),
false
)
<
0
)
goto
_err
;
if
(
tsdbTableSetSName
(
pCfg
,
pMsg
->
superTableId
,
true
)
<
0
)
goto
_err
;
if
(
tsdbTableSetSuperUid
(
pCfg
,
htobe64
(
pMsg
->
superTableUid
))
<
0
)
goto
_err
;
tsdbTableSetTagValue
(
pCfg
,
tdGetKVRowFromBuilder
(
&
kvRowBuilder
),
false
);
tdDestroyKVRowBuilder
(
&
kvRowBuilder
);
// Decode tag values
if
(
pMsg
->
tagDataLen
)
{
int
accBytes
=
0
;
char
*
pTagData
=
pMsg
->
data
+
(
numOfCols
+
numOfTags
)
*
sizeof
(
SSchema
);
SKVRowBuilder
kvRowBuilder
=
{
0
};
if
(
tdInitKVRowBuilder
(
&
kvRowBuilder
)
<
0
)
goto
_err
;
for
(
int
i
=
numOfCols
;
i
<
numOfCols
+
numOfTags
;
i
++
)
{
tdAddColToKVRow
(
&
kvRowBuilder
,
htons
(
pSchema
[
i
].
colId
),
pSchema
[
i
].
type
,
pTagData
+
accBytes
);
accBytes
+=
htons
(
pSchema
[
i
].
bytes
);
}
tsdbTableSetTagValue
(
pCfg
,
tdGetKVRowFromBuilder
(
&
kvRowBuilder
),
false
);
tdDestroyKVRowBuilder
(
&
kvRowBuilder
);
}
}
if
(
pMsg
->
tableType
==
TSDB_STREAM_TABLE
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录