Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ce6459a9
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ce6459a9
编写于
4月 21, 2022
作者:
L
Liu Jicong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(tmq): rebalance
上级
558edd37
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
62 addition
and
23 deletion
+62
-23
source/dnode/mnode/impl/inc/mndOffset.h
source/dnode/mnode/impl/inc/mndOffset.h
+1
-1
source/dnode/mnode/impl/src/mndOffset.c
source/dnode/mnode/impl/src/mndOffset.c
+13
-5
source/dnode/mnode/impl/src/mndSubscribe.c
source/dnode/mnode/impl/src/mndSubscribe.c
+32
-4
source/dnode/vnode/src/tq/tq.c
source/dnode/vnode/src/tq/tq.c
+16
-13
未找到文件。
source/dnode/mnode/impl/inc/mndOffset.h
浏览文件 @
ce6459a9
...
...
@@ -31,7 +31,7 @@ void mndReleaseOffset(SMnode *pMnode, SMqOffsetObj *pOffset);
SSdbRaw
*
mndOffsetActionEncode
(
SMqOffsetObj
*
pOffset
);
SSdbRow
*
mndOffsetActionDecode
(
SSdbRaw
*
pRaw
);
int32_t
mndCreateOffset
(
STrans
*
pTrans
,
const
char
*
cgroup
,
const
char
*
topicName
,
const
SArray
*
vgs
);
int32_t
mndCreateOffset
s
(
STrans
*
pTrans
,
const
char
*
cgroup
,
const
char
*
topicName
,
const
SArray
*
vgs
);
static
FORCE_INLINE
int32_t
mndMakePartitionKey
(
char
*
key
,
const
char
*
cgroup
,
const
char
*
topicName
,
int32_t
vgId
)
{
return
snprintf
(
key
,
TSDB_PARTITION_KEY_LEN
,
"%d:%s:%s"
,
vgId
,
cgroup
,
topicName
);
...
...
source/dnode/mnode/impl/src/mndOffset.c
浏览文件 @
ce6459a9
...
...
@@ -130,8 +130,7 @@ OFFSET_DECODE_OVER:
return
pRow
;
}
int32_t
mndCreateOffset
(
STrans
*
pTrans
,
const
char
*
cgroup
,
const
char
*
topicName
,
const
SArray
*
vgs
)
{
int32_t
code
=
0
;
int32_t
mndCreateOffsets
(
STrans
*
pTrans
,
const
char
*
cgroup
,
const
char
*
topicName
,
const
SArray
*
vgs
)
{
int32_t
sz
=
taosArrayGetSize
(
vgs
);
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
SMqConsumerEp
*
pConsumerEp
=
taosArrayGet
(
vgs
,
i
);
...
...
@@ -170,13 +169,22 @@ static int32_t mndProcessCommitOffsetReq(SNodeMsg *pMsg) {
if
(
mndMakePartitionKey
(
key
,
pOffset
->
cgroup
,
pOffset
->
topicName
,
pOffset
->
vgId
)
<
0
)
{
return
-
1
;
}
bool
create
=
false
;
SMqOffsetObj
*
pOffsetObj
=
mndAcquireOffset
(
pMnode
,
key
);
ASSERT
(
pOffsetObj
);
if
(
pOffsetObj
==
NULL
)
{
pOffsetObj
=
taosMemoryMalloc
(
sizeof
(
SMqOffset
));
memcpy
(
pOffsetObj
->
key
,
key
,
TSDB_PARTITION_KEY_LEN
);
create
=
true
;
}
pOffsetObj
->
offset
=
pOffset
->
offset
;
SSdbRaw
*
pOffsetRaw
=
mndOffsetActionEncode
(
pOffsetObj
);
sdbSetRawStatus
(
pOffsetRaw
,
SDB_STATUS_READY
);
mndTransAppendRedolog
(
pTrans
,
pOffsetRaw
);
mndReleaseOffset
(
pMnode
,
pOffsetObj
);
if
(
create
)
{
taosMemoryFree
(
pOffsetObj
);
}
else
{
mndReleaseOffset
(
pMnode
,
pOffsetObj
);
}
}
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
{
...
...
@@ -201,7 +209,7 @@ static int32_t mndOffsetActionDelete(SSdb *pSdb, SMqOffsetObj *pOffset) {
static
int32_t
mndOffsetActionUpdate
(
SSdb
*
pSdb
,
SMqOffsetObj
*
pOldOffset
,
SMqOffsetObj
*
pNewOffset
)
{
mTrace
(
"offset:%s, perform update action"
,
pOldOffset
->
key
);
pOldOffset
->
offset
=
pNewOffset
->
offset
;
atomic_store_64
(
&
pOldOffset
->
offset
,
pNewOffset
->
offset
)
;
return
0
;
}
...
...
source/dnode/mnode/impl/src/mndSubscribe.c
浏览文件 @
ce6459a9
...
...
@@ -813,6 +813,20 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
SMqConsumerEpInSub
*
pEpInSub
=
(
SMqConsumerEpInSub
*
)
pIter
;
if
(
pEpInSub
->
consumerId
==
-
1
)
continue
;
ASSERT
(
pEpInSub
->
consumerId
>
0
);
// push until equal minVg
while
(
taosArrayGetSize
(
pEpInSub
->
vgs
)
<
minVgCnt
)
{
// iter hash and find one vg
pRemovedIter
=
taosHashIterate
(
pHash
,
pRemovedIter
);
ASSERT
(
pRemovedIter
);
pRebVg
=
(
SMqRebOutputVg
*
)
pRemovedIter
;
// push
taosArrayPush
(
pEpInSub
->
vgs
,
&
pRebVg
->
pVgEp
);
pRebVg
->
newConsumerId
=
pEpInSub
->
consumerId
;
taosArrayPush
(
pOutput
->
rebVgs
,
pRebVg
);
}
#if 0
/*int32_t consumerVgNum = taosArrayGetSize(pEpInSub->vgs);*/
if (imbCnt < imbConsumerNum) {
imbCnt++;
...
...
@@ -840,13 +854,25 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
taosArrayPush(pOutput->rebVgs, pRebVg);
}
}
#endif
}
// 7. handle unassigned vg
if
(
taosHashGetSize
(
pOutput
->
pSub
->
consumerHash
)
!=
1
)
{
// if has consumer, vg should be all assigned
pRemovedIter
=
taosHashIterate
(
pHash
,
pRemovedIter
);
ASSERT
(
pRemovedIter
==
NULL
);
// if has consumer, assign all left vg
while
(
1
)
{
pRemovedIter
=
taosHashIterate
(
pHash
,
pRemovedIter
);
if
(
pRemovedIter
==
NULL
)
break
;
pIter
=
taosHashIterate
(
pOutput
->
pSub
->
consumerHash
,
pIter
);
ASSERT
(
pIter
);
pRebVg
=
(
SMqRebOutputVg
*
)
pRemovedIter
;
SMqConsumerEpInSub
*
pEpInSub
=
(
SMqConsumerEpInSub
*
)
pIter
;
if
(
pEpInSub
->
consumerId
==
-
1
)
continue
;
ASSERT
(
pEpInSub
->
consumerId
>
0
);
taosArrayPush
(
pEpInSub
->
vgs
,
&
pRebVg
->
pVgEp
);
pRebVg
->
newConsumerId
=
pEpInSub
->
consumerId
;
taosArrayPush
(
pOutput
->
rebVgs
,
pRebVg
);
}
}
else
{
// if all consumer is removed, put all vg into unassigned
int64_t
unexistKey
=
-
1
;
...
...
@@ -992,7 +1018,9 @@ static int32_t mndProcessRebalanceReq(SNodeMsg *pMsg) {
// TODO replace assert with error check
ASSERT
(
mndDoRebalance
(
pMnode
,
&
rebInput
,
&
rebOutput
)
==
0
);
ASSERT
(
taosArrayGetSize
(
rebOutput
.
rebVgs
)
!=
0
);
// if add more consumer to balanced subscribe,
// possibly no vg is changed
/*ASSERT(taosArrayGetSize(rebOutput.rebVgs) != 0);*/
ASSERT
(
mndPersistRebResult
(
pMnode
,
pMsg
,
&
rebOutput
)
==
0
);
if
(
rebInput
.
pTopic
)
{
...
...
source/dnode/vnode/src/tq/tq.c
浏览文件 @
ce6459a9
...
...
@@ -355,6 +355,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
TD_VID
(
pTq
->
pVnode
),
fetchOffset
,
consumerId
,
pReq
->
epoch
,
rsp
.
blockNum
,
rsp
.
reqOffset
,
rsp
.
rspOffset
);
// TODO destroy
taosArrayDestroy
(
rsp
.
blockData
);
taosArrayDestroy
(
rsp
.
blockDataLen
);
return
0
;
}
...
...
@@ -599,19 +601,20 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) {
taosHashPut
(
pTq
->
tqMetaNew
,
req
.
subKey
,
strlen
(
req
.
subKey
),
pExec
,
sizeof
(
STqExec
));
return
0
;
}
else
{
if
(
req
.
newConsumerId
!=
-
1
)
{
/*taosWLockLatch(&pExec->lock);*/
ASSERT
(
pExec
->
consumerId
==
req
.
oldConsumerId
);
// TODO handle qmsg and exec modification
atomic_store_64
(
&
pExec
->
consumerId
,
req
.
newConsumerId
);
atomic_add_fetch_32
(
&
pExec
->
epoch
,
1
);
/*taosWUnLockLatch(&pExec->lock);*/
return
0
;
}
else
{
// TODO
/*taosHashRemove(pTq->tqMetaNew, req.subKey, strlen(req.subKey));*/
return
0
;
}
/*if (req.newConsumerId != -1) {*/
/*taosWLockLatch(&pExec->lock);*/
ASSERT
(
pExec
->
consumerId
==
req
.
oldConsumerId
);
// TODO handle qmsg and exec modification
atomic_store_32
(
&
pExec
->
epoch
,
-
1
);
atomic_store_64
(
&
pExec
->
consumerId
,
req
.
newConsumerId
);
atomic_add_fetch_32
(
&
pExec
->
epoch
,
1
);
/*taosWUnLockLatch(&pExec->lock);*/
return
0
;
/*} else {*/
// TODO
/*taosHashRemove(pTq->tqMetaNew, req.subKey, strlen(req.subKey));*/
/*return 0;*/
/*}*/
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录