You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by pe...@apache.org on 2022/03/19 06:02:25 UTC
[pulsar] 11/14: Set splitNamespaceBundle with `readonly=false`. (#14680)
This is an automated email from the ASF dual-hosted git repository.
penghui pushed a commit to branch branch-2.10
in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit 379322ca14cc11ea2f55df60b07b37a0f2518e5d
Author: Jiwei Guo <te...@apache.org>
AuthorDate: Tue Mar 15 16:00:37 2022 +0800
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)
---
.../apache/pulsar/broker/admin/impl/NamespacesBase.java | 2 +-
.../org/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 382128c..e4ff7cd 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
@@ -1137,7 +1137,7 @@ public abstract class NamespacesBase extends AdminResource {
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 a6436f0..0b62f6e 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
@@ -1742,4 +1742,18 @@ public class NamespacesTest extends MockedPulsarServiceBaseTest {
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);
+ }
}