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

feat(spanner): add per-operation options to Commit() and Rollback() #7714

Merged
merged 1 commit into from
Dec 9, 2021

Conversation

devbww
Copy link
Contributor

@devbww devbww commented Dec 9, 2021

Part of #7690 to add an Options opts = {} argument to Commit()
and Rollback() operations. Add new TransactionTagOption and
CommitReturnStatsOption types to accompany RequestPriorityOption.
This means the caller no longer needs CommitOptions (although it is
still used in the Connection layer).

Run the Client options through spanner_internal::DefaultOptions().
Note that per-operation options strictly override those client-level
options.

Add OptionsSpan local variables to Commit() and Rollback()
(and also ExecuteBatchDml(), which already took plain Options).

Clarify which constructor and operation overloads are for backwards
compatibility so that they will be easier to deprecate/remove later.
Also clarify some doxygen comments about Options parameters.

Finally, update the Client test and sample code to use the new
options.


This change is Reviewable

Part of googleapis#7690 to add an `Options opts = {}` argument to `Commit()`
and `Rollback()` operations.  Add new `TransactionTagOption` and
`CommitReturnStatsOption` types to accompany `RequestPriorityOption`.
This means the caller no longer needs `CommitOptions` (although it is
still used in the `Connection` layer).

Run the `Client` options through `spanner_internal::DefaultOptions()`.
Note that per-operation options strictly override those client-level
options.

Add `OptionsSpan` local variables to `Commit()` and `Rollback()`
(and also `ExecuteBatchDml()`, which already took plain `Options`).

Clarify which constructor and operation overloads are for backwards
compatibility so that they will be easier to deprecate/remove later.
Also clarify some doxygen comments about `Options` parameters.

Finally, update the `Client` test and sample code to use the new
options.
@product-auto-label product-auto-label bot added the api: spanner Issues related to the Spanner API. label Dec 9, 2021
@google-cloud-cpp-bot
Copy link
Collaborator

Google Cloud Build Logs
For commit: e3fd3681a9a6f5f964961b05d63851aa2498c767

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

@codecov
Copy link

codecov bot commented Dec 9, 2021

Codecov Report

Merging #7714 (e3fd368) into main (d4ca5dd) will decrease coverage by 0.00%.
The diff coverage is 96.72%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7714      +/-   ##
==========================================
- Coverage   95.30%   95.29%   -0.01%     
==========================================
  Files        1256     1257       +1     
  Lines      113697   113741      +44     
==========================================
+ Hits       108355   108395      +40     
- Misses       5342     5346       +4     
Impacted Files Coverage Δ
google/cloud/spanner/commit_options.h 100.00% <ø> (ø)
google/cloud/spanner/commit_options.cc 93.75% <93.75%> (ø)
google/cloud/spanner/client.cc 98.14% <96.29%> (-0.36%) ⬇️
google/cloud/spanner/client.h 100.00% <100.00%> (ø)
google/cloud/spanner/client_test.cc 95.92% <100.00%> (ø)
google/cloud/spanner/commit_options_test.cc 100.00% <100.00%> (ø)
google/cloud/spanner/samples/samples.cc 63.15% <100.00%> (+0.01%) ⬆️
google/cloud/internal/async_rpc_details.h 94.44% <0.00%> (-5.56%) ⬇️
...ud/spanner/integration_tests/client_stress_test.cc 85.52% <0.00%> (-0.66%) ⬇️
...cloud/pubsub/internal/subscription_session_test.cc 97.75% <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 d4ca5dd...e3fd368. Read the comment docs.

@devbww devbww marked this pull request as ready for review December 9, 2021 06:12
@devbww devbww requested a review from a team as a code owner December 9, 2021 06:12
return Commit(mutator, std::move(rerun_policy), std::move(backoff_policy),
Options(commit_options));
}
StatusOr<CommitResult> Commit(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: here and below, blank line before the overload?

Copy link
Contributor Author

@devbww devbww Dec 9, 2021

Choose a reason for hiding this comment

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

The idea was to group the compatibility overloads tightly within the @{...@} braces, so I would vote for leaving it out. I'm happy to be outvoted though.

Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM.

GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN

CommitOptions::CommitOptions(Options const& opts)
: return_stats_(opts.has<CommitReturnStatsOption>()
Copy link
Contributor

Choose a reason for hiding this comment

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

consider reimplementing CommitOptions using a single Options member variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately perhaps, I don't think the CommitOptions API allows for this as transaction_tag() returns an absl::optional<std::string> by const&, which Options doesn't provide. Perhaps one of both of those choices was a mistake, but so be it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ack.

* Converts to the new, recommended way to represent options of all
* varieties, `google::cloud::Options`.
*/
explicit operator Options() const;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do applications need this conversion operator? If not, maybe we could use a friend function in spanner_internal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The thought was that this might be useful to a customer doing their own step-wise migration.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but once introduced it cannot be removed in basically forever. 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.

I think that is fine, because "forever" is bounded by the lifetime of CommitOptions itself, which we should deprecate along with the other specialty spanner::*Options classes when the Options migration is complete.

@coryan
Copy link
Contributor

coryan commented Dec 9, 2021

Happy if you merge as-is.

@devbww devbww merged commit fc44681 into googleapis:main Dec 9, 2021
@devbww devbww deleted the spanner-options-span branch December 9, 2021 19:16
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