Skip to content

Commit a2dc298

Browse files
authored
impl(spanner): add AsyncCreateSession method to stubs (#15218)
1 parent 2d8e23a commit a2dc298

12 files changed

+127
-0
lines changed

generator/generator_config.textproto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3621,6 +3621,7 @@ service {
36213621
"Read"
36223622
]
36233623
gen_async_rpcs: [
3624+
"CreateSession",
36243625
"BatchCreateSessions",
36253626
"DeleteSession",
36263627
"ExecuteSql"

google/cloud/spanner/internal/spanner_auth_decorator.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,25 @@ SpannerAuth::BatchWrite(std::shared_ptr<grpc::ClientContext> context,
149149
return child_->BatchWrite(std::move(context), options, request);
150150
}
151151

152+
future<StatusOr<google::spanner::v1::Session>> SpannerAuth::AsyncCreateSession(
153+
google::cloud::CompletionQueue& cq,
154+
std::shared_ptr<grpc::ClientContext> context,
155+
google::cloud::internal::ImmutableOptions options,
156+
google::spanner::v1::CreateSessionRequest const& request) {
157+
return auth_->AsyncConfigureContext(std::move(context))
158+
.then([cq, child = child_, options = std::move(options),
159+
request](future<StatusOr<std::shared_ptr<grpc::ClientContext>>>
160+
f) mutable {
161+
auto context = f.get();
162+
if (!context) {
163+
return make_ready_future(StatusOr<google::spanner::v1::Session>(
164+
std::move(context).status()));
165+
}
166+
return child->AsyncCreateSession(cq, *std::move(context),
167+
std::move(options), request);
168+
});
169+
}
170+
152171
future<StatusOr<google::spanner::v1::BatchCreateSessionsResponse>>
153172
SpannerAuth::AsyncBatchCreateSessions(
154173
google::cloud::CompletionQueue& cq,

google/cloud/spanner/internal/spanner_auth_decorator.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ class SpannerAuth : public SpannerStub {
9696
Options const& options,
9797
google::spanner::v1::BatchWriteRequest const& request) override;
9898

99+
future<StatusOr<google::spanner::v1::Session>> AsyncCreateSession(
100+
google::cloud::CompletionQueue& cq,
101+
std::shared_ptr<grpc::ClientContext> context,
102+
google::cloud::internal::ImmutableOptions options,
103+
google::spanner::v1::CreateSessionRequest const& request) override;
104+
99105
future<StatusOr<google::spanner::v1::BatchCreateSessionsResponse>>
100106
AsyncBatchCreateSessions(
101107
google::cloud::CompletionQueue& cq,

google/cloud/spanner/internal/spanner_logging_decorator.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,24 @@ SpannerLogging::BatchWrite(
224224
std::move(context), options, request, __func__, tracing_options_);
225225
}
226226

227+
future<StatusOr<google::spanner::v1::Session>>
228+
SpannerLogging::AsyncCreateSession(
229+
google::cloud::CompletionQueue& cq,
230+
std::shared_ptr<grpc::ClientContext> context,
231+
google::cloud::internal::ImmutableOptions options,
232+
google::spanner::v1::CreateSessionRequest const& request) {
233+
return google::cloud::internal::LogWrapper(
234+
[this](google::cloud::CompletionQueue& cq,
235+
std::shared_ptr<grpc::ClientContext> context,
236+
google::cloud::internal::ImmutableOptions options,
237+
google::spanner::v1::CreateSessionRequest const& request) {
238+
return child_->AsyncCreateSession(cq, std::move(context),
239+
std::move(options), request);
240+
},
241+
cq, std::move(context), std::move(options), request, __func__,
242+
tracing_options_);
243+
}
244+
227245
future<StatusOr<google::spanner::v1::BatchCreateSessionsResponse>>
228246
SpannerLogging::AsyncBatchCreateSessions(
229247
google::cloud::CompletionQueue& cq,

google/cloud/spanner/internal/spanner_logging_decorator.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ class SpannerLogging : public SpannerStub {
9696
Options const& options,
9797
google::spanner::v1::BatchWriteRequest const& request) override;
9898

99+
future<StatusOr<google::spanner::v1::Session>> AsyncCreateSession(
100+
google::cloud::CompletionQueue& cq,
101+
std::shared_ptr<grpc::ClientContext> context,
102+
google::cloud::internal::ImmutableOptions options,
103+
google::spanner::v1::CreateSessionRequest const& request) override;
104+
99105
future<StatusOr<google::spanner::v1::BatchCreateSessionsResponse>>
100106
AsyncBatchCreateSessions(
101107
google::cloud::CompletionQueue& cq,

google/cloud/spanner/internal/spanner_metadata_decorator.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,19 @@ SpannerMetadata::BatchWrite(
159159
return child_->BatchWrite(std::move(context), options, request);
160160
}
161161

162+
future<StatusOr<google::spanner::v1::Session>>
163+
SpannerMetadata::AsyncCreateSession(
164+
google::cloud::CompletionQueue& cq,
165+
std::shared_ptr<grpc::ClientContext> context,
166+
google::cloud::internal::ImmutableOptions options,
167+
google::spanner::v1::CreateSessionRequest const& request) {
168+
SetMetadata(
169+
*context, *options,
170+
absl::StrCat("database=", internal::UrlEncode(request.database())));
171+
return child_->AsyncCreateSession(cq, std::move(context), std::move(options),
172+
request);
173+
}
174+
162175
future<StatusOr<google::spanner::v1::BatchCreateSessionsResponse>>
163176
SpannerMetadata::AsyncBatchCreateSessions(
164177
google::cloud::CompletionQueue& cq,

google/cloud/spanner/internal/spanner_metadata_decorator.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ class SpannerMetadata : public SpannerStub {
9696
Options const& options,
9797
google::spanner::v1::BatchWriteRequest const& request) override;
9898

99+
future<StatusOr<google::spanner::v1::Session>> AsyncCreateSession(
100+
google::cloud::CompletionQueue& cq,
101+
std::shared_ptr<grpc::ClientContext> context,
102+
google::cloud::internal::ImmutableOptions options,
103+
google::spanner::v1::CreateSessionRequest const& request) override;
104+
99105
future<StatusOr<google::spanner::v1::BatchCreateSessionsResponse>>
100106
AsyncBatchCreateSessions(
101107
google::cloud::CompletionQueue& cq,

google/cloud/spanner/internal/spanner_stub.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,24 @@ DefaultSpannerStub::BatchWrite(
177177
std::move(stream));
178178
}
179179

180+
future<StatusOr<google::spanner::v1::Session>>
181+
DefaultSpannerStub::AsyncCreateSession(
182+
google::cloud::CompletionQueue& cq,
183+
std::shared_ptr<grpc::ClientContext> context,
184+
// NOLINTNEXTLINE(performance-unnecessary-value-param)
185+
google::cloud::internal::ImmutableOptions,
186+
google::spanner::v1::CreateSessionRequest const& request) {
187+
return internal::MakeUnaryRpcImpl<google::spanner::v1::CreateSessionRequest,
188+
google::spanner::v1::Session>(
189+
cq,
190+
[this](grpc::ClientContext* context,
191+
google::spanner::v1::CreateSessionRequest const& request,
192+
grpc::CompletionQueue* cq) {
193+
return grpc_stub_->AsyncCreateSession(context, request, cq);
194+
},
195+
request, std::move(context));
196+
}
197+
180198
future<StatusOr<google::spanner::v1::BatchCreateSessionsResponse>>
181199
DefaultSpannerStub::AsyncBatchCreateSessions(
182200
google::cloud::CompletionQueue& cq,

google/cloud/spanner/internal/spanner_stub.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ class SpannerStub {
9898
Options const& options,
9999
google::spanner::v1::BatchWriteRequest const& request) = 0;
100100

101+
virtual future<StatusOr<google::spanner::v1::Session>> AsyncCreateSession(
102+
google::cloud::CompletionQueue& cq,
103+
std::shared_ptr<grpc::ClientContext> context,
104+
google::cloud::internal::ImmutableOptions options,
105+
google::spanner::v1::CreateSessionRequest const& request) = 0;
106+
101107
virtual future<StatusOr<google::spanner::v1::BatchCreateSessionsResponse>>
102108
AsyncBatchCreateSessions(
103109
google::cloud::CompletionQueue& cq,
@@ -182,6 +188,12 @@ class DefaultSpannerStub : public SpannerStub {
182188
Options const& options,
183189
google::spanner::v1::BatchWriteRequest const& request) override;
184190

191+
future<StatusOr<google::spanner::v1::Session>> AsyncCreateSession(
192+
google::cloud::CompletionQueue& cq,
193+
std::shared_ptr<grpc::ClientContext> context,
194+
google::cloud::internal::ImmutableOptions options,
195+
google::spanner::v1::CreateSessionRequest const& request) override;
196+
185197
future<StatusOr<google::spanner::v1::BatchCreateSessionsResponse>>
186198
AsyncBatchCreateSessions(
187199
google::cloud::CompletionQueue& cq,

google/cloud/spanner/internal/spanner_tracing_stub.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,20 @@ SpannerTracingStub::BatchWrite(
187187
std::move(context), std::move(stream), std::move(span));
188188
}
189189

190+
future<StatusOr<google::spanner::v1::Session>>
191+
SpannerTracingStub::AsyncCreateSession(
192+
google::cloud::CompletionQueue& cq,
193+
std::shared_ptr<grpc::ClientContext> context,
194+
google::cloud::internal::ImmutableOptions options,
195+
google::spanner::v1::CreateSessionRequest const& request) {
196+
auto span =
197+
internal::MakeSpanGrpc("google.spanner.v1.Spanner", "CreateSession");
198+
internal::OTelScope scope(span);
199+
internal::InjectTraceContext(*context, *propagator_);
200+
auto f = child_->AsyncCreateSession(cq, context, std::move(options), request);
201+
return internal::EndSpan(std::move(context), std::move(span), std::move(f));
202+
}
203+
190204
future<StatusOr<google::spanner::v1::BatchCreateSessionsResponse>>
191205
SpannerTracingStub::AsyncBatchCreateSessions(
192206
google::cloud::CompletionQueue& cq,

0 commit comments

Comments
 (0)