Google Cloud Bigtable C++ Client 2.13.0
A C++ Client Library for Google Cloud Bigtable
Loading...
Searching...
No Matches
data_connection.h
1// Copyright 2022 Google LLC
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_CONNECTION_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_DATA_CONNECTION_H
17
18#include "google/cloud/bigtable/filters.h"
19#include "google/cloud/bigtable/internal/bigtable_stub.h"
20#include "google/cloud/bigtable/mutation_branch.h"
21#include "google/cloud/bigtable/mutations.h"
22#include "google/cloud/bigtable/row.h"
23#include "google/cloud/bigtable/row_key_sample.h"
24#include "google/cloud/bigtable/row_reader.h"
25#include "google/cloud/bigtable/row_set.h"
26#include "google/cloud/backoff_policy.h"
27#include "google/cloud/options.h"
28#include "google/cloud/status_or.h"
29#include "google/cloud/stream_range.h"
30#include "google/cloud/version.h"
31#include <memory>
32
33namespace google {
34namespace cloud {
35namespace bigtable_internal {
36GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
37
38std::vector<bigtable::FailedMutation> MakeFailedMutations(Status const& status,
39 std::size_t n);
40GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
41} // namespace bigtable_internal
42namespace bigtable {
43GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
44
45/// Wrap the arguments to `ReadRows()`.
46struct ReadRowsParams {
47 std::string table_name;
48 std::string app_profile_id;
52};
53
54/**
55 * A connection to the Cloud Bigtable Data API.
56 *
57 * This interface defines pure-virtual methods for each of the user-facing
58 * overload sets in `Table`. This allows users to inject custom behavior (e.g.,
59 * with a Google Mock object) in a `Table` object for use in their own tests.
60 *
61 * To create a concrete instance, see `MakeDataConnection()`.
62 *
63 * For mocking, see `bigtable_mocks::MockDataConnection`.
64 *
65 * @par Connection Pool
66 * This class opens a number of [gRPC Channels] upon its construction. These
67 * channels each initiate a connection to the Cloud Bigtable service. This is a
68 * relatively slow operation that can take milliseconds, so applications are
69 * advised to reuse `DataConnection` objects when possible.
70 *
71 * The exact number of channels can be configured with the
72 * `google::cloud::GrpcNumChannelsOption`. If this option is not set, the class
73 * creates between 1 and 64 channels. The specific algorithm and number of
74 * channels is an implementation detail, and subject to change without notice.
75 *
76 * Each request sent from the client library cycles through the channels in the
77 * connection pool in a round robin fashion.
78 *
79 * Unused gRPC channels can enter an idle state. Refreshing them during a
80 * request may incur additional latency. To avoid this, the client library keeps
81 * connections open by refreshing the channels in a background thread. Advanced
82 * users can configure the frequency of the refreshes, or disable this feature,
83 * by using `bigtable::MinConnectionRefreshOption` and
84 * `bigtable::MaxConnectionRefreshOption`.
85 *
86 * [gRPC Channels]: https://grpc.io/docs/what-is-grpc/core-concepts/#channels
87 */
88class DataConnection {
89 public:
90 virtual ~DataConnection() = 0;
91
92 virtual Options options() { return Options{}; }
93
94 virtual Status Apply(std::string const& table_name, SingleRowMutation mut);
95
96 virtual future<Status> AsyncApply(std::string const& table_name,
98
99 virtual std::vector<FailedMutation> BulkApply(std::string const& table_name,
100 BulkMutation mut);
101
102 virtual future<std::vector<FailedMutation>> AsyncBulkApply(
103 std::string const& table_name, BulkMutation mut);
104
105 /// Prefer to use `ReadRowsFull()` in mocks.
106 virtual RowReader ReadRows(std::string const& table_name, RowSet row_set,
107 std::int64_t rows_limit, Filter filter);
108
109 virtual RowReader ReadRowsFull(ReadRowsParams params);
110
111 virtual StatusOr<std::pair<bool, Row>> ReadRow(std::string const& table_name,
112 std::string row_key,
113 Filter filter);
114
115 virtual StatusOr<MutationBranch> CheckAndMutateRow(
116 std::string const& table_name, std::string row_key, Filter filter,
117 std::vector<Mutation> true_mutations,
118 std::vector<Mutation> false_mutations);
119
121 std::string const& table_name, std::string row_key, Filter filter,
122 std::vector<Mutation> true_mutations,
123 std::vector<Mutation> false_mutations);
124
125 virtual StatusOr<std::vector<RowKeySample>> SampleRows(
126 std::string const& table_name);
127
128 virtual future<StatusOr<std::vector<RowKeySample>>> AsyncSampleRows(
129 std::string const& table_name);
130
131 virtual StatusOr<Row> ReadModifyWriteRow(
132 google::bigtable::v2::ReadModifyWriteRowRequest request);
133
134 virtual future<StatusOr<Row>> AsyncReadModifyWriteRow(
135 google::bigtable::v2::ReadModifyWriteRowRequest request);
136
137 virtual void AsyncReadRows(std::string const& table_name,
138 std::function<future<bool>(Row)> on_row,
139 std::function<void(Status)> on_finish,
140 RowSet row_set, std::int64_t rows_limit,
141 Filter filter);
142
143 virtual future<StatusOr<std::pair<bool, Row>>> AsyncReadRow(
144 std::string const& table_name, std::string row_key, Filter filter);
145};
146
147/**
148 * Returns a `DataConnection` object that can be used for interacting with
149 * the Cloud Bigtable Data API.
150 *
151 * The returned connection object should not be used directly; instead it
152 * should be given to a `Table` instance, and methods should be invoked on
153 * `Table`.
154 *
155 * The optional @p opts argument may be used to configure aspects of the
156 * returned `DataConnection`. Expected options are any of the following options
157 * or types in the option lists.
158 *
159 * - `google::cloud::CommonOptionList`
160 * - `google::cloud::GrpcOptionList`
161 * - `google::cloud::UnifiedCredentialsOptionList`
162 * - `google::cloud::bigtable::AppProfileIdOption`
163 * - `google::cloud::bigtable::ClientOptionsList`
164 * - `google::cloud::bigtable::DataPolicyOptionList`
165 *
166 * @note Unrecognized options will be ignored. To debug issues with options set
167 * `GOOGLE_CLOUD_CPP_ENABLE_CLOG=yes` in the environment and unexpected
168 * options will be logged.
169 *
170 * @param options (optional) Configure the `DataConnection` created by this
171 * function.
172 */
173std::shared_ptr<DataConnection> MakeDataConnection(Options options = {});
174
175GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
176} // namespace bigtable
177} // namespace cloud
178} // namespace google
179
180#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_DATA_CONNECTION_H
Represent a set of mutations across multiple rows.
Definition: mutations.h:492
A connection to the Cloud Bigtable Data API.
Definition: data_connection.h:88
virtual StatusOr< MutationBranch > CheckAndMutateRow(std::string const &table_name, std::string row_key, Filter filter, std::vector< Mutation > true_mutations, std::vector< Mutation > false_mutations)
virtual Options options()
Definition: data_connection.h:92
virtual StatusOr< Row > ReadModifyWriteRow(google::bigtable::v2::ReadModifyWriteRowRequest request)
virtual future< StatusOr< std::vector< RowKeySample > > > AsyncSampleRows(std::string const &table_name)
virtual future< std::vector< FailedMutation > > AsyncBulkApply(std::string const &table_name, BulkMutation mut)
virtual future< Status > AsyncApply(std::string const &table_name, SingleRowMutation mut)
virtual RowReader ReadRowsFull(ReadRowsParams params)
virtual Status Apply(std::string const &table_name, SingleRowMutation mut)
virtual future< StatusOr< Row > > AsyncReadModifyWriteRow(google::bigtable::v2::ReadModifyWriteRowRequest request)
virtual StatusOr< std::vector< RowKeySample > > SampleRows(std::string const &table_name)
virtual future< StatusOr< std::pair< bool, Row > > > AsyncReadRow(std::string const &table_name, std::string row_key, Filter filter)
virtual future< StatusOr< MutationBranch > > AsyncCheckAndMutateRow(std::string const &table_name, std::string row_key, Filter filter, std::vector< Mutation > true_mutations, std::vector< Mutation > false_mutations)
virtual RowReader ReadRows(std::string const &table_name, RowSet row_set, std::int64_t rows_limit, Filter filter)
Prefer to use ReadRowsFull() in mocks.
virtual std::vector< FailedMutation > BulkApply(std::string const &table_name, BulkMutation mut)
virtual void AsyncReadRows(std::string const &table_name, std::function< future< bool >(Row)> on_row, std::function< void(Status)> on_finish, RowSet row_set, std::int64_t rows_limit, Filter filter)
virtual StatusOr< std::pair< bool, Row > > ReadRow(std::string const &table_name, std::string row_key, Filter filter)
A SingleRowMutation that failed.
Definition: mutations.h:409
Define the interfaces to create filter expressions.
Definition: filters.h:52
static Filter PassAllFilter()
Return a filter that passes on all data.
Definition: filters.h:71
Object returned by Table::ReadRows(), enumerates rows in the response.
Definition: row_reader.h:54
Represent a (possibly non-continuous) set of row keys.
Definition: row_set.h:33
The in-memory representation of a Bigtable row.
Definition: row.h:34
Represent a single row mutation.
Definition: mutations.h:296
friend friend class future
Contains all the Cloud Bigtable C++ client APIs.
Definition: admin_client.h:28
std::shared_ptr< DataConnection > MakeDataConnection(Options options={})
Returns a DataConnection object that can be used for interacting with the Cloud Bigtable Data API.
MutationBranch
The branch taken by a Table::CheckAndMutateRow operation.
Definition: mutation_branch.h:26
Represent a single change to a specific row in a Table.
Definition: mutations.h:45
Wrap the arguments to ReadRows().
Definition: data_connection.h:46
std::int64_t rows_limit
Definition: data_connection.h:50
RowSet row_set
Definition: data_connection.h:49
std::string table_name
Definition: data_connection.h:47
Filter filter
Definition: data_connection.h:51
std::string app_profile_id
Definition: data_connection.h:48
A simple wrapper to represent the response from Table::SampleRowKeys().
Definition: row_key_sample.h:27