lucasbru commented on code in PR #24256:
URL: https://github.com/apache/kafka/pull/24256#discussion_r4642884798
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StoreChangelogReader.java:
##########
@@ -866,11 +870,7 @@ private Set<Task> getTasksFromPartitions(final Map<TaskId,
Task> tasks,
}
private void clearTaskTimeout(final Set<Task> tasks) {
- tasks.forEach(t -> {
- if (t != null) {
- t.clearTaskTimeout();
- }
- });
+ tasks.forEach(Task::clearTaskTimeout);
}
Review Comment:
Same as above: callers only pass partitions of tasks given to restore(), so
the set can't contain null, and a null would be a caller bug we want to fail
fast on.
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/StoreChangelogReaderTest.java:
##########
@@ -1260,6 +1261,70 @@ public void
logicalChangelogEndOffsetsShouldReturnNullWhenBothSourcesUnknown() {
assertNull(changelogReader.logicalChangelogEndOffsets().get(tp));
}
+ @Test
+ public void shouldNotLookUpLimitOffsetsForChangelogsOfPausedStandbyTasks()
{
+ setupStandbyStateManager();
+ setupStoreMetadata();
+ setupStore();
+ final TaskId taskId = new TaskId(0, 0);
+ when(standbyStateManager.taskId()).thenReturn(taskId);
+ when(standbyStateManager.changelogAsSource(tp)).thenReturn(true);
+ when(storeMetadata.offset()).thenReturn(3L);
+
+ final AtomicBoolean failLookups = new AtomicBoolean(false);
+ final AtomicInteger lookups = new AtomicInteger();
+ final MockAdminClient adminClient = new MockAdminClient() {
+ @Override
+ public synchronized ListConsumerGroupOffsetsResult
listConsumerGroupOffsets(final Map<String, ListConsumerGroupOffsetsSpec>
groupSpecs, final ListConsumerGroupOffsetsOptions options) {
+ lookups.incrementAndGet();
+ if (failLookups.get()) {
+ return
AdminClientTestUtils.listConsumerGroupOffsetsResult(groupSpecs.keySet().iterator().next(),
new TimeoutException("KABOOM!"));
+ }
+ return super.listConsumerGroupOffsets(groupSpecs, options);
+ }
+ };
+ adminClient.updateConsumerGroupOffsets(Collections.singletonMap(tp,
7L));
+
+ final long now = time.milliseconds();
+ final Properties properties = new Properties();
+ properties.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 100L);
+ final StreamsConfig config = new
StreamsConfig(StreamsTestUtils.getStreamsConfig("test-reader", properties));
+ final StoreChangelogReader changelogReader = new
StoreChangelogReader(time, config, logContext, adminClient, consumer, callback,
standbyListener);
+ changelogReader.transitToUpdateStandby();
+
+ consumer.updateBeginningOffsets(Collections.singletonMap(tp, 0L));
+ changelogReader.register(tp, standbyStateManager);
+ final Map<TaskId, Task> tasks = Collections.singletonMap(taskId,
mock(Task.class));
+ changelogReader.restore(tasks);
+ assertEquals(7L, (long)
changelogReader.changelogMetadata(tp).endOffset());
+
+ // records beyond the limit stay buffered
+ for (long offset = 4L; offset < 10L; offset++) {
+ consumer.addRecord(new ConsumerRecord<>(topicName, 0, offset,
"key".getBytes(), "value".getBytes()));
+ }
+ changelogReader.restore(tasks);
+ assertEquals(3,
changelogReader.changelogMetadata(tp).bufferedRecords().size());
+ final int lookupsBeforePause = lookups.get();
+
+ // the task is paused, so it is not passed to restore, and the lookup
of committed offsets would fail
+ failLookups.set(true);
+ time.setCurrentTimeMs(now + 101L);
+ changelogReader.restore(Collections.emptyMap());
+
+ assertEquals(lookupsBeforePause, lookups.get());
+ assertEquals(7L, (long)
changelogReader.changelogMetadata(tp).endOffset());
+ assertEquals(3,
changelogReader.changelogMetadata(tp).bufferedRecords().size());
+
+ // once the task is resumed, its limit offset is updated again
+ failLookups.set(false);
+ adminClient.updateConsumerGroupOffsets(Collections.singletonMap(tp,
9L));
+ changelogReader.restore(tasks);
+
+ assertEquals(lookupsBeforePause + 1, lookups.get());
Review Comment:
The exact count is intended: one refresh cycle should make exactly one
lookup, so a change in batching is worth noticing. Leaving it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]