[Spark 4] Clear the watermark of keys without timers or state in the streaming stateful ParDo #40550
All Vouch review confidence checks passed
Residual risk 0.14 = Change Risk (0.36) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.36 · 191 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.315
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #40550"
general
weight: 0.35
schizophrenicmaniac
BeamStatefulProcessor wrote beamWatermark on every visit and never removed it, so each key that ever went through a streaming stateful ParDo kept a row in the state store even after all its windows expired. beamTimers was already cleared by persistTimers once no timers remain. The watermark was the only thing left behind.
storeWatermark, called from handleInputRows and handleExpiredTimer, now clears beamWatermark when the key has no timers and beamState is empty, for example after the GC timer of its last window fired. The change stays inside those two code paths, so it should rebase cleanly onto #40516 and the GroupByKey base-class split.
On late data: after the cleanup, the key's next visit is a first visit and filters late data against TIMESTAMP_MIN_VALUE, so a late element for an already expired window of that key is processed instead of dropped. I went with accepting this as part of #40446. A brand-new key already behaves this way. Keeping any marker per key means keeping the same Long the issue wants gone. A TTLConfig is processing-time based, so it doesn't line up with allowed lateness. I updated the contract comment in timerInternals to cover cleared keys.
The new test, testExpiredKeyLeavesNoState, sends a single element for one key and lets its only window expire as the source watermark advances. It then reads the checkpoint through the statestore data source and asserts that beamState, beamTimers and beamWatermark have no rows left. Without the change one beamWatermark row remains.
Fixes #40517