lordcheng10 commented on code in PR #17797:
URL: https://github.com/apache/pulsar/pull/17797#discussion_r990754024
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/NamespaceService.java:
##########
@@ -959,6 +970,34 @@ void splitAndOwnBundleOnceAndRetry(NamespaceBundle bundle,
});
}
+ /**
+ * Update new bundle-range to admin/policies/namespace.
+ * Update may fail because of concurrent write to Zookeeper.
+ *
+ * @param nsname
+ * @param nsBundles
+ * @throws Exception
+ */
+ private CompletableFuture<Void>
updateNamespaceBundlesForPolicies(NamespaceName nsname,
+
NamespaceBundles nsBundles) {
+ Objects.requireNonNull(nsname);
+ Objects.requireNonNull(nsBundles);
+
+ return
pulsar.getPulsarResources().getNamespaceResources().getPoliciesAsync(nsname).thenCompose(policies
-> {
+ if (policies.isPresent()) {
+ return
pulsar.getPulsarResources().getNamespaceResources().setPoliciesAsync(nsname,
oldPolicies -> {
+ oldPolicies.bundles = nsBundles.getBundlesData();
+ return oldPolicies;
+ });
+ } else {
+ Policies newPolicies = new Policies();
Review Comment:
Fixed,PTAL,thanks! @AnonHxy
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/NamespaceService.java:
##########
@@ -880,12 +881,22 @@ void splitAndOwnBundleOnceAndRetry(NamespaceBundle bundle,
for (NamespaceBundle sBundle :
splittedBundles.getRight()) {
Objects.requireNonNull(ownershipCache.tryAcquiringOwnership(sBundle));
}
- updateNamespaceBundles(nsname,
splittedBundles.getLeft())
- .thenRun(() -> {
-
bundleFactory.invalidateBundleCache(bundle.getNamespaceObject());
-
updateFuture.complete(splittedBundles.getRight());
- }).exceptionally(ex1 -> {
- String msg = format("failed to update
namespace policies [%s], "
+ updateNamespaceBundles(nsname,
splittedBundles.getLeft()).thenRun(() -> {
+
updateNamespaceBundlesForPolicies(nsname, splittedBundles.getLeft())
+ .thenRun(() -> {
+
bundleFactory.invalidateBundleCache(bundle.getNamespaceObject());
+
updateFuture.complete(splittedBundles.getRight());
+ }).exceptionally(e -> {
+ String msg =
format("failed to update namespace policies [%s], "
+ +
"NamespaceBundle: %s due to %s",
+ nsname.toString(),
bundle.getBundleRange(), e.getMessage());
+ LOG.warn(msg);
+
updateFuture.completeExceptionally(
+ new
ServiceUnitNotReadyException(msg, e.getCause()));
+ return null;
+ });
Review Comment:
Fixed,PTAL,thanks! @AnonHxy
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]