Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
fe4538e3
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,发现更多精彩内容 >>
未验证
提交
fe4538e3
编写于
4月 29, 2022
作者:
L
Liu Jicong
提交者:
GitHub
4月 29, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #12069 from taosdata/feature/tq
refactor: rebalance input
上级
99cf4ec4
3496381f
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
52 addition
and
57 deletion
+52
-57
include/common/tmsg.h
include/common/tmsg.h
+17
-17
source/dnode/mnode/impl/inc/mndDef.h
source/dnode/mnode/impl/inc/mndDef.h
+2
-3
source/dnode/mnode/impl/src/mndConsumer.c
source/dnode/mnode/impl/src/mndConsumer.c
+6
-6
source/dnode/mnode/impl/src/mndDef.c
source/dnode/mnode/impl/src/mndDef.c
+3
-0
source/dnode/mnode/impl/src/mndSubscribe.c
source/dnode/mnode/impl/src/mndSubscribe.c
+24
-31
未找到文件。
include/common/tmsg.h
浏览文件 @
fe4538e3
...
...
@@ -842,7 +842,7 @@ typedef struct {
char
db
[
TSDB_DB_FNAME_LEN
];
int64_t
dbUid
;
int32_t
vgVersion
;
int32_t
numOfStables
;
int32_t
numOfStables
;
int32_t
buffer
;
int32_t
pageSize
;
int32_t
pages
;
...
...
@@ -1442,32 +1442,32 @@ typedef struct {
SArray
*
lostConsumers
;
// SArray<int64_t>
SArray
*
removedConsumers
;
// SArray<int64_t>
SArray
*
newConsumers
;
// SArray<int64_t>
}
SMqReb
Subscribe
;
}
SMqReb
Info
;
static
FORCE_INLINE
SMqReb
Subscribe
*
tNewSMqRebSubscribe
(
const
char
*
key
)
{
SMqReb
Subscribe
*
pRebSub
=
(
SMqRebSubscribe
*
)
taosMemoryCalloc
(
1
,
sizeof
(
SMqRebSubscribe
));
if
(
pReb
Sub
==
NULL
)
{
static
FORCE_INLINE
SMqReb
Info
*
tNewSMqRebSubscribe
(
const
char
*
key
)
{
SMqReb
Info
*
pRebInfo
=
(
SMqRebInfo
*
)
taosMemoryCalloc
(
1
,
sizeof
(
SMqRebInfo
));
if
(
pReb
Info
==
NULL
)
{
goto
_err
;
}
strcpy
(
pReb
Sub
->
key
,
key
);
pReb
Sub
->
lostConsumers
=
taosArrayInit
(
0
,
sizeof
(
int64_t
));
if
(
pReb
Sub
->
lostConsumers
==
NULL
)
{
strcpy
(
pReb
Info
->
key
,
key
);
pReb
Info
->
lostConsumers
=
taosArrayInit
(
0
,
sizeof
(
int64_t
));
if
(
pReb
Info
->
lostConsumers
==
NULL
)
{
goto
_err
;
}
pReb
Sub
->
removedConsumers
=
taosArrayInit
(
0
,
sizeof
(
int64_t
));
if
(
pReb
Sub
->
removedConsumers
==
NULL
)
{
pReb
Info
->
removedConsumers
=
taosArrayInit
(
0
,
sizeof
(
int64_t
));
if
(
pReb
Info
->
removedConsumers
==
NULL
)
{
goto
_err
;
}
pReb
Sub
->
newConsumers
=
taosArrayInit
(
0
,
sizeof
(
int64_t
));
if
(
pReb
Sub
->
newConsumers
==
NULL
)
{
pReb
Info
->
newConsumers
=
taosArrayInit
(
0
,
sizeof
(
int64_t
));
if
(
pReb
Info
->
newConsumers
==
NULL
)
{
goto
_err
;
}
return
pReb
Sub
;
return
pReb
Info
;
_err:
taosArrayDestroy
(
pReb
Sub
->
lostConsumers
);
taosArrayDestroy
(
pReb
Sub
->
removedConsumers
);
taosArrayDestroy
(
pReb
Sub
->
newConsumers
);
taosMemoryFreeClear
(
pReb
Sub
);
taosArrayDestroy
(
pReb
Info
->
lostConsumers
);
taosArrayDestroy
(
pReb
Info
->
removedConsumers
);
taosArrayDestroy
(
pReb
Info
->
newConsumers
);
taosMemoryFreeClear
(
pReb
Info
);
return
NULL
;
}
...
...
source/dnode/mnode/impl/inc/mndDef.h
浏览文件 @
fe4538e3
...
...
@@ -554,9 +554,8 @@ int32_t tEncodeSMqSubActionLogObj(void** buf, const SMqSubActionLogO
void
*
tDecodeSMqSubActionLogObj
(
const
void
*
buf
,
SMqSubActionLogObj
*
pLog
);
typedef
struct
{
const
SMqSubscribeObj
*
pOldSub
;
const
SMqTopicObj
*
pTopic
;
const
SMqRebSubscribe
*
pRebInfo
;
int32_t
oldConsumerNum
;
const
SMqRebInfo
*
pRebInfo
;
}
SMqRebInputObj
;
typedef
struct
{
...
...
source/dnode/mnode/impl/src/mndConsumer.c
浏览文件 @
fe4538e3
...
...
@@ -134,15 +134,15 @@ FAIL:
return
-
1
;
}
static
SMqReb
Subscribe
*
mndGetOrCreateRebSub
(
SHashObj
*
pHash
,
const
char
*
key
)
{
SMqReb
Subscribe
*
pRebSub
=
taosHashGet
(
pHash
,
key
,
strlen
(
key
)
+
1
);
static
SMqReb
Info
*
mndGetOrCreateRebSub
(
SHashObj
*
pHash
,
const
char
*
key
)
{
SMqReb
Info
*
pRebSub
=
taosHashGet
(
pHash
,
key
,
strlen
(
key
)
+
1
);
if
(
pRebSub
==
NULL
)
{
pRebSub
=
tNewSMqRebSubscribe
(
key
);
if
(
pRebSub
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
taosHashPut
(
pHash
,
key
,
strlen
(
key
)
+
1
,
pRebSub
,
sizeof
(
SMqReb
Subscribe
));
taosHashPut
(
pHash
,
key
,
strlen
(
key
)
+
1
,
pRebSub
,
sizeof
(
SMqReb
Info
));
}
return
pRebSub
;
}
...
...
@@ -189,7 +189,7 @@ static int32_t mndProcessMqTimerMsg(SNodeMsg *pMsg) {
char
key
[
TSDB_SUBSCRIBE_KEY_LEN
];
char
*
removedTopic
=
taosArrayGetP
(
pConsumer
->
currentTopics
,
i
);
mndMakeSubscribeKey
(
key
,
pConsumer
->
cgroup
,
removedTopic
);
SMqReb
Subscribe
*
pRebSub
=
mndGetOrCreateRebSub
(
pRebMsg
->
rebSubHash
,
key
);
SMqReb
Info
*
pRebSub
=
mndGetOrCreateRebSub
(
pRebMsg
->
rebSubHash
,
key
);
taosArrayPush
(
pRebSub
->
removedConsumers
,
&
pConsumer
->
consumerId
);
}
taosRUnLockLatch
(
&
pConsumer
->
lock
);
...
...
@@ -200,7 +200,7 @@ static int32_t mndProcessMqTimerMsg(SNodeMsg *pMsg) {
char
key
[
TSDB_SUBSCRIBE_KEY_LEN
];
char
*
newTopic
=
taosArrayGetP
(
pConsumer
->
rebNewTopics
,
i
);
mndMakeSubscribeKey
(
key
,
pConsumer
->
cgroup
,
newTopic
);
SMqReb
Subscribe
*
pRebSub
=
mndGetOrCreateRebSub
(
pRebMsg
->
rebSubHash
,
key
);
SMqReb
Info
*
pRebSub
=
mndGetOrCreateRebSub
(
pRebMsg
->
rebSubHash
,
key
);
taosArrayPush
(
pRebSub
->
newConsumers
,
&
pConsumer
->
consumerId
);
}
...
...
@@ -209,7 +209,7 @@ static int32_t mndProcessMqTimerMsg(SNodeMsg *pMsg) {
char
key
[
TSDB_SUBSCRIBE_KEY_LEN
];
char
*
removedTopic
=
taosArrayGetP
(
pConsumer
->
rebRemovedTopics
,
i
);
mndMakeSubscribeKey
(
key
,
pConsumer
->
cgroup
,
removedTopic
);
SMqReb
Subscribe
*
pRebSub
=
mndGetOrCreateRebSub
(
pRebMsg
->
rebSubHash
,
key
);
SMqReb
Info
*
pRebSub
=
mndGetOrCreateRebSub
(
pRebMsg
->
rebSubHash
,
key
);
taosArrayPush
(
pRebSub
->
removedConsumers
,
&
pConsumer
->
consumerId
);
}
taosRUnLockLatch
(
&
pConsumer
->
lock
);
...
...
source/dnode/mnode/impl/src/mndDef.c
浏览文件 @
fe4538e3
...
...
@@ -277,6 +277,7 @@ SMqSubscribeObj *tCloneSubscribeObj(const SMqSubscribeObj *pSub) {
memcpy
(
pSubNew
->
key
,
pSub
->
key
,
TSDB_SUBSCRIBE_KEY_LEN
);
taosInitRWLatch
(
&
pSubNew
->
lock
);
pSubNew
->
dbUid
=
pSub
->
dbUid
;
pSubNew
->
subType
=
pSub
->
subType
;
pSubNew
->
withTbName
=
pSub
->
withTbName
;
pSubNew
->
withSchema
=
pSub
->
withSchema
;
...
...
@@ -310,6 +311,7 @@ void tDeleteSubscribeObj(SMqSubscribeObj *pSub) {
int32_t
tEncodeSubscribeObj
(
void
**
buf
,
const
SMqSubscribeObj
*
pSub
)
{
int32_t
tlen
=
0
;
tlen
+=
taosEncodeString
(
buf
,
pSub
->
key
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pSub
->
dbUid
);
tlen
+=
taosEncodeFixedI32
(
buf
,
pSub
->
vgNum
);
tlen
+=
taosEncodeFixedI8
(
buf
,
pSub
->
subType
);
tlen
+=
taosEncodeFixedI8
(
buf
,
pSub
->
withTbName
);
...
...
@@ -336,6 +338,7 @@ int32_t tEncodeSubscribeObj(void **buf, const SMqSubscribeObj *pSub) {
void
*
tDecodeSubscribeObj
(
const
void
*
buf
,
SMqSubscribeObj
*
pSub
)
{
//
buf
=
taosDecodeStringTo
(
buf
,
pSub
->
key
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pSub
->
dbUid
);
buf
=
taosDecodeFixedI32
(
buf
,
&
pSub
->
vgNum
);
buf
=
taosDecodeFixedI8
(
buf
,
&
pSub
->
subType
);
buf
=
taosDecodeFixedI8
(
buf
,
&
pSub
->
withTbName
);
...
...
source/dnode/mnode/impl/src/mndSubscribe.c
浏览文件 @
fe4538e3
...
...
@@ -175,27 +175,20 @@ static int32_t mndSplitSubscribeKey(const char *key, char *topic, char *cgroup)
return
0
;
}
static
SMqReb
Subscribe
*
mndGetOrCreateRebSub
(
SHashObj
*
pHash
,
const
char
*
key
)
{
SMqReb
Subscribe
*
pRebSub
=
taosHashGet
(
pHash
,
key
,
strlen
(
key
)
+
1
);
static
SMqReb
Info
*
mndGetOrCreateRebSub
(
SHashObj
*
pHash
,
const
char
*
key
)
{
SMqReb
Info
*
pRebSub
=
taosHashGet
(
pHash
,
key
,
strlen
(
key
)
+
1
);
if
(
pRebSub
==
NULL
)
{
pRebSub
=
tNewSMqRebSubscribe
(
key
);
if
(
pRebSub
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
taosHashPut
(
pHash
,
key
,
strlen
(
key
)
+
1
,
pRebSub
,
sizeof
(
SMqReb
Subscribe
));
taosHashPut
(
pHash
,
key
,
strlen
(
key
)
+
1
,
pRebSub
,
sizeof
(
SMqReb
Info
));
}
return
pRebSub
;
}
static
int32_t
mndDoRebalance
(
SMnode
*
pMnode
,
const
SMqRebInputObj
*
pInput
,
SMqRebOutputObj
*
pOutput
)
{
if
(
pInput
->
pTopic
!=
NULL
)
{
// create subscribe
pOutput
->
pSub
=
mndCreateSub
(
pMnode
,
pInput
->
pTopic
,
pInput
->
pRebInfo
->
key
);
ASSERT
(
taosHashGetSize
(
pOutput
->
pSub
->
consumerHash
)
==
0
);
}
else
{
pOutput
->
pSub
=
tCloneSubscribeObj
(
pInput
->
pOldSub
);
}
int32_t
totalVgNum
=
pOutput
->
pSub
->
vgNum
;
mInfo
(
"mq rebalance subscription: %s, vgNum: %d"
,
pOutput
->
pSub
->
key
,
pOutput
->
pSub
->
vgNum
);
...
...
@@ -246,12 +239,8 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
}
// 3. calc vg number of each consumer
int32_t
oldSz
=
0
;
if
(
pInput
->
pOldSub
)
{
oldSz
=
taosHashGetSize
(
pInput
->
pOldSub
->
consumerHash
);
}
int32_t
afterRebConsumerNum
=
oldSz
+
taosArrayGetSize
(
pInput
->
pRebInfo
->
newConsumers
)
-
taosArrayGetSize
(
pInput
->
pRebInfo
->
removedConsumers
);
int32_t
afterRebConsumerNum
=
pInput
->
oldConsumerNum
+
taosArrayGetSize
(
pInput
->
pRebInfo
->
newConsumers
)
-
taosArrayGetSize
(
pInput
->
pRebInfo
->
removedConsumers
);
int32_t
minVgCnt
=
0
;
int32_t
imbConsumerNum
=
0
;
// calc num
...
...
@@ -489,22 +478,34 @@ static int32_t mndProcessRebalanceReq(SNodeMsg *pMsg) {
rebOutput
.
touchedConsumers
=
taosArrayInit
(
0
,
sizeof
(
void
*
));
rebOutput
.
rebVgs
=
taosArrayInit
(
0
,
sizeof
(
SMqRebOutputVg
));
SMqRebSubscribe
*
pRebSub
=
(
SMqRebSubscribe
*
)
pIter
;
SMqSubscribeObj
*
pSub
=
mndAcquireSubscribeByKey
(
pMnode
,
pRebSub
->
key
);
SMqRebInfo
*
pRebInfo
=
(
SMqRebInfo
*
)
pIter
;
SMqSubscribeObj
*
pSub
=
mndAcquireSubscribeByKey
(
pMnode
,
pRebInfo
->
key
);
rebInput
.
pRebInfo
=
pRebInfo
;
if
(
pSub
==
NULL
)
{
// split sub key and extract topic
char
topic
[
TSDB_TOPIC_FNAME_LEN
];
char
cgroup
[
TSDB_CGROUP_LEN
];
mndSplitSubscribeKey
(
pReb
Sub
->
key
,
topic
,
cgroup
);
mndSplitSubscribeKey
(
pReb
Info
->
key
,
topic
,
cgroup
);
SMqTopicObj
*
pTopic
=
mndAcquireTopic
(
pMnode
,
topic
);
ASSERT
(
pTopic
);
taosRLockLatch
(
&
pTopic
->
lock
);
rebInput
.
pTopic
=
pTopic
;
}
rebInput
.
pRebInfo
=
pRebSub
;
rebInput
.
pOldSub
=
pSub
;
rebOutput
.
pSub
=
mndCreateSub
(
pMnode
,
pTopic
,
pRebInfo
->
key
);
ASSERT
(
taosHashGetSize
(
rebOutput
.
pSub
->
consumerHash
)
==
0
);
taosRUnLockLatch
(
&
pTopic
->
lock
);
mndReleaseTopic
(
pMnode
,
pTopic
);
rebInput
.
oldConsumerNum
=
0
;
}
else
{
taosRLockLatch
(
&
pSub
->
lock
);
rebInput
.
oldConsumerNum
=
taosHashGetSize
(
pSub
->
consumerHash
);
rebOutput
.
pSub
=
tCloneSubscribeObj
(
pSub
);
taosRUnLockLatch
(
&
pSub
->
lock
);
mndReleaseSubscribe
(
pMnode
,
pSub
);
}
// TODO replace assert with error check
ASSERT
(
mndDoRebalance
(
pMnode
,
&
rebInput
,
&
rebOutput
)
==
0
);
...
...
@@ -517,14 +518,6 @@ static int32_t mndProcessRebalanceReq(SNodeMsg *pMsg) {
if
(
mndPersistRebResult
(
pMnode
,
pMsg
,
&
rebOutput
)
<
0
)
{
mError
(
"persist rebalance output error, possibly vnode splitted or dropped"
);
}
if
(
rebInput
.
pTopic
)
{
SMqTopicObj
*
pTopic
=
(
SMqTopicObj
*
)
rebInput
.
pTopic
;
taosRUnLockLatch
(
&
pTopic
->
lock
);
mndReleaseTopic
(
pMnode
,
pTopic
);
}
else
{
mndReleaseSubscribe
(
pMnode
,
pSub
);
}
}
// reset flag
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录