-
Notifications
You must be signed in to change notification settings - Fork 123
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
Conversation
…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.
@Override | ||
public void close() { | ||
super.close(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
- It is the client that creates the
BatchReadOnlyTransaction
: It creates a session here. - 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.
There was a problem hiding this comment.
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!
google-cloud-spanner/src/main/java/com/google/cloud/spanner/BatchClientImpl.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner/src/main/java/com/google/cloud/spanner/BatchReadOnlyTransaction.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Knut Olav Løite <[email protected]>
Co-authored-by: Knut Olav Løite <[email protected]>
…leapis/java-spanner into java-spanner-issue-1651-fix
…leapis/java-spanner into java-spanner-issue-1651-fix
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:
Fixes #1651 ☕️