Google Cloud Bigtable C++ Client 2.13.0
A C++ Client Library for Google Cloud Bigtable
Loading...
Searching...
No Matches
data_client.h
1// Copyright 2017 Google Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_DATA_CLIENT_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_DATA_CLIENT_H
17
18#include "google/cloud/bigtable/client_options.h"
19#include "google/cloud/bigtable/completion_queue.h"
20#include "google/cloud/bigtable/row.h"
21#include "google/cloud/bigtable/version.h"
22#include <google/bigtable/v2/bigtable.grpc.pb.h>
23#include <string>
24
25namespace google {
26namespace cloud {
27// Forward declare some classes so we can be friends.
28namespace bigtable_internal {
29GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
30class LegacyAsyncRowReader;
31class LegacyRowReader;
32GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
33} // namespace bigtable_internal
34namespace bigtable {
35GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
36class Table;
37namespace internal {
38class AsyncRetryBulkApply;
39class LegacyAsyncRowSampler;
40class BulkMutator;
41class LoggingDataClient;
42} // namespace internal
43
44/**
45 * Connects to Cloud Bigtable's data manipulation APIs.
46 *
47 * This class is used by the Cloud Bigtable wrappers to access Cloud Bigtable.
48 * Multiple `bigtable::Table` objects may share a connection via a single
49 * `DataClient` object. The `DataClient` object is configured at construction
50 * time, this configuration includes the credentials, access endpoints, default
51 * timeouts, and other gRPC configuration options. This is an interface class
52 * because it is also used as a dependency injection point in some of the tests.
53 *
54 * @par Cost
55 * Applications should avoid unnecessarily creating new objects of type
56 * `DataClient`. Creating a new object of this type typically requires
57 * connecting to the Cloud Bigtable servers, and performing the authentication
58 * workflows with Google Cloud Platform. These operations can take many
59 * milliseconds, therefore applications should try to reuse the same
60 * `DataClient` instances when possible.
61 *
62 * @deprecated #google::cloud::bigtable::DataConnection is the preferred way to
63 * communicate with the Bigtable Data API. To migrate existing code, see
64 * @ref migrating-from-dataclient "Migrating from DataClient".
65 */
66class DataClient {
67 public:
68 virtual ~DataClient() = default;
69
70 virtual std::string const& project_id() const = 0;
71 virtual std::string const& instance_id() const = 0;
72
73 /**
74 * Return a new channel to handle admin operations.
75 *
76 * Intended to access rarely used services in the same endpoints as the
77 * Bigtable admin interfaces, for example, the google.longrunning.Operations.
78 *
79 * @deprecated This member function is scheduled for deletion and `DataClient`
80 * will be marked as `final`. Do not extend this class. Application
81 * developers who need to configure the gRPC Channel can pass any of the
82 * following options into `MakeDataClient(...)`:
83 * * `google::cloud::GrpcChannelArgumentsOption`
84 * * `google::cloud::GrpcChannelArgumentsNativeOption`
85 */
87 virtual std::shared_ptr<grpc::Channel> Channel() = 0;
88
89 /**
90 * Reset and create new Channels.
91 *
92 * @deprecated This member function is scheduled for deletion and `DataClient`
93 * will be marked as `final`. Do not extend this class. The client library
94 * will handle all interactions with the gRPC channels.
95 */
97 virtual void reset() = 0;
98
99 /**
100 * The thread factory this client was created with.
101 *
102 * @deprecated This member function is scheduled for deletion and `DataClient`
103 * will be marked as `final`. Do not extend this class. Application
104 * developers who need to configure the background threads can pass any
105 * of the following options into `MakeDataClient(...)`:
106 * * `google::cloud::GrpcBackgroundThreadPoolSizeOption`
107 * * `google::cloud::GrpcCompletionQueueOption`
108 * * `google::cloud::GrpcBackgroundThreadFactoryOption`
109 */
110 virtual google::cloud::BackgroundThreadsFactory
112
113 // The member functions of this class are not intended for general use by
114 // application developers (they are simply a dependency injection point). Make
115 // them protected, so the mock classes can override them, and then make the
116 // classes that do use them friends.
117 protected:
118 friend class Table;
119 friend class internal::AsyncRetryBulkApply;
120 friend class internal::LegacyAsyncRowSampler;
121 friend class internal::BulkMutator;
122 friend class bigtable_internal::LegacyRowReader;
123 friend class bigtable_internal::LegacyAsyncRowReader;
124 friend class internal::LoggingDataClient;
125
126 ///@{
127 /// @name the `google.bigtable.v2.Bigtable` wrappers.
128 virtual grpc::Status MutateRow(
129 grpc::ClientContext* context,
130 google::bigtable::v2::MutateRowRequest const& request,
131 google::bigtable::v2::MutateRowResponse* response) = 0;
132 virtual std::unique_ptr<grpc::ClientAsyncResponseReaderInterface<
133 google::bigtable::v2::MutateRowResponse>>
134 AsyncMutateRow(grpc::ClientContext* context,
135 google::bigtable::v2::MutateRowRequest const& request,
136 grpc::CompletionQueue* cq) = 0;
137 virtual grpc::Status CheckAndMutateRow(
138 grpc::ClientContext* context,
139 google::bigtable::v2::CheckAndMutateRowRequest const& request,
140 google::bigtable::v2::CheckAndMutateRowResponse* response) = 0;
141 virtual std::unique_ptr<grpc::ClientAsyncResponseReaderInterface<
142 google::bigtable::v2::CheckAndMutateRowResponse>>
144 grpc::ClientContext* context,
145 google::bigtable::v2::CheckAndMutateRowRequest const& request,
146 grpc::CompletionQueue* cq) = 0;
147 virtual grpc::Status ReadModifyWriteRow(
148 grpc::ClientContext* context,
149 google::bigtable::v2::ReadModifyWriteRowRequest const& request,
150 google::bigtable::v2::ReadModifyWriteRowResponse* response) = 0;
151 virtual std::unique_ptr<grpc::ClientAsyncResponseReaderInterface<
152 google::bigtable::v2::ReadModifyWriteRowResponse>>
154 grpc::ClientContext* context,
155 google::bigtable::v2::ReadModifyWriteRowRequest const& request,
156 grpc::CompletionQueue* cq) = 0;
157 virtual std::unique_ptr<
158 grpc::ClientReaderInterface<google::bigtable::v2::ReadRowsResponse>>
159 ReadRows(grpc::ClientContext* context,
160 google::bigtable::v2::ReadRowsRequest const& request) = 0;
161 virtual std::unique_ptr<
162 grpc::ClientAsyncReaderInterface<google::bigtable::v2::ReadRowsResponse>>
163 AsyncReadRows(grpc::ClientContext* context,
164 google::bigtable::v2::ReadRowsRequest const& request,
165 grpc::CompletionQueue* cq, void* tag) = 0;
166 virtual std::unique_ptr<::grpc::ClientAsyncReaderInterface<
167 google::bigtable::v2::ReadRowsResponse>>
168 PrepareAsyncReadRows(::grpc::ClientContext* context,
169 google::bigtable::v2::ReadRowsRequest const& request,
170 grpc::CompletionQueue* cq) = 0;
171 virtual std::unique_ptr<
172 grpc::ClientReaderInterface<google::bigtable::v2::SampleRowKeysResponse>>
173 SampleRowKeys(grpc::ClientContext* context,
174 google::bigtable::v2::SampleRowKeysRequest const& request) = 0;
175 virtual std::unique_ptr<::grpc::ClientAsyncReaderInterface<
176 google::bigtable::v2::SampleRowKeysResponse>>
177 AsyncSampleRowKeys(grpc::ClientContext* context,
178 google::bigtable::v2::SampleRowKeysRequest const& request,
179 grpc::CompletionQueue* cq, void* tag) = 0;
180 virtual std::unique_ptr<::grpc::ClientAsyncReaderInterface<
181 google::bigtable::v2::SampleRowKeysResponse>>
183 grpc::ClientContext* context,
184 google::bigtable::v2::SampleRowKeysRequest const& request,
185 grpc::CompletionQueue* cq);
186 virtual std::unique_ptr<
187 grpc::ClientReaderInterface<google::bigtable::v2::MutateRowsResponse>>
188 MutateRows(grpc::ClientContext* context,
189 google::bigtable::v2::MutateRowsRequest const& request) = 0;
190 virtual std::unique_ptr<::grpc::ClientAsyncReaderInterface<
191 google::bigtable::v2::MutateRowsResponse>>
192 AsyncMutateRows(::grpc::ClientContext* context,
193 google::bigtable::v2::MutateRowsRequest const& request,
194 grpc::CompletionQueue* cq, void* tag) = 0;
195 virtual std::unique_ptr<::grpc::ClientAsyncReaderInterface<
196 google::bigtable::v2::MutateRowsResponse>>
197 PrepareAsyncMutateRows(grpc::ClientContext* context,
198 google::bigtable::v2::MutateRowsRequest const& request,
199 grpc::CompletionQueue* cq) = 0;
200 ///@}
201};
202
203/// Create a new data client configured via @p options.
204std::shared_ptr<DataClient> MakeDataClient(std::string project_id,
205 std::string instance_id,
206 Options options = {});
207
208/**
209 * Create a new data client configured via @p options.
210 *
211 * @deprecated use the `MakeDataClient` method which accepts
212 * `google::cloud::Options` instead.
213 */
214GOOGLE_CLOUD_CPP_DEPRECATED("use `MakeDataClient` instead")
215std::shared_ptr<DataClient> CreateDefaultDataClient(std::string project_id,
216 std::string instance_id,
217 ClientOptions options);
218
219/**
220 * Return the fully qualified instance name for the @p client.
221 *
222 * Compute the full path of the instance associated with the client, i.e.,
223 * `projects/instances/<client->project_id()>/instances/<client->instance_id()>`
224 */
225inline std::string InstanceName(std::shared_ptr<DataClient> const& client) {
226 return "projects/" + client->project_id() + "/instances/" +
227 client->instance_id();
228}
229
230GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
231} // namespace bigtable
232} // namespace cloud
233} // namespace google
234
235#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_DATA_CLIENT_H
Configuration options for the Bigtable Client.
Definition: client_options.h:55
Connects to Cloud Bigtable's data manipulation APIs.
Definition: data_client.h:66
virtual std::unique_ptr<::grpc::ClientAsyncReaderInterface< google::bigtable::v2::ReadRowsResponse > > PrepareAsyncReadRows(::grpc::ClientContext *context, google::bigtable::v2::ReadRowsRequest const &request, grpc::CompletionQueue *cq)=0
virtual std::unique_ptr<::grpc::ClientAsyncReaderInterface< google::bigtable::v2::SampleRowKeysResponse > > AsyncSampleRowKeys(grpc::ClientContext *context, google::bigtable::v2::SampleRowKeysRequest const &request, grpc::CompletionQueue *cq, void *tag)=0
virtual std::string const & instance_id() const =0
virtual std::unique_ptr< grpc::ClientReaderInterface< google::bigtable::v2::SampleRowKeysResponse > > SampleRowKeys(grpc::ClientContext *context, google::bigtable::v2::SampleRowKeysRequest const &request)=0
virtual std::unique_ptr<::grpc::ClientAsyncReaderInterface< google::bigtable::v2::MutateRowsResponse > > AsyncMutateRows(::grpc::ClientContext *context, google::bigtable::v2::MutateRowsRequest const &request, grpc::CompletionQueue *cq, void *tag)=0
virtual std::unique_ptr<::grpc::ClientAsyncReaderInterface< google::bigtable::v2::SampleRowKeysResponse > > PrepareAsyncSampleRowKeys(grpc::ClientContext *context, google::bigtable::v2::SampleRowKeysRequest const &request, grpc::CompletionQueue *cq)
virtual std::unique_ptr< grpc::ClientAsyncResponseReaderInterface< google::bigtable::v2::MutateRowResponse > > AsyncMutateRow(grpc::ClientContext *context, google::bigtable::v2::MutateRowRequest const &request, grpc::CompletionQueue *cq)=0
virtual std::string const & project_id() const =0
virtual std::unique_ptr< grpc::ClientReaderInterface< google::bigtable::v2::ReadRowsResponse > > ReadRows(grpc::ClientContext *context, google::bigtable::v2::ReadRowsRequest const &request)=0
virtual std::unique_ptr< grpc::ClientReaderInterface< google::bigtable::v2::MutateRowsResponse > > MutateRows(grpc::ClientContext *context, google::bigtable::v2::MutateRowsRequest const &request)=0
virtual google::cloud::BackgroundThreadsFactory BackgroundThreadsFactory()=0
The thread factory this client was created with.
virtual std::unique_ptr< grpc::ClientAsyncResponseReaderInterface< google::bigtable::v2::ReadModifyWriteRowResponse > > AsyncReadModifyWriteRow(grpc::ClientContext *context, google::bigtable::v2::ReadModifyWriteRowRequest const &request, grpc::CompletionQueue *cq)=0
virtual void reset()=0
Reset and create new Channels.
virtual grpc::Status CheckAndMutateRow(grpc::ClientContext *context, google::bigtable::v2::CheckAndMutateRowRequest const &request, google::bigtable::v2::CheckAndMutateRowResponse *response)=0
virtual std::unique_ptr<::grpc::ClientAsyncReaderInterface< google::bigtable::v2::MutateRowsResponse > > PrepareAsyncMutateRows(grpc::ClientContext *context, google::bigtable::v2::MutateRowsRequest const &request, grpc::CompletionQueue *cq)=0
virtual grpc::Status MutateRow(grpc::ClientContext *context, google::bigtable::v2::MutateRowRequest const &request, google::bigtable::v2::MutateRowResponse *response)=0
virtual grpc::Status ReadModifyWriteRow(grpc::ClientContext *context, google::bigtable::v2::ReadModifyWriteRowRequest const &request, google::bigtable::v2::ReadModifyWriteRowResponse *response)=0
virtual std::unique_ptr< grpc::ClientAsyncResponseReaderInterface< google::bigtable::v2::CheckAndMutateRowResponse > > AsyncCheckAndMutateRow(grpc::ClientContext *context, google::bigtable::v2::CheckAndMutateRowRequest const &request, grpc::CompletionQueue *cq)=0
virtual std::unique_ptr< grpc::ClientAsyncReaderInterface< google::bigtable::v2::ReadRowsResponse > > AsyncReadRows(grpc::ClientContext *context, google::bigtable::v2::ReadRowsRequest const &request, grpc::CompletionQueue *cq, void *tag)=0
The main interface to interact with data in a Cloud Bigtable table.
Definition: table.h:166
Contains all the Cloud Bigtable C++ client APIs.
Definition: admin_client.h:28
std::string InstanceName(std::shared_ptr< DataClient > const &client)
Return the fully qualified instance name for the client.
Definition: data_client.h:225
std::shared_ptr< DataClient > CreateDefaultDataClient(std::string project_id, std::string instance_id, ClientOptions options)
Create a new data client configured via options.
std::shared_ptr< DataClient > MakeDataClient(std::string project_id, std::string instance_id, Options options={})
Create a new data client configured via options.
#define GOOGLE_CLOUD_CPP_BIGTABLE_DATA_CLIENT_DEPRECATED(name)
Definition: version.h:22