Skip to content

[ISSUE #7534]use a new class to replace topiclist in concurrent scene #7559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个类似乎与之前的TopicList完全一致,有什么区别吗

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

目前问题是原来的TopicList中改成CopyOnWriteArraySet后,在某些接口调用时,如果topic数很大会有超时的问题,但如果用原来的HashSet则不会有这个问题,新增的需要并发修改的接口则用新增的ConcurrentTopicList这个类,避免并发修改的异常,通过这种方式把两类接口区分开

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如何判断是这里慢而不是 config json flush 慢呢

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

增加了一个单元测试证明两个类在add huge topiclist时效率的差异

* 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.remoting.protocol.body;

import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import org.apache.rocketmq.remoting.protocol.RemotingSerializable;

public class ConcurrentTopicList extends RemotingSerializable {
private Set<String> topicList = new CopyOnWriteArraySet<>();
private String brokerAddr;

public Set<String> getTopicList() {
return topicList;
}

public void setTopicList(Set<String> topicList) {
this.topicList = topicList;
}

public String getBrokerAddr() {
return brokerAddr;
}

public void setBrokerAddr(String brokerAddr) {
this.brokerAddr = brokerAddr;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
*/
package org.apache.rocketmq.remoting.protocol.body;

import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import org.apache.rocketmq.remoting.protocol.RemotingSerializable;

public class TopicList extends RemotingSerializable {
private Set<String> topicList = new CopyOnWriteArraySet<>();
private Set<String> topicList = new HashSet<>();
private String brokerAddr;

public Set<String> getTopicList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.apache.rocketmq.remoting.protocol.body.BrokerStatsData;
import org.apache.rocketmq.remoting.protocol.body.ClusterAclVersionInfo;
import org.apache.rocketmq.remoting.protocol.body.ClusterInfo;
import org.apache.rocketmq.remoting.protocol.body.ConcurrentTopicList;
import org.apache.rocketmq.remoting.protocol.body.ConsumeMessageDirectlyResult;
import org.apache.rocketmq.remoting.protocol.body.ConsumeStatsList;
import org.apache.rocketmq.remoting.protocol.body.ConsumerConnection;
Expand Down Expand Up @@ -505,7 +506,7 @@ public TopicList queryTopicsByConsumer(String group)
}

@Override
public AdminToolResult<TopicList> queryTopicsByConsumerConcurrent(String group) {
public AdminToolResult<ConcurrentTopicList> queryTopicsByConsumerConcurrent(String group) {
return defaultMQAdminExtImpl.queryTopicsByConsumerConcurrent(group);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
import org.apache.rocketmq.remoting.protocol.body.BrokerStatsData;
import org.apache.rocketmq.remoting.protocol.body.ClusterAclVersionInfo;
import org.apache.rocketmq.remoting.protocol.body.ClusterInfo;
import org.apache.rocketmq.remoting.protocol.body.ConcurrentTopicList;
import org.apache.rocketmq.remoting.protocol.body.ConsumeMessageDirectlyResult;
import org.apache.rocketmq.remoting.protocol.body.ConsumeStatsList;
import org.apache.rocketmq.remoting.protocol.body.ConsumerConnection;
Expand Down Expand Up @@ -1084,7 +1085,7 @@ public TopicList queryTopicsByConsumer(
}

@Override
public AdminToolResult<TopicList> queryTopicsByConsumerConcurrent(final String group) {
public AdminToolResult<ConcurrentTopicList> queryTopicsByConsumerConcurrent(final String group) {
return adminToolExecute(new AdminToolHandler() {
@Override
public AdminToolResult doExecute() throws Exception {
Expand All @@ -1094,7 +1095,7 @@ public AdminToolResult doExecute() throws Exception {
if (topicRouteData == null || CollectionUtils.isEmpty(topicRouteData.getBrokerDatas())) {
return AdminToolResult.failure(AdminToolsResultCodeEnum.TOPIC_ROUTE_INFO_NOT_EXIST, "router info not found.");
}
final TopicList result = new TopicList();
final ConcurrentTopicList result = new ConcurrentTopicList();
final CountDownLatch latch = new CountDownLatch(topicRouteData.getBrokerDatas().size());
for (final BrokerData bd : topicRouteData.getBrokerDatas()) {
threadPoolExecutor.submit(new Runnable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.apache.rocketmq.remoting.protocol.body.BrokerStatsData;
import org.apache.rocketmq.remoting.protocol.body.ClusterAclVersionInfo;
import org.apache.rocketmq.remoting.protocol.body.ClusterInfo;
import org.apache.rocketmq.remoting.protocol.body.ConcurrentTopicList;
import org.apache.rocketmq.remoting.protocol.body.ConsumeMessageDirectlyResult;
import org.apache.rocketmq.remoting.protocol.body.ConsumeStatsList;
import org.apache.rocketmq.remoting.protocol.body.ConsumerConnection;
Expand Down Expand Up @@ -243,7 +244,7 @@ GroupList queryTopicConsumeByWho(final String topic) throws RemotingConnectExcep
TopicList queryTopicsByConsumer(
final String group) throws InterruptedException, MQBrokerException, RemotingException, MQClientException;

AdminToolResult<TopicList> queryTopicsByConsumerConcurrent(final String group);
AdminToolResult<ConcurrentTopicList> queryTopicsByConsumerConcurrent(final String group);

SubscriptionData querySubscription(final String group,
final String topic) throws InterruptedException, MQBrokerException, RemotingException, MQClientException;
Expand Down