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(spanner): add Options save/restore to PartialResultSetSource #8355

Merged
merged 2 commits into from
Feb 13, 2022

Conversation

devbww
Copy link
Contributor

@devbww devbww commented Feb 12, 2022

Save the options in force during PartialResultSetSource construction,
and then restore them over PartialResultSetReader calls. This means
that NextRow(), Finish() and TryCancel() will have the right
options installed during any RPCs they execute.

Tighten up the test by installing a non-matching OptionsSpan before
any NextRow() calls are made, and by expecting no TryCancel()s in
cases that complete their enumeration.

This is the Spanner equivalent of #8256.


This change is Reviewable

Save the options in force during `PartialResultSetSource` construction,
and then restore them over `PartialResultSetReader` calls.  This means
that `NextRow()`, `Finish()` and `TryCancel()` will have the right
options installed during any RPCs they execute.

Tighten up the test by installing a non-matching `OptionsSpan` before
any `NextRow()` calls are made, and by expecting no `TryCancel()`s in
cases that complete their enumeration.

This is the Spanner equivalent of googleapis#8256.
@product-auto-label product-auto-label bot added the api: spanner Issues related to the Spanner API. label Feb 12, 2022
@google-cloud-cpp-bot
Copy link
Collaborator

Google Cloud Build Logs
For commit: 1c104a1a6c68272d388db673cf628b3ce9914ffe

ℹ️ NOTE: Kokoro logs are linked from "Details" below.

@codecov
Copy link

codecov bot commented Feb 12, 2022

Codecov Report

Merging #8355 (3e475aa) into main (fe2d568) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #8355   +/-   ##
=======================================
  Coverage   94.99%   94.99%           
=======================================
  Files        1355     1355           
  Lines      120749   120790   +41     
=======================================
+ Hits       114700   114748   +48     
+ Misses       6049     6042    -7     
Impacted Files Coverage Δ
google/cloud/spanner/results.h 91.66% <ø> (ø)
...loud/spanner/internal/partial_result_set_source.cc 95.18% <100.00%> (+0.11%) ⬆️
...cloud/spanner/internal/partial_result_set_source.h 100.00% <100.00%> (ø)
...spanner/internal/partial_result_set_source_test.cc 100.00% <100.00%> (ø)
google/cloud/bigtable/async_read_stream_test.cc 97.32% <0.00%> (-0.67%) ⬇️
...le/cloud/internal/default_completion_queue_impl.cc 97.15% <0.00%> (-0.57%) ⬇️
...cloud/pubsub/internal/subscription_session_test.cc 97.75% <0.00%> (-0.50%) ⬇️
google/cloud/completion_queue_test.cc 96.95% <0.00%> (-0.20%) ⬇️
google/cloud/pubsub/samples/samples.cc 92.10% <0.00%> (+0.07%) ⬆️
...le/cloud/spanner/database_admin_connection_test.cc 99.70% <0.00%> (+0.29%) ⬆️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a5a5458...3e475aa. Read the comment docs.

@devbww devbww marked this pull request as ready for review February 12, 2022 02:40
@devbww devbww requested a review from a team as a code owner February 12, 2022 02:40
Copy link
Contributor

@coryan coryan left a comment

Choose a reason for hiding this comment

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

This got me thinking, should we make analogous changes to the resumable streaming RPC:

absl::variant<Status, ResponseType> Read() override {
auto response = impl_->Read();
if (absl::holds_alternative<ResponseType>(response)) {
updater_(absl::get<ResponseType>(response), request_);
has_received_data_ = true;
return response;
}

EXPECT_CALL(*grpc_reader, Finish()).WillOnce(Return(Status()));

auto reader = PartialResultSetSource::Create(std::move(grpc_reader));
.WillOnce([&response] {
Copy link
Contributor

Choose a reason for hiding this comment

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

optional:

auto make_read_mock = [&response](int i) {
  return [&response, i]() {
    EXPECT_EQ(internal::CurrentOptions().get<StringOption>(), "ErrorOnIncompleteRow");
    return response[i];
  }
};
EXPECT_CALL(*grpc_reader, Read)
  .WillOnce(make_read_mock(0))
  .WillOnce(make_read_mock(1))
....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. I did something similar that eliminates the duplication and makes the mocks easier to use and understand. PTAL.

@google-cloud-cpp-bot
Copy link
Collaborator

Google Cloud Build Logs
For commit: 3e475aab1df59db0360992887bafbd1a0c15de5c

ℹ️ NOTE: Kokoro logs are linked from "Details" below.

@devbww
Copy link
Contributor Author

devbww commented Feb 13, 2022

This got me thinking, should we make analogous changes to the resumable streaming RPC

I'll look into it.

@devbww devbww merged commit 98fb6c9 into googleapis:main Feb 13, 2022
@devbww devbww deleted the spanner-result-source-options-span branch February 13, 2022 18:28
@devbww
Copy link
Contributor Author

devbww commented Feb 14, 2022

This got me thinking, should we make analogous changes to the resumable streaming RPC

I'll look into it.

I had thought that the StreamRange changes would handle this, but it looks like there is a hole when the StreamRange destroys its reader_, as that might cause a cancellation RPC without the right options if the reader is not yet finished. I'm investigating fixing that, and making the generated and Spanner cases look as similar as possible.

@devbww
Copy link
Contributor Author

devbww commented Feb 17, 2022

This got me thinking, should we make analogous changes to the resumable streaming RPC

I'll look into it.

I had thought that the StreamRange changes would handle this, but it looks like there is a hole when the StreamRange destroys its reader_, as that might cause a cancellation RPC without the right options if the reader is not yet finished. I'm investigating fixing that, and making the generated and Spanner cases look as similar as possible.

I don't think there was really a hole, as destroying the unfinished streaming reader only calls directly into gRPC to try to cancel the stream. That is, there is no cancellation RPC or other code that might look at our Options. But, we should probably always restore the operation-start options whenever the user can call back into the library, no matter what code we think that executes. So, I created #8403.

@coryan
Copy link
Contributor

coryan commented Feb 17, 2022

I don't think there was really a hole, as destroying the unfinished streaming reader only calls directly into gRPC to try to cancel the stream.

I was thinking about google::cloud::internal::ResumableStreamingReadRpc<>, I just created #8404, you can tell me there if the changes are not needed.

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 Spanner API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants