Skip to content

Conversation

@larkee
Copy link
Contributor

@larkee larkee commented May 1, 2020

Currently, PingingPool pings sessions in the background by calling session.exists() which calls GetSession.

Using SELECT 1 is preferred and is used in other client libraries such as Go:

@larkee larkee requested review from hengfengli and skuruppu May 1, 2020 04:53
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label May 1, 2020
Copy link

@hengfengli hengfengli left a comment

Choose a reason for hiding this comment

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

Generally, it looks good to me. Please resolve the comments.

Copy link

@hengfengli hengfengli left a comment

Choose a reason for hiding this comment

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

LGTM. So when a session is deleted, calling session.ping() will cause a NotFound error, is this right?

@larkee
Copy link
Contributor Author

larkee commented May 1, 2020

LGTM. So when a session is deleted, calling session.ping() will cause a NotFound error, is this right?

Yes. However there seems to be a delay before the error appears. Given the following code, the error only occurs when DELAY is over ~35s

from google.cloud import spanner
from time import sleep

client = spanner.Client()
instance = client.instance(INSTANCE_ID)
database = instance.database(DATABASE_ID)
session = database.session()
session.create()
session.delete()
sleep(DELAY)
session.ping()

@hengfengli
Copy link

It makes sense. The deletion needs time to be propagated.

So if a session is deleted, when we still execute a transaction on it, what will happen then? When it gets a SessionNotFound error, will it try to get a new session?

@larkee
Copy link
Contributor Author

larkee commented May 1, 2020

It makes sense. The deletion needs time to be propagated.

So if a session is deleted, when we still execute a transaction on it, what will happen then? When it gets a SessionNotFound error, will it try to get a new session?

Currently, it will not. However, if we keep the session.exists() call in the get() then we don't have to worry about users encountering this error. Since, that isn't called in the background I think it's still acceptable.

@larkee larkee requested a review from hengfengli May 4, 2020 23:22
Copy link

@hengfengli hengfengli left a comment

Choose a reason for hiding this comment

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

LGTM. So now, pool.get() uses session.exists() to verify the validness of a session instead of session.ping(). Can we leave a comment over there why we don't use session.ping()?

The reason why we don't use session.ping() is that it has a cached/outdated result, which is inaccurate, is this correct?

@larkee
Copy link
Contributor Author

larkee commented May 5, 2020

LGTM. So now, pool.get() uses session.exists() to verify the validness of a session instead of session.ping(). Can we leave a comment over there why we don't use session.ping()?

Good suggestion! Done :)

The reason why we don't use session.ping() is that it has a cached/outdated result, which is inaccurate, is this correct?

Yes, the backend uses a cached value which means a delete may have occurred but not propagated yet.

Copy link

@hengfengli hengfengli left a comment

Choose a reason for hiding this comment

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

LGTM.

@larkee larkee added automerge Merge the pull request once unit tests and other checks pass. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels May 5, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 5, 2020
@gcf-merge-on-green gcf-merge-on-green bot merged commit 7a07c2b into googleapis:master May 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge Merge the pull request once unit tests and other checks pass. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants