GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Implement multi-use snapshots by tseaver · Pull Request #3615 · googleapis/google-cloud-python

Conversation

@tseaver

@tseaver tseaver commented Jul 17, 2017

Copy link
Copy Markdown
Contributor

Multi-use snapshots trigger an "implicit" server-side transaction, and capture its ID on the first request. Subsequent requests return that ID, allowing for isolation from other changes. We default to multi_use=False because that mode is much more performant for the simple case.

This feature is one which we originally decided to leave out, but the P0 system test list requires that it be implemented.

I think that a commitwise review might be easier than reviewing the whole enchilada.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@tseaver tseaver added api: spanner Issues related to the Spanner API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels Jul 17, 2017
@tseaver
tseaver requested review from dhermes and lukesneeringer July 17, 2017 18:38
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jul 17, 2017
dhermes
dhermes reviewed Jul 19, 2017
View reviewed changes

@dhermes dhermes left a comment

Copy link
Copy Markdown
Contributor

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.

No real issues, just cosmetics.

Sorry for the delay in review.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread spanner/google/cloud/spanner/database.py

def snapshot(self, read_timestamp=None, min_read_timestamp=None,
max_staleness=None, exact_staleness=None):
def snapshot(self, **kw):

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Comment thread spanner/google/cloud/spanner/snapshot.py Outdated
if len(flagged) > 1:
raise ValueError("Supply zero or one options.")

if multi_use and (min_read_timestamp or max_staleness):

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Comment thread spanner/google/cloud/spanner/snapshot.py Outdated

if multi_use and (min_read_timestamp or max_staleness):
raise ValueError(
"'multi_use' is incompatile with "

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Comment thread spanner/google/cloud/spanner/streamed.py Outdated
self._resume_token = response.resume_token

if self._metadata is None: # first response
# XXX: copy implicit txn ID to snapshot, if present.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Comment thread spanner/tests/unit/test_snapshot.py Outdated
self.assertEqual(options.kwargs['metadata'],
[('google-cloud-resource-prefix', database.name)])

def test_execute_sql_wo_mulit_use(self):

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Comment thread spanner/tests/unit/test_streamed.py Outdated
return Value(list_value=_make_list_value_pb(values))

@staticmethod
def _makeResultSetMetadata(fields=(), transaction_id=None):

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Comment thread spanner/tests/unit/test_streamed.py Outdated
# limitations under the License.


import mock

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver
tseaver force-pushed the spanner-multi_use_snapshot branch 2 times, most recently from ad62692 to d445a73 Compare July 19, 2017 22:43
dhermes
dhermes reviewed Jul 19, 2017
View reviewed changes

@dhermes dhermes left a comment

Copy link
Copy Markdown
Contributor

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.

@tseaver Can you stop adding system tests to this PR? They keep coming in "after review" (e.g. 7d6fa02)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread spanner/tests/system/test_system.py Outdated

def test_multiuse_snapshot_read_isolation_exact_staleness(self):
import time
from datetime import timedelta

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Jul 19, 2017

Copy link
Copy Markdown
Contributor Author

Can you stop adding system tests to this PR? They keep coming in "after review"

I haven't added any: I had to rebase to fix the conflicts with your assertIs PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

vkedia
vkedia reviewed Jul 19, 2017
View reviewed changes
Comment thread spanner/google/cloud/spanner/snapshot.py
return StreamedResultSet(iterator)

def execute_sql(self, sql, params=None, param_types=None, query_mode=None,
resume_token=b''):

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

vkedia
vkedia reviewed Jul 19, 2017
View reviewed changes
Comment thread spanner/google/cloud/spanner/snapshot.py Outdated
``exact_staleness`` old.

:type multi_use: :class:`bool`
:param multi_use: If true, the first read operation creates a read-only

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

vkedia
vkedia reviewed Jul 19, 2017
View reviewed changes
Comment thread spanner/google/cloud/spanner/snapshot.py
if self._multi_use:
return StreamedResultSet(iterator, source=self)
else:
return StreamedResultSet(iterator)

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vkedia

vkedia commented Jul 20, 2017

Copy link
Copy Markdown

The documentation on this page suggests that snapshot already allows you to do multiple reads at a consistent snapshot.
This is what it says:

A Snapshot represents a read-only transaction: when multiple read operations are peformed via a Snapshot, the results are consistent as of a particular point in time.

In light of this PR that is clearly incorrect.

@jonparrott We also claim the same thing in our [sample code])
https://cloud.google.com/spanner/docs/getting-started/python/#retrieve_data_using_read-only_transactions). That too is incorrect.

@lukesneeringer @bjwatson Can we please get this merged asap. This is a severe bug.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vkedia vkedia added priority: p0 Highest priority. Critical issue. P0 implies highest priority. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels Jul 20, 2017
lukesneeringer
lukesneeringer approved these changes Jul 20, 2017
View reviewed changes

@lukesneeringer lukesneeringer left a comment

Copy link
Copy Markdown
Contributor

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.

Seeing no actual concerns (either in my own review or the other comments), this is good to go out.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vkedia

vkedia commented Jul 20, 2017

Copy link
Copy Markdown

@lukesneeringer I believe my comments need to be addressed before merging this. Specifically
#3615 (comment)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lukesneeringer

lukesneeringer commented Jul 20, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Ah -- confirmed. Thanks @vkedia. (@tseaver His proposed solution seems reasonable to me. Thoughts?)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vkedia

vkedia commented Jul 21, 2017

Copy link
Copy Markdown

@tseaver Any updates on this?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Jul 24, 2017

Copy link
Copy Markdown
Contributor Author

I can see adding an explicit Snapshot.begin to capture a transaction ID.

In addition, I had thought of having a _transaction_pending flag on the multi-use snapshot, which would cause subsequent read / execute_sql requests to raise an exception. This would smooth the "garden path" usage (i.e., reading / querying with fetch, rather than interleaving).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tseaver added 8 commits July 24, 2017 13:12
@tseaver
Add 'multi_use' param to 'Snapshot'.
cdfa43a
- Convert 'Database.snapshot' and 'Session.snapshot' factories to take /
  forward '**kw'.
@tseaver
Pass txn options as 'begin' when 'multi_use' is set.
43f44e4
@tseaver
Add 'source' parameter to 'StreamedResultIterator'.
5d3964f
- When reading / executing SQL for a multi-use snapshot, pass the snapshot
  as the iterator's source.
@tseaver
Use real protobuf classes:
2e5686f
- PartialResultSet
- ResultSetMetadata
- ResultSetStats.
@tseaver
On first read, propagate transaction id to source.
bd15294
- Source will only be set for multi-use snapshots.
@tseaver
For subsequent reads from multi-use snapshots, pass the transaction ID.
9f07550
@tseaver
Add system tests exercising multi-use snapshots.
22ad580
@tseaver
Add systets for multiuse snapshots w/ read_timestamp / exact_staleness.
3fc3aef
@tseaver
tseaver force-pushed the spanner-multi_use_snapshot branch from 799ce25 to 230d715 Compare July 24, 2017 17:49
@tseaver
Address docstring review comment.
1e72890
@tseaver

tseaver commented Jul 24, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

To implement the single-use request guard, the snapshot needs to maintain a request counter, which we can use to detect the "interleaved" case.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vkedia

vkedia commented Jul 24, 2017

Copy link
Copy Markdown

That sounds good. We can have an explicit begin which users can chose to call to get a transaction id and then they can interleave reads. If they do not call begin then the first read or query will create the transaction and if they try to interleave before it has returned they will get back an error.
So essentially users can interleave reads only after there is a transaction id which can be got by either calling begin or by the first read

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver
Add guard against reusing single-use snapshots.
ec38b8b
@vkedia

