dejii opened a new pull request, #38149: URL: https://github.com/apache/beam/pull/38149
## Problem IcebergIO write pipelines fail with "connection pool shut down" errors after processing more than one bundle on the same worker thread. The root cause: - The catalog is `@MonotonicNonNull` on the DoFn — created once, reused across all bundles on that DoFn instance - `RecordWriterManager.close()` (called in `@FinishBundle`) was calling `table.io().close()` to release FileIO resources - `RESTSessionCatalog` share a single `FileIO` across all tables. Closing it per-bundle permanently kills the connection pool on the catalog — all subsequent bundles fail ## Fix **Remove FileIO close from `RecordWriterManager`** — it must not own the lifecycle of a resource it doesn't own. **Add `@Teardown` to all IcebergIO write DoFns** — the catalog (and its underlying FileIO) is closed exactly once when the DoFn instance is destroyed by the runner, not after each bundle: - `WriteUngroupedRowsToFilesDoFn` - `WriteGroupedRowsToFilesDoFn` - `WriteDirectRowsToFilesDoFn` - `AppendFilesToTablesDoFn` ## Catalog compatibility All major Iceberg catalogs verified against source: | Catalog | FileIO in close() | |---|---| | RESTSessionCatalog | ✅ via CloseableGroup + FileIOTracker - [1](https://github.com/apache/iceberg/blob/2114bf631e49af532d66e2ce148ee49dd1dd1f1f/core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java#L242-L243), [2](https://github.com/apache/iceberg/blob/2114bf631e49af532d66e2ce148ee49dd1dd1f1f/core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java#L671) | | GlueCatalog | ✅ via CloseableGroup + FileIOTracker - [1](https://github.com/apache/iceberg/blob/2114bf631e49af532d66e2ce148ee49dd1dd1f1f/aws/src/main/java/org/apache/iceberg/aws/glue/GlueCatalog.java#L198), [2](https://github.com/apache/iceberg/blob/2114bf631e49af532d66e2ce148ee49dd1dd1f1f/aws/src/main/java/org/apache/iceberg/aws/glue/GlueCatalog.java#L634) | | JdbcCatalog | ✅ via CloseableGroup - [1](https://github.com/apache/iceberg/blob/2114bf631e49af532d66e2ce148ee49dd1dd1f1f/core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java#L156), [2](https://github.com/apache/iceberg/blob/2114bf631e49af532d66e2ce148ee49dd1dd1f1f/core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java#L611) | | NessieCatalog | ✅ via CloseableGroup - [1](https://github.com/apache/iceberg/blob/2114bf631e49af532d66e2ce148ee49dd1dd1f1f/nessie/src/main/java/org/apache/iceberg/nessie/NessieCatalog.java#L178), [2](https://github.com/apache/iceberg/blob/2114bf631e49af532d66e2ce148ee49dd1dd1f1f/nessie/src/main/java/org/apache/iceberg/nessie/NessieCatalog.java#L217) | | HadoopCatalog | N/A — [defaults](https://github.com/apache/iceberg/blob/2114bf631e49af532d66e2ce148ee49dd1dd1f1f/core/src/main/java/org/apache/iceberg/hadoop/HadoopCatalog.java#L116) to `HadoopFileIO` which has no `close()` ([HadoopFileIO.java](https://github.com/apache/iceberg/blob/2114bf631e49af532d66e2ce148ee49dd1dd1f1f/core/src/main/java/org/apache/iceberg/hadoop/HadoopFileIO.java)) | | HiveCatalog | N/A — [defaults](https://github.com/apache/iceberg/blob/2114bf631e49af532d66e2ce148ee49dd1dd1f1f/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java#L122) to `HadoopFileIO` which has no `close()` ([HadoopFileIO.java](https://github.com/apache/iceberg/blob/2114bf631e49af532d66e2ce148ee49dd1dd1f1f/core/src/main/java/org/apache/iceberg/hadoop/HadoopFileIO.java)) | ## Tests - `testRecordWriterManagerDoesNotCloseSharedFileIO` — verifies FileIO survives `RecordWriterManager.close()` - `testFileIOSurvivesAcrossBundles` — two sequential bundles succeed with shared FileIO (core regression test) - `testFullLifecycleBundlesThenCatalogClose` — full DoFn lifecycle: multiple bundles + catalog.close() at teardown - `testNonCloseableCatalogSkippedOnTeardown` — verifies non-Closeable catalog (HadoopCatalog) is safely skipped follow up on: #37782 ------------------------ 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]
