Skip to content

Commit

Permalink
[fix][broker] Fix ownership loss
Browse files Browse the repository at this point in the history
Signed-off-by: Zixuan Liu <nodeces@gmail.com>
  • Loading branch information
nodece committed Nov 2, 2024
1 parent 570cb44 commit c765197
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,17 @@ public CompletableFuture<Optional<NamespaceEphemeralData>> getOwnerAsync(Namespa

// If we're not the owner, we need to check if anybody else is
String path = ServiceUnitUtils.path(suName);
return lockManager.readLock(path);
return lockManager.readLock(path).thenCompose(owner -> {
//If the current broker is the owner, we must try to acquire ownership to avoid cache loss.
if (owner.isPresent() && owner.get().equals(selfOwnerInfo)) {
try {
return tryAcquiringOwnership(suName).thenApply(Optional::ofNullable);
} catch (Exception e) {
return CompletableFuture.failedFuture(e);
}
}
return CompletableFuture.completedFuture(owner);
});
}

/**
Expand Down

0 comments on commit c765197

Please sign in to comment.