This is an automated email from the ASF dual-hosted git repository.
aloyszhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 6ca9ee98ebd [fix][broker] Fixed that newly added brokers cannot be
assigned bundles for UniformLoadShedder (#16401)
6ca9ee98ebd is described below
commit 6ca9ee98ebd9dceab130f28f5638f722fec3a8d9
Author: LinChen <[email protected]>
AuthorDate: Wed Jul 27 10:08:31 2022 +0800
[fix][broker] Fixed that newly added brokers cannot be assigned bundles for
UniformLoadShedder (#16401)
* Fixed the issue that newly added brokers could not be assigned bundles
* skip bundle==1
* add test UniformLoadShedderTest
* check style
---
.../loadbalance/impl/UniformLoadShedder.java | 5 --
.../loadbalance/impl/UniformLoadShedderTest.java | 82 ++++++++++++++++++++++
2 files changed, 82 insertions(+), 5 deletions(-)
diff --git
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/UniformLoadShedder.java
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/UniformLoadShedder.java
index 645019c0ddf..3d400b07cae 100644
---
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/UniformLoadShedder.java
+++
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/UniformLoadShedder.java
@@ -75,11 +75,6 @@ public class UniformLoadShedder implements
LoadSheddingStrategy {
MutableDouble minMsgRate = new MutableDouble(Integer.MAX_VALUE);
MutableDouble minThroughputRate = new MutableDouble(Integer.MAX_VALUE);
brokersData.forEach((broker, data) -> {
- //broker with one bundle can't be considered for bundle unloading
- if (data.getLocalData().getBundles().size() <= 1) {
- return;
- }
-
double msgRate = data.getLocalData().getMsgRateIn() +
data.getLocalData().getMsgRateOut();
double throughputRate = data.getLocalData().getMsgThroughputIn()
+ data.getLocalData().getMsgThroughputOut();
diff --git
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/impl/UniformLoadShedderTest.java
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/impl/UniformLoadShedderTest.java
new file mode 100644
index 00000000000..7affb52c2e4
--- /dev/null
+++
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/impl/UniformLoadShedderTest.java
@@ -0,0 +1,82 @@
+/**
+ * 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.pulsar.broker.loadbalance.impl;
+
+import com.google.common.collect.Multimap;
+import org.apache.pulsar.broker.ServiceConfiguration;
+import org.apache.pulsar.broker.loadbalance.LoadData;
+import org.apache.pulsar.policies.data.loadbalancer.*;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+import static org.testng.Assert.assertFalse;
+
+@Test(groups = "broker")
+public class UniformLoadShedderTest {
+ private UniformLoadShedder uniformLoadShedder;
+
+ private final ServiceConfiguration conf;
+
+ public UniformLoadShedderTest() {
+ conf = new ServiceConfiguration();
+ }
+
+ @BeforeMethod
+ public void setup() {
+ uniformLoadShedder = new UniformLoadShedder();
+ }
+
+ @Test
+ public void testBrokerWithMultipleBundles() {
+ int numBundles = 10;
+ LoadData loadData = new LoadData();
+
+ LocalBrokerData broker1 = new LocalBrokerData();
+ LocalBrokerData broker2 = new LocalBrokerData();
+
+ String broker2Name = "broker2";
+
+ double brokerThroughput = 0;
+
+ for (int i = 1; i <= numBundles; ++i) {
+ broker1.getBundles().add("bundle-" + i);
+
+ BundleData bundle = new BundleData();
+
+ TimeAverageMessageData timeAverageMessageData = new
TimeAverageMessageData();
+
+ double throughput = i * 1024 * 1024;
+ timeAverageMessageData.setMsgThroughputIn(throughput);
+ timeAverageMessageData.setMsgThroughputOut(throughput);
+ bundle.setShortTermData(timeAverageMessageData);
+ loadData.getBundleData().put("bundle-" + i, bundle);
+
+ brokerThroughput += throughput;
+ }
+
+ broker1.setMsgThroughputIn(brokerThroughput);
+ broker1.setMsgThroughputOut(brokerThroughput);
+
+ loadData.getBrokerData().put("broker-1", new BrokerData(broker1));
+ loadData.getBrokerData().put(broker2Name, new BrokerData(broker2));
+
+ Multimap<String, String> bundlesToUnload =
uniformLoadShedder.findBundlesForUnloading(loadData, conf);
+ assertFalse(bundlesToUnload.isEmpty());
+ }
+
+}