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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to