Skip to content

Commit

Permalink
Set splitNamespaceBundle with readonly=false. (#14680)
Browse files Browse the repository at this point in the history
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 4ffef1a)
  • Loading branch information
Technoboy- authored and codelipenghui committed Mar 18, 2022
1 parent 08eceb7 commit a61aa5c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit a61aa5c

Please sign in to comment.