tzulitai opened a new pull request #13772:
URL: https://github.com/apache/flink/pull/13772
This PR is based on top of #13761, since a new test was added in #13761 that
would also cover the fix in this PR.
Only the last 2 commits are relevant.
## What is the purpose of the change
When iterating through key groups in restored raw keyed state streams, the
iterator (`StreamTaskStateInitializerImpl#KeyGroupStreamIterator`) doesn't
respect that fact that some key groups were skipped and were not written, .e.g:
```
// on snapshots
KeyedStateCheckpointOutputStream rawKeyedStream =
snapshotContext.getRawKeyedOperatorStateOutput();
rawKeyedStream.startNewKeyGroup(0);
rawKeyedStream.startNewKeyGroup(3); // skipped key groups 1 and 2
```
In this case, the offsets for key groups 1 and 2 written in the checkpoint
metadata will be `-1` (meaning, an undefined offset).
On restore, however, the iterator still attempts to seek the restored keyed
state streams with the offsets, ultimately failing with a position out of
bounds when it attempts to seek to position `-1`.
The usage behaviour of skipping key groups when writing to the raw keyed
state stream is currently completely valid as the
`KeyedStateCheckpointOutputStream` API does not forbid it. StateFun, for
example, did exactly that.
## Solution
This PR solves the issue by modifying
`StreamTaskStateInitializerImpl#KeyGroupStreamIterator` to skip key groups with
undefined offsets (i.e. `-1`).
The changes are isolated such that is should only affect the restore of raw
keyed state streams, and does not affect the restore of state backends.
## Brief change log
- a130d84 Wraps the original key group offsets iterator to filter out key
groups with undefined offsets.
- c6bae68 Adjusts the existing
`AbstractStreamOperatorTest.testCustomRawKeyedStateSnapshotAndRestore` test to
only write some key groups, and not all of them.
## Verifying this change
- The new
`AbstractStreamOperatorTest.testCustomRawKeyedStateSnapshotAndRestore` test
should pass.
- There are existing integration tests that test snapshotting and restoring
of heap-based timers, which should cover the current usage of the raw keyed
state stream in Flink.
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): (yes / **no**)
- The public API, i.e., is any changed class annotated with
`@Public(Evolving)`: (yes / **no**)
- The serializers: (yes / **no** / don't know)
- The runtime per-record code paths (performance sensitive): (yes / **no**
/ don't know)
- Anything that affects deployment or recovery: JobManager (and its
components), Checkpointing, Kubernetes/Yarn/Mesos, ZooKeeper: (**yes** / no /
don't know)
- The S3 file system connector: (yes / **no** / don't know)
## Documentation
- Does this pull request introduce a new feature? (yes / **no**)
- If yes, how is the feature documented? (**not applicable** / docs /
JavaDocs / not documented)
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]