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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]