merlimat commented on code in PR #19844:
URL: https://github.com/apache/pulsar/pull/19844#discussion_r1139032736
##########
pulsar-metadata/src/main/java/org/apache/pulsar/metadata/coordination/impl/ResourceLockImpl.java:
##########
@@ -197,76 +191,81 @@ private CompletableFuture<Void>
acquireWithNoRevalidation(T newValue) {
}
synchronized void lockWasInvalidated() {
- if (state != State.Valid) {
- // Ignore notifications while we're releasing the lock ourselves
- return;
- }
-
- log.info("Lock on resource {} was invalidated", path);
- revalidate(value, true, true)
- .thenRun(() -> log.info("Successfully revalidated the lock on
{}", path));
+ log.info("Lock on resource {} was invalidated. state {}", path, state);
+ silentRevalidateOnce();
}
synchronized CompletableFuture<Void> revalidateIfNeededAfterReconnection()
{
if (revalidateAfterReconnection) {
- revalidateAfterReconnection = false;
+ ResourceLockImpl.this.revalidateAfterReconnection = false;
Review Comment:
Is the `ResourceLockImpl.this.` part needed here?
##########
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:
I don't think we should ignore the exception here. If the pending
revalidation fails, we are not the owner of the lock anymore and we shouldn't
be updating the lock (which will anyway fail, because the version has changed).
##########
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.
--
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]