apache / apache/beam

Simple pattern for per-bundle and per-DoFn Closeable resources

Open
#18,083 0 comments 0 reactions 0 assignees View on GitHub
improvement P3 sdk-ideas
Dominant language
Java
Stars
8.7k
Forks
4.7k
Avg merge
1d 20h
Merged PRs (30d)
196

Description

Dealing with Closeable resources inside a processElement call is easy: simply use try-with-resources.

However, bundle- or DoFn-scoped resources, such as long-lived database connections, are less convenient to deal with: you have to open them in startBundle and conditionally close in finishBundle (likewise setup/teardown), taking special care if there's multiple resources to close all of them.

Perhaps we should provide something like Guava's Closer to DoFn's https://github.com/google/guava/wiki/ClosingResourcesExplained. Ideally, the user would need to only write a startBundle() or setup() method, but not write finishBundle() or teardown() - resources would be closed automatically.

Imported from Jira [BEAM-702](https://issues.apache.org/jira/browse/BEAM-702). Original Jira may contain additional context.
Reported by: jkff.

Contributor guide

Open the contributing guide

Research direction

Start by reading the DoFn lifecycle methods named in the issue: startBundle(), finishBundle(), setup(), and teardown(). Review Guava's Closer design for the proposed resource-management pattern, then determine the API and lifecycle behavior needed for automatic closing; done means bundle- and DoFn-scoped Closeable resources are reliably closed without user-written cleanup methods.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.