mattisonchao commented on code in PR #19844:
URL: https://github.com/apache/pulsar/pull/19844#discussion_r1139218700
##########
pulsar-metadata/src/main/java/org/apache/pulsar/metadata/coordination/impl/ResourceLockImpl.java:
##########
@@ -74,22 +74,16 @@ public synchronized T getValue() {
public synchronized CompletableFuture<Void> updateValue(T newValue) {
// If there is an operation in progress, we're going to let it
complete before attempting to
// update the value
- if (pendingOperationFuture.isDone()) {
- pendingOperationFuture = CompletableFuture.completedFuture(null);
- }
-
- pendingOperationFuture = pendingOperationFuture.thenCompose(v -> {
- synchronized (ResourceLockImpl.this) {
- if (state != State.Valid) {
- return CompletableFuture.failedFuture(
- new IllegalStateException("Lock was not in valid
state: " + state));
- }
-
- return acquire(newValue);
- }
- });
-
- return pendingOperationFuture;
+ return pendingOperationFuture =
pendingOperationFuture.exceptionally(ex -> null) // ignore all the exception
Review Comment:
>Another issue here is that we keep chaining at the back of the same future.
With many updates the link of future can become very long. We should break it
by starting with a dummy completed future when the existing one is completed.
There is a question:
From the source code of `CompletableFuture`, it will always create a new
future while we use `thenCompose`.
https://github.com/mattisonchao/jdk/blob/5b2e2e4695768a6bd8090fb9a6c342fcddcbb3fd/src/java.base/share/classes/java/util/concurrent/CompletableFuture.java#L1170
So, what do you mean by "back of the same future. ". could you please explan
it? : )
--
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]