You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2017/10/26 18:34:08 UTC
[GitHub] merlimat closed pull request #859: fix: return correct error while splitting bundle which can't be split further
merlimat closed pull request #859: fix: return correct error while splitting bundle which can't be split further
URL: https://github.com/apache/incubator-pulsar/pull/859
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/Namespaces.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/Namespaces.java
index f8397e359..f18ff2d39 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/Namespaces.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/Namespaces.java
@@ -857,6 +857,10 @@ public void splitNamespaceBundle(@PathParam("property") String property, @PathPa
try {
pulsar().getNamespaceService().splitAndOwnBundle(nsBundle).get();
log.info("[{}] Successfully split namespace bundle {}", clientAppId(), nsBundle.toString());
+ } catch (IllegalArgumentException e) {
+ log.error("[{}] Failed to split namespace bundle {}/{} due to {}", clientAppId(), fqnn.toString(),
+ bundleRange, e.getMessage());
+ throw new RestException(Status.PRECONDITION_FAILED, "Split bundle failed due to invalid request");
} catch (Exception e) {
log.error("[{}] Failed to split namespace bundle {}/{}", clientAppId(), fqnn.toString(), bundleRange, e);
throw new RestException(e);
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/common/naming/NamespaceBundleFactory.java b/pulsar-broker/src/main/java/org/apache/pulsar/common/naming/NamespaceBundleFactory.java
index b5944886a..94d6859f6 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/common/naming/NamespaceBundleFactory.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/common/naming/NamespaceBundleFactory.java
@@ -192,6 +192,7 @@ public static BundlesData getBundlesData(NamespaceBundles bundles) throws Except
*/
public Pair<NamespaceBundles, List<NamespaceBundle>> splitBundles(NamespaceBundle targetBundle, int numBundles)
throws Exception {
+ checkArgument(canSplitBundle(targetBundle), "%s bundle can't be split further", targetBundle);
checkNotNull(targetBundle, "can't split null bundle");
checkNotNull(targetBundle.getNamespaceObject(), "namespace must be present");
NamespaceName nsname = targetBundle.getNamespaceObject();
@@ -202,8 +203,8 @@ public static BundlesData getBundlesData(NamespaceBundles bundles) throws Except
final long[] partitions = new long[sourceBundle.partitions.length + (numBundles - 1)];
int pos = 0;
int splitPartition = -1;
+ final Range<Long> range = targetBundle.getKeyRange();
for (int i = 0; i < lastIndex; i++) {
- final Range<Long> range = targetBundle.getKeyRange();
if (sourceBundle.partitions[i] == range.lowerEndpoint()
&& (range.upperEndpoint() == sourceBundle.partitions[i + 1])) {
splitPartition = i;
@@ -230,6 +231,11 @@ public static BundlesData getBundlesData(NamespaceBundles bundles) throws Except
return null;
}
+ private boolean canSplitBundle(NamespaceBundle bundle) {
+ Range<Long> range = bundle.getKeyRange();
+ return range.upperEndpoint() - range.lowerEndpoint() > 1;
+ }
+
public static void validateFullRange(SortedSet<String> partitions) {
checkArgument(partitions.first().equals(FIRST_BOUNDARY) && partitions.last().equals(LAST_BOUNDARY));
}
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 63bb3e698..e737a9d5c 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
@@ -861,6 +861,31 @@ public void testSplitBundles() throws Exception {
}
@Test
+ public void testSplitBundleWithUnDividedRange() throws Exception {
+ URL localWebServiceUrl = new URL(pulsar.getWebServiceAddress());
+ String bundledNsLocal = "test-bundled-namespace-1";
+ BundlesData bundleData = new BundlesData(
+ Lists.newArrayList("0x00000000", "0x08375b1a", "0x08375b1b", "0xffffffff"));
+ createBundledTestNamespaces(this.testProperty, this.testLocalCluster, bundledNsLocal, bundleData);
+ final NamespaceName testNs = new NamespaceName(this.testProperty, this.testLocalCluster, bundledNsLocal);
+
+ OwnershipCache MockOwnershipCache = spy(pulsar.getNamespaceService().getOwnershipCache());
+ doNothing().when(MockOwnershipCache).disableOwnership(any(NamespaceBundle.class));
+ Field ownership = NamespaceService.class.getDeclaredField("ownershipCache");
+ ownership.setAccessible(true);
+ ownership.set(pulsar.getNamespaceService(), MockOwnershipCache);
+ mockWebUrl(localWebServiceUrl, testNs);
+
+ // split bundles
+ try {
+ namespaces.splitNamespaceBundle(testProperty, testLocalCluster, bundledNsLocal, "0x08375b1a_0x08375b1b",
+ false);
+ } catch (RestException re) {
+ assertEquals(re.getResponse().getStatus(), Status.PRECONDITION_FAILED.getStatusCode());
+ }
+ }
+
+ @Test
public void testUnloadNamespaceWithBundles() throws Exception {
URL localWebServiceUrl = new URL(pulsar.getWebServiceAddress());
String bundledNsLocal = "test-bundled-namespace-1";
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services