Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
f569bb4b
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
f569bb4b
编写于
7月 17, 2020
作者:
B
Bomin Zhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
td-909: fix subscription bugs
上级
3fb51717
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
96 addition
and
68 deletion
+96
-68
src/client/src/tscSub.c
src/client/src/tscSub.c
+95
-67
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+1
-1
未找到文件。
src/client/src/tscSub.c
浏览文件 @
f569bb4b
...
...
@@ -34,6 +34,7 @@ typedef struct SSubscriptionProgress {
typedef
struct
SSub
{
void
*
signature
;
char
topic
[
32
];
sem_t
sem
;
int64_t
lastSyncTime
;
int64_t
lastConsumeTime
;
TAOS
*
taos
;
...
...
@@ -83,84 +84,107 @@ void tscUpdateSubscriptionProgress(void* sub, int64_t uid, TSKEY ts) {
static
void
asyncCallback
(
void
*
param
,
TAOS_RES
*
tres
,
int
code
)
{
assert
(
param
!=
NULL
);
SSqlObj
*
pSql
=
((
SSqlObj
*
)
param
);
pSql
->
res
.
code
=
code
;
sem_post
(
&
pSql
->
rspSem
);
SSub
*
pSub
=
((
SSub
*
)
param
);
pSub
->
pSql
->
res
.
code
=
code
;
sem_post
(
&
pSub
->
sem
);
}
static
SSub
*
tscCreateSubscription
(
STscObj
*
pObj
,
const
char
*
topic
,
const
char
*
sql
)
{
SSub
*
pSub
=
NULL
;
TRY
(
8
)
{
SSqlObj
*
pSql
=
calloc_throw
(
1
,
sizeof
(
SSqlObj
));
CLEANUP_PUSH_FREE
(
true
,
pSql
);
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
int
code
=
TSDB_CODE_SUCCESS
,
line
=
__LINE__
;
if
(
tsem_init
(
&
pSql
->
rspSem
,
0
,
0
)
==
-
1
)
{
THROW
(
TAOS_SYSTEM_ERROR
(
errno
));
SSub
*
pSub
=
calloc
(
1
,
sizeof
(
SSub
));
if
(
pSub
==
NULL
)
{
line
=
__LINE__
;
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
fail
;
}
pSub
->
signature
=
pSub
;
if
(
tsem_init
(
&
pSub
->
sem
,
0
,
0
)
==
-
1
)
{
line
=
__LINE__
;
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
fail
;
}
tstrncpy
(
pSub
->
topic
,
topic
,
sizeof
(
pSub
->
topic
));
pSub
->
progress
=
taosArrayInit
(
32
,
sizeof
(
SSubscriptionProgress
));
if
(
pSub
->
progress
==
NULL
)
{
line
=
__LINE__
;
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
fail
;
}
CLEANUP_PUSH_INT_PTR
(
true
,
tsem_destroy
,
&
pSql
->
rspSem
);
SSqlObj
*
pSql
=
calloc
(
1
,
sizeof
(
SSqlObj
));
if
(
pSql
==
NULL
)
{
line
=
__LINE__
;
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
fail
;
}
pSql
->
signature
=
pSql
;
pSql
->
param
=
pSql
;
pSql
->
pTscObj
=
pObj
;
pSql
->
maxRetry
=
TSDB_MAX_REPLICA
;
pSql
->
fp
=
asyncCallback
;
pSql
->
pSubscription
=
pSub
;
pSub
->
pSql
=
pSql
;
int
code
=
tscAllocPayload
(
pCmd
,
TSDB_DEFAULT_PAYLOAD_SIZE
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
THROW
(
code
);
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
if
(
tsem_init
(
&
pSql
->
rspSem
,
0
,
0
)
==
-
1
)
{
line
=
__LINE__
;
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
fail
;
}
CLEANUP_PUSH_FREE
(
true
,
pCmd
->
payload
);
pSql
->
param
=
pSub
;
pSql
->
maxRetry
=
TSDB_MAX_REPLICA
;
pSql
->
fp
=
asyncCallback
;
pSql
->
fetchFp
=
asyncCallback
;
pSql
->
sqlstr
=
strdup
(
sql
);
if
(
pSql
->
sqlstr
==
NULL
)
{
line
=
__LINE__
;
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
fail
;
}
strtolower
(
pSql
->
sqlstr
,
pSql
->
sqlstr
);
pRes
->
qhandle
=
0
;
pRes
->
numOfRows
=
1
;
pSql
->
sqlstr
=
strdup_throw
(
sql
);
CLEANUP_PUSH_FREE
(
true
,
pSql
->
sqlstr
);
strtolower
(
pSql
->
sqlstr
,
pSql
->
sqlstr
);
code
=
tscAllocPayload
(
pCmd
,
TSDB_DEFAULT_PAYLOAD_SIZE
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
line
=
__LINE__
;
goto
fail
;
}
code
=
tsParseSql
(
pSql
,
false
);
if
(
code
==
TSDB_CODE_TSC_ACTION_IN_PROGRESS
)
{
// wait for the callback function to post the semaphore
sem_wait
(
&
pSql
->
rspSem
);
sem_wait
(
&
pSub
->
sem
);
code
=
pSql
->
res
.
code
;
}
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
tscError
(
"failed to parse sql statement: %s, error: %s"
,
pSub
->
topic
,
tstrerror
(
code
))
;
THROW
(
code
)
;
line
=
__LINE__
;
goto
fail
;
}
if
(
pSql
->
cmd
.
command
!=
TSDB_SQL_SELECT
)
{
tscError
(
"only 'select' statement is allowed in subscription: %s"
,
pSub
->
topic
);
THROW
(
-
1
);
// TODO
}
pSub
=
calloc_throw
(
1
,
sizeof
(
SSub
));
CLEANUP_PUSH_FREE
(
true
,
pSub
);
pSql
->
pSubscription
=
pSub
;
pSub
->
pSql
=
pSql
;
pSub
->
signature
=
pSub
;
strncpy
(
pSub
->
topic
,
topic
,
sizeof
(
pSub
->
topic
));
pSub
->
topic
[
sizeof
(
pSub
->
topic
)
-
1
]
=
0
;
pSub
->
progress
=
taosArrayInit
(
32
,
sizeof
(
SSubscriptionProgress
));
if
(
pSub
->
progress
==
NULL
)
{
THROW
(
TSDB_CODE_TSC_OUT_OF_MEMORY
);
line
=
__LINE__
;
code
=
TSDB_CODE_TSC_INVALID_SQL
;
goto
fail
;
}
CLEANUP_EXECUTE
()
;
return
pSub
;
}
CATCH
(
code
)
{
tscError
(
"failed to create subscription object: %s"
,
tstrerror
(
code
));
CLEANUP_EXECUTE
();
fail:
tscError
(
"tscCreateSubscription failed at line %d, reason: %s"
,
line
,
tstrerror
(
code
));
if
(
pSql
!=
NULL
)
{
tscFreeSqlObj
(
pSql
);
pSql
=
NULL
;
}
if
(
pSub
!=
NULL
)
{
taosArrayDestroy
(
pSub
->
progress
);
tsem_destroy
(
&
pSub
->
sem
);
free
(
pSub
);
pSub
=
NULL
;
}
}
END_TRY
return
pSub
;
terrno
=
code
;
return
NULL
;
}
...
...
@@ -405,9 +429,10 @@ TAOS_RES *taos_consume(TAOS_SUB *tsub) {
tscGetTableMetaInfoFromCmd
(
&
pSql
->
cmd
,
0
,
0
)
->
vgroupIndex
=
0
;
pSql
->
fp
=
asyncCallback
;
pSql
->
param
=
pSql
;
pSql
->
fetchFp
=
asyncCallback
;
pSql
->
param
=
pSub
;
tscDoQuery
(
pSql
);
sem_wait
(
&
pS
ql
->
rspS
em
);
sem_wait
(
&
pS
ub
->
s
em
);
if
(
pRes
->
code
!=
TSDB_CODE_SUCCESS
)
{
continue
;
...
...
@@ -437,7 +462,9 @@ void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress) {
}
if
(
keepProgress
)
{
if
(
pSub
->
progress
!=
NULL
)
{
tscSaveSubscriptionProgress
(
pSub
);
}
}
else
{
char
path
[
256
];
sprintf
(
path
,
"%s/subscribe/%s"
,
tsDataDir
,
pSub
->
topic
);
...
...
@@ -448,6 +475,7 @@ void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress) {
tscFreeSqlObj
(
pSub
->
pSql
);
taosArrayDestroy
(
pSub
->
progress
);
tsem_destroy
(
&
pSub
->
sem
);
memset
(
pSub
,
0
,
sizeof
(
*
pSub
));
free
(
pSub
);
}
src/query/src/qExecutor.c
浏览文件 @
f569bb4b
...
...
@@ -4918,7 +4918,7 @@ static void tableMultiOutputProcess(SQInfo *pQInfo, STableQueryInfo* pTableInfo)
pQuery
->
current
->
lastKey
,
pQuery
->
window
.
ekey
);
}
else
if
(
Q_STATUS_EQUAL
(
pQuery
->
status
,
QUERY_COMPLETED
))
{
STableIdInfo
tidInfo
;
STableId
*
id
=
TSDB_TABLEID
(
pQuery
->
current
);
STableId
*
id
=
TSDB_TABLEID
(
pQuery
->
current
->
pTable
);
tidInfo
.
uid
=
id
->
uid
;
tidInfo
.
tid
=
id
->
tid
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录