beam icon indicating copy to clipboard operation
beam copied to clipboard

Add SessionPoolOptions to SpannerConfig

Open manitgupta opened this issue 1 year ago • 6 comments

Add support for configuring SessionPoolOptions in SpannerAccessor.


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • [ ] 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.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels Python tests Java tests Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

manitgupta avatar Jun 21 '24 07:06 manitgupta

Assigning reviewers. If you would like to opt out of this review, comment assign to next reviewer:

R: @robertwb for label java. R: @damondouglas for label io. R: @nielm for label spanner.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

github-actions[bot] avatar Jun 21 '24 11:06 github-actions[bot]

Can you explain why you believe this is necessary to add?

The default session pool options in Java are:

  • MinSessions =100
  • MaxSessions = 400
  • WriteSessionsFraction = 0.2

These will apply to each worker indivudually.

@olavloite for comment.

nielm avatar Jun 21 '24 11:06 nielm

This is my primary motivation - https://github.com/googleapis/java-spanner/blob/main/session-and-channel-pool-configuration.md#automatically-clean-inactive-transactions

Currently, there is no way to set setWarnAndCloseIfInactiveTransactions(). SpannerAccessor is used in Dataflow templates like DatastreamToSpanner, which customers use as a black box, therefore, having this enabled by default makes sense.

manitgupta avatar Jun 21 '24 12:06 manitgupta

In theory there should never be an inactive transaction left open by SpannerIO. If there is, then it is a bug in SpannerIO.

Writes use blind writes by calling DatabaseClient.writeAtLeastOnce, which internally uses the single_use_transaction feature of the Commit API so that a transaction is automatically started and closed by the Spanner server.

Reads use a single read transaction, which is shared across all workers. By their nature these are long-running transactions.

SpannerIO is intended to isolate users from needing to worry about transactions, and to just pass their data in and let the connecter deal with it.

If you are experiencing issues with session pool exhaustion, and believe that there may be a bug, then please raise an issue.

nielm avatar Jun 21 '24 13:06 nielm

SpannerAccessor is not only consumed by SpannerIO, it is directly used by Flex templates such as DatastreamToSpanner here. Therefore a pipeline may leverage the accessor from beam directly and have a session leak in the application code they write using the accessor.

manitgupta avatar Jun 21 '24 13:06 manitgupta

Reminder, please take a look at this pr: @robertwb @damondouglas @nielm

github-actions[bot] avatar Jun 29 '24 12:06 github-actions[bot]

Bump! @nielm @olavloite

manitgupta avatar Jul 02 '24 05:07 manitgupta

Assigning new set of reviewers because Pr has gone too long without review. If you would like to opt out of this review, comment assign to next reviewer:

R: @kennknowles for label java. R: @ahmedabu98 for label io. R: @nielm for label spanner.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

github-actions[bot] avatar Jul 04 '24 12:07 github-actions[bot]

Result of out-of-band discussion between @manitgupta and @olavloite - Change the PR such that SpannerAccessor always sets

SessionPoolOptions.setFailIfPoolExhausted()

to avoid expanding the SpannerIO public API surface while also catching potential session leak bugs.

nielm avatar Jul 05 '24 10:07 nielm

LGTM

Precommit fails for unrelated reason in org.apache.beam.sdk.io.gcp.spanner.changestreams.it.SpannerChangeStreamOrderedWithinKeyIT > restOrderedWithinKey

nielm avatar Jul 05 '24 11:07 nielm

Reminder, please take a look at this pr: @kennknowles @ahmedabu98 @nielm

github-actions[bot] avatar Jul 16 '24 12:07 github-actions[bot]

reverted in #32694

nielm avatar Oct 08 '24 16:10 nielm