You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by xi...@apache.org on 2022/12/05 09:53:29 UTC
[pulsar] branch branch-2.10 updated: [fix][broker] Fix Npe thrown by splitBundle (#17370)
This is an automated email from the ASF dual-hosted git repository.
xiangying pushed a commit to branch branch-2.10
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.10 by this push:
new e72007d269c [fix][broker] Fix Npe thrown by splitBundle (#17370)
e72007d269c is described below
commit e72007d269cf1b3cc1a5a3cc86b7aae681788475
Author: gaozhangmin <zh...@apache.org>
AuthorDate: Thu Sep 1 20:27:09 2022 +0800
[fix][broker] Fix Npe thrown by splitBundle (#17370)
(cherry picked from commit 1668c072a235ff7b87c88c7781beab09dc2742d1)
---
.../pulsar/broker/admin/impl/NamespacesBase.java | 13 +++++++++++--
.../broker/namespace/NamespaceServiceTest.java | 21 +++++++++++++++++++++
2 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java
index 174f6a2b139..87bbc4527f4 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java
@@ -1224,6 +1224,10 @@ public abstract class NamespacesBase extends AdminResource {
log.info("[{}] Split namespace bundle {}/{}", clientAppId(), namespaceName, bundleName);
String bundleRange = getBundleRange(bundleName);
+ if (bundleRange == null) {
+ throw new RestException(Status.NOT_FOUND,
+ String.format("Bundle range %s not found", bundleName));
+ }
Policies policies = getNamespacePolicies(namespaceName);
@@ -1276,13 +1280,18 @@ public abstract class NamespacesBase extends AdminResource {
}
private String getBundleRange(String bundleName) {
+ NamespaceBundle nsBundle;
if (BundleType.LARGEST.toString().equals(bundleName)) {
- return findLargestBundleWithTopics(namespaceName).getBundleRange();
+ nsBundle = findLargestBundleWithTopics(namespaceName);
} else if (BundleType.HOT.toString().equals(bundleName)) {
- return findHotBundle(namespaceName).getBundleRange();
+ nsBundle = findHotBundle(namespaceName);
} else {
return bundleName;
}
+ if (nsBundle == null) {
+ return null;
+ }
+ return nsBundle.getBundleRange();
}
private NamespaceBundle findLargestBundleWithTopics(NamespaceName namespaceName) {
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/namespace/NamespaceServiceTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/namespace/NamespaceServiceTest.java
index f1e42b80a09..1fc42214401 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/namespace/NamespaceServiceTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/namespace/NamespaceServiceTest.java
@@ -55,6 +55,7 @@ import org.apache.pulsar.broker.lookup.LookupResult;
import org.apache.pulsar.broker.service.BrokerTestBase;
import org.apache.pulsar.broker.service.Topic;
import org.apache.pulsar.broker.service.persistent.PersistentTopic;
+import org.apache.pulsar.client.admin.PulsarAdminException;
import org.apache.pulsar.client.api.Consumer;
import org.apache.pulsar.common.naming.NamespaceBundle;
import org.apache.pulsar.common.naming.NamespaceBundleFactory;
@@ -586,6 +587,26 @@ public class NamespaceServiceTest extends BrokerTestBase {
}
}
+ public void testSplitBUndleWithNoBundle() throws Exception {
+ conf.setLoadManagerClassName(ModularLoadManagerImpl.class.getName());
+ restartBroker();
+ String namespace = "prop/test/ns-abc2";
+
+ BundlesData bundleData = BundlesData.builder().numBundles(10).build();
+ admin.namespaces().createNamespace(namespace, bundleData);
+
+ NamespaceService namespaceService = pulsar.getNamespaceService();
+ NamespaceName nsname = NamespaceName.get(namespace);
+ NamespaceBundles bundles = namespaceService.getNamespaceBundleFactory().getBundles(nsname);
+
+ try {
+ admin.namespaces().splitNamespaceBundle(namespace, Policies.BundleType.HOT.toString(), false, null);
+ fail("should have failed.");
+ } catch (Exception ex) {
+ Assert.assertEquals(404, ((PulsarAdminException) ex).getStatusCode());
+ Assert.assertEquals("Bundle range HOT not found", ex.getMessage());
+ }
+ }
/**
* Test bundle split with hot bundle which is serving highest load.
*