ian-Liaozy opened a new pull request, #39161:
URL: https://github.com/apache/beam/pull/39161
This PR resolves several critical caching issues in Interactive Beam when
executing pipelines in notebook environments (like Colab), preventing
deadlocks, duplicate execution of runner jobs, and stale dependency resolution.
### Changes:
1. **Fix Background Thread Deadlock**:
Updated `_wait_for_dependencies` to skip checking the target PCollection
itself when executing inside the background thread (indicated by the presence
of `async_result`). This avoids a self-deadlock where the background thread
blocked waiting for its own future to resolve.
2. **Fix Wait Race Condition**:
Previously, calling `future.result()` in `_wait_for_dependencies` was
insufficient because the future resolves *before* the `_on_done` callback
finishes executing to mark the PCollection as computed. This created a race
condition where the main thread resumed, saw the PCollection was still
"uncomputed", and started a duplicate execution job.
We resolved this by introducing a `threading.Event` (`_completed_event`)
in `AsyncComputationResult` that is set at the very end of `_on_done`. The main
thread now blocks on `comp.wait_for_completion()`, guaranteeing that it only
continues after the PCollection is fully marked as computed.
3. **Recalculate Uncomputed PCollections**:
Updated `record()` to recalculate the subset of remaining uncomputed
PCollections *after* the dependency wait completes. If a PCollection finished
computing during the wait, it skips the duplicate fragment execution.
4. **Fix Stale Pipeline Graph**:
Removed caching of the `PipelineGraph` in `RecordingManager`. Re-creating
the graph dynamically ensures that any new transforms added by users in
subsequent notebook cells are correctly detected and resolved as dependencies.
5. **Unit Tests Added**:
Added three new tests to `recording_manager_test.py` covering:
- Deadlock avoidance and waiting behavior depending on `async_result`.
- Dynamic recreation of the `PipelineGraph` when new transforms are
appended.
- Recalculation of uncomputed PCollections in `record()` after wait
completion.
------------------------
fixes #37220
------------------------
Thank you for your contribution! Follow this checklist to help us
incorporate your contribution quickly and easily:
- [x] Mention the appropriate issue in your description (for example:
`addresses #123`), if applicable. This will automatically add a link to the
pull request in the issue. If you would like the issue to automatically close
on merging the pull request, comment `fixes #<ISSUE NUMBER>` instead.
- [ ] Update `CHANGES.md` with noteworthy changes.
- [ ] If this contribution is large, please file an Apache [Individual
Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
See the [Contributor Guide](https://beam.apache.org/contribute) for more
tips on [how to make review process
smoother](https://github.com/apache/beam/blob/master/CONTRIBUTING.md#make-the-reviewers-job-easier).
To check the build health, please visit
[https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md)
GitHub Actions Tests Status (on master branch)
------------------------------------------------------------------------------------------------
[](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Go+tests%22+branch%3Amaster+event%3Aschedule)
See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more
information about GitHub Actions CI or the [workflows
README](https://github.com/apache/beam/blob/master/.github/workflows/README.md)
to see a list of phrases to trigger workflows.
--
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]