amalsaidov opened a new pull request, #29925:
URL: https://github.com/apache/flink/pull/29925

   ## What is the purpose of the change
   
   `StateFutureUtils#toIterable` casts every non-null `StateIterator` to 
`InternalStateIterator`. The async TTL wrappers 
`TtlListState.AsyncIteratorWrapper` and `TtlMapState.AsyncEntriesIterator` only 
implement `StateIterator`, not `InternalStateIterator`. So on ForSt with TTL 
enabled, `toIterable` throws a `ClassCastException` on the first non-empty list 
state read and on every `asyncEntries()`, `asyncKeys()` and `asyncValues()` 
result. A keyed job with `enableAsyncState()`, ForSt and a TTL list state that 
reads through `toIterable` fails on its first non-empty read, while the same 
job without TTL or on the heap backend finishes.
   
   This fixes [FLINK-41416](https://issues.apache.org/jira/browse/FLINK-41416).
   
   ## Brief change log
   
     - Guard the `InternalStateIterator` cast in `StateFutureUtils#toIterable` 
with an `instanceof` check.
     - When the iterator is not an `InternalStateIterator`, collect its 
elements through `onNext` instead of casting.
     - Keep the already-loaded-cache fast path for the `InternalStateIterator` 
case unchanged.
   
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   
     - `StateFutureUtilsTest#testToIterableWithNonInternalStateIterator` and 
`testToIterableWithEmptyNonInternalStateIterator` cover a `StateIterator` that 
is not an `InternalStateIterator` (the shape of the async TTL wrappers). Both 
throw `ClassCastException` before the fix and pass after it.
     - `testToIterableWithFullyLoadedInternalStateIterator` and 
`testToIterableWithLoadingInternalStateIterator` cover the existing 
`InternalStateIterator` cache and loading paths to guard against a regression.
     - `testToIterableWithNullIterator` covers the null iterator case.
     - Verified red/green locally: without the fix 2 tests error with 
`ClassCastException`; with the fix all 5 pass (`mvn -pl flink-core -am test 
-Dtest=StateFutureUtilsTest`).
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): no
     - The public API, i.e., is any changed class annotated with 
`@Public(Evolving)`: no
     - The serializers: no
     - The runtime per-record code paths (performance sensitive): no
     - Anything that affects deployment or recovery: JobManager (and its 
components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
     - The S3 file system connector: no
   
   ## Documentation
   
     - Does this pull request introduce a new feature? no
     - If yes, how is the feature documented? not applicable
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   AI-assisted; directed, reviewed and tested by the author (amalsaidov).
   
   - [X] Yes (please specify the tool below)
   
   Generated-by: Claude Code (Opus 4.8)
   


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