Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
71c26d5c
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1185
Star
22015
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看板
未验证
提交
71c26d5c
编写于
5月 22, 2020
作者:
S
Shengliang Guan
提交者:
GitHub
5月 22, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1990 from taosdata/enhance/cq
set up DB connection only when there is a continuous query
上级
0812c3d8
42e44b4b
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
33 addition
and
27 deletion
+33
-27
src/cq/src/cqMain.c
src/cq/src/cqMain.c
+33
-27
未找到文件。
src/cq/src/cqMain.c
浏览文件 @
71c26d5c
...
...
@@ -40,6 +40,7 @@ typedef struct {
int
num
;
// number of continuous streams
struct
SCqObj
*
pHead
;
void
*
dbConn
;
int
master
;
pthread_mutex_t
mutex
;
}
SCqContext
;
...
...
@@ -58,6 +59,7 @@ typedef struct SCqObj {
int
cqDebugFlag
=
135
;
static
void
cqProcessStreamRes
(
void
*
param
,
TAOS_RES
*
tres
,
TAOS_ROW
row
);
static
void
cqCreateStream
(
SCqContext
*
pContext
,
SCqObj
*
pObj
);
void
*
cqOpen
(
void
*
ahandle
,
const
SCqCfg
*
pCfg
)
{
...
...
@@ -69,6 +71,7 @@ void *cqOpen(void *ahandle, const SCqCfg *pCfg) {
pContext
->
vgId
=
pCfg
->
vgId
;
pContext
->
cqWrite
=
pCfg
->
cqWrite
;
pContext
->
ahandle
=
ahandle
;
tscEmbedded
=
1
;
pthread_mutex_init
(
&
pContext
->
mutex
,
NULL
);
...
...
@@ -84,6 +87,8 @@ void cqClose(void *handle) {
cqStop
(
pContext
);
// free all resources
pthread_mutex_lock
(
&
pContext
->
mutex
);
SCqObj
*
pObj
=
pContext
->
pHead
;
while
(
pObj
)
{
SCqObj
*
pTemp
=
pObj
;
...
...
@@ -91,6 +96,8 @@ void cqClose(void *handle) {
free
(
pTemp
);
}
pthread_mutex_unlock
(
&
pContext
->
mutex
);
pthread_mutex_destroy
(
&
pContext
->
mutex
);
cTrace
(
"vgId:%d, CQ is closed"
,
pContext
->
vgId
);
...
...
@@ -100,28 +107,15 @@ void cqClose(void *handle) {
void
cqStart
(
void
*
handle
)
{
SCqContext
*
pContext
=
handle
;
cTrace
(
"vgId:%d, start all CQs"
,
pContext
->
vgId
);
if
(
pContext
->
dbConn
)
return
;
if
(
pContext
->
dbConn
||
pContext
->
master
)
return
;
pthread_mutex_lock
(
&
pContext
->
mutex
);
tscEmbedded
=
1
;
pContext
->
dbConn
=
taos_connect
(
"localhost"
,
pContext
->
user
,
pContext
->
pass
,
NULL
,
0
);
if
(
pContext
->
dbConn
==
NULL
)
{
cError
(
"vgId:%d, failed to connect to TDengine(%s)"
,
pContext
->
vgId
,
tstrerror
(
terrno
));
pthread_mutex_unlock
(
&
pContext
->
mutex
);
return
;
}
pContext
->
master
=
1
;
SCqObj
*
pObj
=
pContext
->
pHead
;
while
(
pObj
)
{
int64_t
lastKey
=
0
;
pObj
->
pStream
=
taos_open_stream
(
pContext
->
dbConn
,
pObj
->
sqlStr
,
cqProcessStreamRes
,
lastKey
,
pObj
,
NULL
);
if
(
pObj
->
pStream
)
{
pContext
->
num
++
;
cTrace
(
"vgId:%d, id:%d CQ:%s is openned"
,
pContext
->
vgId
,
pObj
->
tid
,
pObj
->
sqlStr
);
}
else
{
cError
(
"vgId:%d, id:%d CQ:%s, failed to open"
,
pContext
->
vgId
,
pObj
->
tid
,
pObj
->
sqlStr
);
}
cqCreateStream
(
pContext
,
pObj
);
pObj
=
pObj
->
next
;
}
...
...
@@ -131,10 +125,11 @@ void cqStart(void *handle) {
void
cqStop
(
void
*
handle
)
{
SCqContext
*
pContext
=
handle
;
cTrace
(
"vgId:%d, stop all CQs"
,
pContext
->
vgId
);
if
(
pContext
->
dbConn
==
NULL
)
return
;
if
(
pContext
->
dbConn
==
NULL
||
pContext
->
master
==
0
)
return
;
pthread_mutex_lock
(
&
pContext
->
mutex
);
pContext
->
master
=
0
;
SCqObj
*
pObj
=
pContext
->
pHead
;
while
(
pObj
)
{
if
(
pObj
->
pStream
)
{
...
...
@@ -176,16 +171,7 @@ void *cqCreate(void *handle, int tid, char *sqlStr, SSchema *pSchema, int column
if
(
pContext
->
pHead
)
pContext
->
pHead
->
prev
=
pObj
;
pContext
->
pHead
=
pObj
;
if
(
pContext
->
dbConn
)
{
int64_t
lastKey
=
0
;
pObj
->
pStream
=
taos_open_stream
(
pContext
->
dbConn
,
pObj
->
sqlStr
,
cqProcessStreamRes
,
lastKey
,
pObj
,
NULL
);
if
(
pObj
->
pStream
)
{
pContext
->
num
++
;
cTrace
(
"vgId:%d, id:%d CQ:%s is openned"
,
pContext
->
vgId
,
pObj
->
tid
,
pObj
->
sqlStr
);
}
else
{
cError
(
"vgId:%d, id:%d CQ:%s, failed to launch"
,
pContext
->
vgId
,
pObj
->
tid
,
pObj
->
sqlStr
);
}
}
cqCreateStream
(
pContext
,
pObj
);
pthread_mutex_unlock
(
&
pContext
->
mutex
);
...
...
@@ -218,6 +204,26 @@ void cqDrop(void *handle) {
pthread_mutex_lock
(
&
pContext
->
mutex
);
}
static
void
cqCreateStream
(
SCqContext
*
pContext
,
SCqObj
*
pObj
)
{
if
(
pContext
->
dbConn
==
NULL
)
{
pContext
->
dbConn
=
taos_connect
(
"localhost"
,
pContext
->
user
,
pContext
->
pass
,
NULL
,
0
);
if
(
pContext
->
dbConn
==
NULL
)
{
cError
(
"vgId:%d, failed to connect to TDengine(%s)"
,
pContext
->
vgId
,
tstrerror
(
terrno
));
}
return
;
}
int64_t
lastKey
=
0
;
pObj
->
pStream
=
taos_open_stream
(
pContext
->
dbConn
,
pObj
->
sqlStr
,
cqProcessStreamRes
,
lastKey
,
pObj
,
NULL
);
if
(
pObj
->
pStream
)
{
pContext
->
num
++
;
cTrace
(
"vgId:%d, id:%d CQ:%s is openned"
,
pContext
->
vgId
,
pObj
->
tid
,
pObj
->
sqlStr
);
}
else
{
cError
(
"vgId:%d, id:%d CQ:%s, failed to open"
,
pContext
->
vgId
,
pObj
->
tid
,
pObj
->
sqlStr
);
}
}
static
void
cqProcessStreamRes
(
void
*
param
,
TAOS_RES
*
tres
,
TAOS_ROW
row
)
{
SCqObj
*
pObj
=
(
SCqObj
*
)
param
;
SCqContext
*
pContext
=
pObj
->
pContext
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录