Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4b4199ce
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看板
提交
4b4199ce
编写于
5月 26, 2021
作者:
T
tickduan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cq support continue query from last stop time
上级
1ee65f6c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
33 addition
and
9 deletion
+33
-9
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+1
-0
src/client/src/tscStream.c
src/client/src/tscStream.c
+32
-9
未找到文件。
src/client/inc/tsclient.h
浏览文件 @
4b4199ce
...
...
@@ -422,6 +422,7 @@ typedef struct SSqlStream {
int64_t
ctime
;
// stream created time
int64_t
stime
;
// stream next executed time
int64_t
etime
;
// stream end query time, when time is larger then etime, the stream will be closed
int64_t
ltime
;
// stream last row time in stream table
SInterval
interval
;
void
*
pTimer
;
...
...
src/client/src/tscStream.c
浏览文件 @
4b4199ce
...
...
@@ -538,12 +538,11 @@ static int64_t tscGetLaunchTimestamp(const SSqlStream *pStream) {
return
(
pStream
->
precision
==
TSDB_TIME_PRECISION_MICRO
)
?
timer
/
1000L
:
timer
;
}
///*
//
// get tableName last row time, if have error return zero.
//
static
int64_t
tscGetStreamTableLastTime
(
SSqlObj
*
pSql
,
SSqlStream
*
pStream
,
const
char
*
tableName
)
{
int64_t
last_time
=
0
;
char
sql
[
128
]
=
""
;
sprintf
(
sql
,
"select last_row(*) from %s;"
,
tableName
);
...
...
@@ -555,7 +554,7 @@ static int64_t tscGetStreamTableLastTime(SSqlObj* pSql, SSqlStream* pStream, con
// only fetch one row
TAOS_ROW
row
=
taos_fetch_row
(
res
);
if
(
row
[
0
]
)
{
if
(
row
&&
row
[
0
]
)
{
last_time
=
*
((
int64_t
*
)
row
[
0
]);
}
...
...
@@ -563,7 +562,7 @@ static int64_t tscGetStreamTableLastTime(SSqlObj* pSql, SSqlStream* pStream, con
taos_free_result
(
res
);
return
last_time
;
}
//*/
static
void
tscCreateStream
(
void
*
param
,
TAOS_RES
*
res
,
int
code
)
{
SSqlStream
*
pStream
=
(
SSqlStream
*
)
param
;
SSqlObj
*
pSql
=
pStream
->
pSql
;
...
...
@@ -597,10 +596,14 @@ static void tscCreateStream(void *param, TAOS_RES *res, int code) {
pStream
->
stime
=
tscGetStreamStartTimestamp
(
pSql
,
pStream
,
pStream
->
stime
);
// set output table last record time to stime if have, why do this, because continue with last break
int64_t
last_time
=
tscGetStreamTableLastTime
(
pSql
,
pStream
,
pStream
->
dstTable
);
// set output table last record time to stime if have, why do this, because continue with last brea
const
char
*
dstTable
=
pStream
->
dstTable
?
pStream
->
dstTable
:
""
;
int64_t
last_time
=
tscGetStreamTableLastTime
(
pSql
,
pStream
,
dstTable
);
pStream
->
ltime
=
last_time
;
tscDebug
(
" CQ get table=%s lasttime=%"
PRId64
" end."
,
dstTable
,
last_time
);
if
(
last_time
>
0
&&
last_time
>
pStream
->
stime
)
{
// can replace stime with last row time
tscDebug
(
" CQ set table %s stime=%"
PRId64
" with lasttime=%"
PRId64
" "
,
dstTable
,
pStream
->
stime
,
last_time
);
pStream
->
stime
=
last_time
;
}
...
...
@@ -619,6 +622,24 @@ void tscSetStreamDestTable(SSqlStream* pStream, const char* dstTable) {
pStream
->
dstTable
=
dstTable
;
}
// already run on another thread
void
tscCreateStreamThread
(
SSchedMsg
*
pMsg
)
{
tscDebug
(
" new thread Sched call tscCreateStream begin..."
);
tscCreateStream
(
pMsg
->
ahandle
,
NULL
,
0
);
tscDebug
(
" new thread Sched call tscCreateStream end."
);
return
;
}
// parsesql async response return and change run thread
void
tsParseSqlRet
(
void
*
param
,
TAOS_RES
*
res
,
int
code
)
{
SSchedMsg
schedMsg
=
{
0
};
schedMsg
.
fp
=
tscCreateStreamThread
;
schedMsg
.
ahandle
=
param
;
schedMsg
.
thandle
=
res
;
schedMsg
.
msg
=
NULL
;
taosScheduleTask
(
tscQhandle
,
&
schedMsg
);
}
TAOS_STREAM
*
taos_open_stream
(
TAOS
*
taos
,
const
char
*
sqlstr
,
void
(
*
fp
)(
void
*
param
,
TAOS_RES
*
,
TAOS_ROW
row
),
int64_t
stime
,
void
*
param
,
void
(
*
callback
)(
void
*
))
{
STscObj
*
pObj
=
(
STscObj
*
)
taos
;
...
...
@@ -664,15 +685,17 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p
tscDebugL
(
"%p SQL: %s"
,
pSql
,
pSql
->
sqlstr
);
tsem_init
(
&
pSql
->
rspSem
,
0
,
0
);
pSql
->
fp
=
tscCreateStream
;
pSql
->
fetchFp
=
ts
cCreateStream
;
pSql
->
fp
=
tsParseSqlRet
;
pSql
->
fetchFp
=
ts
ParseSqlRet
;
registerSqlObj
(
pSql
);
int32_t
code
=
tsParseSql
(
pSql
,
true
);
if
(
code
==
TSDB_CODE_SUCCESS
)
{
tscCreateStream
(
pStream
,
pSql
,
code
);
}
else
if
(
code
!=
TSDB_CODE_TSC_ACTION_IN_PROGRESS
)
{
}
else
if
(
code
==
TSDB_CODE_TSC_ACTION_IN_PROGRESS
)
{
tscDebug
(
" cq parseSql IN Process pass. "
);
}
else
{
tscError
(
"0x%"
PRIx64
" open stream failed, sql:%s, code:%s"
,
pSql
->
self
,
sqlstr
,
tstrerror
(
code
));
taosReleaseRef
(
tscObjRef
,
pSql
->
self
);
free
(
pStream
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录