Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not delete session in close method for BatchReadOnlyTransactionImpl #1688

Merged
merged 8 commits into from
Feb 15, 2022

Conversation

rajatbhatta
Copy link
Contributor

  • remove session.close() from close() method implementation in
    BatchReadOnlyTransactionImpl class.

  • add a cleanup() method to BatchReadOnlyTransaction interface
    and give user the control to delete session when the session
    is no longer in use.

  • add tests for txn.cleanup() method.

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #1651 ☕️

…onImpl

-   remove session.close() from close() method implementation in
    BatchReadOnlyTransactionImpl class.

-   add a cleanup() method to BatchReadOnlyTransaction interface
    and give user the control to delete session when the session
    is no longer in use.

-   add tests for txn.cleanup() method.
@rajatbhatta rajatbhatta requested review from a team as code owners February 14, 2022 07:59
@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/java-spanner API. label Feb 14, 2022
@Override
public void close() {
super.close();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, won't this break all the existing clients that are relying on the close method to return the session to the pool? (won't this possibly cause a session pool exhaustion for existing clients?)

cc @olavloite

Copy link
Contributor Author

@rajatbhatta rajatbhatta Feb 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As BatchReadOnlyTransactionImpl is an AutoCloseable (via MultiUseReadOnlyTransaction->AbstractReadContext->ReadContext->AutoClosable), having it within a try-with-resources construct allows automatic closing of the transaction resource, which leads the underlying session to be released to the session pool. IMO, it should not lead to session pool exhaustion.

Having an overridden close method with just super.close() won't make sense, as the super's close method will anyways be called during automatic closing.

@olavloite : Please do share your viewpoint as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thiagotnunes No, the BatchClientImpl does not use sessions from the pool. It gets its session in one of two possible ways:

  1. It is the client that creates the BatchReadOnlyTransaction: It creates a session here.
  2. It is a client that receives a batch transaction id from a different client: It just references the already existing session that was created by the other client here.

So it means that we will create one session that will not (always) be deleted. We choose to do it this way because we do not know how long all clients will need to finish reading, and the session must be kept alive as long as there are clients still reading. The session will eventually be garbage collected by the backend.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh got it, thanks for the explanation!

@rajatbhatta rajatbhatta merged commit 5dc3e19 into main Feb 15, 2022
@rajatbhatta rajatbhatta deleted the java-spanner-issue-1651-fix branch February 15, 2022 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/java-spanner API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Spanner: BatchReadOnlyTransaction closes shared sessions on close()
3 participants