github-actions[bot] commented on code in PR #41822:
URL: https://github.com/apache/beam/pull/41822#discussion_r4747359160


##########
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/state/StateFetchingIterators.java:
##########
@@ -623,7 +622,7 @@ public boolean isReady() {
                 currentCachedBlockValueIndex = 0;
               } else {
                 // If not found, then we need to load it.
-                return false;
+                return underlyingStateFetchingIterator.isReady();

Review Comment:
   **🟠 High**: When advancing through cached blocks (either in `isReady()` or 
`hasNext()`), `currentBlock` advances its `nextToken`, but 
`underlyingStateFetchingIterator` is not repositioned until `prefetch()` or 
`loadNextBlock()` is called. If `existing != null` and the iterator advances 
through one or more cached blocks before reaching the end of the cached prefix, 
`underlyingStateFetchingIterator` may still be positioned at an older 
continuation token (or even have a completed `prefetchedResponse` from an 
earlier position, e.g., if `LazyBlockingStateFetchingIterator.next()` 
auto-prefetched chunk N+1 while the cache actually had chunks up to N+2, or if 
`underlyingStateFetchingIterator` reached EOF at an earlier point).
   
   Before querying `underlyingStateFetchingIterator.isReady()`, 
`underlyingStateFetchingIterator.seekToContinuationToken(nextToken)` should be 
called (at both line 606 and line 625) to ensure 
`underlyingStateFetchingIterator` is checking readiness for `nextToken`.
   
   ```suggestion
                   
underlyingStateFetchingIterator.seekToContinuationToken(nextToken);
                   return underlyingStateFetchingIterator.isReady();
   ```



##########
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/state/StateFetchingIterators.java:
##########
@@ -603,8 +603,7 @@ public boolean isReady() {
           @Nullable Blocks<T> existing = cache.peek(IterableCacheKey.INSTANCE);
           boolean isFirstBlock = ByteString.EMPTY.equals(nextToken);
           if (existing == null) {
-            // If there is nothing cached and we are on the first block then 
we are not ready.
-            return false;
+            return underlyingStateFetchingIterator.isReady();

Review Comment:
   **🟡 Medium**: Similar to line 625, if the cache was evicted after the 
iterator already consumed some blocks, `nextToken` will be non-empty and might 
not match `underlyingStateFetchingIterator`'s current token (for example, if 
the iterator previously read from cache before eviction). Calling 
`underlyingStateFetchingIterator.seekToContinuationToken(nextToken)` before 
`underlyingStateFetchingIterator.isReady()` ensures it checks the readiness of 
the expected chunk.
   
   ```suggestion
               
underlyingStateFetchingIterator.seekToContinuationToken(nextToken);
               return underlyingStateFetchingIterator.isReady();
   ```



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