vkedia commented Jul 24, 2017

Copy link
Copy Markdown

Actually why do we need Snapshot to support single_use? For single use transactions database.read and database.query method should be sufficient. We should extend those methods to also take timestamp bound specific options.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver tseaver mentioned this pull request Jul 24, 2017
Expose read-isolation parameters in 'Database.read'/'Database.execute_sql' #3659
Closed
@tseaver

tseaver commented Jul 24, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Database.read and Database.execute_sql create Snapshot instances under the covers (via Session.read / Session.execute_sql). I just opened #3659 to track adding the read isolation parameters to those methods.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tseaver added 2 commits July 24, 2017 15:04
@tseaver
Add guard against pending transaction for multi-use snapshots.
8244af9
@tseaver
Update system tests for proper multi-use snapshot semantics.
5dc09f8
@tseaver
tseaver force-pushed the spanner-multi_use_snapshot branch from 1fff028 to 5dc09f8 Compare July 24, 2017 19:15
@tseaver

tseaver commented Jul 24, 2017

Copy link
Copy Markdown
Contributor Author

@vkedia I've just updated the system tests to pass multi_use=True where needed (I also fixed a new bug where Transaction was not implicitly multi-use for reads). I am, however, seeing system failures on the third invocation using multi-use snapshots:

________________ TestSessionAPI.test_execute_sql_w_query_param _________________
Traceback (most recent call last):
  File "/home/tseaver/projects/agendaless/Google/src/google-cloud-python/spanner/tests/system/test_system.py", line 960, in test_execute_sql_w_query_param
    expected=[(19,), (99,)],
  File "/home/tseaver/projects/agendaless/Google/src/google-cloud-python/spanner/tests/system/test_system.py", line 888, in _check_sql_results
    sql, params=params, param_types=param_types))
  File "/home/tseaver/projects/agendaless/Google/src/google-cloud-python/spanner/.nox/sys-3-6/lib/python3.6/site-packages/google/cloud/spanner/streamed.py", line 166, in __iter__
    self.consume_next()  # raises StopIteration
  File "/home/tseaver/projects/agendaless/Google/src/google-cloud-python/spanner/.nox/sys-3-6/lib/python3.6/site-packages/google/cloud/spanner/streamed.py", line 132, in consume_next
    response = six.next(self._response_iterator)
  File "/home/tseaver/projects/agendaless/Google/src/google-cloud-python/spanner/.nox/sys-3-6/lib/python3.6/site-packages/grpc/_channel.py", line 363, in __next__
    return self._next()
  File "/home/tseaver/projects/agendaless/Google/src/google-cloud-python/spanner/.nox/sys-3-6/lib/python3.6/site-packages/grpc/_channel.py", line 357, in _next
    raise self
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.INVALID_ARGUMENT, Transaction was started in a different session.)>
______________________ TestSessionAPI.test_read_w_ranges _______________________
Traceback (most recent call last):
  File "/home/tseaver/projects/agendaless/Google/src/google-cloud-python/spanner/tests/system/test_system.py", line 846, in test_read_w_ranges
    self.TABLE, self.COLUMNS, keyset))
  File "/home/tseaver/projects/agendaless/Google/src/google-cloud-python/spanner/.nox/sys-3-6/lib/python3.6/site-packages/google/cloud/spanner/streamed.py", line 166, in __iter__
    self.consume_next()  # raises StopIteration
  File "/home/tseaver/projects/agendaless/Google/src/google-cloud-python/spanner/.nox/sys-3-6/lib/python3.6/site-packages/google/cloud/spanner/streamed.py", line 132, in consume_next
    response = six.next(self._response_iterator)
  File "/home/tseaver/projects/agendaless/Google/src/google-cloud-python/spanner/.nox/sys-3-6/lib/python3.6/site-packages/grpc/_channel.py", line 363, in __next__
    return self._next()
  File "/home/tseaver/projects/agendaless/Google/src/google-cloud-python/spanner/.nox/sys-3-6/lib/python3.6/site-packages/grpc/_channel.py", line 357, in _next
    raise self
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.INVALID_ARGUMENT, Transaction was started in a different session.)>

