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/08/22 11:13:54 UTC

[GitHub] [pulsar] AnonHxy commented on a diff in pull request #17206: [improve][broker][PIP-149]make deletePersistence method async in Namespaces

AnonHxy commented on code in PR #17206:
URL: https://github.com/apache/pulsar/pull/17206#discussion_r951288419


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java:
##########
@@ -1559,19 +1560,37 @@ protected void internalSetPersistence(PersistencePolicies persistence) {
 
     private void doUpdatePersistence(PersistencePolicies persistence) {
         try {
-            updatePolicies(namespaceName, policies -> {
-                policies.persistence = persistence;
-                return policies;
-            });
-            log.info("[{}] Successfully updated persistence configuration: namespace={}, map={}", clientAppId(),
-                    namespaceName, jsonMapper().writeValueAsString(persistence));
+            doUpdatePersistenceAsyn(persistence).get(namespaceResources().getOperationTimeoutSec(), TimeUnit.SECONDS);
         } catch (Exception e) {
-            log.error("[{}] Failed to update persistence configuration for namespace {}", clientAppId(), namespaceName,
-                    e);
-            throw new RestException(e);
+            Throwable cause = e.getCause();
+            if (!(cause instanceof RestException)) {
+                throw new RestException(cause);
+            } else {
+                throw (RestException) cause;
+            }
         }
     }
 
+    private CompletableFuture<Void> doUpdatePersistenceAsyn(PersistencePolicies persistence) {
+        CompletableFuture<Void> result = new CompletableFuture<>();
+        updatePoliciesAsync(namespaceName, policies -> {
+            policies.persistence = persistence;
+            return policies;
+        }).thenAccept(v -> {
+            try {
+                log.info("[{}] Successfully updated persistence configuration: namespace={}, map={}", clientAppId(),
+                        namespaceName, jsonMapper().writeValueAsString(persistence));
+            } catch (JsonProcessingException ignore) {}

Review Comment:
   ```suggestion
               } catch (Exception ignore) {}
   ```



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java:
##########
@@ -1543,10 +1544,10 @@ protected void internalSetRetention(RetentionPolicies retention) {
         }
     }
 
-    protected void internalDeletePersistence() {
-        validateNamespacePolicyOperation(namespaceName, PolicyName.PERSISTENCE, PolicyOperation.WRITE);
-        validatePoliciesReadOnlyAccess();
-        doUpdatePersistence(null);
+    protected CompletableFuture<Void> internalDeletePersistenceAsyn() {

Review Comment:
   ```suggestion
       protected CompletableFuture<Void> internalDeletePersistenceAsync() {
   ```



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java:
##########
@@ -1559,19 +1560,37 @@ protected void internalSetPersistence(PersistencePolicies persistence) {
 
     private void doUpdatePersistence(PersistencePolicies persistence) {
         try {
-            updatePolicies(namespaceName, policies -> {
-                policies.persistence = persistence;
-                return policies;
-            });
-            log.info("[{}] Successfully updated persistence configuration: namespace={}, map={}", clientAppId(),
-                    namespaceName, jsonMapper().writeValueAsString(persistence));
+            doUpdatePersistenceAsyn(persistence).get(namespaceResources().getOperationTimeoutSec(), TimeUnit.SECONDS);

Review Comment:
   I thinks the modification of this method is unrelated to this PR,  we'd better do not change it now



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java:
##########
@@ -1559,19 +1560,37 @@ protected void internalSetPersistence(PersistencePolicies persistence) {
 
     private void doUpdatePersistence(PersistencePolicies persistence) {
         try {
-            updatePolicies(namespaceName, policies -> {
-                policies.persistence = persistence;
-                return policies;
-            });
-            log.info("[{}] Successfully updated persistence configuration: namespace={}, map={}", clientAppId(),
-                    namespaceName, jsonMapper().writeValueAsString(persistence));
+            doUpdatePersistenceAsyn(persistence).get(namespaceResources().getOperationTimeoutSec(), TimeUnit.SECONDS);
         } catch (Exception e) {
-            log.error("[{}] Failed to update persistence configuration for namespace {}", clientAppId(), namespaceName,
-                    e);
-            throw new RestException(e);
+            Throwable cause = e.getCause();
+            if (!(cause instanceof RestException)) {
+                throw new RestException(cause);
+            } else {
+                throw (RestException) cause;
+            }
         }
     }
 
+    private CompletableFuture<Void> doUpdatePersistenceAsyn(PersistencePolicies persistence) {
+        CompletableFuture<Void> result = new CompletableFuture<>();
+        updatePoliciesAsync(namespaceName, policies -> {

Review Comment:
   ```suggestion
           return updatePoliciesAsync(namespaceName, policies -> {
   ```
   It's better return directly I think :)



-- 
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