-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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][tableview] fixed ack failure in ReaderImpl due to null messageId #17728
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,17 +177,15 @@ public Message<T> readNext(int timeout, TimeUnit unit) throws PulsarClientExcept | |
|
||
@Override | ||
public CompletableFuture<Message<T>> readNextAsync() { | ||
CompletableFuture<Message<T>> receiveFuture = consumer.receiveAsync(); | ||
receiveFuture.whenComplete((msg, t) -> { | ||
if (msg != null) { | ||
consumer.acknowledgeCumulativeAsync(msg).exceptionally(ex -> { | ||
log.warn("[{}][{}] acknowledge message {} cumulative fail.", getTopic(), | ||
getConsumer().getSubscription(), msg.getMessageId(), ex); | ||
return null; | ||
}); | ||
} | ||
return consumer.receiveAsync().thenApply(msg -> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does this fix work? Your error message says Unless I'm reading this wrong, your change is a cleaner way but the effect remains the same. Baring very unexpected behaviors (for example, If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, the modification is to return the CompetedFuture downstream from The messageId can be null after |
||
consumer.acknowledgeCumulativeAsync(msg) | ||
.exceptionally(ex -> { | ||
log.error("[{}][{}] acknowledge message {} cumulative fail.", getTopic(), | ||
getConsumer().getSubscription(), msg.getMessageId(), ex); | ||
return null; | ||
}); | ||
return msg; | ||
}); | ||
return receiveFuture; | ||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,8 +21,10 @@ | |
import static org.testng.AssertJUnit.assertFalse; | ||
import static org.testng.AssertJUnit.assertTrue; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ConcurrentLinkedQueue; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import org.apache.commons.lang3.reflect.FieldUtils; | ||
import org.apache.pulsar.client.api.Consumer; | ||
import org.apache.pulsar.client.api.Message; | ||
import org.apache.pulsar.client.api.Schema; | ||
|
@@ -64,13 +66,20 @@ public void clean() { | |
} | ||
|
||
@Test | ||
void shouldSupportCancellingReadNextAsync() { | ||
void shouldSupportCancellingReadNextAsync() throws IllegalAccessException { | ||
// given | ||
CompletableFuture<Message<byte[]>> future = reader.readNextAsync(); | ||
reader.readNextAsync(); | ||
Awaitility.await().untilAsserted(() -> { | ||
assertTrue(reader.getConsumer().hasNextPendingReceive()); | ||
}); | ||
|
||
ConsumerBase consumer = (ConsumerBase) | ||
FieldUtils.readDeclaredField(reader, "consumer", true); | ||
ConcurrentLinkedQueue<CompletableFuture<Message<byte[]>>> | ||
pendingReceives = (ConcurrentLinkedQueue<CompletableFuture<Message<byte[]>>>) | ||
FieldUtils.readField(consumer, "pendingReceives", true); | ||
CompletableFuture<Message<byte[]>> future = pendingReceives.peek(); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will break the I have tried this one, it should work for this case. public CompletableFuture<Message<T>> readNextAsync() {
CompletableFuture<Message<T>> originalFuture = consumer.receiveAsync();
CompletableFuture<Message<T>> result = originalFuture.thenApply(msg -> {
consumer.acknowledgeCumulativeAsync(msg)
.exceptionally(ex -> {
log.error("[{}][{}] acknowledge message {} cumulative fail.", getTopic(),
getConsumer().getSubscription(), msg.getMessageId(), ex);
return null;
});
return msg;
});
CompletableFutureCancellationHandler handler = new CompletableFutureCancellationHandler();
handler.attachToFuture(result);
handler.setCancelAction(() -> originalFuture.cancel(false));
return result;
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this seems to be the better approach if we want to keep supporting the I see that the original future, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume the current behavior of |
||
// when | ||
future.cancel(false); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I try the test on my laptop.
Looks like the test for the partitioned topic will always get passed without the fix.
The non-partitioned topic test works fine, I see the warning logs. After applying the fix, the test can get passed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, partitioned topics should pass without this fix.
But we should see the test assert failure from the non-partitioned topic, without this fix.
Please let me know if you see different behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@heesung-sn Yes, the same behavior.