I tried putting an explicit snapshot.begin() before the repeated read / execute_sql calls, but that didnt' change anything. Would the back-end be somehow be passing back a new transaction ID for the second read / execute_sql request (which does succeed)?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver
Avoid clearning snapshot txn ID when back-end returns blank.
0966806
@tseaver

tseaver commented Jul 24, 2017

Copy link
Copy Markdown
Contributor Author

Looks like the back-end passes back an empty transaction ID for read requests after the first one. 0966806 keeps us from clearing it in that case.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver
Untangle 'Transaction._id' vs. '_SnapshotBase._transaction_id'.
10f7126
@vkedia

vkedia commented Jul 24, 2017

Copy link
Copy Markdown

Thats right. Transaction field is only set if the read or query started a new transaction.
https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.ResultSetMetadata

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Jul 24, 2017

Copy link
Copy Markdown
Contributor Author

The new system tests are passing.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes

dhermes commented Jul 24, 2017

Copy link
Copy Markdown
Contributor

@tseaver What are you looking for here in terms of review?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Jul 24, 2017

Copy link
Copy Markdown
Contributor Author

@dhermes the commits which are new since @lukesneeringer gave an LGTM on Thursday (the rest are just rebase to fix conflicts). a5219a5 is the hash of that rebased commit, so the diff would be: a5219a5...spanner-multi_use_snapshot

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver tseaver mentioned this pull request Jul 24, 2017
Add a test which provokes abort-during-read during 'run_in_transaction'. #3663
Merged
@tseaver

tseaver commented Jul 26, 2017

Copy link
Copy Markdown
Contributor Author

@vkedia, @dhermes any issues remaining?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes

dhermes commented Jul 26, 2017

Copy link
Copy Markdown
Contributor

LGTM

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver
tseaver merged commit e273319 into master Jul 26, 2017
@tseaver
tseaver deleted the spanner-multi_use_snapshot branch July 26, 2017 22:00
@bjwatson

bjwatson commented Jul 26, 2017

Copy link
Copy Markdown

@tseaver I just saw this. I think that @vkedia will want to review this more when he returns from vacation on Monday. I guess if he finds anything else, it can be addressed in a separate PR.

Let's remain Alpha until next week. (FYI @lukesneeringer)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bjwatson

bjwatson commented Aug 8, 2017

Copy link
Copy Markdown

@vkedia Do you plan to finish reviewing this post-merge?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

landrito pushed a commit to landrito/google-cloud-python that referenced this pull request Aug 21, 2017
@tseaver @landrito
Implement multi-use snapshots (googleapis#3615)
d9a3dbe
landrito pushed a commit to landrito/google-cloud-python that referenced this pull request Aug 22, 2017
@tseaver @landrito
Implement multi-use snapshots (googleapis#3615)
e2ec1e1
landrito pushed a commit to landrito/google-cloud-python that referenced this pull request Aug 22, 2017
@tseaver @landrito
Implement multi-use snapshots (googleapis#3615)
5b82533
parthea pushed a commit that referenced this pull request Mar 9, 2026
@tseaver
Implement multi-use snapshots (#3615)
d724687
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

4 more reviewers
@theacodes theacodes theacodes left review comments
@dhermes dhermes dhermes left review comments
@vkedia vkedia vkedia left review comments
@lukesneeringer lukesneeringer lukesneeringer approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

api: spanner Issues related to the Spanner API. cla: yes This human has signed the Contributor License Agreement. priority: p0 Highest priority. Critical issue. P0 implies highest priority. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@tseaver @vkedia @lukesneeringer @dhermes @bjwatson @theacodes @googlebot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.