Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
Rocketmq
提交
f225fd05
R
Rocketmq
项目概览
s920243400
/
Rocketmq
与 Fork 源项目一致
Fork自
Apache RocketMQ / Rocketmq
通知
1
Star
1
Fork
0
代码
文件
提交
分支
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看板
提交
f225fd05
编写于
11月 18, 2021
作者:
D
dongeforever
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish the code for command
上级
165e133a
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
225 addition
and
142 deletion
+225
-142
common/src/main/java/org/apache/rocketmq/common/statictopic/TopicQueueMappingUtils.java
...e/rocketmq/common/statictopic/TopicQueueMappingUtils.java
+9
-8
common/src/main/java/org/apache/rocketmq/common/statictopic/TopicRemappingDetailWrapper.java
...ketmq/common/statictopic/TopicRemappingDetailWrapper.java
+25
-0
tools/src/main/java/org/apache/rocketmq/tools/command/topic/RemappingStaticTopicSubCommand.java
...q/tools/command/topic/RemappingStaticTopicSubCommand.java
+176
-123
tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateStaticTopicSubCommand.java
...etmq/tools/command/topic/UpdateStaticTopicSubCommand.java
+15
-11
未找到文件。
common/src/main/java/org/apache/rocketmq/common/statictopic/TopicQueueMappingUtils.java
浏览文件 @
f225fd05
...
...
@@ -116,13 +116,12 @@ public class TopicQueueMappingUtils {
return
detailList
;
}
public
static
Map
.
Entry
<
Long
,
Integer
>
validConsistenceOfTopicConfigAndQueueMapping
(
Map
<
String
,
TopicConfigAndQueueMapping
>
brokerConfigMap
)
{
public
static
Map
.
Entry
<
Long
,
Integer
>
checkConsistenceOfTopicConfigAndQueueMapping
(
String
topic
,
Map
<
String
,
TopicConfigAndQueueMapping
>
brokerConfigMap
)
{
if
(
brokerConfigMap
==
null
||
brokerConfigMap
.
isEmpty
())
{
return
null
;
}
//make sure it it not null
String
topic
=
null
;
long
maxEpoch
=
-
1
;
int
maxNum
=
-
1
;
for
(
Map
.
Entry
<
String
,
TopicConfigAndQueueMapping
>
entry
:
brokerConfigMap
.
entrySet
())
{
...
...
@@ -143,9 +142,7 @@ public class TopicQueueMappingUtils {
}
if
(
topic
!=
null
&&
!
topic
.
equals
(
mappingDetail
.
getTopic
()))
{
throw
new
RuntimeException
(
"The topic name is inconsistent in broker "
+
broker
);
}
else
{
topic
=
mappingDetail
.
getTopic
();
throw
new
RuntimeException
(
"The topic name is not match for broker "
+
broker
);
}
if
(
maxEpoch
!=
-
1
...
...
@@ -165,7 +162,7 @@ public class TopicQueueMappingUtils {
return
new
AbstractMap
.
SimpleEntry
<
Long
,
Integer
>(
maxEpoch
,
maxNum
);
}
public
static
Map
<
Integer
,
TopicQueueMappingOne
>
b
uildMappingItems
(
List
<
TopicQueueMappingDetail
>
mappingDetailList
,
boolean
replace
,
boolean
checkConsistence
)
{
public
static
Map
<
Integer
,
TopicQueueMappingOne
>
checkAndB
uildMappingItems
(
List
<
TopicQueueMappingDetail
>
mappingDetailList
,
boolean
replace
,
boolean
checkConsistence
)
{
Collections
.
sort
(
mappingDetailList
,
new
Comparator
<
TopicQueueMappingDetail
>()
{
@Override
public
int
compare
(
TopicQueueMappingDetail
o1
,
TopicQueueMappingDetail
o2
)
{
...
...
@@ -216,10 +213,14 @@ public class TopicQueueMappingUtils {
return
items
.
get
(
items
.
size
()
-
1
);
}
public
static
String
writeToTemp
(
TopicRemappingDetailWrapper
wrapper
,
String
suffix
)
{
public
static
String
writeToTemp
(
TopicRemappingDetailWrapper
wrapper
,
boolean
after
)
{
String
topic
=
wrapper
.
getTopic
();
String
data
=
wrapper
.
toJson
();
String
fileName
=
System
.
getProperty
(
"java.io.tmpdir"
)
+
File
.
separator
+
topic
+
"-"
+
wrapper
.
getEpoch
()
+
"-"
+
suffix
;
String
suffix
=
TopicRemappingDetailWrapper
.
SUFFIX_BEFORE
;
if
(
after
)
{
suffix
=
TopicRemappingDetailWrapper
.
SUFFIX_AFTER
;
}
String
fileName
=
System
.
getProperty
(
"java.io.tmpdir"
)
+
File
.
separator
+
topic
+
"-"
+
wrapper
.
getEpoch
()
+
suffix
;
try
{
MixAll
.
string2File
(
data
,
fileName
);
return
fileName
;
...
...
common/src/main/java/org/apache/rocketmq/common/statictopic/TopicRemappingDetailWrapper.java
浏览文件 @
f225fd05
...
...
@@ -3,12 +3,17 @@ package org.apache.rocketmq.common.statictopic;
import
org.apache.rocketmq.remoting.protocol.RemotingSerializable
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Set
;
public
class
TopicRemappingDetailWrapper
extends
RemotingSerializable
{
public
static
final
String
TYPE_CREATE_OR_UPDATE
=
"CREATE_OR_UPDATE"
;
public
static
final
String
TYPE_REMAPPING
=
"REMAPPING"
;
public
static
final
String
SUFFIX_BEFORE
=
".before"
;
public
static
final
String
SUFFIX_AFTER
=
".after"
;
private
final
String
topic
;
private
final
String
type
;
...
...
@@ -17,6 +22,10 @@ public class TopicRemappingDetailWrapper extends RemotingSerializable {
private
Map
<
String
,
TopicConfigAndQueueMapping
>
brokerConfigMap
=
new
HashMap
<
String
,
TopicConfigAndQueueMapping
>();
private
Set
<
String
>
brokerToMapIn
=
new
HashSet
<
String
>();
private
Set
<
String
>
brokerToMapOut
=
new
HashSet
<
String
>();
public
TopicRemappingDetailWrapper
(
String
topic
,
String
type
,
long
epoch
,
Map
<
Integer
,
String
>
expectedIdToBroker
,
Map
<
String
,
TopicConfigAndQueueMapping
>
brokerConfigMap
)
{
this
.
topic
=
topic
;
this
.
type
=
type
;
...
...
@@ -44,4 +53,20 @@ public class TopicRemappingDetailWrapper extends RemotingSerializable {
public
Map
<
String
,
TopicConfigAndQueueMapping
>
getBrokerConfigMap
()
{
return
brokerConfigMap
;
}
public
Set
<
String
>
getBrokerToMapIn
()
{
return
brokerToMapIn
;
}
public
void
setBrokerToMapIn
(
Set
<
String
>
brokerToMapIn
)
{
this
.
brokerToMapIn
=
brokerToMapIn
;
}
public
Set
<
String
>
getBrokerToMapOut
()
{
return
brokerToMapOut
;
}
public
void
setBrokerToMapOut
(
Set
<
String
>
brokerToMapOut
)
{
this
.
brokerToMapOut
=
brokerToMapOut
;
}
}
tools/src/main/java/org/apache/rocketmq/tools/command/topic/RemappingStaticTopicSubCommand.java
浏览文件 @
f225fd05
此差异已折叠。
点击以展开。
tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateStaticTopicSubCommand.java
浏览文件 @
f225fd05
...
...
@@ -39,7 +39,6 @@ import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
import
org.apache.rocketmq.tools.command.SubCommand
;
import
org.apache.rocketmq.tools.command.SubCommandException
;
import
java.nio.charset.Charset
;
import
java.util.AbstractMap
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
...
...
@@ -84,7 +83,7 @@ public class UpdateStaticTopicSubCommand implements SubCommand {
options
.
addOption
(
opt
);
opt
=
new
Option
(
"f"
,
"mapFile"
,
true
,
"The map file name"
);
opt
.
setRequired
(
tru
e
);
opt
.
setRequired
(
fals
e
);
options
.
addOption
(
opt
);
return
options
;
...
...
@@ -99,12 +98,13 @@ public class UpdateStaticTopicSubCommand implements SubCommand {
ClientMetadata
clientMetadata
=
new
ClientMetadata
();
try
{
String
topic
=
commandLine
.
getOptionValue
(
't'
).
trim
();
String
mapFileName
=
commandLine
.
getOptionValue
(
'f'
).
trim
();
String
mapData
=
MixAll
.
file2String
(
mapFileName
);
TopicRemappingDetailWrapper
wrapper
=
TopicRemappingDetailWrapper
.
decode
(
mapData
.
getBytes
(),
TopicRemappingDetailWrapper
.
class
);
//double check the config
TopicQueueMappingUtils
.
validConsistenceOfTopicConfigAndQueueMapping
(
wrapper
.
getBrokerConfigMap
());
TopicQueueMappingUtils
.
b
uildMappingItems
(
new
ArrayList
<>(
TopicQueueMappingUtils
.
getMappingDetailFromConfig
(
wrapper
.
getBrokerConfigMap
().
values
())),
false
,
true
);
TopicQueueMappingUtils
.
checkConsistenceOfTopicConfigAndQueueMapping
(
topic
,
wrapper
.
getBrokerConfigMap
());
TopicQueueMappingUtils
.
checkAndB
uildMappingItems
(
new
ArrayList
<>(
TopicQueueMappingUtils
.
getMappingDetailFromConfig
(
wrapper
.
getBrokerConfigMap
().
values
())),
false
,
true
);
ClusterInfo
clusterInfo
=
defaultMQAdminExt
.
examineBrokerClusterInfo
();
if
(
clusterInfo
==
null
...
...
@@ -131,6 +131,11 @@ public class UpdateStaticTopicSubCommand implements SubCommand {
@Override
public
void
execute
(
final
CommandLine
commandLine
,
final
Options
options
,
RPCHook
rpcHook
)
throws
SubCommandException
{
if
(!
commandLine
.
hasOption
(
't'
))
{
ServerUtil
.
printCommandLineHelp
(
"mqadmin "
+
this
.
commandName
(),
options
);
return
;
}
if
(
commandLine
.
hasOption
(
"f"
))
{
executeFromFile
(
commandLine
,
options
,
rpcHook
);
return
;
...
...
@@ -159,7 +164,6 @@ public class UpdateStaticTopicSubCommand implements SubCommand {
}
clientMetadata
.
refreshClusterInfo
(
clusterInfo
);
String
clusters
=
commandLine
.
getOptionValue
(
'c'
).
trim
();
for
(
String
cluster
:
clusters
.
split
(
","
))
{
cluster
=
cluster
.
trim
();
...
...
@@ -200,8 +204,8 @@ public class UpdateStaticTopicSubCommand implements SubCommand {
Map
.
Entry
<
Long
,
Integer
>
maxEpochAndNum
=
new
AbstractMap
.
SimpleImmutableEntry
<>(
System
.
currentTimeMillis
(),
queueNum
);
if
(!
brokerConfigMap
.
isEmpty
())
{
maxEpochAndNum
=
TopicQueueMappingUtils
.
validConsistenceOfTopicConfigAndQueueMapping
(
brokerConfigMap
);
globalIdMap
=
TopicQueueMappingUtils
.
b
uildMappingItems
(
new
ArrayList
<>(
TopicQueueMappingUtils
.
getMappingDetailFromConfig
(
brokerConfigMap
.
values
())),
false
,
true
);
maxEpochAndNum
=
TopicQueueMappingUtils
.
checkConsistenceOfTopicConfigAndQueueMapping
(
topic
,
brokerConfigMap
);
globalIdMap
=
TopicQueueMappingUtils
.
checkAndB
uildMappingItems
(
new
ArrayList
<>(
TopicQueueMappingUtils
.
getMappingDetailFromConfig
(
brokerConfigMap
.
values
())),
false
,
true
);
}
if
(
queueNum
<
globalIdMap
.
size
())
{
throw
new
RuntimeException
(
String
.
format
(
"Cannot decrease the queue num for static topic %d < %d"
,
queueNum
,
globalIdMap
.
size
()));
...
...
@@ -213,7 +217,7 @@ public class UpdateStaticTopicSubCommand implements SubCommand {
{
TopicRemappingDetailWrapper
oldWrapper
=
new
TopicRemappingDetailWrapper
(
topic
,
TopicRemappingDetailWrapper
.
TYPE_CREATE_OR_UPDATE
,
maxEpochAndNum
.
getKey
(),
new
HashMap
<>(),
brokerConfigMap
);
String
oldMappingDataFile
=
TopicQueueMappingUtils
.
writeToTemp
(
oldWrapper
,
"before"
);
String
oldMappingDataFile
=
TopicQueueMappingUtils
.
writeToTemp
(
oldWrapper
,
false
);
System
.
out
.
println
(
"The old mapping data is written to file "
+
oldMappingDataFile
);
}
...
...
@@ -264,12 +268,12 @@ public class UpdateStaticTopicSubCommand implements SubCommand {
configMapping
.
getMappingDetail
().
setTotalQueues
(
queueNum
);
});
//double check the config
TopicQueueMappingUtils
.
validConsistenceOfTopicConfigAndQueueMapping
(
brokerConfigMap
);
TopicQueueMappingUtils
.
b
uildMappingItems
(
new
ArrayList
<>(
TopicQueueMappingUtils
.
getMappingDetailFromConfig
(
brokerConfigMap
.
values
())),
false
,
true
);
TopicQueueMappingUtils
.
checkConsistenceOfTopicConfigAndQueueMapping
(
topic
,
brokerConfigMap
);
TopicQueueMappingUtils
.
checkAndB
uildMappingItems
(
new
ArrayList
<>(
TopicQueueMappingUtils
.
getMappingDetailFromConfig
(
brokerConfigMap
.
values
())),
false
,
true
);
{
TopicRemappingDetailWrapper
newWrapper
=
new
TopicRemappingDetailWrapper
(
topic
,
TopicRemappingDetailWrapper
.
TYPE_CREATE_OR_UPDATE
,
newEpoch
,
newIdToBroker
,
brokerConfigMap
);
String
newMappingDataFile
=
TopicQueueMappingUtils
.
writeToTemp
(
newWrapper
,
"after"
);
String
newMappingDataFile
=
TopicQueueMappingUtils
.
writeToTemp
(
newWrapper
,
true
);
System
.
out
.
println
(
"The new mapping data is written to file "
+
newMappingDataFile
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录