damccorm opened a new pull request, #41846:
URL: https://github.com/apache/beam/pull/41846

   Note: this PR was auto-generated by tooling. Before moving it out of draft, 
the author has done a full review of the PR, specifically evaluating it on the 
following criteria:
   
   - The PR is an appropriate fix for the issue (e.g. we're not changing a test 
to avoid a bug)
   - The PR is a simple fix to the issue (e.g. we're not adding infra when we 
could just modify a test)
   - The PR is not covering for other problems (e.g. if we're bumping timeouts, 
it is not because we're covering for a performance problem)
     
   Full details of the methodology of generation and review can be found here - 
https://docs.google.com/document/d/14lj7ECVov4T4EdwmIzNlWrRGE3lLDMOwX5xUMGzaLoc/edit?usp=sharing
   
   If you have concerns with the PR or with the underlying methodology used to 
generate this, please comment below - they will be addressed by the author not 
the tooling :)
   
   ## Summary
   Fixes an intermittent `NoSuchElementException: Empty PCollection accessed as 
a singleton view` race in Prism (e.g., 
`CombineFnsTest.testComposedCombineWithContext` in [PreCommit Java PVR Prism 
Loopback 
#45002844821](https://github.com/apache/beam/actions/runs/45002844821)).
   
   ## Root Cause
   In `stageState.bundleReady` 
(`sdks/go/pkg/beam/runners/prism/internal/engine/elementmanager.go`), 
side-input readiness only checked `if upstreamW > ow` (comparing the consumer's 
main-input `upstreamW` against the side-input producer's 
`parent.OutputWatermark()`).
   
   While a side-input producer (such as a `View.AsSingleton` extract stage) is 
actively executing a bundle with timestamp `window.MaxTimestamp()` (e.g., 
`mtime.EndOfGlobalWindowTime` for `GlobalWindow`), `parent.OutputWatermark()` 
sits at `window.MaxTimestamp()` before `PersistBundle` writes side-input 
elements via `AddPendingSide`. Whenever the consumer's main-input `upstreamW` 
advances to any value `<= ow` (such as transiently `0` during an upstream 
GBK/Combine persist, or `EndOfGlobalWindowTime`), `upstreamW > ow` evaluates to 
`false` and Prism schedules the consumer before the side input is persisted.
   
   Additionally, if the consumer is held by a side input while `input == 
upstreamW`, the subsequent watermark refresh triggered by the side-input 
producer completing would hit `inputW == upstreamW && previousInputW == inputW` 
and fail to re-evaluate readiness unless the blocked state is remembered.
   
   ## Changes
   - **`sdks/go/pkg/beam/runners/prism/internal/engine/elementmanager.go`**:
     - Added `maxPendingWindowEndLocked(upstreamW)` and updated 
`stageState.bundleReady` so that when a stage has eligible pending elements and 
side inputs, each side-input producer's output watermark `ow` must strictly 
exceed the required window's `MaxTimestamp()` (or reach `mtime.MaxTimestamp`), 
in addition to `ow >= upstreamW`.
     - Added `ElementManager.SetGlobalWindowSideInput(pcolID)` so globally 
windowed side inputs require `ow > mtime.EndOfGlobalWindowTime` even when 
main-input elements belong to smaller windows (e.g., `FixedWindow` main input 
with `GlobalWindow` side input).
     - Tracked `sideInputBlocked` on `stageState` so a stage previously held by 
a side input re-evaluates readiness when the side-input producer advances even 
if the main-input upstream watermark did not change.
   - **`sdks/go/pkg/beam/runners/prism/internal/execute.go`**:
     - Called `em.SetGlobalWindowSideInput(si.Global)` when registering stages 
whose side-input PCollection uses `urns.WindowFnGlobal`.
   - 
**`sdks/go/pkg/beam/runners/prism/internal/engine/elementmanager_test.go`**:
     - Added `TestStageState_bundleReady_SideInputWindowCompletion` covering 
in-flight `GlobalWindow` side input at `EndOfGlobalWindowTime` (including 
unblock with unchanged `upstreamW == 0`), `IntervalWindow` boundary 
`MaxTimestamp()`, `FixedWindow` main input with `GlobalWindow` side input, and 
empty side input completion without deadlock.
   
   ## Verification
   - Ran `gofmt -l` (clean).
   - Ran `go test -race -v -run 
TestStageState_bundleReady_SideInputWindowCompletion 
./pkg/beam/runners/prism/internal/engine/...` locally (4/4 subtests passed).
   - Ran `go test ./pkg/beam/runners/prism/...` locally (all 6 test packages 
passed, including `ValidateWindowedSideInputs`).
   - Triggered `.github/workflows/beam_PreCommit_Java_PVR_Prism_Loopback.yml` 
on this branch.
   
   ## Related Failures
   - https://github.com/apache/beam/actions/runs/45002844821
   
   ### Verification
   - Triggered `.github/workflows/beam_PreCommit_Java_PVR_Prism_Loopback.yml` 
workflow run on branch: 
[`46692527641`](https://github.com/apache/beam/actions/runs/46692527641)
   


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