alanlau28 commented on code in PR #23298:
URL: https://github.com/apache/kafka/pull/23298#discussion_r3972814307


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StoreChangelogReader.java:
##########
@@ -749,6 +749,10 @@ private int restoreChangelog(final Task task, final 
ChangelogMetadata changelogM
             // markers) so the remaining-records metric reaches exactly zero 
on completion
             recordRestorationProgress(task, changelogMetadata, 0, 
storeMetadata.offset(), changelogMetadata.restoreEndOffset);
 
+            // Catch-up boundary: advertise restoreEndOffset, not the live 
consumer position, which may
+            // already be past records that were buffered and never applied 
(KAFKA-14302).

Review Comment:
   Maybe this can be worded with the file's own `end offset` term ("catch-up 
boundary" isn't used elsewhere) and `advance to` over `advertise`?
   
   (also dropping the repeated `KAFKA-14302` here — kept once on the 
`advanceRestoredOffsetTo` Javadoc.)
   
   ```java
   // restoration reached the end offset: advance to restoreEndOffset, not the 
consumer position,
   // which may already be past buffered records that were never applied
   ```



##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StoreChangelogReader.java:
##########
@@ -769,6 +775,41 @@ private int restoreChangelog(final Task task, final 
ChangelogMetadata changelogM
         return numRecords;
     }
 
+    /**
+     * Advance a standby store's restored offset only at a confirmed catch-up 
boundary (KAFKA-14302).
+     * A zero-record poll is not sufficient: retention seeks, source-changelog 
buffering, and incomplete
+     * fetches can all leave the consumer at a non-zero position while records 
remain to apply.
+     */
+    private void maybeAdvanceStandbyRestoredOffset(final ProcessorStateManager 
stateManager,
+                                                   final ChangelogMetadata 
changelogMetadata,
+                                                   final StateStoreMetadata 
storeMetadata,
+                                                   final TopicPartition 
partition) {
+        if (!changelogMetadata.bufferedRecords().isEmpty()) {
+            return;
+        }
+        try {
+            final Long restoreEndOffset = changelogMetadata.restoreEndOffset;
+            if (restoreEndOffset == null) {
+                // Dedicated changelog: no restoreEndOffset. lag == 0 with an 
empty buffer means
+                // the restore consumer is at LEO and every fetched record has 
already been applied.
+                // position() is the next-fetch boundary, not a last-applied 
offset.
+                final OptionalLong lag = restoreConsumer.currentLag(partition);
+                if (lag.isPresent() && lag.getAsLong() == 0L) {
+                    stateManager.advanceRestoredOffsetTo(storeMetadata, 
restoreConsumer.position(partition));
+                }
+            } else if (restoreEndOffset > 0L) {
+                // Source changelog: restoreEndOffset is the committed-offset 
limit. Advertise
+                // only that boundary, never live position past 
unapplied/uncommitted records.

Review Comment:
   nit, drop "boundary" in favour of the `limit`.
   
   ```java
   // source changelog: restoreEndOffset is the committed-offset limit; advance 
only up to
   // that limit, never the live position past unapplied/uncommitted records
   ```



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