Google Cloud Bigtable C++ Client  1.1.0
A C++ Client Library for Google Cloud Bigtable
data_client.h
Go to the documentation of this file.
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 // http://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/internal/completion_queue_impl.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 
24 namespace google {
25 namespace cloud {
26 namespace bigtable {
27 inline namespace BIGTABLE_CLIENT_NS {
28 // Forward declare some classes so we can be friends.
29 class Table;
30 namespace internal {
31 class AsyncBulkMutatorNoex;
32 class AsyncRetryBulkApply;
33 class AsyncSampleRowKeys;
34 class BulkMutator;
35 template <typename ReadRowCallback,
36  typename std::enable_if<
37  google::cloud::internal::is_invocable<
38  ReadRowCallback, CompletionQueue&, Row, grpc::Status&>::value,
39  int>::type>
40 class AsyncRowReader;
41 } // namespace internal
42 
43 /**
44  * Connects to Cloud Bigtable's data manipulation APIs.
45  *
46  * This class is used by the Cloud Bigtable wrappers to access Cloud Bigtable.
47  * Multiple `bigtable::Table` objects may share a connection via a single
48  * `DataClient` object. The `DataClient` object is configured at construction
49  * time, this configuration includes the credentials, access endpoints, default
50  * timeouts, and other gRPC configuration options. This is an interface class
51  * because it is also used as a dependency injection point in some of the tests.
52  *
53  * @par Cost
54  * Applications should avoid unnecessarily creating new objects of type
55  * `DataClient`. Creating a new object of this type typically requires
56  * connecting to the Cloud Bigtable servers, and performing the authentication
57  * workflows with Google Cloud Platform. These operations can take many
58  * milliseconds, therefore applications should try to reuse the same
59  * `DataClient` instances when possible.
60  */
61 class DataClient {
62  public:
63  virtual ~DataClient() = default;
64 
65  virtual std::string const& project_id() const = 0;
66  virtual std::string const& instance_id() const = 0;
67 
68  /**
69  * Return a new channel to handle admin operations.
70  *
71  * Intended to access rarely used services in the same endpoints as the
72  * Bigtable admin interfaces, for example, the google.longrunning.Operations.
73  */
74  virtual std::shared_ptr<grpc::Channel> Channel() = 0;
75 
76  /**
77  * Reset and create new Channels.
78  *
79  * Currently this is only used in testing. In the future, we expect this,
80  * or a similar member function, will be needed to handle errors that require
81  * a new connection, or an explicit refresh of the credentials.
82  */
83  virtual void reset() = 0;
84 
85  // The member functions of this class are not intended for general use by
86  // application developers (they are simply a dependency injection point). Make
87  // them protected, so the mock classes can override them, and then make the
88  // classes that do use them friends.
89  protected:
90  friend class Table;
91  friend class internal::AsyncBulkMutatorNoex;
92  friend class internal::AsyncRetryBulkApply;
93  friend class internal::AsyncSampleRowKeys;
94  friend class internal::BulkMutator;
95  friend class RowReader;
96  template <typename RowFunctor, typename FinishFunctor>
97  friend class AsyncRowReader;
98  template <typename ReadRowCallback,
99  typename std::enable_if<google::cloud::internal::is_invocable<
100  ReadRowCallback, CompletionQueue&, Row,
101  grpc::Status&>::value,
102  int>::type>
103  friend class internal::AsyncRowReader;
104  //@{
105  /// @name the `google.bigtable.v2.Bigtable` wrappers.
106  virtual grpc::Status MutateRow(
114  grpc::CompletionQueue* cq) = 0;
115  virtual grpc::Status CheckAndMutateRow(
124  grpc::CompletionQueue* cq) = 0;
125  virtual grpc::Status ReadModifyWriteRow(
134  grpc::CompletionQueue* cq) = 0;
135  virtual std::unique_ptr<
138  google::bigtable::v2::ReadRowsRequest const& request) = 0;
139  virtual std::unique_ptr<
143  grpc::CompletionQueue* cq, void* tag) = 0;
148  ::grpc::CompletionQueue* cq) = 0;
149  virtual std::unique_ptr<
158  ::grpc::CompletionQueue* cq, void* tag) = 0;
159  virtual std::unique_ptr<
162  google::bigtable::v2::MutateRowsRequest const& request) = 0;
167  ::grpc::CompletionQueue* cq, void* tag) = 0;
173  ::grpc::CompletionQueue* cq) = 0;
174  //@}
175 };
176 
177 /// Create the default implementation of ClientInterface.
178 std::shared_ptr<DataClient> CreateDefaultDataClient(std::string project_id,
179  std::string instance_id,
180  ClientOptions options);
181 
182 /**
183  * Return the fully qualified instance name for the @p client.
184  *
185  * Compute the full path of the instance associated with the client, i.e.,
186  * `projects/instances/<client->project_id()>/instances/<client->instance_id()>`
187  */
188 inline std::string InstanceName(std::shared_ptr<DataClient> client) {
189  return "projects/" + client->project_id() + "/instances/" +
190  client->instance_id();
191 }
192 
193 } // namespace BIGTABLE_CLIENT_NS
194 } // namespace bigtable
195 } // namespace cloud
196 } // namespace google
197 
198 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_DATA_CLIENT_H_
virtual std::unique_ptr<::grpc::ClientAsyncReaderInterface< ::google::bigtable::v2::MutateRowsResponse > > PrepareAsyncMutateRows(::grpc::ClientContext *context, const ::google::bigtable::v2::MutateRowsRequest &request, ::grpc::CompletionQueue *cq)=0
virtual std::shared_ptr< grpc::Channel > Channel()=0
Return a new channel to handle admin operations.
virtual std::string const & project_id() const =0
std::shared_ptr< DataClient > CreateDefaultDataClient(std::string project_id, std::string instance_id, ClientOptions options)
Create the default implementation of ClientInterface.
Definition: data_client.cc:173
virtual std::string const & instance_id() const =0
std::string InstanceName(std::shared_ptr< DataClient > client)
Return the fully qualified instance name for the client.
Definition: data_client.h:188
virtual grpc::Status MutateRow(grpc::ClientContext *context, google::bigtable::v2::MutateRowRequest const &request, google::bigtable::v2::MutateRowResponse *response)=0
virtual grpc::Status CheckAndMutateRow(grpc::ClientContext *context, google::bigtable::v2::CheckAndMutateRowRequest const &request, google::bigtable::v2::CheckAndMutateRowResponse *response)=0
virtual void reset()=0
Reset and create new Channels.
virtual grpc::Status ReadModifyWriteRow(grpc::ClientContext *context, google::bigtable::v2::ReadModifyWriteRowRequest const &request, google::bigtable::v2::ReadModifyWriteRowResponse *response)=0
#define BIGTABLE_CLIENT_NS
Definition: version.h:22
Configuration options for the Bigtable Client.
Contains all the Cloud Bigtable C++ client APIs.