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): fix Client::OverlayQueryOptions() to merge correctly #7118

Merged
merged 2 commits into from
Aug 5, 2021

Conversation

devbww
Copy link
Contributor

@devbww devbww commented Aug 5, 2021

Client::OverlayQueryOptions() was misbehaving on two fronts:

  • The environment option for optimizer_statistics_package was
    using the value of ${SPANNER_OPTIMIZER_VERSION} instead of
    ${SPANNER_OPTIMIZER_STATISTICS_PACKAGE}.
  • It was not setting an output value for request_priority at all.

At least part of the reason for these errors was that the test:

  • assumed the behavior could be changed by modifying the environment
    whereas the implementation only read the environment once, and
  • only a single MockConnection, with accumulated parameter matches,
    was used across all test cases.

So, fix the implementation, and revamp the test to be more direct
(which eliminates the mocking) and to exercise RequestPriority.

Also add a note to query_options.h to update OverlayQueryOptions()
whenever new options are added.

Finally, add documentation for ${SPANNER_OPTIMIZER_STATISTICS_PACKAGE}.


This change is Reviewable

`Client::OverlayQueryOptions()` was misbehaving on two fronts:
- The environment option for `optimizer_statistics_package` was
  using the value of `${SPANNER_OPTIMIZER_VERSION}` instead of
  `${SPANNER_OPTIMIZER_STATISTICS_PACKAGE}`.
- It was not setting an output value for `request_priority` at all.

At least part of the reason for these errors was that the test:
- assumed the behavior could be changed by modifying the environment
  whereas the implementation only read the environment once, and
- only a single `MockConnection`, with accumulated parameter matches,
  was used across all test cases.

So, fix the implementation, and revamp the test to be more direct
(which eliminates the mocking) and to exercise RequestPriority.

Also add a note to `query_options.h` to update `OverlayQueryOptions()`
whenever new options are added.

Finally, add documentation for `${SPANNER_OPTIMIZER_STATISTICS_PACKAGE}`.
@product-auto-label product-auto-label bot added the api: spanner Issues related to the Spanner API. label Aug 5, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Aug 5, 2021
@google-cloud-cpp-bot
Copy link
Collaborator

Google Cloud Build Logs
For commit: 822832602774fba8adc8cf8533be14e911ff7f3e

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

@codecov
Copy link

codecov bot commented Aug 5, 2021

Codecov Report

Merging #7118 (430f920) into main (a3a3826) will decrease coverage by 0.00%.
The diff coverage is 98.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7118      +/-   ##
==========================================
- Coverage   94.49%   94.49%   -0.01%     
==========================================
  Files        1309     1309              
  Lines      113039   113060      +21     
==========================================
+ Hits       106820   106831      +11     
- Misses       6219     6229      +10     
Impacted Files Coverage Δ
google/cloud/spanner/client.h 100.00% <ø> (ø)
google/cloud/spanner/query_options.h 100.00% <ø> (ø)
google/cloud/spanner/client.cc 98.45% <95.23%> (+1.09%) ⬆️
google/cloud/spanner/client_test.cc 95.86% <100.00%> (+0.09%) ⬆️
...ogle/cloud/spanner/mocks/mock_spanner_connection.h 66.66% <0.00%> (-20.00%) ⬇️
google/cloud/spanner/results.h 91.66% <0.00%> (-8.34%) ⬇️
...bigtable/examples/bigtable_hello_instance_admin.cc 81.31% <0.00%> (-2.20%) ⬇️
...le/cloud/internal/default_completion_queue_impl.cc 97.00% <0.00%> (-0.60%) ⬇️
...le/cloud/storage/internal/curl_download_request.cc 89.15% <0.00%> (-0.41%) ⬇️
...cloud/pubsub/internal/subscription_session_test.cc 97.78% <0.00%> (-0.25%) ⬇️
... and 2 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 a3a3826...430f920. Read the comment docs.

@devbww devbww marked this pull request as ready for review August 5, 2021 08:45
@devbww devbww requested a review from a team as a code owner August 5, 2021 08:45
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.

A lot of nits. The thing about notes to library developers in the Doxygen documentation needs to be fixed, the other stuff is optional.

@@ -643,6 +643,11 @@ class Client {
SqlStatement statement, QueryOptions const& opts = {});

private:
friend class OverlayQueryOptionsTester;
static QueryOptions OverlayQueryOptions(
Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively, put this static function in the spanner_internal namespace and you don't need the friend helper, your call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -30,6 +30,9 @@ inline namespace SPANNER_CLIENT_NS {
* These QueryOptions allow users to configure features about how their SQL
* queries executes on the server.
*
* Note: If you add an attribute here, remember to update the implementation
Copy link
Contributor

Choose a reason for hiding this comment

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

Ugh... that will make it to the public documentation too... Can you add the comment to a .cc file or to the beginning of the private: section? If not, can you add it after the Doxygen block as non-Doxygen comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no .cc for this interface, so private: section it is.

{{}, "client", "function", "function"},
{"env", "client", "function", "function"},
};
constexpr auto OverlayQueryOptions = // NOLINT(readability-identifier-naming)
Copy link
Contributor

Choose a reason for hiding this comment

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

I am sure you understand the tradeoffs between testing the function that computes the query options vs. verifying the correct query options are sent to the SpannerConnection. This note is just a nudge to consider these tradeoffs one last time before you pull the trigger. I am good either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a separate test, ConnectionImplTest.QueryOptions, for verifying how a final QueryOptions value is propagated into the protos. It is deficient in the request_priority department however, so I'll fix that in another PR.

@google-cloud-cpp-bot
Copy link
Collaborator

Google Cloud Build Logs
For commit: 430f920d635e6eecfa6b1da084bcebc783082044

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

Copy link
Contributor

@devjgm devjgm left a comment

Choose a reason for hiding this comment

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

Thanks for fixing.

@devbww devbww merged commit 8abe1f1 into googleapis:main Aug 5, 2021
@devbww devbww deleted the overlay-query-options branch August 5, 2021 18:26
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. 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