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 4, 2024
1 parent 570cb44 commit f7afe5d
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,22 @@ 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, attempt to reacquire ownership to avoid cache loss.
if (owner.isPresent() && owner.get().equals(selfOwnerInfo)) {
log.warn("Detected ownership loss for broker [{}] on namespace bundle [{}]. "
+ "Attempting to reacquire ownership to maintain cache consistency.",
selfOwnerInfo, suName);
try {
return tryAcquiringOwnership(suName).thenApply(Optional::ofNullable);
} catch (Exception e) {
log.error("Failed to reacquire ownership for namespace bundle [{}] on broker [{}]: {}",
suName, selfOwnerInfo, e.getMessage(), e);
return CompletableFuture.failedFuture(e);
}
}
return CompletableFuture.completedFuture(owner);
});
}

/**
Expand Down

0 comments on commit f7afe5d

Please sign in to comment.