Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
1c245904
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看板
未验证
提交
1c245904
编写于
10月 17, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
10月 17, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #17406 from taosdata/feature/stream
refactor(stream): optimize auto create child table
上级
98f1c3d8
77c4c8fd
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
110 addition
and
72 deletion
+110
-72
source/dnode/vnode/src/tq/tqSink.c
source/dnode/vnode/src/tq/tqSink.c
+108
-70
tests/system-test/7-tmq/tmqAutoCreateTbl.py
tests/system-test/7-tmq/tmqAutoCreateTbl.py
+2
-2
未找到文件。
source/dnode/vnode/src/tq/tqSink.c
浏览文件 @
1c245904
...
...
@@ -293,7 +293,6 @@ void tqTableSink1(SStreamTask* pTask, void* vnode, int64_t ver, void* data) {
SSchemaWrapper
*
pSchemaWrapper
=
pTask
->
tbSink
.
pSchemaWrapper
;
int32_t
blockSz
=
taosArrayGetSize
(
pBlocks
);
bool
createTb
=
true
;
SArray
*
tagArray
=
taosArrayInit
(
1
,
sizeof
(
STagVal
));
if
(
!
tagArray
)
{
...
...
@@ -303,6 +302,7 @@ void tqTableSink1(SStreamTask* pTask, void* vnode, int64_t ver, void* data) {
tqDebug
(
"vgId:%d, task %d write into table, block num: %d"
,
TD_VID
(
pVnode
),
pTask
->
taskId
,
blockSz
);
for
(
int32_t
i
=
0
;
i
<
blockSz
;
i
++
)
{
bool
createTb
=
true
;
SSDataBlock
*
pDataBlock
=
taosArrayGet
(
pBlocks
,
i
);
if
(
pDataBlock
->
info
.
type
==
STREAM_DELETE_RESULT
)
{
SBatchDeleteReq
deleteReq
=
{
0
};
...
...
@@ -337,83 +337,119 @@ void tqTableSink1(SStreamTask* pTask, void* vnode, int64_t ver, void* data) {
tqDebug
(
"failed to put delete req into write-queue since %s"
,
terrstr
());
}
}
else
{
SVCreateTbReq
createTbReq
=
{
0
};
// set const
createTbReq
.
flags
=
0
;
createTbReq
.
type
=
TSDB_CHILD_TABLE
;
createTbReq
.
ctb
.
suid
=
suid
;
char
*
ctbName
=
NULL
;
// set child table name
if
(
pDataBlock
->
info
.
parTbName
[
0
])
{
ctbName
=
strdup
(
pDataBlock
->
info
.
parTbName
);
}
else
{
ctbName
=
buildCtbNameByGroupId
(
stbFullName
,
pDataBlock
->
info
.
groupId
);
}
// set super table name
SName
name
=
{
0
};
tNameFromString
(
&
name
,
stbFullName
,
T_NAME_ACCT
|
T_NAME_DB
|
T_NAME_TABLE
);
createTbReq
.
ctb
.
stbName
=
strdup
((
char
*
)
tNameGetTableName
(
&
name
));
// strdup(stbFullName);
int32_t
schemaLen
=
0
;
void
*
schemaStr
=
NULL
;
int64_t
uid
=
0
;
SMetaReader
mr
=
{
0
};
metaReaderInit
(
&
mr
,
pVnode
->
pMeta
,
0
);
if
(
metaGetTableEntryByName
(
&
mr
,
ctbName
)
<
0
)
{
metaReaderClear
(
&
mr
);
tqDebug
(
"vgId:%d, stream write into %s, table auto created"
,
TD_VID
(
pVnode
),
ctbName
);
SVCreateTbReq
createTbReq
=
{
0
};
// set const
createTbReq
.
flags
=
0
;
createTbReq
.
type
=
TSDB_CHILD_TABLE
;
createTbReq
.
ctb
.
suid
=
suid
;
// set super table name
SName
name
=
{
0
};
tNameFromString
(
&
name
,
stbFullName
,
T_NAME_ACCT
|
T_NAME_DB
|
T_NAME_TABLE
);
createTbReq
.
ctb
.
stbName
=
strdup
((
char
*
)
tNameGetTableName
(
&
name
));
// strdup(stbFullName);
createTbReq
.
name
=
ctbName
;
ctbName
=
NULL
;
// set tag content
taosArrayClear
(
tagArray
);
STagVal
tagVal
=
{
.
cid
=
taosArrayGetSize
(
pDataBlock
->
pDataBlock
)
+
1
,
.
type
=
TSDB_DATA_TYPE_UBIGINT
,
.
i64
=
(
int64_t
)
pDataBlock
->
info
.
groupId
,
};
taosArrayPush
(
tagArray
,
&
tagVal
);
createTbReq
.
ctb
.
tagNum
=
taosArrayGetSize
(
tagArray
);
STag
*
pTag
=
NULL
;
tTagNew
(
tagArray
,
1
,
false
,
&
pTag
);
if
(
pTag
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
taosArrayDestroy
(
tagArray
);
tdDestroySVCreateTbReq
(
&
createTbReq
);
return
;
}
createTbReq
.
ctb
.
pTag
=
(
uint8_t
*
)
pTag
;
// set tag name
SArray
*
tagName
=
taosArrayInit
(
1
,
TSDB_COL_NAME_LEN
);
char
tagNameStr
[
TSDB_COL_NAME_LEN
]
=
{
0
};
strcpy
(
tagNameStr
,
"group_id"
);
taosArrayPush
(
tagName
,
tagNameStr
);
createTbReq
.
ctb
.
tagName
=
tagName
;
int32_t
code
;
tEncodeSize
(
tEncodeSVCreateTbReq
,
&
createTbReq
,
schemaLen
,
code
);
if
(
code
<
0
)
{
tdDestroySVCreateTbReq
(
&
createTbReq
);
taosArrayDestroy
(
tagArray
);
return
;
}
// set tag content
taosArrayClear
(
tagArray
);
STagVal
tagVal
=
{
.
cid
=
taosArrayGetSize
(
pDataBlock
->
pDataBlock
)
+
1
,
.
type
=
TSDB_DATA_TYPE_UBIGINT
,
.
i64
=
(
int64_t
)
pDataBlock
->
info
.
groupId
,
};
taosArrayPush
(
tagArray
,
&
tagVal
);
createTbReq
.
ctb
.
tagNum
=
taosArrayGetSize
(
tagArray
);
// set schema str
schemaStr
=
taosMemoryMalloc
(
schemaLen
);
if
(
schemaStr
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
tdDestroySVCreateTbReq
(
&
createTbReq
);
taosArrayDestroy
(
tagArray
);
return
;
}
STag
*
pTag
=
NULL
;
tTagNew
(
tagArray
,
1
,
false
,
&
pTag
);
if
(
pTag
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
taosArrayDestroy
(
tagArray
);
SEncoder
encoder
=
{
0
};
tEncoderInit
(
&
encoder
,
schemaStr
,
schemaLen
);
code
=
tEncodeSVCreateTbReq
(
&
encoder
,
&
createTbReq
);
if
(
code
<
0
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
tdDestroySVCreateTbReq
(
&
createTbReq
);
taosArrayDestroy
(
tagArray
);
tEncoderClear
(
&
encoder
);
taosMemoryFree
(
schemaStr
);
return
;
}
tEncoderClear
(
&
encoder
);
tdDestroySVCreateTbReq
(
&
createTbReq
);
return
;
}
createTbReq
.
ctb
.
pTag
=
(
uint8_t
*
)
pTag
;
// set tag name
SArray
*
tagName
=
taosArrayInit
(
1
,
TSDB_COL_NAME_LEN
);
char
tagNameStr
[
TSDB_COL_NAME_LEN
]
=
{
0
};
strcpy
(
tagNameStr
,
"group_id"
);
taosArrayPush
(
tagName
,
tagNameStr
);
createTbReq
.
ctb
.
tagName
=
tagName
;
// set table name
if
(
pDataBlock
->
info
.
parTbName
[
0
])
{
createTbReq
.
name
=
strdup
(
pDataBlock
->
info
.
parTbName
);
}
else
{
createTbReq
.
name
=
buildCtbNameByGroupId
(
stbFullName
,
pDataBlock
->
info
.
groupId
);
}
if
(
mr
.
me
.
type
!=
TSDB_CHILD_TABLE
)
{
tqError
(
"vgId:%d, failed to write into %s, since table type incorrect, type %d"
,
TD_VID
(
pVnode
),
ctbName
,
mr
.
me
.
type
);
metaReaderClear
(
&
mr
);
taosMemoryFree
(
ctbName
);
continue
;
}
if
(
mr
.
me
.
ctbEntry
.
suid
!=
suid
)
{
tqError
(
"vgId:%d, failed to write into %s, since suid mismatch, expect suid: %ld, actual suid %ld"
,
TD_VID
(
pVnode
),
ctbName
,
suid
,
mr
.
me
.
ctbEntry
);
metaReaderClear
(
&
mr
);
taosMemoryFree
(
ctbName
);
continue
;
}
int32_t
schemaLen
;
int32_t
code
;
tEncodeSize
(
tEncodeSVCreateTbReq
,
&
createTbReq
,
schemaLen
,
code
);
if
(
code
<
0
)
{
tdDestroySVCreateTbReq
(
&
createTbReq
);
taosArrayDestroy
(
tagArray
);
return
;
}
createTb
=
false
;
uid
=
mr
.
me
.
uid
;
metaReaderClear
(
&
mr
);
// save schema str
void
*
schemaStr
=
taosMemoryMalloc
(
schemaLen
);
if
(
schemaStr
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
tdDestroySVCreateTbReq
(
&
createTbReq
);
taosArrayDestroy
(
tagArray
);
return
;
}
tqDebug
(
"vgId:%d, stream write, table %s, uid %ld already exist, skip create"
,
TD_VID
(
pVnode
),
ctbName
,
uid
);
SEncoder
encoder
=
{
0
};
tEncoderInit
(
&
encoder
,
schemaStr
,
schemaLen
);
code
=
tEncodeSVCreateTbReq
(
&
encoder
,
&
createTbReq
);
if
(
code
<
0
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
tdDestroySVCreateTbReq
(
&
createTbReq
);
taosArrayDestroy
(
tagArray
);
tEncoderClear
(
&
encoder
);
taosMemoryFree
(
schemaStr
);
return
;
taosMemoryFreeClear
(
ctbName
);
}
tEncoderClear
(
&
encoder
);
tdDestroySVCreateTbReq
(
&
createTbReq
);
int32_t
cap
=
sizeof
(
SSubmitReq
);
...
...
@@ -445,9 +481,11 @@ void tqTableSink1(SStreamTask* pTask, void* vnode, int64_t ver, void* data) {
memcpy
(
blkSchema
,
schemaStr
,
schemaLen
);
blkHead
->
schemaLen
=
htonl
(
schemaLen
);
rowData
=
POINTER_SHIFT
(
blkSchema
,
schemaLen
);
}
else
{
blkHead
->
uid
=
htobe64
(
uid
);
}
taosMemoryFree
(
schemaStr
);
taosMemoryFree
Clear
(
schemaStr
);
for
(
int32_t
j
=
0
;
j
<
rows
;
j
++
)
{
SRowBuilder
rb
=
{
0
};
...
...
tests/system-test/7-tmq/tmqAutoCreateTbl.py
浏览文件 @
1c245904
...
...
@@ -42,7 +42,7 @@ class TDTestCase:
'rowsPerTbl'
:
1000
,
'batchNum'
:
500
,
'startTs'
:
1640966400000
,
# 2022-01-01 00:00:00.000
'pollDelay'
:
3
,
'pollDelay'
:
20
,
'showMsg'
:
1
,
'showRow'
:
1
,
'snapshot'
:
0
}
...
...
@@ -87,7 +87,7 @@ class TDTestCase:
'rowsPerTbl'
:
1000
,
'batchNum'
:
500
,
'startTs'
:
1640966400000
,
# 2022-01-01 00:00:00.000
'pollDelay'
:
5
,
'pollDelay'
:
20
,
'showMsg'
:
1
,
'showRow'
:
1
,
'snapshot'
:
0
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录