[runtime][api][python] Add checkpoint-aligned Kafka action-state cleanup - #1101
Draft
rob-9 wants to merge 30 commits into
Draft
[runtime][api][python] Add checkpoint-aligned Kafka action-state cleanup#1101rob-9 wants to merge 30 commits into
rob-9 wants to merge 30 commits into
Conversation
- add kafkaActionStateTombstoneEnabled (default false) so tombstone emission is opt-in; rebuildState still honors tombstones already in the topic regardless of the flag - match the parsed key part exactly in pruneState so pruning key "a_1" can no longer tombstone state of the distinct key "a" - report async tombstone send failures via producer callback (flush() does not surface per-record errors) - narrow the prune catch to IllegalArgumentException and state the retention consequence in the warning - remove dead inner try/catch in rebuildState (deserialization errors throw from poll(), not from the map ops it wrapped) - document the durable-deletion replay constraint on ActionStateStore.pruneState and add the new option to the config docs - tests: default-off pruning, prefix-collision regression, tombstone replay in rebuildState; simplify assertions
…neState - testPruneStateEvictsCacheEvenWhenTombstoneSendFails: verifies pruneState degrades gracefully and still evicts the in-memory entry when a tombstone send fails asynchronously (the callback-reporting fix from the prior commit) - testPruneStateSkipsUnparseableKeys: verifies a state key that cannot be parsed into 4 parts is retained rather than pruned (the narrowed IllegalArgumentException catch) Both were verified to fail when the corresponding fix is reverted.
…neState to cache eviction only
rob-9
force-pushed
the
feat/checkpoint-aligned-kafka-cleanup
branch
from
September 4, 2026 19:10
e71972e to
d075edd
Compare
Contributor
Author
|
the job failure here looks unrelated to the PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1034.
This branch is stacked on PR #885, which adds opt-in Kafka tombstones for per-key action-state pruning. This change adds checkpoint-aligned prefix cleanup.
Purpose of change
Kafka action-state records can remain essential to Flink checkpoints and savepoints. Deleting a record too early can erase the evidence that an action already completed, allowing recovery to repeat the action and its external side effects. Flink Agents therefore needs a durable agreement about the oldest recovery point that operators still expect to use.
This change gives operators a plan/apply workflow for choosing that recovery point and reclaiming the older Kafka prefix. The plan shows the exact partition offsets that become eligible for deletion. Apply records the boundary before asking Kafka to delete data. Recovery then enforces the boundary and gives a clear error for an older checkpoint or savepoint.
For example, checkpoint C0 needs partition 0 from offset 100 and C1 needs it from offset 150. Choosing C1 allows Kafka to discard records before offset 150. C1 and newer recovery points remain supported. Restoring C0 stops with an error that names offsets 100 and 150.
Runtime flow
KafkaActionStateCleanupTool planagainst the selected checkpoint or savepoint. The tool reads every subtask marker through Flink's State Processor API, takes the minimum offset for each partition, and writes a deterministic JSON plan whose ID comes from its contents.apply.COMMITTEDrecord to a dedicated compacted control topic, and callsdeleteRecords.APPLIED. ACOMMITTEDoperation can safely resume after interruption.kafkaActionStateCleanupControlTopicconfigured, recovery validates its marker and Kafka metadata against the effective committed boundary before replaying the captured offset range.Key decisions
COMMITTEDrecord precedes deletion, giving interrupted operations one stable plan to retry.deleteRecords, which operates on a topic name that a recreated topic could reuse.Related work
PR #885 writes tombstones for selected keys. This PR deletes an entire Kafka prefix after the operator advances the oldest supported recovery point. Cleanup mode rejects simultaneous tombstones because each mechanism defines a different recovery guarantee. Issue #1099 fixes typed identity for individual records; the combined replay path must retain its key validation before applying values or tombstones.
Behavioral Semantics
Interaction decisions
Behavioral contracts
COMMITTEDalways precedesdeleteRecords;APPLIEDfollows verification of every resulting beginning offset.Failure behavior
COMMITTED.COMMITTEDleaves the same plan ready for retry.Tests
KafkaActionStateCleanupPlanTestKafkaActionStateCleanupCoordinatorTestdeleteRecords, beginning offsets, and boundary readsKafkaActionStateCleanupCoordinatorIntegrationTestKafkaActionStateStoreTestKafkaActionStateCleanupToolTestpython/flink_agents/api/tests/test_core_options.pyVerification performed:
git diff --checkpassed.Remaining integration coverage: the Docker-backed Kafka integration test compiled and awaits a Docker environment. The real Flink savepoint and State Processor path passed locally.
Implementation details for traceability
cleanup.policy=compact.deleteRecords. Recovery refreshes metadata before offset reads and after replay.API
This change adds
kafkaActionStateCleanupControlTopicto the Java and Python configuration APIs and adds a language-neutral administrative CLI backed by internal Java runtime types.Existing configurations keep coordinated cleanup disabled. Legacy marker maps continue to support standard recovery in that mode. Newly written markers use the versioned, topic-aware format. Cleanup mode adds explicit checks for topic identity, partition identity, boundary position, and offset availability.
Documentation
doc-neededdoc-not-neededdoc-includedThe deployment and configuration documentation covers the operator workflow, control-topic requirements, recovery guarantees, failure behavior, and tombstone interaction.
Was this patch authored or co-authored using generative AI tooling?