Skip to content

Commit 19728fa

Browse files
authored
refactor(spanner): do not expose PrecommitToken in public interface (#15368)
1 parent f361fa3 commit 19728fa

File tree

8 files changed

+30
-31
lines changed

8 files changed

+30
-31
lines changed

google/cloud/spanner/connection.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ class StatusOnlyResultSetSource : public ResultSourceInterface {
3535
absl::optional<google::spanner::v1::ResultSetStats> Stats() const override {
3636
return {};
3737
}
38-
absl::optional<google::spanner::v1::MultiplexedSessionPrecommitToken>
39-
PrecommitToken() const override {
40-
return absl::nullopt;
41-
}
4238

4339
private:
4440
Status status_;

google/cloud/spanner/internal/connection_impl.cc

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,6 @@ class StatusOnlyResultSetSource : public spanner::ResultSourceInterface {
258258
absl::optional<google::spanner::v1::ResultSetStats> Stats() const override {
259259
return {};
260260
}
261-
absl::optional<google::spanner::v1::MultiplexedSessionPrecommitToken>
262-
PrecommitToken() const override {
263-
return absl::nullopt;
264-
}
265261

266262
private:
267263
google::cloud::Status status_;
@@ -274,11 +270,11 @@ ResultType MakeStatusOnlyResult(Status status) {
274270
std::make_unique<StatusOnlyResultSetSource>(std::move(status)));
275271
}
276272

277-
class DmlResultSetSource : public spanner::ResultSourceInterface {
273+
class DmlResultSetSource : public PartialResultSourceInterface {
278274
public:
279-
static StatusOr<std::unique_ptr<spanner::ResultSourceInterface>> Create(
275+
static StatusOr<std::unique_ptr<PartialResultSourceInterface>> Create(
280276
google::spanner::v1::ResultSet result_set) {
281-
return std::unique_ptr<spanner::ResultSourceInterface>(
277+
return std::unique_ptr<PartialResultSourceInterface>(
282278
new DmlResultSetSource(std::move(result_set)));
283279
}
284280

@@ -802,7 +798,7 @@ StatusOr<ResultType> ConnectionImpl::ExecuteSqlImpl(
802798
StatusOr<google::spanner::v1::TransactionSelector>& selector,
803799
TransactionContext& ctx, SqlParams params,
804800
google::spanner::v1::ExecuteSqlRequest::QueryMode query_mode,
805-
std::function<StatusOr<std::unique_ptr<spanner::ResultSourceInterface>>(
801+
std::function<StatusOr<std::unique_ptr<PartialResultSourceInterface>>(
806802
google::spanner::v1::ExecuteSqlRequest& request)> const&
807803
retry_resume_fn) {
808804
if (!selector.ok()) return selector.status();
@@ -901,7 +897,7 @@ ResultType ConnectionImpl::CommonQueryImpl(
901897
[stub, retry_policy_prototype, backoff_policy_prototype,
902898
route_to_leader = ctx.route_to_leader, tracing_enabled,
903899
tracing_options](google::spanner::v1::ExecuteSqlRequest& request) mutable
904-
-> StatusOr<std::unique_ptr<spanner::ResultSourceInterface>> {
900+
-> StatusOr<std::unique_ptr<PartialResultSourceInterface>> {
905901
auto factory = [stub, request, route_to_leader, tracing_enabled,
906902
tracing_options](std::string const& resume_token) mutable {
907903
if (!resume_token.empty()) request.set_resume_token(resume_token);
@@ -979,7 +975,7 @@ StatusOr<ResultType> ConnectionImpl::CommonDmlImpl(
979975
[function_name, stub, retry_policy_prototype, backoff_policy_prototype,
980976
session, route_to_leader = ctx.route_to_leader,
981977
current](google::spanner::v1::ExecuteSqlRequest& request) mutable
982-
-> StatusOr<std::unique_ptr<ResultSourceInterface>> {
978+
-> StatusOr<std::unique_ptr<PartialResultSourceInterface>> {
983979
StatusOr<google::spanner::v1::ResultSet> response = RetryLoop(
984980
retry_policy_prototype->clone(), backoff_policy_prototype->clone(),
985981
Idempotency::kIdempotent,

google/cloud/spanner/internal/connection_impl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "google/cloud/spanner/connection.h"
1919
#include "google/cloud/spanner/database.h"
20+
#include "google/cloud/spanner/internal/partial_result_set_source.h"
2021
#include "google/cloud/spanner/internal/session.h"
2122
#include "google/cloud/spanner/internal/session_pool.h"
2223
#include "google/cloud/spanner/internal/spanner_stub.h"
@@ -152,7 +153,7 @@ class ConnectionImpl : public spanner::Connection {
152153
StatusOr<google::spanner::v1::TransactionSelector>& selector,
153154
TransactionContext& ctx, SqlParams params,
154155
google::spanner::v1::ExecuteSqlRequest::QueryMode query_mode,
155-
std::function<StatusOr<std::unique_ptr<spanner::ResultSourceInterface>>(
156+
std::function<StatusOr<std::unique_ptr<PartialResultSourceInterface>>(
156157
google::spanner::v1::ExecuteSqlRequest& request)> const&
157158
retry_resume_fn);
158159

google/cloud/spanner/internal/partial_result_set_resume_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ std::unique_ptr<PartialResultSetReader> MakeTestResume(
6868
.clone());
6969
}
7070

71-
StatusOr<std::unique_ptr<spanner::ResultSourceInterface>>
71+
StatusOr<std::unique_ptr<PartialResultSourceInterface>>
7272
CreatePartialResultSetSource(std::unique_ptr<PartialResultSetReader> reader,
7373
Options opts = {}) {
7474
internal::OptionsSpan span(

google/cloud/spanner/internal/partial_result_set_source.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void ExtractSubrangeAndAppend(Values& src, int start, Values& dst) {
5656

5757
} // namespace
5858

59-
StatusOr<std::unique_ptr<spanner::ResultSourceInterface>>
59+
StatusOr<std::unique_ptr<PartialResultSourceInterface>>
6060
PartialResultSetSource::Create(std::unique_ptr<PartialResultSetReader> reader) {
6161
std::unique_ptr<PartialResultSetSource> source(
6262
new PartialResultSetSource(std::move(reader)));

google/cloud/spanner/internal/partial_result_set_source.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,32 @@ namespace cloud {
3737
namespace spanner_internal {
3838
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
3939

40+
class PrecommitInterface {
41+
public:
42+
/**
43+
* A precommit token is included if the read-write transaction is on
44+
* a multiplexed session. The precommit token with the highest sequence
45+
* number from this transaction attempt is added to the Commit request for
46+
* this transaction by the library.
47+
*/
48+
virtual absl::optional<google::spanner::v1::MultiplexedSessionPrecommitToken>
49+
PrecommitToken() const {
50+
return absl::nullopt;
51+
}
52+
};
53+
54+
class PartialResultSourceInterface : public spanner::ResultSourceInterface,
55+
public PrecommitInterface {};
56+
4057
/**
4158
* This class serves as a bridge between the gRPC `PartialResultSet` streaming
4259
* reader and the spanner `ResultSet`, and is used to iterate over the rows
4360
* returned from a read operation.
4461
*/
45-
class PartialResultSetSource : public spanner::ResultSourceInterface {
62+
class PartialResultSetSource : public PartialResultSourceInterface {
4663
public:
4764
/// Factory method to create a PartialResultSetSource.
48-
static StatusOr<std::unique_ptr<spanner::ResultSourceInterface>> Create(
65+
static StatusOr<std::unique_ptr<PartialResultSourceInterface>> Create(
4966
std::unique_ptr<PartialResultSetReader> reader);
5067

5168
~PartialResultSetSource() override;

google/cloud/spanner/internal/partial_result_set_source_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct StringOption {
5252
// Create the `PartialResultSetSource` within an `OptionsSpan` that has its
5353
// `StringOption` set to the current test name, so that we might check that
5454
// all `PartialResultSetReader` calls happen within a matching span.
55-
StatusOr<std::unique_ptr<spanner::ResultSourceInterface>>
55+
StatusOr<std::unique_ptr<PartialResultSourceInterface>>
5656
CreatePartialResultSetSource(std::unique_ptr<PartialResultSetReader> reader,
5757
Options opts = {}) {
5858
internal::OptionsSpan span(internal::MergeOptions(

google/cloud/spanner/results.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,6 @@ class ResultSourceInterface {
7070
* for more information.
7171
*/
7272
virtual absl::optional<google::spanner::v1::ResultSetStats> Stats() const = 0;
73-
74-
/**
75-
* A precommit token is included if the read-write transaction is on
76-
* a multiplexed session. The precommit token with the highest sequence
77-
* number from this transaction attempt is added to the Commit request for
78-
* this transaction by the library.
79-
*/
80-
virtual absl::optional<google::spanner::v1::MultiplexedSessionPrecommitToken>
81-
PrecommitToken() const {
82-
return absl::nullopt;
83-
}
8473
};
8574

8675
/**

0 commit comments

Comments
 (0)