Copilot commented on code in PR #24256:
URL: https://github.com/apache/kafka/pull/24256#discussion_r4642742909


##########
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 test asserts an exact increment of `+ 1` lookup after resuming. This can 
be brittle if the implementation later performs multiple Admin lookups per 
refresh cycle (or changes batching behavior) while still satisfying the 
intended requirement ('a lookup occurs after resume'). To make the test more 
robust while preserving intent, consider asserting `lookups.get() > 
lookupsBeforePause` (and keep the exact equality assertion for the paused case 
where 'no lookup' is the key behavior).



##########
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:
   This change removes the previous null-guard and will now throw a 
NullPointerException if `tasks` ever contains a null entry. Unless it’s 
guaranteed everywhere that the `Set<Task>` cannot contain nulls, this is a 
behavior change that can reintroduce NPEs in error/edge paths. Consider either 
(a) keeping the null check here, or (b) ensuring all call sites/builders (e.g., 
any helper that constructs the `Set<Task>`) filter out nulls before calling 
`clearTaskTimeout` (e.g., by filtering `Objects::nonNull`).



-- 
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]

Reply via email to