Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c89ada70
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看板
未验证
提交
c89ada70
编写于
3月 26, 2021
作者:
sangshuduo
提交者:
GitHub
3月 26, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-3524] <fix>: taosdemo query multithreading workaround. (#5587)
Co-authored-by:
N
Shuduo Sang
<
sdsang@taosdata.com
>
上级
ccbb062c
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
105 addition
and
29 deletion
+105
-29
src/kit/taosdemo/taosdemo.c
src/kit/taosdemo/taosdemo.c
+105
-29
未找到文件。
src/kit/taosdemo/taosdemo.c
浏览文件 @
c89ada70
...
@@ -5418,6 +5418,22 @@ static int insertTestProcess() {
...
@@ -5418,6 +5418,22 @@ static int insertTestProcess() {
static
void
*
superQueryProcess
(
void
*
sarg
)
{
static
void
*
superQueryProcess
(
void
*
sarg
)
{
threadInfo
*
winfo
=
(
threadInfo
*
)
sarg
;
threadInfo
*
winfo
=
(
threadInfo
*
)
sarg
;
if
(
winfo
->
taos
==
NULL
)
{
TAOS
*
taos
=
NULL
;
taos
=
taos_connect
(
g_queryInfo
.
host
,
g_queryInfo
.
user
,
g_queryInfo
.
password
,
NULL
,
g_queryInfo
.
port
);
if
(
taos
==
NULL
)
{
errorPrint
(
"[%d] Failed to connect to TDengine, reason:%s
\n
"
,
winfo
->
threadID
,
taos_errstr
(
NULL
));
return
NULL
;
}
else
{
winfo
->
taos
=
taos
;
}
}
//char sqlStr[MAX_TB_NAME_SIZE*2];
//char sqlStr[MAX_TB_NAME_SIZE*2];
//sprintf(sqlStr, "use %s", g_queryInfo.dbName);
//sprintf(sqlStr, "use %s", g_queryInfo.dbName);
//queryDB(winfo->taos, sqlStr);
//queryDB(winfo->taos, sqlStr);
...
@@ -5493,6 +5509,23 @@ static void replaceSubTblName(char* inSql, char* outSql, int tblIndex) {
...
@@ -5493,6 +5509,23 @@ static void replaceSubTblName(char* inSql, char* outSql, int tblIndex) {
static
void
*
subQueryProcess
(
void
*
sarg
)
{
static
void
*
subQueryProcess
(
void
*
sarg
)
{
char
sqlstr
[
1024
];
char
sqlstr
[
1024
];
threadInfo
*
winfo
=
(
threadInfo
*
)
sarg
;
threadInfo
*
winfo
=
(
threadInfo
*
)
sarg
;
if
(
winfo
->
taos
==
NULL
)
{
TAOS
*
taos
=
NULL
;
taos
=
taos_connect
(
g_queryInfo
.
host
,
g_queryInfo
.
user
,
g_queryInfo
.
password
,
NULL
,
g_queryInfo
.
port
);
if
(
taos
==
NULL
)
{
errorPrint
(
"[%d] Failed to connect to TDengine, reason:%s
\n
"
,
winfo
->
threadID
,
taos_errstr
(
NULL
));
return
NULL
;
}
else
{
winfo
->
taos
=
taos
;
}
}
int64_t
st
=
0
;
int64_t
st
=
0
;
int64_t
et
=
(
int64_t
)
g_queryInfo
.
subQueryInfo
.
rate
*
1000
;
int64_t
et
=
(
int64_t
)
g_queryInfo
.
subQueryInfo
.
rate
*
1000
;
int
queryTimes
=
g_args
.
query_times
;
int
queryTimes
=
g_args
.
query_times
;
...
@@ -5585,28 +5618,30 @@ static int queryTestProcess() {
...
@@ -5585,28 +5618,30 @@ static int queryTestProcess() {
t_info
->
threadID
=
i
;
t_info
->
threadID
=
i
;
if
(
0
==
strncasecmp
(
g_queryInfo
.
queryMode
,
"taosc"
,
5
))
{
if
(
0
==
strncasecmp
(
g_queryInfo
.
queryMode
,
"taosc"
,
5
))
{
t_info
->
taos
=
taos
;
char
sqlStr
[
MAX_TB_NAME_SIZE
*
2
];
char
sqlStr
[
MAX_TB_NAME_SIZE
*
2
];
sprintf
(
sqlStr
,
"use %s"
,
g_queryInfo
.
dbName
);
sprintf
(
sqlStr
,
"use %s"
,
g_queryInfo
.
dbName
);
verbosePrint
(
"%s() %d sqlStr: %s
\n
"
,
__func__
,
__LINE__
,
sqlStr
);
verbosePrint
(
"%s() %d sqlStr: %s
\n
"
,
__func__
,
__LINE__
,
sqlStr
);
if
(
0
!=
queryDbExec
(
t_info
->
taos
,
sqlStr
,
NO_INSERT_TYPE
,
false
))
{
if
(
0
!=
queryDbExec
(
taos
,
sqlStr
,
NO_INSERT_TYPE
,
false
))
{
taos_close
(
taos
);
free
(
infos
);
free
(
infos
);
free
(
pids
);
free
(
pids
);
errorPrint
(
"use database %s failed!
\n\n
"
,
errorPrint
(
"use database %s failed!
\n\n
"
,
g_queryInfo
.
dbName
);
g_queryInfo
.
dbName
);
return
-
1
;
return
-
1
;
}
}
}
else
{
t_info
->
taos
=
NULL
;
}
}
t_info
->
taos
=
NULL
;
// TODO: workaround to use separate taos connection;
pthread_create
(
pids
+
i
,
NULL
,
superQueryProcess
,
t_info
);
pthread_create
(
pids
+
i
,
NULL
,
superQueryProcess
,
t_info
);
}
}
}
else
{
}
else
{
g_queryInfo
.
superQueryInfo
.
concurrent
=
0
;
g_queryInfo
.
superQueryInfo
.
concurrent
=
0
;
}
}
taos_close
(
taos
);
pthread_t
*
pidsOfSub
=
NULL
;
pthread_t
*
pidsOfSub
=
NULL
;
threadInfo
*
infosOfSub
=
NULL
;
threadInfo
*
infosOfSub
=
NULL
;
//==== create sub threads for query from all sub table of the super table
//==== create sub threads for query from all sub table of the super table
...
@@ -5614,7 +5649,6 @@ static int queryTestProcess() {
...
@@ -5614,7 +5649,6 @@ static int queryTestProcess() {
&&
(
g_queryInfo
.
subQueryInfo
.
threadCnt
>
0
))
{
&&
(
g_queryInfo
.
subQueryInfo
.
threadCnt
>
0
))
{
pidsOfSub
=
malloc
(
g_queryInfo
.
subQueryInfo
.
threadCnt
*
sizeof
(
pthread_t
));
pidsOfSub
=
malloc
(
g_queryInfo
.
subQueryInfo
.
threadCnt
*
sizeof
(
pthread_t
));
if
(
NULL
==
pidsOfSub
)
{
if
(
NULL
==
pidsOfSub
)
{
taos_close
(
taos
);
free
(
infos
);
free
(
infos
);
free
(
pids
);
free
(
pids
);
...
@@ -5623,7 +5657,6 @@ static int queryTestProcess() {
...
@@ -5623,7 +5657,6 @@ static int queryTestProcess() {
infosOfSub
=
malloc
(
g_queryInfo
.
subQueryInfo
.
threadCnt
*
sizeof
(
threadInfo
));
infosOfSub
=
malloc
(
g_queryInfo
.
subQueryInfo
.
threadCnt
*
sizeof
(
threadInfo
));
if
(
NULL
==
infosOfSub
)
{
if
(
NULL
==
infosOfSub
)
{
taos_close
(
taos
);
free
(
pidsOfSub
);
free
(
pidsOfSub
);
free
(
infos
);
free
(
infos
);
free
(
pids
);
free
(
pids
);
...
@@ -5653,7 +5686,7 @@ static int queryTestProcess() {
...
@@ -5653,7 +5686,7 @@ static int queryTestProcess() {
t_info
->
ntables
=
i
<
b
?
a
+
1
:
a
;
t_info
->
ntables
=
i
<
b
?
a
+
1
:
a
;
t_info
->
end_table_to
=
i
<
b
?
startFrom
+
a
:
startFrom
+
a
-
1
;
t_info
->
end_table_to
=
i
<
b
?
startFrom
+
a
:
startFrom
+
a
-
1
;
startFrom
=
t_info
->
end_table_to
+
1
;
startFrom
=
t_info
->
end_table_to
+
1
;
t_info
->
taos
=
taos
;
t_info
->
taos
=
NULL
;
// TODO: workaround to use separate taos connection
;
pthread_create
(
pidsOfSub
+
i
,
NULL
,
subQueryProcess
,
t_info
);
pthread_create
(
pidsOfSub
+
i
,
NULL
,
subQueryProcess
,
t_info
);
}
}
...
@@ -5676,7 +5709,7 @@ static int queryTestProcess() {
...
@@ -5676,7 +5709,7 @@ static int queryTestProcess() {
tmfree
((
char
*
)
pidsOfSub
);
tmfree
((
char
*
)
pidsOfSub
);
tmfree
((
char
*
)
infosOfSub
);
tmfree
((
char
*
)
infosOfSub
);
taos_close
(
taos
)
;
// taos_close(taos);// TODO: workaround to use separate taos connection
;
return
0
;
return
0
;
}
}
...
@@ -5717,10 +5750,27 @@ static void *subSubscribeProcess(void *sarg) {
...
@@ -5717,10 +5750,27 @@ static void *subSubscribeProcess(void *sarg) {
threadInfo
*
winfo
=
(
threadInfo
*
)
sarg
;
threadInfo
*
winfo
=
(
threadInfo
*
)
sarg
;
char
subSqlstr
[
1024
];
char
subSqlstr
[
1024
];
if
(
winfo
->
taos
==
NULL
)
{
TAOS
*
taos
=
NULL
;
taos
=
taos_connect
(
g_queryInfo
.
host
,
g_queryInfo
.
user
,
g_queryInfo
.
password
,
g_queryInfo
.
dbName
,
g_queryInfo
.
port
);
if
(
taos
==
NULL
)
{
errorPrint
(
"[%d] Failed to connect to TDengine, reason:%s
\n
"
,
winfo
->
threadID
,
taos_errstr
(
NULL
));
return
NULL
;
}
else
{
winfo
->
taos
=
taos
;
}
}
char
sqlStr
[
MAX_TB_NAME_SIZE
*
2
];
char
sqlStr
[
MAX_TB_NAME_SIZE
*
2
];
sprintf
(
sqlStr
,
"use %s"
,
g_queryInfo
.
dbName
);
sprintf
(
sqlStr
,
"use %s"
,
g_queryInfo
.
dbName
);
debugPrint
(
"%s() %d sqlStr: %s
\n
"
,
__func__
,
__LINE__
,
sqlStr
);
debugPrint
(
"%s() %d sqlStr: %s
\n
"
,
__func__
,
__LINE__
,
sqlStr
);
if
(
0
!=
queryDbExec
(
winfo
->
taos
,
sqlStr
,
NO_INSERT_TYPE
,
false
)){
if
(
0
!=
queryDbExec
(
winfo
->
taos
,
sqlStr
,
NO_INSERT_TYPE
,
false
))
{
taos_close
(
winfo
->
taos
);
return
NULL
;
return
NULL
;
}
}
...
@@ -5742,8 +5792,10 @@ static void *subSubscribeProcess(void *sarg) {
...
@@ -5742,8 +5792,10 @@ static void *subSubscribeProcess(void *sarg) {
if
(
g_queryInfo
.
subQueryInfo
.
result
[
i
][
0
]
!=
0
)
{
if
(
g_queryInfo
.
subQueryInfo
.
result
[
i
][
0
]
!=
0
)
{
sprintf
(
tmpFile
,
"%s-%d"
,
g_queryInfo
.
subQueryInfo
.
result
[
i
],
winfo
->
threadID
);
sprintf
(
tmpFile
,
"%s-%d"
,
g_queryInfo
.
subQueryInfo
.
result
[
i
],
winfo
->
threadID
);
}
}
g_queryInfo
.
subQueryInfo
.
tsub
[
i
]
=
subscribeImpl
(
winfo
->
taos
,
subSqlstr
,
topic
,
tmpFile
);
g_queryInfo
.
subQueryInfo
.
tsub
[
i
]
=
subscribeImpl
(
winfo
->
taos
,
subSqlstr
,
topic
,
tmpFile
);
if
(
NULL
==
g_queryInfo
.
subQueryInfo
.
tsub
[
i
])
{
if
(
NULL
==
g_queryInfo
.
subQueryInfo
.
tsub
[
i
])
{
taos_close
(
winfo
->
taos
);
return
NULL
;
return
NULL
;
}
}
}
}
...
@@ -5777,16 +5829,35 @@ static void *subSubscribeProcess(void *sarg) {
...
@@ -5777,16 +5829,35 @@ static void *subSubscribeProcess(void *sarg) {
taos_unsubscribe
(
g_queryInfo
.
subQueryInfo
.
tsub
[
i
],
taos_unsubscribe
(
g_queryInfo
.
subQueryInfo
.
tsub
[
i
],
g_queryInfo
.
subQueryInfo
.
subscribeKeepProgress
);
g_queryInfo
.
subQueryInfo
.
subscribeKeepProgress
);
}
}
taos_close
(
winfo
->
taos
);
return
NULL
;
return
NULL
;
}
}
static
void
*
superSubscribeProcess
(
void
*
sarg
)
{
static
void
*
superSubscribeProcess
(
void
*
sarg
)
{
threadInfo
*
winfo
=
(
threadInfo
*
)
sarg
;
threadInfo
*
winfo
=
(
threadInfo
*
)
sarg
;
if
(
winfo
->
taos
==
NULL
)
{
TAOS
*
taos
=
NULL
;
taos
=
taos_connect
(
g_queryInfo
.
host
,
g_queryInfo
.
user
,
g_queryInfo
.
password
,
g_queryInfo
.
dbName
,
g_queryInfo
.
port
);
if
(
taos
==
NULL
)
{
errorPrint
(
"[%d] Failed to connect to TDengine, reason:%s
\n
"
,
winfo
->
threadID
,
taos_errstr
(
NULL
));
return
NULL
;
}
else
{
winfo
->
taos
=
taos
;
}
}
char
sqlStr
[
MAX_TB_NAME_SIZE
*
2
];
char
sqlStr
[
MAX_TB_NAME_SIZE
*
2
];
sprintf
(
sqlStr
,
"use %s"
,
g_queryInfo
.
dbName
);
sprintf
(
sqlStr
,
"use %s"
,
g_queryInfo
.
dbName
);
debugPrint
(
"%s() %d sqlStr: %s
\n
"
,
__func__
,
__LINE__
,
sqlStr
);
debugPrint
(
"%s() %d sqlStr: %s
\n
"
,
__func__
,
__LINE__
,
sqlStr
);
if
(
0
!=
queryDbExec
(
winfo
->
taos
,
sqlStr
,
NO_INSERT_TYPE
,
false
))
{
if
(
0
!=
queryDbExec
(
winfo
->
taos
,
sqlStr
,
NO_INSERT_TYPE
,
false
))
{
taos_close
(
winfo
->
taos
);
return
NULL
;
return
NULL
;
}
}
...
@@ -5812,6 +5883,7 @@ static void *superSubscribeProcess(void *sarg) {
...
@@ -5812,6 +5883,7 @@ static void *superSubscribeProcess(void *sarg) {
g_queryInfo
.
superQueryInfo
.
sql
[
i
],
g_queryInfo
.
superQueryInfo
.
sql
[
i
],
topic
,
tmpFile
);
topic
,
tmpFile
);
if
(
NULL
==
g_queryInfo
.
superQueryInfo
.
tsub
[
i
])
{
if
(
NULL
==
g_queryInfo
.
superQueryInfo
.
tsub
[
i
])
{
taos_close
(
winfo
->
taos
);
return
NULL
;
return
NULL
;
}
}
}
}
...
@@ -5844,6 +5916,8 @@ static void *superSubscribeProcess(void *sarg) {
...
@@ -5844,6 +5916,8 @@ static void *superSubscribeProcess(void *sarg) {
taos_unsubscribe
(
g_queryInfo
.
superQueryInfo
.
tsub
[
i
],
taos_unsubscribe
(
g_queryInfo
.
superQueryInfo
.
tsub
[
i
],
g_queryInfo
.
superQueryInfo
.
subscribeKeepProgress
);
g_queryInfo
.
superQueryInfo
.
subscribeKeepProgress
);
}
}
taos_close
(
winfo
->
taos
);
return
NULL
;
return
NULL
;
}
}
...
@@ -5854,7 +5928,7 @@ static int subscribeTestProcess() {
...
@@ -5854,7 +5928,7 @@ static int subscribeTestProcess() {
if
(
!
g_args
.
answer_yes
)
{
if
(
!
g_args
.
answer_yes
)
{
printf
(
"Press enter key to continue
\n\n
"
);
printf
(
"Press enter key to continue
\n\n
"
);
(
void
)
getchar
();
(
void
)
getchar
();
}
}
TAOS
*
taos
=
NULL
;
TAOS
*
taos
=
NULL
;
...
@@ -5877,6 +5951,8 @@ static int subscribeTestProcess() {
...
@@ -5877,6 +5951,8 @@ static int subscribeTestProcess() {
&
g_queryInfo
.
subQueryInfo
.
childTblCount
);
&
g_queryInfo
.
subQueryInfo
.
childTblCount
);
}
}
taos_close
(
taos
);
// TODO: workaround to use separate taos connection;
pthread_t
*
pids
=
NULL
;
pthread_t
*
pids
=
NULL
;
threadInfo
*
infos
=
NULL
;
threadInfo
*
infos
=
NULL
;
//==== create sub threads for query from super table
//==== create sub threads for query from super table
...
@@ -5892,14 +5968,13 @@ static int subscribeTestProcess() {
...
@@ -5892,14 +5968,13 @@ static int subscribeTestProcess() {
infos
=
malloc
(
g_queryInfo
.
superQueryInfo
.
concurrent
*
sizeof
(
threadInfo
));
infos
=
malloc
(
g_queryInfo
.
superQueryInfo
.
concurrent
*
sizeof
(
threadInfo
));
if
((
NULL
==
pids
)
||
(
NULL
==
infos
))
{
if
((
NULL
==
pids
)
||
(
NULL
==
infos
))
{
errorPrint
(
"%s() LN%d, malloc failed for create threads
\n
"
,
__func__
,
__LINE__
);
errorPrint
(
"%s() LN%d, malloc failed for create threads
\n
"
,
__func__
,
__LINE__
);
taos_close
(
taos
);
exit
(
-
1
);
exit
(
-
1
);
}
}
for
(
int
i
=
0
;
i
<
g_queryInfo
.
superQueryInfo
.
concurrent
;
i
++
)
{
for
(
int
i
=
0
;
i
<
g_queryInfo
.
superQueryInfo
.
concurrent
;
i
++
)
{
threadInfo
*
t_info
=
infos
+
i
;
threadInfo
*
t_info
=
infos
+
i
;
t_info
->
threadID
=
i
;
t_info
->
threadID
=
i
;
t_info
->
taos
=
taos
;
t_info
->
taos
=
NULL
;
// TODO: workaround to use separate taos connection
;
pthread_create
(
pids
+
i
,
NULL
,
superSubscribeProcess
,
t_info
);
pthread_create
(
pids
+
i
,
NULL
,
superSubscribeProcess
,
t_info
);
}
}
...
@@ -5913,8 +5988,9 @@ static int subscribeTestProcess() {
...
@@ -5913,8 +5988,9 @@ static int subscribeTestProcess() {
infosOfSub
=
malloc
(
g_queryInfo
.
subQueryInfo
.
threadCnt
*
infosOfSub
=
malloc
(
g_queryInfo
.
subQueryInfo
.
threadCnt
*
sizeof
(
threadInfo
));
sizeof
(
threadInfo
));
if
((
NULL
==
pidsOfSub
)
||
(
NULL
==
infosOfSub
))
{
if
((
NULL
==
pidsOfSub
)
||
(
NULL
==
infosOfSub
))
{
printf
(
"malloc failed for create threads
\n
"
);
errorPrint
(
"%s() LN%d, malloc failed for create threads
\n
"
,
taos_close
(
taos
);
__func__
,
__LINE__
);
// taos_close(taos);
exit
(
-
1
);
exit
(
-
1
);
}
}
...
@@ -5941,7 +6017,7 @@ static int subscribeTestProcess() {
...
@@ -5941,7 +6017,7 @@ static int subscribeTestProcess() {
t_info
->
ntables
=
i
<
b
?
a
+
1
:
a
;
t_info
->
ntables
=
i
<
b
?
a
+
1
:
a
;
t_info
->
end_table_to
=
i
<
b
?
startFrom
+
a
:
startFrom
+
a
-
1
;
t_info
->
end_table_to
=
i
<
b
?
startFrom
+
a
:
startFrom
+
a
-
1
;
startFrom
=
t_info
->
end_table_to
+
1
;
startFrom
=
t_info
->
end_table_to
+
1
;
t_info
->
taos
=
taos
;
t_info
->
taos
=
NULL
;
// TODO: workaround to use separate taos connection
;
pthread_create
(
pidsOfSub
+
i
,
NULL
,
subSubscribeProcess
,
t_info
);
pthread_create
(
pidsOfSub
+
i
,
NULL
,
subSubscribeProcess
,
t_info
);
}
}
g_queryInfo
.
subQueryInfo
.
threadCnt
=
threads
;
g_queryInfo
.
subQueryInfo
.
threadCnt
=
threads
;
...
@@ -5960,7 +6036,7 @@ static int subscribeTestProcess() {
...
@@ -5960,7 +6036,7 @@ static int subscribeTestProcess() {
tmfree
((
char
*
)
pidsOfSub
);
tmfree
((
char
*
)
pidsOfSub
);
tmfree
((
char
*
)
infosOfSub
);
tmfree
((
char
*
)
infosOfSub
);
taos_close
(
taos
);
//
taos_close(taos);
return
0
;
return
0
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录