Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
18993d50
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看板
提交
18993d50
编写于
6月 17, 2022
作者:
L
Liu Jicong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(tmq): offset storage
上级
aef7c7eb
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
48 addition
and
23 deletion
+48
-23
source/client/src/tmq.c
source/client/src/tmq.c
+33
-16
source/dnode/vnode/src/tq/tq.c
source/dnode/vnode/src/tq/tq.c
+14
-7
tests/test/c/tmqSim.c
tests/test/c/tmqSim.c
+1
-0
未找到文件。
source/client/src/tmq.c
浏览文件 @
18993d50
...
@@ -376,6 +376,9 @@ int32_t tmqCommitCb2(void* param, const SDataBuf* pBuf, int32_t code) {
...
@@ -376,6 +376,9 @@ int32_t tmqCommitCb2(void* param, const SDataBuf* pBuf, int32_t code) {
}
}
#endif
#endif
/*tscDebug("receive offset commit cb of %s on vg %d, offset is %ld", pParam->pOffset->subKey, pParam->->vgId,
* pOffset->version);*/
// count down waiting rsp
// count down waiting rsp
int32_t
waitingRspNum
=
atomic_sub_fetch_32
(
&
pParamSet
->
waitingRspNum
,
1
);
int32_t
waitingRspNum
=
atomic_sub_fetch_32
(
&
pParamSet
->
waitingRspNum
,
1
);
ASSERT
(
waitingRspNum
>=
0
);
ASSERT
(
waitingRspNum
>=
0
);
...
@@ -421,10 +424,20 @@ int32_t tmqCommitInner2(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, int8
...
@@ -421,10 +424,20 @@ int32_t tmqCommitInner2(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, int8
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
tmq
->
clientTopics
);
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
tmq
->
clientTopics
);
i
++
)
{
SMqClientTopic
*
pTopic
=
taosArrayGet
(
tmq
->
clientTopics
,
i
);
SMqClientTopic
*
pTopic
=
taosArrayGet
(
tmq
->
clientTopics
,
i
);
tscDebug
(
"consumer %ld begin commit for topic %s, vgNum %d"
,
tmq
->
consumerId
,
pTopic
->
topicName
,
(
int32_t
)
taosArrayGetSize
(
pTopic
->
vgs
));
for
(
int32_t
j
=
0
;
j
<
taosArrayGetSize
(
pTopic
->
vgs
);
j
++
)
{
for
(
int32_t
j
=
0
;
j
<
taosArrayGetSize
(
pTopic
->
vgs
);
j
++
)
{
SMqClientVg
*
pVg
=
taosArrayGet
(
pTopic
->
vgs
,
i
);
SMqClientVg
*
pVg
=
taosArrayGet
(
pTopic
->
vgs
,
j
);
if
(
pVg
->
currentOffset
<
0
)
{
/*if (pVg->currentOffset < 0 || pVg->committedOffset == pVg->currentOffset) {*/
tscDebug
(
"consumer %ld begin commit for topic %s, vgId %d"
,
tmq
->
consumerId
,
pTopic
->
topicName
,
pVg
->
vgId
);
/*if (pVg->currentOffset < 0) {*/
if
(
pVg
->
currentOffset
<
0
||
pVg
->
committedOffset
==
pVg
->
currentOffset
)
{
tscDebug
(
"consumer %ld skip commit for topic %s vg %d, current offset is %ld, committed offset is %ld"
,
tmq
->
consumerId
,
pTopic
->
topicName
,
pVg
->
vgId
,
pVg
->
currentOffset
,
pVg
->
committedOffset
);
continue
;
continue
;
}
}
STqOffset
*
pOffset
=
taosMemoryCalloc
(
1
,
sizeof
(
STqOffset
));
STqOffset
*
pOffset
=
taosMemoryCalloc
(
1
,
sizeof
(
STqOffset
));
...
@@ -434,10 +447,12 @@ int32_t tmqCommitInner2(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, int8
...
@@ -434,10 +447,12 @@ int32_t tmqCommitInner2(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, int8
}
}
pOffset
->
type
=
TMQ_OFFSET__LOG
;
pOffset
->
type
=
TMQ_OFFSET__LOG
;
pOffset
->
version
=
pVg
->
currentOffset
;
pOffset
->
version
=
pVg
->
currentOffset
;
int32_t
tlen
=
strlen
(
tmq
->
groupId
);
memcpy
(
pOffset
->
subKey
,
tmq
->
groupId
,
tlen
);
int32_t
groupLen
=
strlen
(
tmq
->
groupId
);
pOffset
->
subKey
[
tlen
]
=
TMQ_SEPARATOR
;
memcpy
(
pOffset
->
subKey
,
tmq
->
groupId
,
groupLen
);
strcpy
(
pOffset
->
subKey
+
tlen
+
1
,
pTopic
->
topicName
);
pOffset
->
subKey
[
groupLen
]
=
TMQ_SEPARATOR
;
strcpy
(
pOffset
->
subKey
+
groupLen
+
1
,
pTopic
->
topicName
);
int32_t
len
;
int32_t
len
;
int32_t
code
;
int32_t
code
;
tEncodeSize
(
tEncodeSTqOffset
,
pOffset
,
len
,
code
);
tEncodeSize
(
tEncodeSTqOffset
,
pOffset
,
len
,
code
);
...
@@ -470,6 +485,9 @@ int32_t tmqCommitInner2(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, int8
...
@@ -470,6 +485,9 @@ int32_t tmqCommitInner2(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, int8
.
handle
=
NULL
,
.
handle
=
NULL
,
};
};
tscDebug
(
"consumer %ld commit offset of %s on vg %d, offset is %ld"
,
tmq
->
consumerId
,
pOffset
->
subKey
,
pVg
->
vgId
,
pOffset
->
version
);
// TODO: put into cb
// TODO: put into cb
pVg
->
committedOffset
=
pVg
->
currentOffset
;
pVg
->
committedOffset
=
pVg
->
currentOffset
;
...
@@ -1039,14 +1057,13 @@ bool tmqUpdateEp2(tmq_t* tmq, int32_t epoch, SMqAskEpRsp* pRsp) {
...
@@ -1039,14 +1057,13 @@ bool tmqUpdateEp2(tmq_t* tmq, int32_t epoch, SMqAskEpRsp* pRsp) {
if
(
pTopicCur
->
vgs
)
{
if
(
pTopicCur
->
vgs
)
{
int32_t
vgNumCur
=
taosArrayGetSize
(
pTopicCur
->
vgs
);
int32_t
vgNumCur
=
taosArrayGetSize
(
pTopicCur
->
vgs
);
tscDebug
(
"consumer %ld new vg num: %d"
,
tmq
->
consumerId
,
vgNumCur
);
tscDebug
(
"consumer %ld new vg num: %d"
,
tmq
->
consumerId
,
vgNumCur
);
if
(
vgNumCur
==
0
)
break
;
for
(
int32_t
j
=
0
;
j
<
vgNumCur
;
j
++
)
{
for
(
int32_t
j
=
0
;
j
<
vgNumCur
;
j
++
)
{
SMqClientVg
*
pVgCur
=
taosArrayGet
(
pTopicCur
->
vgs
,
j
);
SMqClientVg
*
pVgCur
=
taosArrayGet
(
pTopicCur
->
vgs
,
j
);
sprintf
(
vgKey
,
"%s:%d"
,
pTopicCur
->
topicName
,
pVgCur
->
vgId
);
sprintf
(
vgKey
,
"%s:%d"
,
pTopicCur
->
topicName
,
pVgCur
->
vgId
);
tscDebug
(
"consumer %ld epoch %d vg %d build %s"
,
tmq
->
consumerId
,
epoch
,
pVgCur
->
vgId
,
vgKey
);
tscDebug
(
"consumer %ld epoch %d vg %d vgKey is %s, offset is %ld"
,
tmq
->
consumerId
,
epoch
,
pVgCur
->
vgId
,
vgKey
,
pVgCur
->
currentOffset
);
taosHashPut
(
pHash
,
vgKey
,
strlen
(
vgKey
),
&
pVgCur
->
currentOffset
,
sizeof
(
int64_t
));
taosHashPut
(
pHash
,
vgKey
,
strlen
(
vgKey
),
&
pVgCur
->
currentOffset
,
sizeof
(
int64_t
));
}
}
break
;
}
}
}
}
...
@@ -1054,7 +1071,6 @@ bool tmqUpdateEp2(tmq_t* tmq, int32_t epoch, SMqAskEpRsp* pRsp) {
...
@@ -1054,7 +1071,6 @@ bool tmqUpdateEp2(tmq_t* tmq, int32_t epoch, SMqAskEpRsp* pRsp) {
SMqClientTopic
topic
=
{
0
};
SMqClientTopic
topic
=
{
0
};
SMqSubTopicEp
*
pTopicEp
=
taosArrayGet
(
pRsp
->
topics
,
i
);
SMqSubTopicEp
*
pTopicEp
=
taosArrayGet
(
pRsp
->
topics
,
i
);
topic
.
schema
=
pTopicEp
->
schema
;
topic
.
schema
=
pTopicEp
->
schema
;
taosHashClear
(
pHash
);
topic
.
topicName
=
strdup
(
pTopicEp
->
topic
);
topic
.
topicName
=
strdup
(
pTopicEp
->
topic
);
tstrncpy
(
topic
.
db
,
pTopicEp
->
db
,
TSDB_DB_FNAME_LEN
);
tstrncpy
(
topic
.
db
,
pTopicEp
->
db
,
TSDB_DB_FNAME_LEN
);
...
@@ -1071,7 +1087,8 @@ bool tmqUpdateEp2(tmq_t* tmq, int32_t epoch, SMqAskEpRsp* pRsp) {
...
@@ -1071,7 +1087,8 @@ bool tmqUpdateEp2(tmq_t* tmq, int32_t epoch, SMqAskEpRsp* pRsp) {
offset
=
*
pOffset
;
offset
=
*
pOffset
;
}
}
tscDebug
(
"consumer %ld(epoch %d) offset of vg %d updated to %ld"
,
tmq
->
consumerId
,
epoch
,
pVgEp
->
vgId
,
offset
);
tscDebug
(
"consumer %ld(epoch %d) offset of vg %d updated to %ld, vgKey is %s"
,
tmq
->
consumerId
,
epoch
,
pVgEp
->
vgId
,
offset
,
vgKey
);
SMqClientVg
clientVg
=
{
SMqClientVg
clientVg
=
{
.
pollCnt
=
0
,
.
pollCnt
=
0
,
.
currentOffset
=
offset
,
.
currentOffset
=
offset
,
...
@@ -1350,10 +1367,10 @@ SMqPollReq* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t timeout, SMqClientTopic*
...
@@ -1350,10 +1367,10 @@ SMqPollReq* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t timeout, SMqClientTopic*
/*strcpy(pReq->topic, pTopic->topicName);*/
/*strcpy(pReq->topic, pTopic->topicName);*/
/*strcpy(pReq->cgroup, tmq->groupId);*/
/*strcpy(pReq->cgroup, tmq->groupId);*/
int32_t
tl
en
=
strlen
(
tmq
->
groupId
);
int32_t
groupL
en
=
strlen
(
tmq
->
groupId
);
memcpy
(
pReq
->
subKey
,
tmq
->
groupId
,
tl
en
);
memcpy
(
pReq
->
subKey
,
tmq
->
groupId
,
groupL
en
);
pReq
->
subKey
[
tl
en
]
=
TMQ_SEPARATOR
;
pReq
->
subKey
[
groupL
en
]
=
TMQ_SEPARATOR
;
strcpy
(
pReq
->
subKey
+
tl
en
+
1
,
pTopic
->
topicName
);
strcpy
(
pReq
->
subKey
+
groupL
en
+
1
,
pTopic
->
topicName
);
pReq
->
withTbName
=
tmq
->
withTbName
;
pReq
->
withTbName
=
tmq
->
withTbName
;
pReq
->
timeout
=
timeout
;
pReq
->
timeout
=
timeout
;
...
...
source/dnode/vnode/src/tq/tq.c
浏览文件 @
18993d50
...
@@ -124,17 +124,20 @@ int32_t tqProcessOffsetCommitReq(STQ* pTq, char* msg, int32_t msgLen) {
...
@@ -124,17 +124,20 @@ int32_t tqProcessOffsetCommitReq(STQ* pTq, char* msg, int32_t msgLen) {
tDecoderClear
(
&
decoder
);
tDecoderClear
(
&
decoder
);
if
(
offset
.
type
==
TMQ_OFFSET__SNAPSHOT
)
{
if
(
offset
.
type
==
TMQ_OFFSET__SNAPSHOT
)
{
tqDebug
(
"receive offset commit msg to %s
, offset(type:snapshot) uid: %ld, ts: %ld"
,
offset
.
subKey
,
offset
.
uid
,
tqDebug
(
"receive offset commit msg to %s
on vg %d, offset(type:snapshot) uid: %ld, ts: %ld"
,
offset
.
subKey
,
offset
.
ts
);
pTq
->
pVnode
->
config
.
vgId
,
offset
.
uid
,
offset
.
ts
);
}
else
if
(
offset
.
type
==
TMQ_OFFSET__LOG
)
{
}
else
if
(
offset
.
type
==
TMQ_OFFSET__LOG
)
{
tqDebug
(
"receive offset commit msg to %s, offset(type:log) version: %ld"
,
offset
.
subKey
,
offset
.
version
);
tqDebug
(
"receive offset commit msg to %s on vg %d, offset(type:log) version: %ld"
,
offset
.
subKey
,
pTq
->
pVnode
->
config
.
vgId
,
offset
.
version
);
}
else
{
}
else
{
ASSERT
(
0
);
ASSERT
(
0
);
}
}
STqOffset
*
pOffset
=
tqOffsetRead
(
pTq
->
pOffsetStore
,
offset
.
subKey
);
if
(
tqOffsetWrite
(
pTq
->
pOffsetStore
,
&
offset
)
<
0
)
{
if
(
pOffset
==
NULL
||
pOffset
->
version
<
offset
.
version
)
{
ASSERT
(
0
);
if
(
tqOffsetWrite
(
pTq
->
pOffsetStore
,
&
offset
)
<
0
)
{
return
-
1
;
ASSERT
(
0
);
return
-
1
;
}
}
}
return
0
;
return
0
;
...
@@ -155,6 +158,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
...
@@ -155,6 +158,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
STqOffset
*
pOffset
=
tqOffsetRead
(
pTq
->
pOffsetStore
,
pReq
->
subKey
);
STqOffset
*
pOffset
=
tqOffsetRead
(
pTq
->
pOffsetStore
,
pReq
->
subKey
);
if
(
pOffset
!=
NULL
)
{
if
(
pOffset
!=
NULL
)
{
ASSERT
(
pOffset
->
type
==
TMQ_OFFSET__LOG
);
ASSERT
(
pOffset
->
type
==
TMQ_OFFSET__LOG
);
tqDebug
(
"consumer %ld, restore offset of %s on vg %d, offset(type:log) version: %ld"
,
consumerId
,
pReq
->
subKey
,
pTq
->
pVnode
->
config
.
vgId
,
pOffset
->
version
);
fetchOffset
=
pOffset
->
version
+
1
;
fetchOffset
=
pOffset
->
version
+
1
;
}
else
{
}
else
{
if
(
pReq
->
currentOffset
==
TMQ_CONF__RESET_OFFSET__EARLIEAST
)
{
if
(
pReq
->
currentOffset
==
TMQ_CONF__RESET_OFFSET__EARLIEAST
)
{
...
@@ -166,6 +171,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
...
@@ -166,6 +171,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
pTq
->
pVnode
->
config
.
vgId
,
pReq
->
subKey
);
pTq
->
pVnode
->
config
.
vgId
,
pReq
->
subKey
);
return
-
1
;
return
-
1
;
}
}
tqDebug
(
"consumer %ld, restore offset of %s on vg %d failed, config is %ld, set to %ld"
,
consumerId
,
pReq
->
subKey
,
pTq
->
pVnode
->
config
.
vgId
,
pReq
->
currentOffset
,
fetchOffset
);
}
}
}
}
...
...
tests/test/c/tmqSim.c
浏览文件 @
18993d50
...
@@ -513,6 +513,7 @@ void* consumeThreadFunc(void* param) {
...
@@ -513,6 +513,7 @@ void* consumeThreadFunc(void* param) {
/*tmq_commit(pInfo->tmq, NULL, 0);*/
/*tmq_commit(pInfo->tmq, NULL, 0);*/
tmq_commit_sync
(
pInfo
->
tmq
,
NULL
);
tmq_commit_sync
(
pInfo
->
tmq
,
NULL
);
taosFprintfFile
(
g_fp
,
"tmq_commit() manual commit over.
\n
"
);
taosFprintfFile
(
g_fp
,
"tmq_commit() manual commit over.
\n
"
);
pPrint
(
"tmq_commit() manual commit over.
\n
"
);
}
}
err
=
tmq_unsubscribe
(
pInfo
->
tmq
);
err
=
tmq_unsubscribe
(
pInfo
->
tmq
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录