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

Pubsub added message abandonment #4250

Merged
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 @@ -25,10 +25,12 @@ public interface AckReplyConsumer {
* message again.
*/
void ack();

/**
* Signals that the message has not been successfully processed. The service should resend the
* message.
*/
void nack();

void abandon();
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ private class AckHandler implements ApiFutureCallback<AckReply> {
private final int outstandingBytes;
private final long receivedTimeMillis;
private final Instant totalExpiration;
private boolean extending = true;

AckHandler(String ackId, int outstandingBytes, Instant totalExpiration) {
this.ackId = ackId;
Expand All @@ -152,6 +153,7 @@ private void forget() {
*/
return;
}
extending = false;
flowController.release(1, outstandingBytes);
messagesWaiter.incrementPendingMessages(-1);
processOutstandingBatches();
Expand Down Expand Up @@ -415,6 +417,11 @@ public void ack() {
public void nack() {
response.set(AckReply.NACK);
}

@Override
public void abandon() {
ackHandler.forget();
}
};
ApiFutures.addCallback(response, ackHandler, MoreExecutors.directExecutor());
executor.execute(
Expand Down Expand Up @@ -466,6 +473,9 @@ void extendDeadlines() {
Instant extendTo = now.plusSeconds(extendSeconds);

for (Map.Entry<String, AckHandler> entry : pendingMessages.entrySet()) {
if (!entry.getValue().extending) {
continue;
}
String ackId = entry.getKey();
Instant totalExpiration = entry.getValue().totalExpiration;
if (totalExpiration.isAfter(extendTo)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ public void testNack() throws Exception {
assertThat(sentModAcks).contains(ModAckItem.of(TEST_MESSAGE.getAckId(), 0));
}

@Test
public void testAbandon() throws Exception {
dispatcher.processReceivedMessages(Collections.singletonList(TEST_MESSAGE), NOOP_RUNNABLE);
consumers.take().abandon();
dispatcher.extendDeadlines();
assertThat(sentModAcks).doesNotContain(TEST_MESSAGE.getAckId());
}

@Test
public void testExtension() throws Exception {
dispatcher.processReceivedMessages(Collections.singletonList(TEST_MESSAGE), NOOP_RUNNABLE);
Expand Down