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 pulsar-admin topics stats-internal caused a BK client thread a deadlock #23258

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
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 @@ -48,6 +48,7 @@
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -2819,13 +2820,13 @@ public CompletableFuture<PersistentTopicInternalStats> getInternalStats(boolean
info.entries = -1;
info.size = -1;

Optional<CompactedTopicContext> compactedTopicContext = getCompactedTopicContext();
if (compactedTopicContext.isPresent()) {
CompactedTopicContext ledgerContext = compactedTopicContext.get();
info.ledgerId = ledgerContext.getLedger().getId();
info.entries = ledgerContext.getLedger().getLastAddConfirmed() + 1;
info.size = ledgerContext.getLedger().getLength();
}
futures.add(getCompactedTopicContextAsync().thenAccept(v -> {
if (v != null) {
info.ledgerId = v.getLedger().getId();
info.entries = v.getLedger().getLastAddConfirmed() + 1;
info.size = v.getLedger().getLength();
}
}));

stats.compactedLedger = info;

Expand Down Expand Up @@ -2951,12 +2952,24 @@ public Optional<CompactedTopicContext> getCompactedTopicContext() {
if (topicCompactionService instanceof PulsarTopicCompactionService pulsarCompactedService) {
return pulsarCompactedService.getCompactedTopic().getCompactedTopicContext();
}
} catch (ExecutionException | InterruptedException e) {
} catch (ExecutionException | InterruptedException | TimeoutException e) {
log.warn("[{}]Fail to get ledger information for compacted topic.", topic);
}
return Optional.empty();
}

public CompletableFuture<CompactedTopicContext> getCompactedTopicContextAsync() {
if (topicCompactionService instanceof PulsarTopicCompactionService pulsarCompactedService) {
CompletableFuture<CompactedTopicContext> res =
pulsarCompactedService.getCompactedTopic().getCompactedTopicContextFuture();
if (res == null) {
return CompletableFuture.completedFuture(null);
}
return res;
}
return CompletableFuture.completedFuture(null);
}

public long getBacklogSize() {
return ledger.getEstimatedBacklogSize();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Predicate;
import javax.annotation.Nullable;
import org.apache.bookkeeper.client.BKException;
Expand Down Expand Up @@ -304,8 +306,10 @@ static CompletableFuture<List<Entry>> readEntries(LedgerHandle lh, long from, lo
* Getter for CompactedTopicContext.
* @return CompactedTopicContext
*/
public Optional<CompactedTopicContext> getCompactedTopicContext() throws ExecutionException, InterruptedException {
return compactedTopicContext == null ? Optional.empty() : Optional.of(compactedTopicContext.get());
public Optional<CompactedTopicContext> getCompactedTopicContext() throws ExecutionException, InterruptedException,
nodece marked this conversation as resolved.
Show resolved Hide resolved
poorbarcode marked this conversation as resolved.
Show resolved Hide resolved
TimeoutException {
return compactedTopicContext == null ? Optional.empty() :
Optional.of(compactedTopicContext.get(30, TimeUnit.SECONDS));
}

@Override
Expand Down
Loading