From a61aa5c5e925492321583f0b1416b6ac0772ec3a Mon Sep 17 00:00:00 2001 From: Jiwei Guo Date: Tue, 15 Mar 2022 16:00:37 +0800 Subject: [PATCH] Set splitNamespaceBundle with `readonly=false`. (#14680) Master Issue: #14668 Fixes: #14668 ### Motivation When we split a not loaded namespace bundle, we will meet the below error: ``` Failed to find ownership for ServiceUnit:tenant/namespace/0x00000000_0x10000000 ``` Because when validating namespace bundle ownership with `readonly=true` : https://github.com/apache/pulsar/blob/fe7e55d9f353925a559e88f8ceef2b47b59668e0/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java#L1145-L1151 and if the bundle is not owned by any broker, it will return empty(line-392): https://github.com/apache/pulsar/blob/fe7e55d9f353925a559e88f8ceef2b47b59668e0/pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/NamespaceService.java#L388-L400 so throw the below exception : https://github.com/apache/pulsar/blob/fe7e55d9f353925a559e88f8ceef2b47b59668e0/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java#L576-L582 ### Modification - Change readonly from `true` to `false` when validating namespace bundle ownership. (cherry picked from commit 4ffef1adbda405caa3359d108f40eed46fd1a8e8) --- .../pulsar/broker/admin/impl/NamespacesBase.java | 2 +- .../apache/pulsar/broker/admin/NamespacesTest.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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 a9f369d42d4b2..310c0d9d7d584 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 @@ -1116,7 +1116,7 @@ protected void internalSplitNamespaceBundle(AsyncResponse asyncResponse, String try { nsBundle = validateNamespaceBundleOwnership(namespaceName, policies.bundles, bundleRange, - authoritative, true); + authoritative, false); } catch (Exception e) { asyncResponse.resume(e); return; diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/NamespacesTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/NamespacesTest.java index abefe449f6dcf..16ae98f0b43cc 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/NamespacesTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/NamespacesTest.java @@ -1737,4 +1737,18 @@ private void assertInvalidRetentionPolicyAsPartOfAllPolicies(Policies policies, assertTrue(e.getMessage().startsWith("Invalid retention policy")); } } + + @Test + public void testSplitBundleForMultiTimes() throws Exception{ + String namespace = BrokerTestUtil.newUniqueName(this.testTenant + "/namespace"); + BundlesData data = BundlesData.builder().numBundles(4).build(); + admin.namespaces().createNamespace(namespace, data); + for (int i = 0; i < 10; i ++) { + final BundlesData bundles = admin.namespaces().getBundles(namespace); + final String bundle = bundles.getBoundaries().get(0) + "_" + bundles.getBoundaries().get(1); + admin.namespaces().splitNamespaceBundle(namespace, bundle, true, null); + } + BundlesData bundles = admin.namespaces().getBundles(namespace); + assertEquals(bundles.getNumBundles(), 14); + } }