Skip to content

Conversation

@dzhang-bap
Copy link

@thiagotnunes and @olavloite , here is a crude prototype for autocommit v2.

  • It is not thoroughly tested. We will do that after the server-side of autocommit v2 is implemented.
  • It has System.out.println(), and test code Donghui.java, which are not meant to be merged.
  • Given that the server does not yet support autocommit v2, this prototype fake it, by adding an explicit BeginTransaction inside commit().
  • The point of providing this pull request is to illustrate how it may be done and whether it may be overly complicated to maintain on the client side. It looks to me that having a separate collection of write sessions (maintained as a PriorityQueue sorted by timeToExpire) does not add too much complexity. What do you think?

@dzhang-bap dzhang-bap requested a review from a team as a code owner August 17, 2021 22:46
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Aug 17, 2021
@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/java-spanner API. label Aug 17, 2021
@thiagotnunes thiagotnunes added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Aug 18, 2021

private <T> T runWithSessionRetry(Function<Session, T> callable) {
PooledSessionFuture session = getSession();
PooledSessionFuture session = getSession(true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should not be statically true, but an input parameter for the method. This method is not a helper for retrying read/write transactions, but for retrying SessionNotFound errors that could occur for both read-only and read/write requests. (This happens when the backend has garbage collected or otherwise deleted/invalidated sessions without the client knowing about it)

sess = sessions.poll();
moveExpiredWriteSessionsToSessions();
if (wantRwTxnId) {
sess = writeSessions.poll();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that we would need to add some more logic here to prevent possible starvation in the following scenario (and similar scenarios):

  1. Assume that maxSessions=10
  2. The client executes 10 read/write transactions in parallel (or enough in parallel to use all 10 different sessions for a r/w transaction). All these sessions have now received a transaction id from the backend, and will be added to the queue of writeSessions and not to the list of sessions.
  3. The client wants to execute a read-only transaction, but there are no sessions in the normal session list, and maxSessions has been reached. It will therefore wait indefinitely.

Also, this list of writeSessions does not seem to be considered when calculating the number of sessions currently in the pool, is not considered for sessions that should be removed from the pool because they have expired, and is not included in the logic for closing the session pool and reporting any leaked sessions. (I know it's prototype so it's logical that not all of this is implemented, but my point is that more complexity than this will still be needed to be added to the session pool.)

@olavloite
Copy link
Collaborator

Closing for now, as some more work is needed.

@olavloite olavloite closed this Oct 28, 2021
gcf-owl-bot bot added a commit that referenced this pull request Feb 25, 2022
Source-Link: googleapis/synthtool@e122cb0
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:387835a1375a0049ec44e02542c844302854c732d8291bdf8e472c0ff70a8f67
gcf-merge-on-green bot pushed a commit that referenced this pull request Mar 1, 2022
Source-Link: googleapis/synthtool@e122cb0
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:387835a1375a0049ec44e02542c844302854c732d8291bdf8e472c0ff70a8f67
rajatbhatta pushed a commit to rajatbhatta/java-spanner that referenced this pull request Nov 17, 2022
…oogleapis#767)

Source-Link: googleapis/synthtool@e122cb0
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:387835a1375a0049ec44e02542c844302854c732d8291bdf8e472c0ff70a8f67
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. cla: yes This human has signed the Contributor License Agreement. do not merge Indicates a pull request not ready for merge, due to either quality or timing.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants