Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
584cdf04
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1185
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,发现更多精彩内容 >>
提交
584cdf04
编写于
4月 14, 2023
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
opti:the logic of mndDoRebalance for clear
上级
02ec67ad
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
49 addition
and
65 deletion
+49
-65
source/dnode/mnode/impl/src/mndSubscribe.c
source/dnode/mnode/impl/src/mndSubscribe.c
+49
-65
未找到文件。
source/dnode/mnode/impl/src/mndSubscribe.c
浏览文件 @
584cdf04
...
@@ -339,13 +339,13 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
...
@@ -339,13 +339,13 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
mInfo
(
"sub:%s mq re-balance %d vgroups, existed consumers:%d, added:%d, removed:%d"
,
pSubKey
,
totalVgNum
,
mInfo
(
"sub:%s mq re-balance %d vgroups, existed consumers:%d, added:%d, removed:%d"
,
pSubKey
,
totalVgNum
,
pInput
->
oldConsumerNum
,
numOfAdded
,
numOfRemoved
);
pInput
->
oldConsumerNum
,
numOfAdded
,
numOfRemoved
);
// 1. build temporary hash(vgId -> SMqRebOutputVg) to store
modified vg
// 1. build temporary hash(vgId -> SMqRebOutputVg) to store
vg that need to be assigned
SHashObj
*
pHash
=
taosHashInit
(
64
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
false
,
HASH_NO_LOCK
);
SHashObj
*
pHash
=
taosHashInit
(
64
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
false
,
HASH_NO_LOCK
);
// 2. check and get actual removed consumers, put their vg into
h
ash
// 2. check and get actual removed consumers, put their vg into
pH
ash
doRemoveExistedConsumers
(
pOutput
,
pHash
,
pInput
);
doRemoveExistedConsumers
(
pOutput
,
pHash
,
pInput
);
// 3. if previously no consumer, there are vgs not assigned
// 3. if previously no consumer, there are vgs not assigned
, put these vg into pHash
addUnassignedVgroups
(
pOutput
,
pHash
);
addUnassignedVgroups
(
pOutput
,
pHash
);
// 4. calc vg number of each consumer
// 4. calc vg number of each consumer
...
@@ -364,19 +364,17 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
...
@@ -364,19 +364,17 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
mInfo
(
"sub:%s no consumer subscribe this topic"
,
pSubKey
);
mInfo
(
"sub:%s no consumer subscribe this topic"
,
pSubKey
);
}
}
// 5. first scan: remove vgroups from te consumers, who have more vgroups than the threashold value that is
// 5. remove vgroups from consumers who have more vgroups than the threshold value(minVgCnt or minVgCnt + 1), and then another vg into pHash
// minVgCnt, and then put them into the recycled hash list
transferVgroupsForConsumers
(
pOutput
,
pHash
,
minVgCnt
,
imbConsumerNum
);
transferVgroupsForConsumers
(
pOutput
,
pHash
,
minVgCnt
,
imbConsumerNum
);
// 6. add new consumer into sub
// 6. add new consumer into sub
doAddNewConsumers
(
pOutput
,
pInput
);
doAddNewConsumers
(
pOutput
,
pInput
);
// 7. second scan: find consumer do not have enough vgroups, extract from temporary hash and assign to them
// All related vg should be put into rebVgs
SMqRebOutputVg
*
pRebVg
=
NULL
;
SMqRebOutputVg
*
pRebVg
=
NULL
;
void
*
pRemovedIter
=
NULL
;
void
*
pRemovedIter
=
NULL
;
void
*
pIter
=
NULL
;
void
*
pIter
=
NULL
;
// 7. extract bgroups from pHash and assign to consumers that do not have enough vgroups
while
(
1
)
{
while
(
1
)
{
pIter
=
taosHashIterate
(
pOutput
->
pSub
->
consumerHash
,
pIter
);
pIter
=
taosHashIterate
(
pOutput
->
pSub
->
consumerHash
,
pIter
);
if
(
pIter
==
NULL
)
{
if
(
pIter
==
NULL
)
{
...
@@ -390,68 +388,55 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
...
@@ -390,68 +388,55 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
// iter hash and find one vg
// iter hash and find one vg
pRemovedIter
=
taosHashIterate
(
pHash
,
pRemovedIter
);
pRemovedIter
=
taosHashIterate
(
pHash
,
pRemovedIter
);
if
(
pRemovedIter
==
NULL
)
{
if
(
pRemovedIter
==
NULL
)
{
mError
(
"sub:%s removed iter is null"
,
pSubKey
);
mError
(
"sub:%s removed iter is null
, never can reach hear
"
,
pSubKey
);
break
;
break
;
}
}
pRebVg
=
(
SMqRebOutputVg
*
)
pRemovedIter
;
pRebVg
=
(
SMqRebOutputVg
*
)
pRemovedIter
;
// push
taosArrayPush
(
pConsumerEp
->
vgs
,
&
pRebVg
->
pVgEp
);
pRebVg
->
newConsumerId
=
pConsumerEp
->
consumerId
;
pRebVg
->
newConsumerId
=
pConsumerEp
->
consumerId
;
taosArrayPush
(
pOutput
->
rebVgs
,
pRebVg
);
taosArrayPush
(
pConsumerEp
->
vgs
,
&
pRebVg
->
pVgEp
);
mInfo
(
"mq rebalance: add vgId:%d to consumer:0x%"
PRIx64
" (second scan) (not enough)"
,
pRebVg
->
pVgEp
->
vgId
,
mInfo
(
"mq rebalance: add vgId:%d to consumer:0x%"
PRIx64
" for average"
,
pRebVg
->
pVgEp
->
vgId
,
pConsumerEp
->
consumerId
);
pConsumerEp
->
consumerId
);
}
}
}
}
// 7. handle unassigned vg
if
(
imbConsumerNum
!=
0
)
{
if
(
taosHashGetSize
(
pOutput
->
pSub
->
consumerHash
)
!=
0
)
{
// if has consumer, assign all left vg
while
(
1
)
{
while
(
1
)
{
SMqConsumerEp
*
pConsumerEp
=
NULL
;
pIter
=
taosHashIterate
(
pOutput
->
pSub
->
consumerHash
,
pIter
);
pRemovedIter
=
taosHashIterate
(
pHash
,
pRemovedIter
);
if
(
pIter
==
NULL
)
{
if
(
pRemovedIter
==
NULL
)
{
if
(
pIter
!=
NULL
)
{
taosHashCancelIterate
(
pOutput
->
pSub
->
consumerHash
,
pIter
);
pIter
=
NULL
;
}
break
;
break
;
}
}
while
(
1
)
{
SMqConsumerEp
*
pConsumerEp
=
(
SMqConsumerEp
*
)
pIter
;
pIter
=
taosHashIterate
(
pOutput
->
pSub
->
consumerHash
,
pIter
);
pConsumerEp
=
(
SMqConsumerEp
*
)
pIter
;
if
(
taosArrayGetSize
(
pConsumerEp
->
vgs
)
==
minVgCnt
)
{
if
(
taosArrayGetSize
(
pConsumerEp
->
vgs
)
==
minVgCnt
)
{
pRemovedIter
=
taosHashIterate
(
pHash
,
pRemovedIter
);
if
(
pRemovedIter
==
NULL
)
{
mError
(
"sub:%s removed iter is null"
,
pSubKey
);
break
;
break
;
}
}
}
pRebVg
=
(
SMqRebOutputVg
*
)
pRemovedIter
;
pRebVg
=
(
SMqRebOutputVg
*
)
pRemovedIter
;
taosArrayPush
(
pConsumerEp
->
vgs
,
&
pRebVg
->
pVgEp
);
pRebVg
->
newConsumerId
=
pConsumerEp
->
consumerId
;
pRebVg
->
newConsumerId
=
pConsumerEp
->
consumerId
;
if
(
pRebVg
->
newConsumerId
==
pRebVg
->
oldConsumerId
)
{
taosArrayPush
(
pConsumerEp
->
vgs
,
&
pRebVg
->
pVgEp
);
mInfo
(
"mq rebalance: skip vg %d for same consumer:0x%"
PRIx64
" (second scan)"
,
pRebVg
->
pVgEp
->
vgId
,
mInfo
(
"mq rebalance: add vgId:%d to consumer:0x%"
PRIx64
" for average + 1"
,
pRebVg
->
pVgEp
->
vgId
,
pConsumerEp
->
consumerId
);
pConsumerEp
->
consumerId
);
continue
;
}
}
taosArrayPush
(
pOutput
->
rebVgs
,
pRebVg
);
mInfo
(
"mq rebalance: add vgId:%d to consumer:0x%"
PRIx64
" (second scan) (unassigned)"
,
pRebVg
->
pVgEp
->
vgId
,
pConsumerEp
->
consumerId
);
}
}
}
else
{
// if all consumer is removed, put all vg into unassigned
}
pIter
=
NULL
;
SMqRebOutputVg
*
pRebOutput
=
NULL
;
// All assigned vg should be put into pOutput->rebVgs
if
(
pRemovedIter
!=
NULL
){
mError
(
"sub:%s pRemovedIter should be NULL"
,
pSubKey
);
}
while
(
1
)
{
while
(
1
)
{
pIter
=
taosHashIterate
(
pHash
,
p
Iter
);
pRemovedIter
=
taosHashIterate
(
pHash
,
pRemoved
Iter
);
if
(
p
Iter
==
NULL
)
{
if
(
pRemoved
Iter
==
NULL
)
{
break
;
break
;
}
}
pRebOutput
=
(
SMqRebOutputVg
*
)
pIter
;
SMqRebOutputVg
*
pRebOutput
=
(
SMqRebOutputVg
*
)
pRemovedIter
;
taosArrayPush
(
pOutput
->
pSub
->
unassignedVgs
,
&
pRebOutput
->
pVgEp
);
taosArrayPush
(
pOutput
->
rebVgs
,
pRebOutput
);
taosArrayPush
(
pOutput
->
rebVgs
,
pRebOutput
);
mInfo
(
"sub:%s mq re-balance unassign vgId:%d (second scan)"
,
pSubKey
,
pRebOutput
->
pVgEp
->
vgId
);
if
(
taosHashGetSize
(
pOutput
->
pSub
->
consumerHash
)
==
0
){
// if all consumer is removed, put all vg into unassigned
taosArrayPush
(
pOutput
->
pSub
->
unassignedVgs
,
&
pRebOutput
->
pVgEp
);
}
}
}
}
...
@@ -462,7 +447,7 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
...
@@ -462,7 +447,7 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
mInfo
(
"sub:%s mq re-balance vgId:%d, moved from consumer:0x%"
PRIx64
", to consumer:0x%"
PRIx64
,
pSubKey
,
mInfo
(
"sub:%s mq re-balance vgId:%d, moved from consumer:0x%"
PRIx64
", to consumer:0x%"
PRIx64
,
pSubKey
,
pOutputRebVg
->
pVgEp
->
vgId
,
pOutputRebVg
->
oldConsumerId
,
pOutputRebVg
->
newConsumerId
);
pOutputRebVg
->
pVgEp
->
vgId
,
pOutputRebVg
->
oldConsumerId
,
pOutputRebVg
->
newConsumerId
);
}
}
{
pIter
=
NULL
;
pIter
=
NULL
;
while
(
1
)
{
while
(
1
)
{
pIter
=
taosHashIterate
(
pOutput
->
pSub
->
consumerHash
,
pIter
);
pIter
=
taosHashIterate
(
pOutput
->
pSub
->
consumerHash
,
pIter
);
...
@@ -476,7 +461,6 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
...
@@ -476,7 +461,6 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
pConsumerEp
->
consumerId
);
pConsumerEp
->
consumerId
);
}
}
}
}
}
// 9. clear
// 9. clear
taosHashCleanup
(
pHash
);
taosHashCleanup
(
pHash
);
...
@@ -653,13 +637,13 @@ static int32_t mndProcessRebalanceReq(SRpcMsg *pMsg) {
...
@@ -653,13 +637,13 @@ static int32_t mndProcessRebalanceReq(SRpcMsg *pMsg) {
mndReleaseTopic
(
pMnode
,
pTopic
);
mndReleaseTopic
(
pMnode
,
pTopic
);
rebInput
.
oldConsumerNum
=
0
;
rebInput
.
oldConsumerNum
=
0
;
mInfo
(
"
topic:%s has no consumers sub yet"
,
topic
);
mInfo
(
"
sub topic:%s has no consumers sub yet"
,
pRebInfo
->
key
);
}
else
{
}
else
{
taosRLockLatch
(
&
pSub
->
lock
);
taosRLockLatch
(
&
pSub
->
lock
);
rebInput
.
oldConsumerNum
=
taosHashGetSize
(
pSub
->
consumerHash
);
rebInput
.
oldConsumerNum
=
taosHashGetSize
(
pSub
->
consumerHash
);
rebOutput
.
pSub
=
tCloneSubscribeObj
(
pSub
);
rebOutput
.
pSub
=
tCloneSubscribeObj
(
pSub
);
taosRUnLockLatch
(
&
pSub
->
lock
);
taosRUnLockLatch
(
&
pSub
->
lock
);
mInfo
(
"topic:%s has %d consumers sub till now"
,
pRebInfo
->
key
,
rebInput
.
oldConsumerNum
);
mInfo
(
"
sub
topic:%s has %d consumers sub till now"
,
pRebInfo
->
key
,
rebInput
.
oldConsumerNum
);
mndReleaseSubscribe
(
pMnode
,
pSub
);
mndReleaseSubscribe
(
pMnode
,
pSub
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录