From dfc7d245733414092378d83c645aab3dd9873d1d Mon Sep 17 00:00:00 2001 From: danpi Date: Sat, 21 Dec 2024 19:20:56 +0800 Subject: [PATCH] [fix][admin] Fix exception loss in getMessageId method (#23766) Co-authored-by: houbonan (cherry picked from commit 3d505742e05e403144d17aef59c95e2758982a26) --- .../pulsar/broker/admin/impl/PersistentTopicsBase.java | 7 ++++--- .../apache/pulsar/broker/admin/PersistentTopicsTest.java | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java index 1300cd3449c27..4b9fea05cd885 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java @@ -2774,9 +2774,10 @@ protected CompletableFuture internalGetMessageById(long ledgerId, long public void readEntryFailed(ManagedLedgerException exception, Object ctx) { if (exception instanceof ManagedLedgerException.LedgerNotExistException) { - throw new RestException(Status.NOT_FOUND, "Message id not found"); + results.completeExceptionally( + new RestException(Status.NOT_FOUND, "Message id not found")); } - throw new RestException(exception); + results.completeExceptionally(new RestException(exception)); } @Override @@ -2784,7 +2785,7 @@ public void readEntryComplete(Entry entry, Object ctx) { try { results.complete(generateResponseWithEntry(entry, (PersistentTopic) topic)); } catch (IOException exception) { - throw new RestException(exception); + results.completeExceptionally(new RestException(exception)); } finally { if (entry != null) { entry.release(); diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/PersistentTopicsTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/PersistentTopicsTest.java index a38413b2aa7c2..ad6412caa274d 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/PersistentTopicsTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/PersistentTopicsTest.java @@ -1419,6 +1419,10 @@ public void testGetMessageById() throws Exception { Assert.expectThrows(PulsarAdminException.NotFoundException.class, () -> { admin.topics().getMessageById(topicName1, id2.getLedgerId(), id2.getEntryId()); }); + + Assert.expectThrows(PulsarAdminException.ServerSideErrorException.class, () -> { + admin.topics().getMessageById(topicName1, id1.getLedgerId(), id1.getEntryId() + 10); + }); } @Test