Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix][broker] Fix ownership loss #23515

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
nodece marked this conversation as resolved.
Show resolved Hide resolved
} catch (Exception e) {
heesung-sn marked this conversation as resolved.
Show resolved Hide resolved
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
Loading