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 2022/06/06 08:23:53 UTC

[GitHub] [pulsar] leizhiyuan commented on a diff in pull request #15857: fix: make internalSetMaxConsumersPerSubscription async

leizhiyuan commented on code in PR #15857:
URL: https://github.com/apache/pulsar/pull/15857#discussion_r889928827


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java:
##########
@@ -2201,28 +2201,27 @@ protected Integer internalGetMaxConsumersPerSubscription() {
         return getNamespacePolicies(namespaceName).max_consumers_per_subscription;
     }
 
-    protected void internalSetMaxConsumersPerSubscription(Integer maxConsumersPerSubscription) {
-        validateNamespacePolicyOperation(namespaceName, PolicyName.MAX_CONSUMERS, PolicyOperation.WRITE);
-        validatePoliciesReadOnlyAccess();
+    protected CompletableFuture<Void> internalSetMaxConsumersPerSubscription(Integer maxConsumersPerSubscription) {
 
-        try {
-            if (maxConsumersPerSubscription != null && maxConsumersPerSubscription < 0) {
-                throw new RestException(Status.PRECONDITION_FAILED,
-                        "maxConsumersPerSubscription must be 0 or more");
-            }
-            updatePolicies(namespaceName, policies -> {
-                policies.max_consumers_per_subscription = maxConsumersPerSubscription;
-                return policies;
-            });
-            log.info("[{}] Successfully updated maxConsumersPerSubscription configuration: namespace={}, value={}",
-                    clientAppId(), namespaceName, maxConsumersPerSubscription);
-        } catch (RestException pfe) {
-            throw pfe;
-        } catch (Exception e) {
-            log.error("[{}] Failed to update maxConsumersPerSubscription configuration for namespace {}",
-                    clientAppId(), namespaceName, e);
-            throw new RestException(e);
-        }
+        CompletableFuture<Void> ret;
+        ret = validateNamespacePolicyOperationAsync(namespaceName, PolicyName.MAX_CONSUMERS, PolicyOperation.WRITE)
+                .thenCompose(__ -> validatePoliciesReadOnlyAccessAsync())
+                .thenCompose(__ -> {
+                    if (maxConsumersPerSubscription != null && maxConsumersPerSubscription < 0) {
+                        throw new RestException(Status.PRECONDITION_FAILED,
+                                "maxConsumersPerSubscription must be 0 or more");
+                    }
+                    return updatePoliciesAsync(namespaceName, policies -> {
+                        policies.max_consumers_per_subscription = maxConsumersPerSubscription;
+                        return policies;
+                    });
+
+                }).exceptionally(ex -> {
+                    Throwable realCause = FutureUtil.unwrapCompletionException(ex);

Review Comment:
   done



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org