Skip to content

Commit 4f3d795

Browse files
committed
leverage CommitOptions to propagate flag
1 parent 49bd49e commit 4f3d795

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

google/cloud/spanner/commit_options.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ CommitOptions::CommitOptions(Options const& opts)
3333
if (opts.has<MaxCommitDelayOption>()) {
3434
max_commit_delay_ = opts.get<MaxCommitDelayOption>();
3535
}
36+
if (opts.has<ExcludeTransactionFromChangeStreamsOption>()) {
37+
exclude_txn_from_change_streams_ =
38+
opts.get<ExcludeTransactionFromChangeStreamsOption>();
39+
}
3640
}
3741

3842
CommitOptions::operator Options() const {
@@ -41,6 +45,10 @@ CommitOptions::operator Options() const {
4145
if (request_priority_) opts.set<RequestPriorityOption>(*request_priority_);
4246
if (transaction_tag_) opts.set<TransactionTagOption>(*transaction_tag_);
4347
if (max_commit_delay_) opts.set<MaxCommitDelayOption>(*max_commit_delay_);
48+
if (exclude_txn_from_change_streams_) {
49+
opts.set<ExcludeTransactionFromChangeStreamsOption>(
50+
*exclude_txn_from_change_streams_);
51+
}
4452
return opts;
4553
}
4654

google/cloud/spanner/commit_options.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,23 @@ class CommitOptions {
107107
return max_commit_delay_;
108108
}
109109

110+
CommitOptions& set_exclude_txn_from_change_streams(bool exclude) {
111+
exclude_txn_from_change_streams_ = exclude;
112+
return *this;
113+
}
114+
115+
absl::optional<bool> const& exclude_txn_from_change_streams() const {
116+
return exclude_txn_from_change_streams_;
117+
}
118+
110119
private:
111120
// Note that CommitRequest.request_options.request_tag is ignored,
112121
// so we do not even provide a mechanism to specify one.
113122
bool return_stats_ = false;
114123
absl::optional<RequestPriority> request_priority_;
115124
absl::optional<std::string> transaction_tag_;
116125
absl::optional<std::chrono::milliseconds> max_commit_delay_;
126+
absl::optional<bool> exclude_txn_from_change_streams_;
117127
};
118128

119129
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END

google/cloud/spanner/internal/connection_impl.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -580,12 +580,6 @@ StatusOr<google::spanner::v1::Transaction> ConnectionImpl::BeginTransaction(
580580

581581
auto stub = GetStubBasedOnSessionMode(*session, ctx);
582582
auto const& current = internal::CurrentOptions();
583-
584-
if (current.has<spanner::ExcludeTransactionFromChangeStreamsOption>() &&
585-
current.get<spanner::ExcludeTransactionFromChangeStreamsOption>()) {
586-
begin.mutable_options()->set_exclude_txn_from_change_streams(true);
587-
}
588-
589583
auto response = RetryLoop(
590584
RetryPolicyPrototype(current)->clone(),
591585
BackoffPolicyPrototype(current)->clone(), Idempotency::kIdempotent,

0 commit comments

Comments
 (0)