Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5b25920f
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5b25920f
编写于
5月 02, 2023
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: do some internal refactor.
上级
79342cf1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
57 addition
and
39 deletion
+57
-39
source/dnode/mnode/impl/src/mndConsumer.c
source/dnode/mnode/impl/src/mndConsumer.c
+40
-25
source/dnode/mnode/impl/src/mndSubscribe.c
source/dnode/mnode/impl/src/mndSubscribe.c
+17
-14
未找到文件。
source/dnode/mnode/impl/src/mndConsumer.c
浏览文件 @
5b25920f
...
...
@@ -672,7 +672,6 @@ int32_t mndProcessSubscribeReq(SRpcMsg *pMsg) {
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
goto
_over
;
}
else
{
/*taosRLockLatch(&pExistedConsumer->lock);*/
int32_t
status
=
atomic_load_32
(
&
pExistedConsumer
->
status
);
mInfo
(
"receive subscribe request from existed consumer:0x%"
PRIx64
...
...
@@ -881,7 +880,7 @@ static void updateConsumerStatus(SMqConsumerObj *pConsumer) {
// remove from new topic
static
void
removeFromNewTopicList
(
SMqConsumerObj
*
pConsumer
,
const
char
*
pTopic
)
{
int32_t
size
=
taosArrayGetSize
(
pConsumer
->
rebNewTopics
);
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pConsumer
->
rebNewTopics
)
;
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
size
;
i
++
)
{
char
*
p
=
taosArrayGetP
(
pConsumer
->
rebNewTopics
,
i
);
if
(
strcmp
(
pTopic
,
p
)
==
0
)
{
taosArrayRemove
(
pConsumer
->
rebNewTopics
,
i
);
...
...
@@ -902,9 +901,42 @@ static void removeFromRemoveTopicList(SMqConsumerObj *pConsumer, const char *pTo
if
(
strcmp
(
pTopic
,
p
)
==
0
)
{
taosArrayRemove
(
pConsumer
->
rebRemovedTopics
,
i
);
taosMemoryFree
(
p
);
mDebug
(
"consumer:0x%"
PRIx64
" remove topic:%s in the removed topic list, remain removedTopics:%d"
,
pConsumer
->
consumerId
,
pTopic
,
(
int
)
taosArrayGetSize
(
pConsumer
->
rebRemovedTopics
));
break
;
}
}
}
static
void
removeFromCurrentTopicList
(
SMqConsumerObj
*
pConsumer
,
const
char
*
pTopic
)
{
int32_t
sz
=
taosArrayGetSize
(
pConsumer
->
currentTopics
);
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
char
*
topic
=
taosArrayGetP
(
pConsumer
->
currentTopics
,
i
);
if
(
strcmp
(
pTopic
,
topic
)
==
0
)
{
taosArrayRemove
(
pConsumer
->
currentTopics
,
i
);
taosMemoryFree
(
topic
);
mDebug
(
"consumer:0x%"
PRIx64
" remove topic:%s in the current topic list, remain currentTopics:%d"
,
pConsumer
->
consumerId
,
pTopic
,
(
int
)
taosArrayGetSize
(
pConsumer
->
currentTopics
));
break
;
}
}
}
static
bool
existInCurrentTopicList
(
const
SMqConsumerObj
*
pConsumer
,
const
char
*
pTopic
)
{
bool
existing
=
false
;
int32_t
size
=
taosArrayGetSize
(
pConsumer
->
currentTopics
);
for
(
int32_t
i
=
0
;
i
<
size
;
i
++
)
{
char
*
topic
=
taosArrayGetP
(
pConsumer
->
currentTopics
,
i
);
if
(
strcmp
(
topic
,
pTopic
)
==
0
)
{
existing
=
true
;
break
;
}
}
return
existing
;
}
static
int32_t
mndConsumerActionUpdate
(
SSdb
*
pSdb
,
SMqConsumerObj
*
pOldConsumer
,
SMqConsumerObj
*
pNewConsumer
)
{
...
...
@@ -951,24 +983,16 @@ static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pOldConsumer,
}
else
if
(
pNewConsumer
->
updateType
==
CONSUMER_UPDATE__ADD
)
{
char
*
pNewTopic
=
taosStrdup
(
taosArrayGetP
(
pNewConsumer
->
rebNewTopics
,
0
));
// not exist in current topic
bool
existing
=
false
;
int32_t
numOfExistedTopics
=
taosArrayGetSize
(
pOldConsumer
->
currentTopics
);
for
(
int32_t
i
=
0
;
i
<
numOfExistedTopics
;
i
++
)
{
char
*
topic
=
taosArrayGetP
(
pOldConsumer
->
currentTopics
,
i
);
if
(
strcmp
(
topic
,
pNewTopic
)
==
0
)
{
existing
=
true
;
}
}
// check if exist in current topic
removeFromNewTopicList
(
pOldConsumer
,
pNewTopic
);
// add to current topic
if
(
!
existing
)
{
bool
existing
=
existInCurrentTopicList
(
pOldConsumer
,
pNewTopic
);
if
(
existing
)
{
taosMemoryFree
(
pNewTopic
);
}
else
{
// added into current topic list
taosArrayPush
(
pOldConsumer
->
currentTopics
,
&
pNewTopic
);
taosArraySort
(
pOldConsumer
->
currentTopics
,
taosArrayCompareString
);
}
else
{
taosMemoryFree
(
pNewTopic
);
}
// set status
...
...
@@ -993,16 +1017,7 @@ static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pOldConsumer,
removeFromRemoveTopicList
(
pOldConsumer
,
removedTopic
);
// remove from current topic
int32_t
i
=
0
;
int32_t
sz
=
taosArrayGetSize
(
pOldConsumer
->
currentTopics
);
for
(
i
=
0
;
i
<
sz
;
i
++
)
{
char
*
topic
=
taosArrayGetP
(
pOldConsumer
->
currentTopics
,
i
);
if
(
strcmp
(
removedTopic
,
topic
)
==
0
)
{
taosArrayRemove
(
pOldConsumer
->
currentTopics
,
i
);
taosMemoryFree
(
topic
);
break
;
}
}
removeFromCurrentTopicList
(
pOldConsumer
,
removedTopic
);
// set status
int32_t
status
=
pOldConsumer
->
status
;
...
...
source/dnode/mnode/impl/src/mndSubscribe.c
浏览文件 @
5b25920f
...
...
@@ -213,13 +213,9 @@ static void doRemoveExistedConsumers(SMqRebOutputObj *pOutput, SHashObj *pHash,
int32_t
consumerVgNum
=
taosArrayGetSize
(
pConsumerEp
->
vgs
);
for
(
int32_t
j
=
0
;
j
<
consumerVgNum
;
j
++
)
{
SMqVgEp
*
pVgEp
=
taosArrayGetP
(
pConsumerEp
->
vgs
,
j
);
SMqRebOutputVg
outputVg
=
{
.
oldConsumerId
=
consumerId
,
.
newConsumerId
=
-
1
,
.
pVgEp
=
pVgEp
,
};
SMqVgEp
*
pVgEp
=
taosArrayGetP
(
pConsumerEp
->
vgs
,
j
);
SMqRebOutputVg
outputVg
=
{.
oldConsumerId
=
consumerId
,
.
newConsumerId
=
-
1
,
.
pVgEp
=
pVgEp
};
taosHashPut
(
pHash
,
&
pVgEp
->
vgId
,
sizeof
(
int32_t
),
&
outputVg
,
sizeof
(
SMqRebOutputVg
));
mInfo
(
"sub:%s mq re-balance remove vgId:%d from consumer:%"
PRIx64
,
pSubKey
,
pVgEp
->
vgId
,
consumerId
);
}
...
...
@@ -584,16 +580,11 @@ static int32_t mndProcessRebalanceReq(SRpcMsg *pMsg) {
// here we only handle one topic rebalance requirement to ensure the atomic execution of this transaction.
while
(
1
)
{
// if (rebalanceOnce) {
// break;
// }
pIter
=
taosHashIterate
(
pReq
->
rebSubHash
,
pIter
);
if
(
pIter
==
NULL
)
{
break
;
}
// todo handle the malloc failure
SMqRebInputObj
rebInput
=
{
0
};
SMqRebOutputObj
rebOutput
=
{
0
};
rebOutput
.
newConsumers
=
taosArrayInit
(
0
,
sizeof
(
int64_t
));
...
...
@@ -601,6 +592,20 @@ static int32_t mndProcessRebalanceReq(SRpcMsg *pMsg) {
rebOutput
.
modifyConsumers
=
taosArrayInit
(
0
,
sizeof
(
int64_t
));
rebOutput
.
rebVgs
=
taosArrayInit
(
0
,
sizeof
(
SMqRebOutputVg
));
if
(
rebOutput
.
newConsumers
==
NULL
||
rebOutput
.
removedConsumers
==
NULL
||
rebOutput
.
modifyConsumers
==
NULL
||
rebOutput
.
rebVgs
==
NULL
)
{
taosArrayDestroy
(
rebOutput
.
newConsumers
);
taosArrayDestroy
(
rebOutput
.
removedConsumers
);
taosArrayDestroy
(
rebOutput
.
modifyConsumers
);
taosArrayDestroy
(
rebOutput
.
rebVgs
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
mInfo
(
"mq re-balance failed, due to out of memory"
);
taosHashCleanup
(
pReq
->
rebSubHash
);
mndRebEnd
();
return
-
1
;
}
SMqRebInfo
*
pRebInfo
=
(
SMqRebInfo
*
)
pIter
;
SMqSubscribeObj
*
pSub
=
mndAcquireSubscribeByKey
(
pMnode
,
pRebInfo
->
key
);
...
...
@@ -640,6 +645,7 @@ static int32_t mndProcessRebalanceReq(SRpcMsg *pMsg) {
rebInput
.
oldConsumerNum
=
taosHashGetSize
(
pSub
->
consumerHash
);
rebOutput
.
pSub
=
tCloneSubscribeObj
(
pSub
);
taosRUnLockLatch
(
&
pSub
->
lock
);
mInfo
(
"sub topic:%s has %d consumers sub till now"
,
pRebInfo
->
key
,
rebInput
.
oldConsumerNum
);
mndReleaseSubscribe
(
pMnode
,
pSub
);
}
...
...
@@ -661,9 +667,6 @@ static int32_t mndProcessRebalanceReq(SRpcMsg *pMsg) {
taosArrayDestroy
(
rebOutput
.
rebVgs
);
tDeleteSubscribeObj
(
rebOutput
.
pSub
);
taosMemoryFree
(
rebOutput
.
pSub
);
// taosSsleep(100);
// rebalanceOnce = true;
}
// reset flag
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录