Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Apache RocketMQ
Rocketmq
提交
7707275e
R
Rocketmq
项目概览
Apache RocketMQ
/
Rocketmq
上一次同步 大约 3 年
通知
268
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看板
提交
7707275e
编写于
11月 07, 2021
作者:
D
dongeforever
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Finish the register process in namesrv
上级
7bbc7ddf
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
181 addition
and
196 deletion
+181
-196
broker/src/main/java/org/apache/rocketmq/broker/BrokerController.java
...ain/java/org/apache/rocketmq/broker/BrokerController.java
+2
-2
broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java
...pache/rocketmq/broker/processor/AdminBrokerProcessor.java
+3
-3
broker/src/main/java/org/apache/rocketmq/broker/topic/TopicQueueMappingManager.java
...pache/rocketmq/broker/topic/TopicQueueMappingManager.java
+6
-6
common/src/main/java/org/apache/rocketmq/common/TopicConfigAndQueueMapping.java
...rg/apache/rocketmq/common/TopicConfigAndQueueMapping.java
+5
-5
common/src/main/java/org/apache/rocketmq/common/TopicQueueMappingDetail.java
...a/org/apache/rocketmq/common/TopicQueueMappingDetail.java
+107
-0
common/src/main/java/org/apache/rocketmq/common/TopicQueueMappingInfo.java
...ava/org/apache/rocketmq/common/TopicQueueMappingInfo.java
+13
-66
common/src/main/java/org/apache/rocketmq/common/protocol/body/RegisterBrokerBody.java
...che/rocketmq/common/protocol/body/RegisterBrokerBody.java
+1
-0
common/src/main/java/org/apache/rocketmq/common/protocol/body/TopicQueueMappingBody.java
.../rocketmq/common/protocol/body/TopicQueueMappingBody.java
+2
-2
common/src/main/java/org/apache/rocketmq/common/protocol/body/TopicQueueMappingSerializeWrapper.java
...mmon/protocol/body/TopicQueueMappingSerializeWrapper.java
+4
-4
common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/GetRouteInfoRequestHeader.java
...on/protocol/header/namesrv/GetRouteInfoRequestHeader.java
+0
-20
common/src/main/java/org/apache/rocketmq/common/protocol/route/TopicRouteData.java
...apache/rocketmq/common/protocol/route/TopicRouteData.java
+15
-12
namesrv/src/main/java/org/apache/rocketmq/namesrv/processor/ClusterTestRequestProcessor.java
...cketmq/namesrv/processor/ClusterTestRequestProcessor.java
+1
-1
namesrv/src/main/java/org/apache/rocketmq/namesrv/processor/DefaultRequestProcessor.java
...e/rocketmq/namesrv/processor/DefaultRequestProcessor.java
+2
-17
namesrv/src/main/java/org/apache/rocketmq/namesrv/routeinfo/RouteInfoManager.java
...g/apache/rocketmq/namesrv/routeinfo/RouteInfoManager.java
+18
-56
namesrv/src/test/java/org/apache/rocketmq/namesrv/processor/DefaultRequestProcessorTest.java
...cketmq/namesrv/processor/DefaultRequestProcessorTest.java
+2
-2
未找到文件。
broker/src/main/java/org/apache/rocketmq/broker/BrokerController.java
浏览文件 @
7707275e
...
...
@@ -1084,7 +1084,7 @@ public class BrokerController {
Map
<
String
,
TopicQueueMappingInfo
>
topicQueueMappingInfoMap
=
topicConfigList
.
stream
()
.
map
(
TopicConfig:
:
getTopicName
)
.
map
(
topicName
->
Optional
.
ofNullable
(
this
.
topicQueueMappingManager
.
getTopicQueueMapping
(
topicName
))
.
map
(
info
->
new
AbstractMap
.
SimpleImmutableEntry
<>(
topicName
,
info
.
clone
4register
()))
.
map
(
info
->
new
AbstractMap
.
SimpleImmutableEntry
<>(
topicName
,
info
.
clone
AsMappingInfo
()))
.
orElse
(
null
))
.
filter
(
Objects:
:
nonNull
)
.
collect
(
Collectors
.
toMap
(
Map
.
Entry
::
getKey
,
Map
.
Entry
::
getValue
));
...
...
@@ -1103,7 +1103,7 @@ public class BrokerController {
topicConfigWrapper
.
setTopicConfigTable
(
this
.
getTopicConfigManager
().
getTopicConfigTable
());
topicConfigWrapper
.
setTopicQueueMappingInfoMap
(
this
.
getTopicQueueMappingManager
().
getTopicQueueMappingTable
().
entrySet
().
stream
().
map
(
entry
->
new
AbstractMap
.
SimpleImmutableEntry
<>(
entry
.
getKey
(),
entry
.
getValue
().
clone
4register
())
entry
->
new
AbstractMap
.
SimpleImmutableEntry
<>(
entry
.
getKey
(),
entry
.
getValue
().
clone
AsMappingInfo
())
).
collect
(
Collectors
.
toMap
(
Map
.
Entry
::
getKey
,
Map
.
Entry
::
getValue
)));
if
(!
PermName
.
isWriteable
(
this
.
getBrokerConfig
().
getBrokerPermission
())
...
...
broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java
浏览文件 @
7707275e
...
...
@@ -1726,11 +1726,11 @@ public class AdminBrokerProcessor extends AsyncNettyRequestProcessor implements
response
.
setRemark
(
"No topic in this broker. topic: "
+
requestHeader
.
getTopic
());
return
response
;
}
TopicQueueMapping
Info
topicQueueMappingInfo
=
null
;
TopicQueueMapping
Detail
topicQueueMappingDetail
=
null
;
if
(
Boolean
.
TRUE
.
equals
(
requestHeader
.
getWithMapping
()))
{
topicQueueMapping
Info
=
this
.
brokerController
.
getTopicQueueMappingManager
().
getTopicQueueMapping
(
requestHeader
.
getTopic
());
topicQueueMapping
Detail
=
this
.
brokerController
.
getTopicQueueMappingManager
().
getTopicQueueMapping
(
requestHeader
.
getTopic
());
}
String
content
=
JSONObject
.
toJSONString
(
new
TopicConfigAndQueueMapping
(
topicConfig
,
topicQueueMapping
Info
));
String
content
=
JSONObject
.
toJSONString
(
new
TopicConfigAndQueueMapping
(
topicConfig
,
topicQueueMapping
Detail
));
try
{
response
.
setBody
(
content
.
getBytes
(
MixAll
.
DEFAULT_CHARSET
));
}
catch
(
UnsupportedEncodingException
e
)
{
...
...
broker/src/main/java/org/apache/rocketmq/broker/topic/TopicQueueMappingManager.java
浏览文件 @
7707275e
...
...
@@ -23,7 +23,7 @@ import org.apache.rocketmq.common.ConfigManager;
import
org.apache.rocketmq.common.DataVersion
;
import
org.apache.rocketmq.common.constant.LoggerName
;
import
org.apache.rocketmq.common.protocol.body.TopicQueueMappingSerializeWrapper
;
import
org.apache.rocketmq.common.TopicQueueMapping
Info
;
import
org.apache.rocketmq.common.TopicQueueMapping
Detail
;
import
org.apache.rocketmq.logging.InternalLogger
;
import
org.apache.rocketmq.logging.InternalLoggerFactory
;
...
...
@@ -41,18 +41,18 @@ public class TopicQueueMappingManager extends ConfigManager {
private
final
DataVersion
dataVersion
=
new
DataVersion
();
private
transient
BrokerController
brokerController
;
private
final
ConcurrentMap
<
String
,
TopicQueueMapping
Info
>
topicQueueMappingTable
=
new
ConcurrentHashMap
<>();
private
final
ConcurrentMap
<
String
,
TopicQueueMapping
Detail
>
topicQueueMappingTable
=
new
ConcurrentHashMap
<>();
public
TopicQueueMappingManager
(
BrokerController
brokerController
)
{
this
.
brokerController
=
brokerController
;
}
public
void
updateTopicQueueMapping
(
TopicQueueMapping
Info
topicQueueMappingInfo
)
{
topicQueueMappingTable
.
put
(
topicQueueMapping
Info
.
getTopic
(),
topicQueueMappingInfo
);
public
void
updateTopicQueueMapping
(
TopicQueueMapping
Detail
topicQueueMappingDetail
)
{
topicQueueMappingTable
.
put
(
topicQueueMapping
Detail
.
getTopic
(),
topicQueueMappingDetail
);
}
public
TopicQueueMapping
Info
getTopicQueueMapping
(
String
topic
)
{
public
TopicQueueMapping
Detail
getTopicQueueMapping
(
String
topic
)
{
return
topicQueueMappingTable
.
get
(
topic
);
}
...
...
@@ -86,7 +86,7 @@ public class TopicQueueMappingManager extends ConfigManager {
}
}
public
ConcurrentMap
<
String
,
TopicQueueMapping
Info
>
getTopicQueueMappingTable
()
{
public
ConcurrentMap
<
String
,
TopicQueueMapping
Detail
>
getTopicQueueMappingTable
()
{
return
topicQueueMappingTable
;
}
...
...
common/src/main/java/org/apache/rocketmq/common/TopicConfigAndQueueMapping.java
浏览文件 @
7707275e
...
...
@@ -18,15 +18,15 @@ package org.apache.rocketmq.common;
public
class
TopicConfigAndQueueMapping
{
private
TopicConfig
topicConfig
;
private
TopicQueueMapping
Info
topicQueueMappingInfo
;
private
TopicQueueMapping
Detail
topicQueueMappingDetail
;
public
TopicConfigAndQueueMapping
(
TopicConfig
topicConfig
,
TopicQueueMapping
Info
topicQueueMappingInfo
)
{
public
TopicConfigAndQueueMapping
(
TopicConfig
topicConfig
,
TopicQueueMapping
Detail
topicQueueMappingDetail
)
{
this
.
topicConfig
=
topicConfig
;
this
.
topicQueueMapping
Info
=
topicQueueMappingInfo
;
this
.
topicQueueMapping
Detail
=
topicQueueMappingDetail
;
}
public
TopicQueueMapping
Info
getTopicQueueMappingInfo
()
{
return
topicQueueMapping
Info
;
public
TopicQueueMapping
Detail
getTopicQueueMappingInfo
()
{
return
topicQueueMapping
Detail
;
}
public
TopicConfig
getTopicConfig
()
{
...
...
common/src/main/java/org/apache/rocketmq/common/TopicQueueMappingDetail.java
0 → 100644
浏览文件 @
7707275e
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.rocketmq.common
;
import
com.google.common.collect.ImmutableList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentMap
;
public
class
TopicQueueMappingDetail
extends
TopicQueueMappingInfo
{
// the mapping info in current broker, do not register to nameserver
ConcurrentMap
<
Integer
/*global id*/
,
ImmutableList
<
LogicQueueMappingItem
>>
hostedQueues
=
new
ConcurrentHashMap
<
Integer
,
ImmutableList
<
LogicQueueMappingItem
>>();
public
TopicQueueMappingDetail
(
String
topic
,
int
totalQueues
,
String
bname
)
{
super
(
topic
,
totalQueues
,
bname
);
buildIdMap
();
}
public
boolean
putMappingInfo
(
Integer
globalId
,
ImmutableList
<
LogicQueueMappingItem
>
mappingInfo
)
{
if
(
mappingInfo
.
isEmpty
())
{
return
true
;
}
hostedQueues
.
put
(
globalId
,
mappingInfo
);
buildIdMap
();
return
true
;
}
public
void
buildIdMap
()
{
this
.
currIdMap
=
buildIdMap
(
LEVEL_0
);
this
.
prevIdMap
=
buildIdMap
(
LEVEL_1
);
}
public
ConcurrentMap
<
Integer
,
Integer
>
buildIdMap
(
int
level
)
{
//level 0 means current leader in this broker
//level 1 means previous leader in this broker
assert
level
==
LEVEL_0
||
level
==
LEVEL_1
;
if
(
hostedQueues
==
null
||
hostedQueues
.
isEmpty
())
{
return
new
ConcurrentHashMap
<
Integer
,
Integer
>();
}
ConcurrentMap
<
Integer
,
Integer
>
tmpIdMap
=
new
ConcurrentHashMap
<
Integer
,
Integer
>();
for
(
Map
.
Entry
<
Integer
,
ImmutableList
<
LogicQueueMappingItem
>>
entry:
hostedQueues
.
entrySet
())
{
Integer
globalId
=
entry
.
getKey
();
ImmutableList
<
LogicQueueMappingItem
>
items
=
entry
.
getValue
();
if
(
level
==
LEVEL_0
&&
items
.
size
()
>=
1
)
{
LogicQueueMappingItem
curr
=
items
.
get
(
items
.
size
()
-
1
);
if
(
bname
.
equals
(
curr
.
getBname
()))
{
tmpIdMap
.
put
(
curr
.
getQueueId
(),
globalId
);
}
}
else
if
(
level
==
LEVEL_1
&&
items
.
size
()
>=
2
)
{
LogicQueueMappingItem
prev
=
items
.
get
(
items
.
size
()
-
1
);
if
(
bname
.
equals
(
prev
.
getBname
()))
{
tmpIdMap
.
put
(
prev
.
getQueueId
(),
globalId
);
}
}
}
return
tmpIdMap
;
}
public
List
<
LogicQueueMappingItem
>
getMappingInfo
(
Integer
globalId
)
{
return
hostedQueues
.
get
(
globalId
);
}
public
TopicQueueMappingInfo
cloneAsMappingInfo
()
{
TopicQueueMappingInfo
topicQueueMappingInfo
=
new
TopicQueueMappingInfo
(
this
.
topic
,
this
.
totalQueues
,
this
.
bname
);
topicQueueMappingInfo
.
currIdMap
=
this
.
buildIdMap
(
LEVEL_0
);
topicQueueMappingInfo
.
prevIdMap
=
this
.
buildIdMap
(
LEVEL_1
);
return
topicQueueMappingInfo
;
}
public
int
getTotalQueues
()
{
return
totalQueues
;
}
public
void
setTotalQueues
(
int
totalQueues
)
{
this
.
totalQueues
=
totalQueues
;
}
public
String
getBname
()
{
return
bname
;
}
public
String
getTopic
()
{
return
topic
;
}
}
common/src/main/java/org/apache/rocketmq/common/TopicQueueMappingInfo.java
浏览文件 @
7707275e
...
...
@@ -16,11 +16,8 @@
*/
package
org.apache.rocketmq.common
;
import
com.google.common.collect.ImmutableList
;
import
org.apache.rocketmq.remoting.protocol.RemotingSerializable
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentMap
;
...
...
@@ -28,78 +25,20 @@ public class TopicQueueMappingInfo extends RemotingSerializable {
public
static
final
int
LEVEL_0
=
0
;
public
static
final
int
LEVEL_1
=
1
;
private
String
topic
;
// redundant field
private
int
totalQueues
;
private
String
bname
;
//identify the hosted broker name
// the mapping info in current broker, do not register to nameserver
private
ConcurrentMap
<
Integer
/*global id*/
,
ImmutableList
<
LogicQueueMappingItem
>>
hostedQueues
=
new
ConcurrentHashMap
<
Integer
,
ImmutableList
<
LogicQueueMappingItem
>>();
String
topic
;
// redundant field
int
totalQueues
;
String
bname
;
//identify the hosted broker name
//register to broker to construct the route
private
ConcurrentMap
<
Integer
,
Integer
>
currIdMap
=
new
ConcurrentHashMap
<
Integer
,
Integer
>();
ConcurrentMap
<
Integer
,
Integer
>
currIdMap
=
new
ConcurrentHashMap
<
Integer
,
Integer
>();
//register to broker to help detect remapping failure
pr
ivate
ConcurrentMap
<
Integer
,
Integer
>
prevIdMap
=
new
ConcurrentHashMap
<
Integer
,
Integer
>();
pr
otected
ConcurrentMap
<
Integer
,
Integer
>
prevIdMap
=
new
ConcurrentHashMap
<
Integer
,
Integer
>();
public
TopicQueueMappingInfo
(
String
topic
,
int
totalQueues
,
String
bname
)
{
this
.
topic
=
topic
;
this
.
totalQueues
=
totalQueues
;
this
.
bname
=
bname
;
buildIdMap
();
}
public
boolean
putMappingInfo
(
Integer
globalId
,
ImmutableList
<
LogicQueueMappingItem
>
mappingInfo
)
{
if
(
mappingInfo
.
isEmpty
())
{
return
true
;
}
hostedQueues
.
put
(
globalId
,
mappingInfo
);
buildIdMap
();
return
true
;
}
public
void
buildIdMap
()
{
this
.
currIdMap
=
buildIdMap
(
LEVEL_0
);
this
.
prevIdMap
=
buildIdMap
(
LEVEL_1
);
}
public
ConcurrentMap
<
Integer
,
Integer
>
buildIdMap
(
int
level
)
{
//level 0 means current leader in this broker
//level 1 means previous leader in this broker
assert
level
==
LEVEL_0
||
level
==
LEVEL_1
;
if
(
hostedQueues
==
null
||
hostedQueues
.
isEmpty
())
{
return
new
ConcurrentHashMap
<
Integer
,
Integer
>();
}
ConcurrentMap
<
Integer
,
Integer
>
tmpIdMap
=
new
ConcurrentHashMap
<
Integer
,
Integer
>();
for
(
Map
.
Entry
<
Integer
,
ImmutableList
<
LogicQueueMappingItem
>>
entry:
hostedQueues
.
entrySet
())
{
Integer
globalId
=
entry
.
getKey
();
ImmutableList
<
LogicQueueMappingItem
>
items
=
entry
.
getValue
();
if
(
level
==
LEVEL_0
&&
items
.
size
()
>=
1
)
{
LogicQueueMappingItem
curr
=
items
.
get
(
items
.
size
()
-
1
);
if
(
bname
.
equals
(
curr
.
getBname
()))
{
tmpIdMap
.
put
(
curr
.
getQueueId
(),
globalId
);
}
}
else
if
(
level
==
LEVEL_1
&&
items
.
size
()
>=
2
)
{
LogicQueueMappingItem
prev
=
items
.
get
(
items
.
size
()
-
1
);
if
(
bname
.
equals
(
prev
.
getBname
()))
{
tmpIdMap
.
put
(
prev
.
getQueueId
(),
globalId
);
}
}
}
return
tmpIdMap
;
}
public
List
<
LogicQueueMappingItem
>
getMappingInfo
(
Integer
globalId
)
{
return
hostedQueues
.
get
(
globalId
);
}
public
TopicQueueMappingInfo
clone4register
()
{
TopicQueueMappingInfo
topicQueueMappingInfo
=
new
TopicQueueMappingInfo
(
this
.
topic
,
this
.
totalQueues
,
this
.
bname
);
topicQueueMappingInfo
.
currIdMap
=
this
.
buildIdMap
(
LEVEL_0
);
topicQueueMappingInfo
.
prevIdMap
=
this
.
buildIdMap
(
LEVEL_1
);
return
topicQueueMappingInfo
;
}
public
int
getTotalQueues
()
{
return
totalQueues
;
...
...
@@ -116,4 +55,12 @@ public class TopicQueueMappingInfo extends RemotingSerializable {
public
String
getTopic
()
{
return
topic
;
}
public
ConcurrentMap
<
Integer
,
Integer
>
getCurrIdMap
()
{
return
currIdMap
;
}
public
ConcurrentMap
<
Integer
,
Integer
>
getPrevIdMap
()
{
return
prevIdMap
;
}
}
common/src/main/java/org/apache/rocketmq/common/protocol/body/RegisterBrokerBody.java
浏览文件 @
7707275e
...
...
@@ -33,6 +33,7 @@ import java.util.zip.InflaterInputStream;
import
org.apache.rocketmq.common.DataVersion
;
import
org.apache.rocketmq.common.MixAll
;
import
org.apache.rocketmq.common.TopicConfig
;
import
org.apache.rocketmq.common.TopicQueueMappingDetail
;
import
org.apache.rocketmq.common.TopicQueueMappingInfo
;
import
org.apache.rocketmq.common.constant.LoggerName
;
import
org.apache.rocketmq.logging.InternalLogger
;
...
...
common/src/main/java/org/apache/rocketmq/common/protocol/body/TopicQueueMappingBody.java
浏览文件 @
7707275e
...
...
@@ -16,9 +16,9 @@
*/
package
org.apache.rocketmq.common.protocol.body
;
import
org.apache.rocketmq.common.TopicQueueMapping
Info
;
import
org.apache.rocketmq.common.TopicQueueMapping
Detail
;
public
class
TopicQueueMappingBody
extends
TopicQueueMapping
Info
{
public
class
TopicQueueMappingBody
extends
TopicQueueMapping
Detail
{
public
TopicQueueMappingBody
(
String
topic
,
int
totalQueues
,
String
bname
)
{
super
(
topic
,
totalQueues
,
bname
);
...
...
common/src/main/java/org/apache/rocketmq/common/protocol/body/TopicQueueMappingSerializeWrapper.java
浏览文件 @
7707275e
...
...
@@ -18,20 +18,20 @@
package
org.apache.rocketmq.common.protocol.body
;
import
org.apache.rocketmq.common.DataVersion
;
import
org.apache.rocketmq.common.TopicQueueMapping
Info
;
import
org.apache.rocketmq.common.TopicQueueMapping
Detail
;
import
org.apache.rocketmq.remoting.protocol.RemotingSerializable
;
import
java.util.Map
;
public
class
TopicQueueMappingSerializeWrapper
extends
RemotingSerializable
{
private
Map
<
String
/* topic */
,
TopicQueueMapping
Info
>
topicQueueMappingInfoMap
;
private
Map
<
String
/* topic */
,
TopicQueueMapping
Detail
>
topicQueueMappingInfoMap
;
private
DataVersion
dataVersion
=
new
DataVersion
();
public
Map
<
String
,
TopicQueueMapping
Info
>
getTopicQueueMappingInfoMap
()
{
public
Map
<
String
,
TopicQueueMapping
Detail
>
getTopicQueueMappingInfoMap
()
{
return
topicQueueMappingInfoMap
;
}
public
void
setTopicQueueMappingInfoMap
(
Map
<
String
,
TopicQueueMapping
Info
>
topicQueueMappingInfoMap
)
{
public
void
setTopicQueueMappingInfoMap
(
Map
<
String
,
TopicQueueMapping
Detail
>
topicQueueMappingInfoMap
)
{
this
.
topicQueueMappingInfoMap
=
topicQueueMappingInfoMap
;
}
...
...
common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/GetRouteInfoRequestHeader.java
浏览文件 @
7707275e
...
...
@@ -20,7 +20,6 @@
*/
package
org.apache.rocketmq.common.protocol.header.namesrv
;
import
java.util.Set
;
import
org.apache.rocketmq.remoting.CommandCustomHeader
;
import
org.apache.rocketmq.remoting.annotation.CFNotNull
;
import
org.apache.rocketmq.remoting.exception.RemotingCommandException
;
...
...
@@ -29,9 +28,6 @@ public class GetRouteInfoRequestHeader implements CommandCustomHeader {
@CFNotNull
private
String
topic
;
private
int
sysFlag
;
private
Set
<
Integer
>
logicalQueueIdsFilter
;
@Override
public
void
checkFields
()
throws
RemotingCommandException
{
}
...
...
@@ -43,20 +39,4 @@ public class GetRouteInfoRequestHeader implements CommandCustomHeader {
public
void
setTopic
(
String
topic
)
{
this
.
topic
=
topic
;
}
public
int
getSysFlag
()
{
return
sysFlag
;
}
public
void
setSysFlag
(
int
sysFlag
)
{
this
.
sysFlag
=
sysFlag
;
}
public
void
setLogicalQueueIdsFilter
(
Set
<
Integer
>
filter
)
{
this
.
logicalQueueIdsFilter
=
filter
;
}
public
Set
<
Integer
>
getLogicalQueueIdsFilter
()
{
return
logicalQueueIdsFilter
;
}
}
common/src/main/java/org/apache/rocketmq/common/protocol/route/TopicRouteData.java
浏览文件 @
7707275e
...
...
@@ -23,6 +23,9 @@ package org.apache.rocketmq.common.protocol.route;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.rocketmq.common.TopicQueueMappingInfo
;
import
org.apache.rocketmq.remoting.protocol.RemotingSerializable
;
public
class
TopicRouteData
extends
RemotingSerializable
{
...
...
@@ -30,7 +33,7 @@ public class TopicRouteData extends RemotingSerializable {
private
List
<
QueueData
>
queueDatas
;
private
List
<
BrokerData
>
brokerDatas
;
private
HashMap
<
String
/* brokerAddr */
,
List
<
String
>
/* Filter Server */
>
filterServerTable
;
private
LogicalQueuesInfo
logicalQueuesInfo
;
private
Map
<
String
,
TopicQueueMappingInfo
>
topicQueueMappingByBroker
;
public
TopicRouteData
()
{
}
...
...
@@ -53,8 +56,8 @@ public class TopicRouteData extends RemotingSerializable {
this
.
filterServerTable
.
putAll
(
topicRouteData
.
filterServerTable
);
}
if
(
topicRouteData
.
logicalQueuesInfo
!=
null
)
{
this
.
logicalQueuesInfo
=
new
LogicalQueuesInfo
(
topicRouteData
.
logicalQueuesInfo
);
if
(
topicRouteData
.
topicQueueMappingByBroker
!=
null
)
{
this
.
topicQueueMappingByBroker
=
new
HashMap
<
String
,
TopicQueueMappingInfo
>(
topicRouteData
.
topicQueueMappingByBroker
);
}
}
...
...
@@ -90,12 +93,12 @@ public class TopicRouteData extends RemotingSerializable {
this
.
orderTopicConf
=
orderTopicConf
;
}
public
LogicalQueuesInfo
getLogicalQueuesInfo
()
{
return
logicalQueuesInfo
;
public
Map
<
String
,
TopicQueueMappingInfo
>
getTopicQueueMappingByBroker
()
{
return
topicQueueMappingByBroker
;
}
public
void
set
LogicalQueuesInfo
(
LogicalQueuesInfo
logicalQueuesInfo
)
{
this
.
logicalQueuesInfo
=
logicalQueuesInfo
;
public
void
set
TopicQueueMappingByBroker
(
Map
<
String
,
TopicQueueMappingInfo
>
topicQueueMappingByBroker
)
{
this
.
topicQueueMappingByBroker
=
topicQueueMappingByBroker
;
}
@Override
...
...
@@ -106,7 +109,7 @@ public class TopicRouteData extends RemotingSerializable {
result
=
prime
*
result
+
((
orderTopicConf
==
null
)
?
0
:
orderTopicConf
.
hashCode
());
result
=
prime
*
result
+
((
queueDatas
==
null
)
?
0
:
queueDatas
.
hashCode
());
result
=
prime
*
result
+
((
filterServerTable
==
null
)
?
0
:
filterServerTable
.
hashCode
());
result
=
prime
*
result
+
((
logicalQueuesInfo
==
null
)
?
0
:
logicalQueuesInfo
.
hashCode
());
result
=
prime
*
result
+
((
topicQueueMappingByBroker
==
null
)
?
0
:
topicQueueMappingByBroker
.
hashCode
());
return
result
;
}
...
...
@@ -139,10 +142,10 @@ public class TopicRouteData extends RemotingSerializable {
return
false
;
}
else
if
(!
filterServerTable
.
equals
(
other
.
filterServerTable
))
return
false
;
if
(
logicalQueuesInfo
==
null
)
{
if
(
other
.
logicalQueuesInfo
!=
null
)
if
(
topicQueueMappingByBroker
==
null
)
{
if
(
other
.
topicQueueMappingByBroker
!=
null
)
return
false
;
}
else
if
(!
logicalQueuesInfo
.
equals
(
other
.
logicalQueuesInfo
))
}
else
if
(!
topicQueueMappingByBroker
.
equals
(
other
.
topicQueueMappingByBroker
))
return
false
;
return
true
;
}
...
...
@@ -150,6 +153,6 @@ public class TopicRouteData extends RemotingSerializable {
@Override
public
String
toString
()
{
return
"TopicRouteData [orderTopicConf="
+
orderTopicConf
+
", queueDatas="
+
queueDatas
+
", brokerDatas="
+
brokerDatas
+
", filterServerTable="
+
filterServerTable
+
",
logicalQueuesInfo="
+
logicalQueuesInfo
+
"]"
;
+
", brokerDatas="
+
brokerDatas
+
", filterServerTable="
+
filterServerTable
+
",
topicQueueMappingInfoTable="
+
topicQueueMappingByBroker
+
"]"
;
}
}
namesrv/src/main/java/org/apache/rocketmq/namesrv/processor/ClusterTestRequestProcessor.java
浏览文件 @
7707275e
...
...
@@ -56,7 +56,7 @@ public class ClusterTestRequestProcessor extends DefaultRequestProcessor {
final
GetRouteInfoRequestHeader
requestHeader
=
(
GetRouteInfoRequestHeader
)
request
.
decodeCommandCustomHeader
(
GetRouteInfoRequestHeader
.
class
);
TopicRouteData
topicRouteData
=
this
.
namesrvController
.
getRouteInfoManager
().
pickupTopicRouteData
(
requestHeader
.
getTopic
()
,
false
);
TopicRouteData
topicRouteData
=
this
.
namesrvController
.
getRouteInfoManager
().
pickupTopicRouteData
(
requestHeader
.
getTopic
());
if
(
topicRouteData
!=
null
)
{
String
orderTopicConf
=
this
.
namesrvController
.
getKvConfigManager
().
getKVConfig
(
NamesrvUtil
.
NAMESPACE_ORDER_TOPIC_CONFIG
,
...
...
namesrv/src/main/java/org/apache/rocketmq/namesrv/processor/DefaultRequestProcessor.java
浏览文件 @
7707275e
...
...
@@ -19,7 +19,6 @@ package org.apache.rocketmq.namesrv.processor;
import
io.netty.channel.ChannelHandlerContext
;
import
java.io.UnsupportedEncodingException
;
import
java.util.Properties
;
import
java.util.Set
;
import
java.util.concurrent.atomic.AtomicLong
;
import
org.apache.rocketmq.common.DataVersion
;
import
org.apache.rocketmq.common.MQVersion
;
...
...
@@ -53,9 +52,7 @@ import org.apache.rocketmq.common.protocol.header.namesrv.RegisterBrokerResponse
import
org.apache.rocketmq.common.protocol.header.namesrv.UnRegisterBrokerRequestHeader
;
import
org.apache.rocketmq.common.protocol.header.namesrv.WipeWritePermOfBrokerRequestHeader
;
import
org.apache.rocketmq.common.protocol.header.namesrv.WipeWritePermOfBrokerResponseHeader
;
import
org.apache.rocketmq.common.protocol.route.LogicalQueuesInfoUnordered
;
import
org.apache.rocketmq.common.protocol.route.TopicRouteDataNameSrv
;
import
org.apache.rocketmq.common.sysflag.MessageSysFlag
;
import
org.apache.rocketmq.common.protocol.route.TopicRouteData
;
import
org.apache.rocketmq.namesrv.NamesrvController
;
import
org.apache.rocketmq.remoting.common.RemotingHelper
;
import
org.apache.rocketmq.remoting.exception.RemotingCommandException
;
...
...
@@ -353,9 +350,7 @@ public class DefaultRequestProcessor extends AsyncNettyRequestProcessor implemen
final
GetRouteInfoRequestHeader
requestHeader
=
(
GetRouteInfoRequestHeader
)
request
.
decodeCommandCustomHeader
(
GetRouteInfoRequestHeader
.
class
);
boolean
includeLogicalQueuesInfo
=
(
requestHeader
.
getSysFlag
()
&
MessageSysFlag
.
LOGICAL_QUEUE_FLAG
)
>
0
;
TopicRouteDataNameSrv
topicRouteData
=
this
.
namesrvController
.
getRouteInfoManager
().
pickupTopicRouteData
(
requestHeader
.
getTopic
(),
includeLogicalQueuesInfo
);
TopicRouteData
topicRouteData
=
this
.
namesrvController
.
getRouteInfoManager
().
pickupTopicRouteData
(
requestHeader
.
getTopic
());
if
(
topicRouteData
!=
null
)
{
if
(
this
.
namesrvController
.
getNamesrvConfig
().
isOrderMessageEnable
())
{
...
...
@@ -365,16 +360,6 @@ public class DefaultRequestProcessor extends AsyncNettyRequestProcessor implemen
topicRouteData
.
setOrderTopicConf
(
orderTopicConf
);
}
Set
<
Integer
>
logicalQueueIdsFilter
=
requestHeader
.
getLogicalQueueIdsFilter
();
if
(
logicalQueueIdsFilter
!=
null
)
{
LogicalQueuesInfoUnordered
logicalQueuesInfo
=
topicRouteData
.
getLogicalQueuesInfoUnordered
();
if
(
logicalQueuesInfo
!=
null
)
{
LogicalQueuesInfoUnordered
filtered
=
new
LogicalQueuesInfoUnordered
(
logicalQueueIdsFilter
.
size
());
logicalQueueIdsFilter
.
forEach
(
integer
->
filtered
.
put
(
integer
,
logicalQueuesInfo
.
get
(
integer
)));
topicRouteData
.
setLogicalQueuesInfoUnordered
(
filtered
);
}
}
byte
[]
content
=
topicRouteData
.
encode
();
response
.
setBody
(
content
);
response
.
setCode
(
ResponseCode
.
SUCCESS
);
...
...
namesrv/src/main/java/org/apache/rocketmq/namesrv/routeinfo/RouteInfoManager.java
浏览文件 @
7707275e
...
...
@@ -17,7 +17,6 @@
package
org.apache.rocketmq.namesrv.routeinfo
;
import
io.netty.channel.Channel
;
import
java.util.Collection
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Iterator
;
...
...
@@ -25,19 +24,18 @@ import java.util.LinkedList;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Objects
;
import
java.util.Set
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentMap
;
import
java.util.concurrent.locks.ReadWriteLock
;
import
java.util.concurrent.locks.ReentrantReadWriteLock
;
import
java.util.stream.Collectors
;
import
org.apache.rocketmq.common.DataVersion
;
import
org.apache.rocketmq.common.MixAll
;
import
org.apache.rocketmq.common.TopicConfig
;
import
org.apache.rocketmq.common.TopicQueueMappingInfo
;
import
org.apache.rocketmq.common.constant.LoggerName
;
import
org.apache.rocketmq.common.constant.PermName
;
import
org.apache.rocketmq.common.protocol.RequestCode
;
import
org.apache.rocketmq.common.protocol.body.TopicConfigAndMappingSerializeWrapper
;
import
org.apache.rocketmq.logging.InternalLogger
;
import
org.apache.rocketmq.logging.InternalLoggerFactory
;
import
org.apache.rocketmq.common.namesrv.RegisterBrokerResult
;
...
...
@@ -45,13 +43,10 @@ import org.apache.rocketmq.common.protocol.body.ClusterInfo;
import
org.apache.rocketmq.common.protocol.body.TopicConfigSerializeWrapper
;
import
org.apache.rocketmq.common.protocol.body.TopicList
;
import
org.apache.rocketmq.common.protocol.route.BrokerData
;
import
org.apache.rocketmq.common.protocol.route.LogicalQueuesInfo
;
import
org.apache.rocketmq.common.protocol.route.LogicalQueuesInfoUnordered
;
import
org.apache.rocketmq.common.protocol.route.QueueData
;
import
org.apache.rocketmq.common.protocol.route.TopicRouteData
NameSrv
;
import
org.apache.rocketmq.common.protocol.route.TopicRouteData
;
import
org.apache.rocketmq.common.sysflag.TopicSysFlag
;
import
org.apache.rocketmq.remoting.common.RemotingUtil
;
import
org.apache.rocketmq.srvutil.ConcurrentHashMapUtil
;
public
class
RouteInfoManager
{
private
static
final
InternalLogger
log
=
InternalLoggerFactory
.
getLogger
(
LoggerName
.
NAMESRV_LOGGER_NAME
);
...
...
@@ -62,7 +57,8 @@ public class RouteInfoManager {
private
final
HashMap
<
String
/* clusterName */
,
Set
<
String
/* brokerName */
>>
clusterAddrTable
;
private
final
HashMap
<
String
/* brokerAddr */
,
BrokerLiveInfo
>
brokerLiveTable
;
private
final
HashMap
<
String
/* brokerAddr */
,
List
<
String
>
/* Filter Server */
>
filterServerTable
;
private
final
ConcurrentMap
<
String
/* topic */
,
LogicalQueuesInfoUnordered
>
logicalQueuesInfoTable
;
private
final
HashMap
<
String
/* topic */
,
Map
<
String
/*brokerName*/
,
TopicQueueMappingInfo
>>
topicQueueMappingInfoTable
;
public
RouteInfoManager
()
{
this
.
topicQueueTable
=
new
HashMap
<
String
,
List
<
QueueData
>>(
1024
);
...
...
@@ -70,7 +66,7 @@ public class RouteInfoManager {
this
.
clusterAddrTable
=
new
HashMap
<
String
,
Set
<
String
>>(
32
);
this
.
brokerLiveTable
=
new
HashMap
<
String
,
BrokerLiveInfo
>(
256
);
this
.
filterServerTable
=
new
HashMap
<
String
,
List
<
String
>>(
256
);
this
.
logicalQueuesInfoTable
=
new
ConcurrentHashMap
<
>(
1024
);
this
.
topicQueueMappingInfoTable
=
new
HashMap
<
String
,
Map
<
String
,
TopicQueueMappingInfo
>
>(
1024
);
}
public
byte
[]
getAllClusterInfo
()
{
...
...
@@ -158,20 +154,21 @@ public class RouteInfoManager {
||
registerFirst
)
{
ConcurrentMap
<
String
,
TopicConfig
>
tcTable
=
topicConfigWrapper
.
getTopicConfigTable
();
Map
<
String
,
LogicalQueuesInfo
>
logicalQueuesInfoMap
=
topicConfigWrapper
.
getLogicalQueuesInfoMap
();
if
(
tcTable
!=
null
)
{
for
(
Map
.
Entry
<
String
,
TopicConfig
>
entry
:
tcTable
.
entrySet
())
{
this
.
createAndUpdateQueueData
(
brokerName
,
entry
.
getValue
());
}
}
if
(
logicalQueuesInfoMap
!=
null
)
{
long
startTime
=
System
.
nanoTime
();
for
(
Map
.
Entry
<
String
,
LogicalQueuesInfo
>
entry
:
logicalQueuesInfoMap
.
entrySet
())
{
String
topicName
=
entry
.
getKey
();
LogicalQueuesInfoUnordered
logicalQueuesInfo
=
ConcurrentHashMapUtil
.
computeIfAbsent
(
this
.
logicalQueuesInfoTable
,
topicName
,
ignore
->
new
LogicalQueuesInfoUnordered
());
mergeLogicalQueuesInfo
(
brokerName
,
topicName
,
logicalQueuesInfo
,
entry
.
getValue
());
TopicConfigAndMappingSerializeWrapper
mappingSerializeWrapper
=
TopicConfigAndMappingSerializeWrapper
.
from
(
topicConfigWrapper
);
Map
<
String
,
TopicQueueMappingInfo
>
topicQueueMappingInfoMap
=
mappingSerializeWrapper
.
getTopicQueueMappingInfoMap
();
for
(
Map
.
Entry
<
String
,
TopicQueueMappingInfo
>
entry
:
topicQueueMappingInfoMap
.
entrySet
())
{
if
(!
topicQueueMappingInfoTable
.
containsKey
(
entry
.
getKey
()))
{
topicQueueMappingInfoTable
.
put
(
entry
.
getKey
(),
new
HashMap
<
String
,
TopicQueueMappingInfo
>());
}
log
.
debug
(
"mergeQueueRouteDataTable topic={} time={}ns"
,
System
.
nanoTime
()
-
startTime
);
topicQueueMappingInfoTable
.
get
(
entry
.
getKey
()).
put
(
entry
.
getValue
().
getBname
(),
entry
.
getValue
()
);
}
}
}
...
...
@@ -403,12 +400,8 @@ public class RouteInfoManager {
}
}
public
TopicRouteDataNameSrv
pickupTopicRouteData
(
final
String
topic
)
{
return
pickupTopicRouteData
(
topic
,
false
);
}
public
TopicRouteDataNameSrv
pickupTopicRouteData
(
final
String
topic
,
boolean
includeLogicalQueuesInfo
)
{
TopicRouteDataNameSrv
topicRouteData
=
new
TopicRouteDataNameSrv
();
public
TopicRouteData
pickupTopicRouteData
(
final
String
topic
)
{
TopicRouteData
topicRouteData
=
new
TopicRouteData
();
boolean
foundQueueData
=
false
;
boolean
foundBrokerData
=
false
;
Set
<
String
>
brokerNameSet
=
new
HashSet
<
String
>();
...
...
@@ -417,6 +410,7 @@ public class RouteInfoManager {
HashMap
<
String
,
List
<
String
>>
filterServerMap
=
new
HashMap
<
String
,
List
<
String
>>();
topicRouteData
.
setFilterServerTable
(
filterServerMap
);
topicRouteData
.
setTopicQueueMappingByBroker
(
this
.
topicQueueMappingInfoTable
.
get
(
topic
));
try
{
try
{
...
...
@@ -456,10 +450,6 @@ public class RouteInfoManager {
log
.
debug
(
"pickupTopicRouteData {} {}"
,
topic
,
topicRouteData
);
if
(
foundBrokerData
&&
foundQueueData
)
{
if
(
includeLogicalQueuesInfo
)
{
topicRouteData
.
setLogicalQueuesInfoUnordered
(
logicalQueuesInfoTable
.
get
(
topic
));
}
return
topicRouteData
;
}
...
...
@@ -790,34 +780,6 @@ public class RouteInfoManager {
return
topicList
.
encode
();
}
private
static
void
mergeLogicalQueuesInfo
(
String
brokerName
,
String
topicName
,
LogicalQueuesInfoUnordered
logicalQueuesInfoInNamesrv
,
LogicalQueuesInfo
logicalQueuesInfoFromBroker
)
{
Set
<
LogicalQueuesInfoUnordered
.
Key
>
newKeys
=
logicalQueuesInfoFromBroker
.
values
()
.
stream
()
.
flatMap
(
Collection:
:
stream
)
.
filter
(
v
->
Objects
.
equals
(
brokerName
,
v
.
getBrokerName
()))
.
map
(
v
->
new
LogicalQueuesInfoUnordered
.
Key
(
null
,
v
.
getQueueId
(),
v
.
getOffsetDelta
()))
.
collect
(
Collectors
.
toSet
());
logicalQueuesInfoInNamesrv
.
values
().
forEach
(
m
->
m
.
values
().
removeIf
(
queueRouteData
->
Objects
.
equals
(
brokerName
,
queueRouteData
.
getBrokerName
())
&&
!
newKeys
.
contains
(
new
LogicalQueuesInfoUnordered
.
Key
(
null
,
queueRouteData
.
getQueueId
(),
queueRouteData
.
getOffsetDelta
()))));
logicalQueuesInfoFromBroker
.
forEach
((
logicalQueueId
,
queueRouteDataListFromBroker
)
->
{
if
(
logicalQueueId
==
null
)
{
log
.
warn
(
"queueRouteDataTable topic {} contains null logicalQueueId: {}"
,
topicName
,
logicalQueuesInfoFromBroker
);
return
;
}
queueRouteDataListFromBroker
.
stream
()
.
filter
(
queueRouteDataFromBroker
->
Objects
.
equals
(
brokerName
,
queueRouteDataFromBroker
.
getBrokerName
()))
.
forEach
(
queueRouteDataFromBroker
->
ConcurrentHashMapUtil
.
computeIfAbsent
(
logicalQueuesInfoInNamesrv
,
logicalQueueId
,
ignored
->
new
ConcurrentHashMap
<>(
queueRouteDataListFromBroker
.
size
()))
.
put
(
new
LogicalQueuesInfoUnordered
.
Key
(
brokerName
,
queueRouteDataFromBroker
.
getQueueId
(),
queueRouteDataFromBroker
.
getOffsetDelta
()),
queueRouteDataFromBroker
)
);
});
}
}
class
BrokerLiveInfo
{
...
...
namesrv/src/test/java/org/apache/rocketmq/namesrv/processor/DefaultRequestProcessorTest.java
浏览文件 @
7707275e
...
...
@@ -200,7 +200,7 @@ public class DefaultRequestProcessorTest {
.
contains
(
new
HashMap
.
SimpleEntry
(
"broker"
,
broker
));
}
@Test
/*
@Test
public void testProcessRequest_RegisterBrokerLogicalQueue() throws Exception {
String cluster = "cluster";
String broker1Name = "broker1";
...
...
@@ -299,7 +299,7 @@ public class DefaultRequestProcessorTest {
assertThat(topicRouteDataNameSrv.getLogicalQueuesInfoUnordered()).isEqualTo(logicalQueuesInfoUnordered);
}
}
*/
@Test
public
void
testProcessRequest_RegisterBrokerWithFilterServer
()
throws
RemotingCommandException
,
NoSuchFieldException
,
IllegalAccessException
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录