-
Notifications
You must be signed in to change notification settings - Fork 444
Expand file tree
/
Copy pathdata_connection.cc
More file actions
225 lines (199 loc) · 8.9 KB
/
data_connection.cc
File metadata and controls
225 lines (199 loc) · 8.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "google/cloud/bigtable/data_connection.h"
#include "google/cloud/bigtable/internal/bigtable_stub_factory.h"
#include "google/cloud/bigtable/internal/data_connection_impl.h"
#include "google/cloud/bigtable/internal/data_tracing_connection.h"
#include "google/cloud/bigtable/internal/defaults.h"
#include "google/cloud/bigtable/internal/mutate_rows_limiter.h"
#include "google/cloud/bigtable/internal/partial_result_set_source.h"
#include "google/cloud/bigtable/internal/row_reader_impl.h"
#include "google/cloud/bigtable/options.h"
#include "google/cloud/bigtable/result_source_interface.h"
#include "google/cloud/background_threads.h"
#include "google/cloud/common_options.h"
#include "google/cloud/credentials.h"
#include "google/cloud/grpc_options.h"
#include "google/cloud/internal/opentelemetry.h"
#include "google/cloud/internal/unified_grpc_credentials.h"
#include <memory>
namespace google {
namespace cloud {
namespace bigtable_internal {
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
std::vector<bigtable::FailedMutation> MakeFailedMutations(Status const& status,
std::size_t n) {
std::vector<bigtable::FailedMutation> mutations;
mutations.reserve(n);
for (int i = 0; i != static_cast<int>(n); ++i) {
mutations.emplace_back(status, i);
}
return mutations;
}
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
} // namespace bigtable_internal
namespace bigtable {
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
DataConnection::~DataConnection() = default;
// NOLINTNEXTLINE(performance-unnecessary-value-param)
Status DataConnection::Apply(std::string const&, SingleRowMutation) {
return Status(StatusCode::kUnimplemented, "not implemented");
}
future<Status> DataConnection::AsyncApply(
// NOLINTNEXTLINE(performance-unnecessary-value-param)
std::string const&, SingleRowMutation) {
return make_ready_future(
Status(StatusCode::kUnimplemented, "not implemented"));
}
std::vector<FailedMutation> DataConnection::BulkApply(
// NOLINTNEXTLINE(performance-unnecessary-value-param)
std::string const&, BulkMutation mut) {
return bigtable_internal::MakeFailedMutations(
Status(StatusCode::kUnimplemented, "not-implemented"), mut.size());
}
future<std::vector<FailedMutation>> DataConnection::AsyncBulkApply(
// NOLINTNEXTLINE(performance-unnecessary-value-param)
std::string const&, BulkMutation mut) {
return make_ready_future(bigtable_internal::MakeFailedMutations(
Status(StatusCode::kUnimplemented, "not-implemented"), mut.size()));
}
RowReader DataConnection::ReadRows(std::string const& table_name,
RowSet row_set, std::int64_t rows_limit,
Filter filter) {
auto const& options = google::cloud::internal::CurrentOptions();
return ReadRowsFull(ReadRowsParams{
std::move(table_name),
options.get<AppProfileIdOption>(),
std::move(row_set),
rows_limit,
std::move(filter),
options.get<ReverseScanOption>(),
});
}
// NOLINTNEXTLINE(performance-unnecessary-value-param)
RowReader DataConnection::ReadRowsFull(ReadRowsParams) {
return MakeRowReader(std::make_shared<bigtable_internal::StatusOnlyRowReader>(
Status(StatusCode::kUnimplemented, "not implemented")));
}
StatusOr<std::pair<bool, Row>> DataConnection::ReadRow(
// NOLINTNEXTLINE(performance-unnecessary-value-param)
std::string const&, std::string, Filter) {
return Status(StatusCode::kUnimplemented, "not implemented");
}
StatusOr<MutationBranch> DataConnection::CheckAndMutateRow(
std::string const&,
// NOLINTNEXTLINE(performance-unnecessary-value-param)
std::string, Filter, std::vector<Mutation>, std::vector<Mutation>) {
return Status(StatusCode::kUnimplemented, "not implemented");
}
future<StatusOr<MutationBranch>> DataConnection::AsyncCheckAndMutateRow(
std::string const&,
// NOLINTNEXTLINE(performance-unnecessary-value-param)
std::string, Filter, std::vector<Mutation>, std::vector<Mutation>) {
return make_ready_future<StatusOr<MutationBranch>>(
Status(StatusCode::kUnimplemented, "not implemented"));
}
StatusOr<std::vector<RowKeySample>> DataConnection::SampleRows(
std::string const&) {
return Status(StatusCode::kUnimplemented, "not implemented");
}
future<StatusOr<std::vector<RowKeySample>>> DataConnection::AsyncSampleRows(
std::string const&) {
return make_ready_future<StatusOr<std::vector<RowKeySample>>>(
Status(StatusCode::kUnimplemented, "not implemented"));
}
StatusOr<Row> DataConnection::ReadModifyWriteRow(
// NOLINTNEXTLINE(performance-unnecessary-value-param)
google::bigtable::v2::ReadModifyWriteRowRequest) {
return Status(StatusCode::kUnimplemented, "not implemented");
}
future<StatusOr<Row>> DataConnection::AsyncReadModifyWriteRow(
// NOLINTNEXTLINE(performance-unnecessary-value-param)
google::bigtable::v2::ReadModifyWriteRowRequest) {
return make_ready_future<StatusOr<Row>>(
Status(StatusCode::kUnimplemented, "not implemented"));
}
void DataConnection::AsyncReadRows(
// NOLINTNEXTLINE(performance-unnecessary-value-param)
std::string const&, std::function<future<bool>(Row)>,
// NOLINTNEXTLINE(performance-unnecessary-value-param)
std::function<void(Status)> on_finish, RowSet, std::int64_t, Filter) {
on_finish(Status(StatusCode::kUnimplemented, "not implemented"));
}
future<StatusOr<std::pair<bool, Row>>> DataConnection::AsyncReadRow(
// NOLINTNEXTLINE(performance-unnecessary-value-param)
std::string const&, std::string, Filter) {
return make_ready_future<StatusOr<std::pair<bool, Row>>>(
Status(StatusCode::kUnimplemented, "not implemented"));
}
StatusOr<bigtable::PreparedQuery> DataConnection::PrepareQuery(
bigtable::PrepareQueryParams const&) {
return Status(StatusCode::kUnimplemented, "not implemented");
}
future<StatusOr<bigtable::PreparedQuery>> DataConnection::AsyncPrepareQuery(
bigtable::PrepareQueryParams const&) {
return make_ready_future<StatusOr<PreparedQuery>>(
Status(StatusCode::kUnimplemented, "not implemented"));
}
bigtable::RowStream DataConnection::ExecuteQuery(bigtable::ExecuteQueryParams) {
return RowStream(
std::make_unique<bigtable_internal::StatusOnlyResultSetSource>(
Status(StatusCode::kUnimplemented, "not implemented")));
}
std::shared_ptr<DataConnection> MakeDataConnection(Options options) {
google::cloud::internal::CheckExpectedOptions<
AppProfileIdOption, CommonOptionList, GrpcOptionList,
UnifiedCredentialsOptionList, ClientOptionList, DataPolicyOptionList>(
options, __func__);
options = bigtable::internal::DefaultDataOptions(std::move(options));
auto background =
google::cloud::internal::MakeBackgroundThreadsFactory(options)();
auto auth = google::cloud::internal::CreateAuthenticationStrategy(
background->cq(), options);
auto limiter =
bigtable_internal::MakeMutateRowsLimiter(background->cq(), options);
std::shared_ptr<DataConnection> conn;
if (options.has<experimental::InstanceChannelAffinityOption>()) {
auto stub_creation_fn =
[auth, cq = background->cq(), options](
std::string_view instance_name,
bigtable_internal::StubManager::Priming priming) {
return bigtable_internal::CreateBigtableStub(auth, cq, instance_name,
priming, options);
};
auto affinity_stubs = bigtable_internal::CreateBigtableAffinityStubs(
options.get<experimental::InstanceChannelAffinityOption>(),
stub_creation_fn);
conn = std::make_shared<bigtable_internal::DataConnectionImpl>(
std::move(background),
std::make_unique<bigtable_internal::StubManager>(
std::move(affinity_stubs), stub_creation_fn),
std::move(limiter), std::move(options));
} else {
auto stub = bigtable_internal::CreateBigtableStub(
std::move(auth), background->cq(), options);
conn = std::make_shared<bigtable_internal::DataConnectionImpl>(
std::move(background),
std::make_unique<bigtable_internal::StubManager>(std::move(stub)),
std::move(limiter), std::move(options));
}
if (google::cloud::internal::TracingEnabled(conn->options())) {
conn = bigtable_internal::MakeDataTracingConnection(std::move(conn));
}
return conn;
}
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
} // namespace bigtable
} // namespace cloud
} // namespace google