Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Apache RocketMQ
Rocketmq
提交
f05cfb92
R
Rocketmq
项目概览
Apache RocketMQ
/
Rocketmq
上一次同步 大约 3 年
通知
270
Star
16139
Fork
68
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rocketmq
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
f05cfb92
编写于
11月 18, 2021
作者:
D
dongeforever
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish the static topic commands
上级
f225fd05
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
39 addition
and
32 deletion
+39
-32
tools/src/main/java/org/apache/rocketmq/tools/command/topic/RemappingStaticTopicSubCommand.java
...q/tools/command/topic/RemappingStaticTopicSubCommand.java
+1
-0
tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateStaticTopicSubCommand.java
...etmq/tools/command/topic/UpdateStaticTopicSubCommand.java
+38
-32
未找到文件。
tools/src/main/java/org/apache/rocketmq/tools/command/topic/RemappingStaticTopicSubCommand.java
浏览文件 @
f05cfb92
...
...
@@ -244,6 +244,7 @@ public class RemappingStaticTopicSubCommand implements SubCommand {
{
TopicRouteData
routeData
=
defaultMQAdminExt
.
examineTopicRouteInfo
(
topic
);
clientMetadata
.
freshTopicRoute
(
topic
,
routeData
);
if
(
routeData
!=
null
&&
!
routeData
.
getQueueDatas
().
isEmpty
())
{
for
(
QueueData
queueData:
routeData
.
getQueueDatas
())
{
...
...
tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateStaticTopicSubCommand.java
浏览文件 @
f05cfb92
...
...
@@ -112,13 +112,7 @@ public class UpdateStaticTopicSubCommand implements SubCommand {
throw
new
RuntimeException
(
"The Cluster info is empty"
);
}
clientMetadata
.
refreshClusterInfo
(
clusterInfo
);
//If some succeed, and others fail, it will cause inconsistent data
for
(
Map
.
Entry
<
String
,
TopicConfigAndQueueMapping
>
entry
:
wrapper
.
getBrokerConfigMap
().
entrySet
())
{
String
broker
=
entry
.
getKey
();
String
addr
=
clientMetadata
.
findMasterBrokerAddr
(
broker
);
TopicConfigAndQueueMapping
configMapping
=
entry
.
getValue
();
defaultMQAdminExt
.
createStaticTopic
(
addr
,
defaultMQAdminExt
.
getCreateTopicKey
(),
configMapping
,
configMapping
.
getMappingDetail
());
}
doUpdate
(
wrapper
.
getBrokerConfigMap
(),
clientMetadata
,
defaultMQAdminExt
);
return
;
}
catch
(
Exception
e
)
{
throw
new
SubCommandException
(
this
.
getClass
().
getSimpleName
()
+
" command failed"
,
e
);
...
...
@@ -127,6 +121,16 @@ public class UpdateStaticTopicSubCommand implements SubCommand {
}
}
public
void
doUpdate
(
Map
<
String
,
TopicConfigAndQueueMapping
>
brokerConfigMap
,
ClientMetadata
clientMetadata
,
DefaultMQAdminExt
defaultMQAdminExt
)
throws
Exception
{
//If some succeed, and others fail, it will cause inconsistent data
for
(
Map
.
Entry
<
String
,
TopicConfigAndQueueMapping
>
entry
:
brokerConfigMap
.
entrySet
())
{
String
broker
=
entry
.
getKey
();
String
addr
=
clientMetadata
.
findMasterBrokerAddr
(
broker
);
TopicConfigAndQueueMapping
configMapping
=
entry
.
getValue
();
defaultMQAdminExt
.
createStaticTopic
(
addr
,
defaultMQAdminExt
.
getCreateTopicKey
(),
configMapping
,
configMapping
.
getMappingDetail
());
}
}
@Override
public
void
execute
(
final
CommandLine
commandLine
,
final
Options
options
,
...
...
@@ -147,15 +151,15 @@ public class UpdateStaticTopicSubCommand implements SubCommand {
Map
<
String
,
TopicConfigAndQueueMapping
>
brokerConfigMap
=
new
HashMap
<>();
Map
<
Integer
,
TopicQueueMappingOne
>
globalIdMap
=
new
HashMap
<>();
Set
<
String
>
b
rokers
=
new
HashSet
<>();
Set
<
String
>
targetB
rokers
=
new
HashSet
<>();
try
{
if
((!
commandLine
.
hasOption
(
"b"
)
&&
!
commandLine
.
hasOption
(
'c'
))
||
!
commandLine
.
hasOption
(
't'
)
||
!
commandLine
.
hasOption
(
"qn"
))
{
ServerUtil
.
printCommandLineHelp
(
"mqadmin "
+
this
.
commandName
(),
options
);
return
;
}
String
topic
=
commandLine
.
getOptionValue
(
't'
).
trim
();
ClusterInfo
clusterInfo
=
defaultMQAdminExt
.
examineBrokerClusterInfo
();
if
(
clusterInfo
==
null
...
...
@@ -163,26 +167,33 @@ public class UpdateStaticTopicSubCommand implements SubCommand {
throw
new
RuntimeException
(
"The Cluster info is empty"
);
}
clientMetadata
.
refreshClusterInfo
(
clusterInfo
);
String
clusters
=
commandLine
.
getOptionValue
(
'c'
).
trim
();
for
(
String
cluster
:
clusters
.
split
(
","
))
{
cluster
=
cluster
.
trim
();
if
(
clusterInfo
.
getClusterAddrTable
().
get
(
cluster
)
!=
null
)
{
brokers
.
addAll
(
clusterInfo
.
getClusterAddrTable
().
get
(
cluster
));
{
if
(
commandLine
.
hasOption
(
"b"
))
{
String
brokerStrs
=
commandLine
.
getOptionValue
(
"b"
).
trim
();
for
(
String
broker:
brokerStrs
.
split
(
","
))
{
targetBrokers
.
add
(
broker
.
trim
());
}
}
else
if
(
commandLine
.
hasOption
(
"c"
))
{
String
clusters
=
commandLine
.
getOptionValue
(
'c'
).
trim
();
for
(
String
cluster
:
clusters
.
split
(
","
))
{
cluster
=
cluster
.
trim
();
if
(
clusterInfo
.
getClusterAddrTable
().
get
(
cluster
)
!=
null
)
{
targetBrokers
.
addAll
(
clusterInfo
.
getClusterAddrTable
().
get
(
cluster
));
}
}
}
}
if
(
brokers
.
isEmpty
())
{
throw
new
RuntimeException
(
"Find none brokers for "
+
clusters
);
}
for
(
String
broker
:
brokers
)
{
String
addr
=
clientMetadata
.
findMasterBrokerAddr
(
broker
);
if
(
addr
==
null
)
{
throw
new
RuntimeException
(
"Can't find addr for broker "
+
broker
);
if
(
targetBrokers
.
isEmpty
())
{
throw
new
RuntimeException
(
"Find none brokers, do nothing"
);
}
for
(
String
broker
:
targetBrokers
)
{
String
addr
=
clientMetadata
.
findMasterBrokerAddr
(
broker
);
if
(
addr
==
null
)
{
throw
new
RuntimeException
(
"Can't find addr for broker "
+
broker
);
}
}
}
//get the existed topic config and mapping
String
topic
=
commandLine
.
getOptionValue
(
't'
).
trim
();
int
queueNum
=
Integer
.
parseInt
(
commandLine
.
getOptionValue
(
"qn"
).
trim
());
{
TopicRouteData
routeData
=
defaultMQAdminExt
.
examineTopicRouteInfo
(
topic
);
...
...
@@ -223,7 +234,7 @@ public class UpdateStaticTopicSubCommand implements SubCommand {
//the check is ok, now do the mapping allocation
Map
<
String
,
Integer
>
brokerNumMap
=
b
rokers
.
stream
().
collect
(
Collectors
.
toMap
(
x
->
x
,
x
->
0
));
Map
<
String
,
Integer
>
brokerNumMap
=
targetB
rokers
.
stream
().
collect
(
Collectors
.
toMap
(
x
->
x
,
x
->
0
));
final
Map
<
Integer
,
String
>
oldIdToBroker
=
new
HashMap
<>();
globalIdMap
.
forEach
((
key
,
value
)
->
{
String
leaderbroker
=
value
.
getBname
();
...
...
@@ -277,13 +288,8 @@ public class UpdateStaticTopicSubCommand implements SubCommand {
System
.
out
.
println
(
"The new mapping data is written to file "
+
newMappingDataFile
);
}
//If some succeed, and others fail, it will cause inconsistent data
for
(
Map
.
Entry
<
String
,
TopicConfigAndQueueMapping
>
entry
:
brokerConfigMap
.
entrySet
())
{
String
broker
=
entry
.
getKey
();
String
addr
=
clientMetadata
.
findMasterBrokerAddr
(
broker
);
TopicConfigAndQueueMapping
configMapping
=
entry
.
getValue
();
defaultMQAdminExt
.
createStaticTopic
(
addr
,
defaultMQAdminExt
.
getCreateTopicKey
(),
configMapping
,
configMapping
.
getMappingDetail
());
}
doUpdate
(
brokerConfigMap
,
clientMetadata
,
defaultMQAdminExt
);
}
catch
(
Exception
e
)
{
throw
new
SubCommandException
(
this
.
getClass
().
getSimpleName
()
+
" command failed"
,
e
);
}
finally
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录