Skip to content

Commit

Permalink
[fix][fn] ack messages for window function when its result is null (a…
Browse files Browse the repository at this point in the history
…pache#23618)

(cherry picked from commit 024ff75)
(cherry picked from commit 510ac3b)
  • Loading branch information
jiangpengcheng authored and srinath-ctds committed Nov 26, 2024
1 parent c5dca5d commit 96f61bf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@ private void processWindow(Context context, List<Record<T>> tuples, List<Record<
}
}
});
} else {
// When window function return null, needs to be acked directly.
if (windowConfig.getProcessingGuarantees() == WindowConfig.ProcessingGuarantees.ATLEAST_ONCE) {
for (Record<T> record : tuples) {
record.ack();
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import com.fasterxml.jackson.databind.JsonNode;
Expand Down Expand Up @@ -322,7 +323,17 @@ protected void testWindowFunction(String type, String[] expectedResults) throws
.enableBatching(false)
.create();

for (int i = 0; i < NUM_OF_MESSAGES; i++) {
// send 3 messages first, and it won't trigger the window and so these 3 messages will not be acked
for (int i = 0; i < 3; i++) {
producer.send(String.format("%d", i).getBytes());
}
TopicStats stats = pulsarAdmin.topics().getStats(inputTopicName, true);
SubscriptionStats subStats = stats.getSubscriptions().get("public/default/" + functionName);
assertNotNull(subStats);
assertEquals(3, subStats.getMsgBacklog());
assertEquals(3, subStats.getUnackedMessages());

for (int i = 3; i < NUM_OF_MESSAGES; i++) {
producer.send(String.format("%d", i).getBytes());
}

Expand All @@ -348,6 +359,13 @@ protected void testWindowFunction(String type, String[] expectedResults) throws
// in case last commit is not updated
assertThat(i).isGreaterThanOrEqualTo(expectedResults.length - 1);

// test that all messages are acked
stats = pulsarAdmin.topics().getStats(inputTopicName, true);
subStats = stats.getSubscriptions().get("public/default/" + functionName);
assertNotNull(subStats);
assertEquals(0, subStats.getMsgBacklog());
assertEquals(0, subStats.getUnackedMessages());

deleteFunction(functionName);

getFunctionInfoNotFound(functionName);
Expand Down

0 comments on commit 96f61bf

Please sign in to comment.