Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
459ec6ed
T
TDengine
项目概览
taosdata
/
TDengine
接近 2 年 前同步成功
通知
1192
Star
22018
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看板
提交
459ec6ed
编写于
3月 30, 2022
作者:
L
Liu Jicong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tmq optimize offset handling
上级
8b00e0ed
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
57 addition
and
33 deletion
+57
-33
source/client/consumer/consumer.c
source/client/consumer/consumer.c
+0
-16
source/client/src/tmq.c
source/client/src/tmq.c
+52
-11
source/dnode/mnode/impl/src/mndTopic.c
source/dnode/mnode/impl/src/mndTopic.c
+3
-5
tests/test/c/tmqDemo.c
tests/test/c/tmqDemo.c
+2
-1
未找到文件。
source/client/consumer/consumer.c
已删除
100644 → 0
浏览文件 @
8b00e0ed
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "consumer.h"
source/client/src/tmq.c
浏览文件 @
459ec6ed
...
@@ -241,6 +241,10 @@ void tmq_list_destroy(tmq_list_t* list) {
...
@@ -241,6 +241,10 @@ void tmq_list_destroy(tmq_list_t* list) {
taosArrayDestroyEx
(
container
,
(
void
(
*
)(
void
*
))
taosMemoryFree
);
taosArrayDestroyEx
(
container
,
(
void
(
*
)(
void
*
))
taosMemoryFree
);
}
}
static
int32_t
tmqMakeTopicVgKey
(
char
*
dst
,
const
char
*
topicName
,
int32_t
vg
)
{
return
sprintf
(
dst
,
"%s:%d"
,
topicName
,
vg
);
}
void
tmqClearUnhandleMsg
(
tmq_t
*
tmq
)
{
void
tmqClearUnhandleMsg
(
tmq_t
*
tmq
)
{
tmq_message_t
*
msg
=
NULL
;
tmq_message_t
*
msg
=
NULL
;
while
(
1
)
{
while
(
1
)
{
...
@@ -827,7 +831,7 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) {
...
@@ -827,7 +831,7 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) {
SMqClientVg
*
pVg
=
pParam
->
pVg
;
SMqClientVg
*
pVg
=
pParam
->
pVg
;
tmq_t
*
tmq
=
pParam
->
tmq
;
tmq_t
*
tmq
=
pParam
->
tmq
;
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
printf
(
"msg discard, code:%x
\n
"
,
code
);
tscWarn
(
"msg discard, code:%x
"
,
code
);
goto
WRITE_QUEUE_FAIL
;
goto
WRITE_QUEUE_FAIL
;
}
}
...
@@ -835,12 +839,12 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) {
...
@@ -835,12 +839,12 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) {
int32_t
tmqEpoch
=
atomic_load_32
(
&
tmq
->
epoch
);
int32_t
tmqEpoch
=
atomic_load_32
(
&
tmq
->
epoch
);
if
(
msgEpoch
<
tmqEpoch
)
{
if
(
msgEpoch
<
tmqEpoch
)
{
tsem_post
(
&
tmq
->
rspSem
);
tsem_post
(
&
tmq
->
rspSem
);
printf
(
"discard rsp epoch %d, current epoch %d
\n
"
,
msgEpoch
,
tmqEpoch
);
tscWarn
(
"discard rsp epoch %d, current epoch %d
"
,
msgEpoch
,
tmqEpoch
);
return
0
;
return
0
;
}
}
if
(
msgEpoch
!=
tmqEpoch
)
{
if
(
msgEpoch
!=
tmqEpoch
)
{
printf
(
"mismatch rsp epoch %d, current epoch %d
\n
"
,
msgEpoch
,
tmqEpoch
);
tscWarn
(
"mismatch rsp epoch %d, current epoch %d
"
,
msgEpoch
,
tmqEpoch
);
}
else
{
}
else
{
atomic_sub_fetch_32
(
&
tmq
->
waitingRequest
,
1
);
atomic_sub_fetch_32
(
&
tmq
->
waitingRequest
,
1
);
}
}
...
@@ -899,19 +903,54 @@ WRITE_QUEUE_FAIL:
...
@@ -899,19 +903,54 @@ WRITE_QUEUE_FAIL:
bool
tmqUpdateEp
(
tmq_t
*
tmq
,
int32_t
epoch
,
SMqCMGetSubEpRsp
*
pRsp
)
{
bool
tmqUpdateEp
(
tmq_t
*
tmq
,
int32_t
epoch
,
SMqCMGetSubEpRsp
*
pRsp
)
{
/*printf("call update ep %d\n", epoch);*/
/*printf("call update ep %d\n", epoch);*/
bool
set
=
false
;
bool
set
=
false
;
int32_t
sz
=
taosArrayGetSize
(
pRsp
->
topics
);
int32_t
topicNumGet
=
taosArrayGetSize
(
pRsp
->
topics
);
SArray
*
newTopics
=
taosArrayInit
(
sz
,
sizeof
(
SMqClientTopic
));
char
vgKey
[
TSDB_TOPIC_FNAME_LEN
+
22
];
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
SArray
*
newTopics
=
taosArrayInit
(
topicNumGet
,
sizeof
(
SMqClientTopic
));
if
(
newTopics
==
NULL
)
{
return
false
;
}
SHashObj
*
pHash
=
taosHashInit
(
64
,
MurmurHash3_32
,
false
,
HASH_NO_LOCK
);
if
(
pHash
==
NULL
)
{
taosArrayDestroy
(
newTopics
);
return
false
;
}
// find topic, build hash
for
(
int32_t
i
=
0
;
i
<
topicNumGet
;
i
++
)
{
SMqClientTopic
topic
=
{
0
};
SMqClientTopic
topic
=
{
0
};
SMqSubTopicEp
*
pTopicEp
=
taosArrayGet
(
pRsp
->
topics
,
i
);
SMqSubTopicEp
*
pTopicEp
=
taosArrayGet
(
pRsp
->
topics
,
i
);
taosHashClear
(
pHash
);
topic
.
topicName
=
strdup
(
pTopicEp
->
topic
);
topic
.
topicName
=
strdup
(
pTopicEp
->
topic
);
int32_t
vgSz
=
taosArrayGetSize
(
pTopicEp
->
vgs
);
topic
.
vgs
=
taosArrayInit
(
vgSz
,
sizeof
(
SMqClientVg
));
int32_t
topicNumCur
=
taosArrayGetSize
(
tmq
->
clientTopics
);
for
(
int32_t
j
=
0
;
j
<
vgSz
;
j
++
)
{
for
(
int32_t
j
=
0
;
j
<
topicNumCur
;
j
++
)
{
// find old topic
SMqClientTopic
*
pTopicCur
=
taosArrayGet
(
tmq
->
clientTopics
,
j
);
if
(
pTopicCur
->
vgs
&&
strcmp
(
pTopicCur
->
topicName
,
pTopicEp
->
topic
)
==
0
)
{
int32_t
vgNumCur
=
taosArrayGetSize
(
pTopicCur
->
vgs
);
if
(
vgNumCur
==
0
)
break
;
for
(
int32_t
k
=
0
;
k
<
vgNumCur
;
k
++
)
{
SMqClientVg
*
pVgCur
=
taosArrayGet
(
pTopicCur
->
vgs
,
k
);
sprintf
(
vgKey
,
"%s:%d"
,
topic
.
topicName
,
pVgCur
->
vgId
);
taosHashPut
(
pHash
,
vgKey
,
strlen
(
vgKey
),
&
pVgCur
->
currentOffset
,
sizeof
(
int64_t
));
}
break
;
}
}
int32_t
vgNumGet
=
taosArrayGetSize
(
pTopicEp
->
vgs
);
topic
.
vgs
=
taosArrayInit
(
vgNumGet
,
sizeof
(
SMqClientVg
));
for
(
int32_t
j
=
0
;
j
<
vgNumGet
;
j
++
)
{
SMqSubVgEp
*
pVgEp
=
taosArrayGet
(
pTopicEp
->
vgs
,
j
);
SMqSubVgEp
*
pVgEp
=
taosArrayGet
(
pTopicEp
->
vgs
,
j
);
sprintf
(
vgKey
,
"%s:%d"
,
topic
.
topicName
,
pVgEp
->
vgId
);
int64_t
*
pOffset
=
taosHashGet
(
pHash
,
vgKey
,
strlen
(
vgKey
));
int64_t
offset
=
pVgEp
->
offset
;
if
(
pOffset
!=
NULL
)
{
offset
=
*
pOffset
;
}
SMqClientVg
clientVg
=
{
SMqClientVg
clientVg
=
{
.
pollCnt
=
0
,
.
pollCnt
=
0
,
.
currentOffset
=
pVgEp
->
offset
,
.
currentOffset
=
offset
,
.
vgId
=
pVgEp
->
vgId
,
.
vgId
=
pVgEp
->
vgId
,
.
epSet
=
pVgEp
->
epSet
,
.
epSet
=
pVgEp
->
epSet
,
.
vgStatus
=
TMQ_VG_STATUS__IDLE
,
.
vgStatus
=
TMQ_VG_STATUS__IDLE
,
...
@@ -922,6 +961,7 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) {
...
@@ -922,6 +961,7 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) {
taosArrayPush
(
newTopics
,
&
topic
);
taosArrayPush
(
newTopics
,
&
topic
);
}
}
if
(
tmq
->
clientTopics
)
taosArrayDestroy
(
tmq
->
clientTopics
);
if
(
tmq
->
clientTopics
)
taosArrayDestroy
(
tmq
->
clientTopics
);
taosHashCleanup
(
pHash
);
tmq
->
clientTopics
=
newTopics
;
tmq
->
clientTopics
=
newTopics
;
atomic_store_32
(
&
tmq
->
epoch
,
epoch
);
atomic_store_32
(
&
tmq
->
epoch
,
epoch
);
return
set
;
return
set
;
...
@@ -931,7 +971,7 @@ int32_t tmqAskEpCb(void* param, const SDataBuf* pMsg, int32_t code) {
...
@@ -931,7 +971,7 @@ int32_t tmqAskEpCb(void* param, const SDataBuf* pMsg, int32_t code) {
SMqAskEpCbParam
*
pParam
=
(
SMqAskEpCbParam
*
)
param
;
SMqAskEpCbParam
*
pParam
=
(
SMqAskEpCbParam
*
)
param
;
tmq_t
*
tmq
=
pParam
->
tmq
;
tmq_t
*
tmq
=
pParam
->
tmq
;
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
printf
(
"get topic endpoint error, not ready, wait:%d
\n
"
,
pParam
->
sync
);
tscError
(
"get topic endpoint error, not ready, wait:%d
\n
"
,
pParam
->
sync
);
goto
END
;
goto
END
;
}
}
...
@@ -1302,6 +1342,7 @@ tmq_message_t* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) {
...
@@ -1302,6 +1342,7 @@ tmq_message_t* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) {
while
(
1
)
{
while
(
1
)
{
/*printf("cycle\n");*/
/*printf("cycle\n");*/
tmqAskEp
(
tmq
,
false
);
tmqPollImpl
(
tmq
,
blocking_time
);
tmqPollImpl
(
tmq
,
blocking_time
);
tsem_wait
(
&
tmq
->
rspSem
);
tsem_wait
(
&
tmq
->
rspSem
);
...
...
source/dnode/mnode/impl/src/mndTopic.c
浏览文件 @
459ec6ed
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
#include "parser.h"
#include "parser.h"
#include "tname.h"
#include "tname.h"
#define MND_TOPIC_VER_NUMBER
1
#define MND_TOPIC_VER_NUMBER 1
#define MND_TOPIC_RESERVE_SIZE 64
#define MND_TOPIC_RESERVE_SIZE 64
static
int32_t
mndTopicActionInsert
(
SSdb
*
pSdb
,
SMqTopicObj
*
pTopic
);
static
int32_t
mndTopicActionInsert
(
SSdb
*
pSdb
,
SMqTopicObj
*
pTopic
);
...
@@ -293,7 +293,7 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq
...
@@ -293,7 +293,7 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq
topicObj
.
dbUid
=
pDb
->
uid
;
topicObj
.
dbUid
=
pDb
->
uid
;
topicObj
.
version
=
1
;
topicObj
.
version
=
1
;
topicObj
.
sql
=
pCreate
->
sql
;
topicObj
.
sql
=
pCreate
->
sql
;
topicObj
.
physicalPlan
=
""
;
topicObj
.
physicalPlan
=
NULL
;
topicObj
.
logicalPlan
=
""
;
topicObj
.
logicalPlan
=
""
;
topicObj
.
sqlLen
=
strlen
(
pCreate
->
sql
);
topicObj
.
sqlLen
=
strlen
(
pCreate
->
sql
);
...
@@ -302,9 +302,7 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq
...
@@ -302,9 +302,7 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq
mError
(
"topic:%s, failed to get plan since %s"
,
pCreate
->
name
,
terrstr
());
mError
(
"topic:%s, failed to get plan since %s"
,
pCreate
->
name
,
terrstr
());
return
-
1
;
return
-
1
;
}
}
if
(
NULL
!=
pPlanStr
)
{
topicObj
.
physicalPlan
=
pPlanStr
;
topicObj
.
physicalPlan
=
pPlanStr
;
}
SNode
*
pAst
=
NULL
;
SNode
*
pAst
=
NULL
;
if
(
nodesStringToNode
(
pCreate
->
ast
,
&
pAst
)
<
0
)
{
if
(
nodesStringToNode
(
pCreate
->
ast
,
&
pAst
)
<
0
)
{
...
...
tests/test/c/tmqDemo.c
浏览文件 @
459ec6ed
...
@@ -387,11 +387,12 @@ void perf_loop(tmq_t* tmq, tmq_list_t* topics, int32_t totalMsgs, int64_t walLog
...
@@ -387,11 +387,12 @@ void perf_loop(tmq_t* tmq, tmq_list_t* topics, int32_t totalMsgs, int64_t walLog
printf
(
"subscribe err
\n
"
);
printf
(
"subscribe err
\n
"
);
return
;
return
;
}
}
/*taosSsleep(3);*/
int32_t
batchCnt
=
0
;
int32_t
batchCnt
=
0
;
int32_t
skipLogNum
=
0
;
int32_t
skipLogNum
=
0
;
int64_t
startTime
=
taosGetTimestampUs
();
int64_t
startTime
=
taosGetTimestampUs
();
while
(
running
)
{
while
(
running
)
{
tmq_message_t
*
tmqmessage
=
tmq_consumer_poll
(
tmq
,
1
);
tmq_message_t
*
tmqmessage
=
tmq_consumer_poll
(
tmq
,
3000
);
if
(
tmqmessage
)
{
if
(
tmqmessage
)
{
batchCnt
++
;
batchCnt
++
;
skipLogNum
+=
tmqGetSkipLogNum
(
tmqmessage
);
skipLogNum
+=
tmqGetSkipLogNum
(
tmqmessage
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录