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


##########
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; record 
only up to
   // that limit, never the live position past unapplied/uncommitted records
   ```



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

Review Comment:
   nit, use `log-end offset` here.
   
   ```java
   // dedicated changelog (no restoreEndOffset): lag == 0 with an empty buffer 
means the
   // consumer is at the log-end offset with every fetched record applied; 
position() is
   // the next-fetch, not last-applied
   ```



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