Google Cloud Bigtable C++ Client 2.13.0
A C++ Client Library for Google Cloud Bigtable
Loading...
Searching...
No Matches
table.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_TABLE_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_TABLE_H
17
18#include "google/cloud/bigtable/completion_queue.h"
19#include "google/cloud/bigtable/data_client.h"
20#include "google/cloud/bigtable/data_connection.h"
21#include "google/cloud/bigtable/filters.h"
22#include "google/cloud/bigtable/idempotent_mutation_policy.h"
23#include "google/cloud/bigtable/internal/defaults.h"
24#include "google/cloud/bigtable/internal/legacy_async_row_reader.h"
25#include "google/cloud/bigtable/mutation_branch.h"
26#include "google/cloud/bigtable/mutations.h"
27#include "google/cloud/bigtable/options.h"
28#include "google/cloud/bigtable/read_modify_write_rule.h"
29#include "google/cloud/bigtable/resource_names.h"
30#include "google/cloud/bigtable/row_key_sample.h"
31#include "google/cloud/bigtable/row_reader.h"
32#include "google/cloud/bigtable/row_set.h"
33#include "google/cloud/bigtable/rpc_backoff_policy.h"
34#include "google/cloud/bigtable/rpc_retry_policy.h"
35#include "google/cloud/bigtable/table_resource.h"
36#include "google/cloud/bigtable/version.h"
37#include "google/cloud/future.h"
38#include "google/cloud/grpc_error_delegate.h"
39#include "google/cloud/internal/group_options.h"
40#include "google/cloud/options.h"
41#include "google/cloud/status.h"
42#include "google/cloud/status_or.h"
43#include "absl/meta/type_traits.h"
44#include <string>
45#include <vector>
46
47namespace google {
48namespace cloud {
49namespace bigtable {
50GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
51
52class MutationBatcher;
53
54/**
55 * Return the full table name.
56 *
57 * The full table name is:
58 *
59 * `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/tables/<table_id>`
60 *
61 * Where the project id and instance id come from the @p client parameter.
62 */
63inline std::string TableName(std::shared_ptr<DataClient> const& client,
64 std::string const& table_id) {
65 return InstanceName(client) + "/tables/" + table_id;
66}
67
68/**
69 * The main interface to interact with data in a Cloud Bigtable table.
70 *
71 * This class provides member functions to:
72 * - read specific rows: `Table::ReadRow()`
73 * - scan a ranges of rows: `Table::ReadRows()`
74 * - update or create a single row: `Table::Apply()`
75 * - update or modify multiple rows: `Table::BulkApply()`
76 * - update a row based on previous values: `Table::CheckAndMutateRow()`
77 * - to atomically append data and/or increment multiple values in a row:
78 * `Table::ReadModifyWriteRow()`
79 * - to sample the row keys: `Table::SampleRows()`.
80 *
81 * The class deals with the most common transient failures, and retries the
82 * underlying RPC calls subject to the policies configured by the application.
83 * These policies are documented in `Table::Table()`.
84 *
85 * @par Thread-safety
86 * Instances of this class created via copy-construction or copy-assignment
87 * share the underlying pool of connections. Access to these copies via multiple
88 * threads is guaranteed to work. Two threads operating concurrently on the same
89 * instance of this class is not guaranteed to work.
90 *
91 * @par Cost
92 * Creating a new object of type `Table` is comparable to creating a few objects
93 * of type `std::string` or a few objects of type `std::shared_ptr<int>`. The
94 * class represents a shallow handle to a remote object.
95 *
96 * @par Error Handling
97 * This class uses `StatusOr<T>` to report errors. When an operation fails to
98 * perform its work the returned `StatusOr<T>` contains the error details. If
99 * the `ok()` member function in the `StatusOr<T>` returns `true` then it
100 * contains the expected result. Operations that do not return a value simply
101 * return a `google::cloud::Status` indicating success or the details of the
102 * error Please consult the [`StatusOr<T>`
103 * documentation](#google::cloud::StatusOr) for more details.
104 *
105 * @code
106 * namespace cbt = google::cloud::bigtable;
107 * cbt::Table = ...;
108 * google::cloud::StatusOr<std::pair<bool, cbt::Row>> row = table.ReadRow(...);
109 *
110 * if (!row) {
111 * std::cerr << "Error reading row\n";
112 * return;
113 * }
114 *
115 * // Use "row" as a smart pointer here, e.g.:
116 * if (!row->first) {
117 * std::cout << "Contacting the server was successful, but the row does not"
118 * << " exist\n";
119 * return;
120 * }
121 * std::cout << "The row has " << row->second.cells().size() << " cells\n";
122 * @endcode
123 *
124 * In addition, the @ref index "main page" contains examples using `StatusOr<T>`
125 * to handle errors.
126 *
127 * @par Retry, Backoff, and Idempotency Policies
128 * The library automatically retries requests that fail with transient errors,
129 * and uses [truncated exponential backoff][backoff-link] to backoff between
130 * retries. The default policies are to continue retrying for up to 10 minutes.
131 * On each transient failure the backoff period is doubled, starting with an
132 * initial backoff of 100 milliseconds. The backoff period growth is truncated
133 * at 60 seconds. The default idempotency policy is to only retry idempotent
134 * operations. Note that most operations that change state are **not**
135 * idempotent.
136 *
137 * The application can override these policies when constructing objects of this
138 * class. The documentation for the constructors show examples of this in
139 * action.
140 *
141 * [backoff-link]: https://cloud.google.com/storage/docs/exponential-backoff
142 *
143 * @see https://cloud.google.com/bigtable/ for an overview of Cloud Bigtable.
144 *
145 * @see https://cloud.google.com/bigtable/docs/overview for an overview of the
146 * Cloud Bigtable data model.
147 *
148 * @see https://cloud.google.com/bigtable/docs/instances-clusters-nodes for an
149 * introduction of the main APIs into Cloud Bigtable.
150 *
151 * @see https://cloud.google.com/bigtable/docs/reference/service-apis-overview
152 * for an overview of the underlying Cloud Bigtable API.
153 *
154 * @see #google::cloud::StatusOr for a description of the error reporting class
155 * used by this library.
156 *
157 * @see `LimitedTimeRetryPolicy` and `LimitedErrorCountRetryPolicy` for
158 * alternative retry policies.
159 *
160 * @see `ExponentialBackoffPolicy` to configure different parameters for the
161 * exponential backoff policy.
162 *
163 * @see `SafeIdempotentMutationPolicy` and `AlwaysRetryMutationPolicy` for
164 * alternative idempotency policies.
165 */
166class Table {
167 private:
168 // We need to eliminate some function overloads from resolution, and that
169 // requires a bit of infrastructure in the private section.
170
171 /// A meta function to check if @p P is a valid Policy type.
172 template <typename P>
173 struct ValidPolicy
174 : absl::disjunction<std::is_base_of<RPCBackoffPolicy, P>,
175 std::is_base_of<RPCRetryPolicy, P>,
176 std::is_base_of<IdempotentMutationPolicy, P>> {};
177
178 /// A meta function to check if all the @p Policies are valid policy types.
179 template <typename... Policies>
180 struct ValidPolicies : absl::conjunction<ValidPolicy<Policies>...> {};
181
182 public:
183 /**
184 * Constructs a `Table` object.
185 *
186 * @param conn the connection to the Cloud Bigtable service. See
187 * `MakeDataConnection()` for how to create a connection. To mock the
188 * behavior of `Table` in your tests, use a
189 * `bigtable_mocks::MockDataConnection`.
190 * @param tr identifies the table resource by its project, instance, and table
191 * ids.
192 * @param options Configuration options for the table. Use
193 * `AppProfileIdOption` to supply an app profile for the `Table`
194 * operations. Or configure retry / backoff / idempotency policies with
195 * the options enumerated in `DataPolicyOptionList`.
196 *
197 * @par Example Using AppProfile
198 * @snippet bigtable_hello_app_profile.cc read with app profile
199 *
200 * @par Idempotency Policy Example
201 * @snippet data_snippets.cc apply relaxed idempotency
202 *
203 * @par Modified Retry Policy Example
204 * @snippet data_snippets.cc apply custom retry
205 */
206 explicit Table(std::shared_ptr<bigtable::DataConnection> conn,
207 TableResource tr, Options options = {})
208 : table_(std::move(tr)),
209 table_name_(table_.FullName()),
210 connection_(std::move(conn)),
211 options_(google::cloud::internal::MergeOptions(std::move(options),
212 connection_->options())),
213 metadata_update_policy_(bigtable_internal::MakeMetadataUpdatePolicy(
214 table_name_, app_profile_id())) {}
215
216 std::string const& table_name() const { return table_name_; }
217 std::string const& app_profile_id() const {
218 return options_.get<AppProfileIdOption>();
219 }
220 std::string const& project_id() const {
221 return table_.instance().project_id();
222 }
223 std::string const& instance_id() const {
224 return table_.instance().instance_id();
225 }
226 std::string const& table_id() const { return table_.table_id(); }
227
228 /**
229 * Returns a Table that reuses the connection and configuration of this
230 * Table, but with a different resource name.
231 *
232 * @note The app profile id is copied from this Table.
233 */
234 Table WithNewTarget(std::string project_id, std::string instance_id,
235 std::string table_id) const {
236 auto table = *this;
237 table.table_ = TableResource(std::move(project_id), std::move(instance_id),
238 std::move(table_id));
239 table.table_name_ = table.table_.FullName();
240 table.metadata_update_policy_ = bigtable_internal::MakeMetadataUpdatePolicy(
241 table.table_name_, table.app_profile_id());
242 return table;
243 }
244
245 /**
246 * Returns a Table that reuses the connection and configuration of this
247 * Table, but with a different resource name.
248 */
249 Table WithNewTarget(std::string project_id, std::string instance_id,
250 std::string app_profile_id, std::string table_id) const {
251 auto table = *this;
252 table.table_ = TableResource(std::move(project_id), std::move(instance_id),
253 std::move(table_id));
254 table.table_name_ = table.table_.FullName();
255 table.options_.set<AppProfileIdOption>(std::move(app_profile_id));
256 table.metadata_update_policy_ = bigtable_internal::MakeMetadataUpdatePolicy(
257 table.table_name_, table.app_profile_id());
258 return table;
259 }
260
261 /**
262 * Attempts to apply the mutation to a row.
263 *
264 * @param mut the mutation. Note that this function takes ownership (and
265 * then discards) the data in the mutation. In general, a
266 * `SingleRowMutation` can be used to modify and/or delete multiple cells,
267 * across different columns and column families.
268 * @param opts (Optional) Override the class-level options, such as retry,
269 * backoff, and idempotency policies.
270 *
271 * @return status of the operation.
272 *
273 * @par Idempotency
274 * This operation is idempotent if the provided mutations are idempotent. Note
275 * that `google::cloud::bigtable::SetCell()` without an explicit timestamp is
276 * **not** an idempotent operation.
277 *
278 * @par Thread-safety
279 * Two threads concurrently calling this member function on the same instance
280 * of this class are **not** guaranteed to work.
281 *
282 * @par Example
283 * @snippet data_snippets.cc apply
284 */
286
287 /**
288 * Makes asynchronous attempts to apply the mutation to a row.
289 *
290 * @param mut the mutation. Note that this function takes ownership
291 * (and then discards) the data in the mutation. In general, a
292 * `SingleRowMutation` can be used to modify and/or delete
293 * multiple cells, across different columns and column families.
294 * @param opts (Optional) Override the class-level options, such as retry,
295 * backoff, and idempotency policies.
296 *
297 * @par Idempotency
298 * This operation is idempotent if the provided mutations are idempotent. Note
299 * that `google::cloud::bigtable::SetCell()` without an explicit timestamp is
300 * **not** an idempotent operation.
301 *
302 * @par Example
303 * @snippet data_async_snippets.cc async-apply
304 */
306
307 /**
308 * Attempts to apply mutations to multiple rows.
309 *
310 * These mutations are applied in bulk, in a single `MutateRowsRequest` RPC.
311 * Failures are handled on a per mutation basis. If the result of a mutation
312 * is a permanent (non-retryable) error, or if a non-idempotent mutation fails
313 * for any reason, the mutation will not be retried. Only idempotent mutations
314 * that encounter transient (retryable) errors can be retried. These mutations
315 * are collected and retried in bulk. This function will continue to retry any
316 * remaining errors until this class's retry policy is exhausted.
317 *
318 * It is possible that some mutations may not be attempted at all. These
319 * mutations are considered failing and will be returned.
320 *
321 * @note This function takes ownership (and then discards) the data in the
322 * mutation. In general, a `BulkMutation` can modify multiple rows, and
323 * the modifications for each row can change (or create) multiple cells,
324 * across different columns and column families.
325 *
326 * @param mut the mutations
327 * @param opts (Optional) Override the class-level options, such as retry,
328 * backoff, and idempotency policies.
329 * @returns a list of failed mutations
330 *
331 * @par Idempotency
332 * This operation is idempotent if the provided mutations are idempotent. Note
333 * that `google::cloud::bigtable::SetCell()` without an explicit timestamp is
334 * **not** an idempotent operation.
335 *
336 * @par Thread-safety
337 * Two threads concurrently calling this member function on the same instance
338 * of this class are **not** guaranteed to work. Consider copying the object
339 * and using different copies in each thread.
340 *
341 * @par Example
342 * @snippet data_snippets.cc bulk apply
343 */
344 std::vector<FailedMutation> BulkApply(BulkMutation mut, Options opts = {});
345
346 /**
347 * Makes asynchronous attempts to apply mutations to multiple rows.
348 *
349 * These mutations are applied in bulk, in a single `MutateRowsRequest` RPC.
350 * Failures are handled on a per mutation basis. If the result of a mutation
351 * is a permanent (non-retryable) error, or if a non-idempotent mutation fails
352 * for any reason, the mutation will not be retried. Only idempotent mutations
353 * that encounter transient (retryable) errors can be retried. These mutations
354 * are collected and retried in bulk. This function will continue to retry any
355 * remaining errors until this class's retry policy is exhausted.
356 *
357 * It is possible that some mutations may not be attempted at all. These
358 * mutations are considered failing and will be returned.
359 *
360 * @note This function takes ownership (and then discards) the data in the
361 * mutation. In general, a `BulkMutation` can modify multiple rows, and
362 * the modifications for each row can change (or create) multiple cells,
363 * across different columns and column families.
364 *
365 * @param mut the mutations
366 * @param opts (Optional) Override the class-level options, such as retry,
367 * backoff, and idempotency policies.
368 * @returns a future to be filled with a list of failed mutations, when the
369 * operation is complete.
370 *
371 * @par Idempotency
372 * This operation is idempotent if the provided mutations are idempotent. Note
373 * that `google::cloud::bigtable::SetCell()` without an explicit timestamp is
374 * **not** an idempotent operation.
375 *
376 * @par Thread-safety
377 * Two threads concurrently calling this member function on the same instance
378 * of this class are **not** guaranteed to work. Consider copying the object
379 * and using different copies in each thread.
380 *
381 * @par Example
382 * @snippet data_async_snippets.cc bulk async-bulk-apply
383 */
385 Options opts = {});
386
387 /**
388 * Reads a set of rows from the table.
389 *
390 * @param row_set the rows to read from.
391 * @param filter is applied on the server-side to data in the rows.
392 * @param opts (Optional) Override the class-level options, such as retry,
393 * backoff, and idempotency policies.
394 *
395 * @par Idempotency
396 * This is a read-only operation and therefore it is always idempotent.
397 *
398 * @par Thread-safety
399 * Two threads concurrently calling this member function on the same instance
400 * of this class are **not** guaranteed to work. Consider copying the object
401 * and using different copies in each thread. The values returned by
402 * different calls are independent with respect to thread-safety, please see
403 * the `RowReader` documentation for more details.
404 *
405 * @par Example
406 * @snippet read_snippets.cc read rows
407 */
408 RowReader ReadRows(RowSet row_set, Filter filter, Options opts = {});
409
410 /**
411 * Reads a limited set of rows from the table.
412 *
413 * @param row_set the rows to read from.
414 * @param rows_limit the maximum number of rows to read. Cannot be a negative
415 * number or zero. Use `ReadRows(RowSet, Filter)` to read all matching
416 * rows.
417 * @param filter is applied on the server-side to data in the rows.
418 * @param opts (Optional) Override the class-level options, such as retry,
419 * backoff, and idempotency policies.
420 *
421 * @par Idempotency
422 * This is a read-only operation and therefore it is always idempotent.
423 *
424 * @par Thread-safety
425 * Two threads concurrently calling this member function on the same instance
426 * of this class are **not** guaranteed to work. Consider copying the object
427 * and using different copies in each thread. The values returned by
428 * different calls are independent with respect to thread-safety, please see
429 * the `RowReader` documentation for more details.
430 *
431 * @par Example
432 * @snippet read_snippets.cc read rows with limit
433 */
434 RowReader ReadRows(RowSet row_set, std::int64_t rows_limit, Filter filter,
435 Options opts = {});
436
437 /**
438 * Read and return a single row from the table.
439 *
440 * @param row_key the row to read.
441 * @param filter a filter expression, can be used to select a subset of the
442 * column families and columns in the row.
443 * @param opts (Optional) Override the class-level options, such as retry,
444 * backoff, and idempotency policies.
445 * @returns a tuple, the first element is a boolean, with value `false` if the
446 * row does not exist. If the first element is `true` the second element
447 * has the contents of the Row. Note that the contents may be empty
448 * if the filter expression removes all column families and columns.
449 *
450 * @par Idempotency
451 * This is a read-only operation and therefore it is always idempotent.
452 *
453 * @par Thread-safety
454 * Two threads concurrently calling this member function on the same instance
455 * of this class are **not** guaranteed to work. Consider copying the object
456 * and using different copies in each thread.
457 *
458 * @par Example
459 * @snippet read_snippets.cc read row
460 */
461 StatusOr<std::pair<bool, Row>> ReadRow(std::string row_key, Filter filter,
462 Options opts = {});
463
464 /**
465 * Atomic test-and-set for a row using filter expressions.
466 *
467 * Atomically check the value of a row using a filter expression. If the
468 * expression passes (meaning at least one element is returned by it), one
469 * set of mutations is applied. If the filter does not pass, a different set
470 * of mutations is applied. The changes are atomically applied in the server.
471 *
472 * @param row_key the row to modify.
473 * @param filter the filter expression.
474 * @param true_mutations the mutations for the "filter passed" case.
475 * @param false_mutations the mutations for the "filter did not pass" case.
476 * @param opts (Optional) Override the class-level options, such as retry,
477 * backoff, and idempotency policies.
478 * @returns true if the filter passed.
479 *
480 * @par Idempotency
481 * This operation is always treated as non-idempotent.
482 *
483 * @par Thread-safety
484 * Two threads concurrently calling this member function on the same instance
485 * of this class are **not** guaranteed to work. Consider copying the object
486 * and using different copies in each thread.
487 *
488 * @par Check for Value Example
489 * @snippet data_snippets.cc check and mutate
490 *
491 * @par Check for Cell Presence Example
492 * @snippet data_snippets.cc check and mutate not present
493 */
495 std::string row_key, Filter filter, std::vector<Mutation> true_mutations,
496 std::vector<Mutation> false_mutations, Options opts = {});
497
498 /**
499 * Make an asynchronous request to conditionally mutate a row.
500 *
501 * @param row_key the row key on which the conditional mutation will be
502 * performed
503 * @param filter the condition, depending on which the mutation will be
504 * performed
505 * @param true_mutations the mutations which will be performed if @p filter is
506 * true
507 * @param false_mutations the mutations which will be performed if @p filter
508 * is false
509 * @param opts (Optional) Override the class-level options, such as retry,
510 * backoff, and idempotency policies.
511 *
512 * @par Idempotency
513 * This operation is always treated as non-idempotent.
514 *
515 * @par Thread-safety
516 * Two threads concurrently calling this member function on the same instance
517 * of this class are **not** guaranteed to work. Consider copying the object
518 * and using different copies in each thread.
519 *
520 * @par Example
521 * @snippet data_async_snippets.cc async check and mutate
522 */
524 std::string row_key, Filter filter, std::vector<Mutation> true_mutations,
525 std::vector<Mutation> false_mutations, Options opts = {});
526
527 /**
528 * Sample of the row keys in the table, including approximate data sizes.
529 *
530 * @note The sample may only include one element for small tables. In
531 * addition, the sample may include row keys that do not exist on the
532 * table, and may include the empty row key to indicate "end of table".
533 *
534 * @par Idempotency
535 * This operation is always treated as idempotent.
536 *
537 * @par Thread-safety
538 * Two threads concurrently calling this member function on the same instance
539 * of this class are **not** guaranteed to work. Consider copying the object
540 * and using different copies in each thread.
541 *
542 * @par Examples
543 * @snippet data_snippets.cc sample row keys
544 */
545 StatusOr<std::vector<bigtable::RowKeySample>> SampleRows(Options opts = {});
546
547 /**
548 * Asynchronously obtains a sample of the row keys in the table, including
549 * approximate data sizes.
550 *
551 * @returns a future, that becomes satisfied when the operation completes.
552 *
553 * @note The sample may only include one element for small tables. In
554 * addition, the sample may include row keys that do not exist on the
555 * table, and may include the empty row key to indicate "end of table".
556 *
557 * @par Idempotency
558 * This operation is always treated as idempotent.
559 *
560 * @par Thread-safety
561 * Two threads concurrently calling this member function on the same instance
562 * of this class are **not** guaranteed to work. Consider copying the object
563 * and using different copies in each thread.
564 *
565 * @par Examples
566 * @snippet data_async_snippets.cc async sample row keys
567 */
568 future<StatusOr<std::vector<bigtable::RowKeySample>>> AsyncSampleRows(
569 Options opts = {});
570
571 /**
572 * Atomically read and modify the row in the server, returning the
573 * resulting row
574 *
575 * @tparam Args this is zero or more ReadModifyWriteRules to apply on a row.
576 * Options to override the class-level options, such as retry, backoff,
577 * and idempotency policies are also be passed via this parameter pack.
578 * @param row_key the row to read
579 * @param rule to modify the row. Two types of rules are applied here
580 * AppendValue which will read the existing value and append the
581 * text provided to the value.
582 * IncrementAmount which will read the existing uint64 big-endian-int
583 * and add the value provided.
584 * Both rules accept the family and column identifier to modify.
585 * @param rules_and_options is the zero or more ReadModifyWriteRules to apply
586 * on a row. Options to override the class-level options, such as retry,
587 * backoff, and idempotency policies are also be passed via this parameter
588 * pack.
589 * @returns the new contents of all modified cells.
590 *
591 * @par Idempotency
592 * This operation is always treated as non-idempotent.
593 *
594 * @par Thread-safety
595 * Two threads concurrently calling this member function on the same instance
596 * of this class are **not** guaranteed to work. Consider copying the object
597 * and using different copies in each thread.
598 *
599 * @par Example
600 * @snippet data_snippets.cc read modify write
601 */
602 template <typename... Args>
603 StatusOr<Row> ReadModifyWriteRow(std::string row_key,
605 Args&&... rules_and_options) {
606 ::google::bigtable::v2::ReadModifyWriteRowRequest request;
607 request.set_row_key(std::move(row_key));
608
609 // Generate a better compile time error message than the default one
610 // if the types do not match
611 static_assert(
612 absl::conjunction<absl::disjunction<
613 std::is_convertible<Args, bigtable::ReadModifyWriteRule>,
614 std::is_same<typename std::decay<Args>::type, Options>>...>::value,
615 "The arguments passed to ReadModifyWriteRow(row_key,...) must be "
616 "convertible to bigtable::ReadModifyWriteRule, or of type "
617 "google::cloud::Options");
618
619 *request.add_rules() = std::move(rule).as_proto();
620 AddRules(request, std::forward<Args>(rules_and_options)...);
621 auto opts = google::cloud::internal::GroupOptions(
622 std::forward<Args>(rules_and_options)...);
623 return ReadModifyWriteRowImpl(std::move(request), std::move(opts));
624 }
625
626 /**
627 * Make an asynchronous request to atomically read and modify a row.
628 *
629 * @tparam Args this is zero or more ReadModifyWriteRules to apply on a row.
630 * Options to override the class-level options, such as retry, backoff,
631 * and idempotency policies are also be passed via this parameter pack.
632 * @param row_key the row key on which modification will be performed
633 * @param rule to modify the row. Two types of rules are applied here
634 * AppendValue which will read the existing value and append the
635 * text provided to the value.
636 * IncrementAmount which will read the existing uint64 big-endian-int
637 * and add the value provided.
638 * Both rules accept the family and column identifier to modify.
639 * @param rules_and_options is the zero or more ReadModifyWriteRules to apply
640 * on a row. Options to override the class-level options, such as retry,
641 * backoff, and idempotency policies are also be passed via this parameter
642 * pack.
643 * @returns a future, that becomes satisfied when the operation completes,
644 * at that point the future has the contents of all modified cells.
645 *
646 * @par Idempotency
647 * This operation is always treated as non-idempotent.
648 *
649 * @par Thread-safety
650 * Two threads concurrently calling this member function on the same instance
651 * of this class are **not** guaranteed to work.
652 *
653 * @par Example
654 * @snippet data_async_snippets.cc async read modify write
655 */
656 template <typename... Args>
658 std::string row_key, bigtable::ReadModifyWriteRule rule,
659 Args&&... rules_and_options) {
660 ::google::bigtable::v2::ReadModifyWriteRowRequest request;
661 request.set_row_key(std::move(row_key));
662
663 // Generate a better compile time error message than the default one
664 // if the types do not match
665 static_assert(
666 absl::conjunction<absl::disjunction<
667 std::is_convertible<Args, bigtable::ReadModifyWriteRule>,
668 std::is_same<typename std::decay<Args>::type, Options>>...>::value,
669 "The arguments passed to AsyncReadModifyWriteRow(row_key,...) must be "
670 "convertible to bigtable::ReadModifyWriteRule, or of type "
671 "google::cloud::Options");
672
673 *request.add_rules() = std::move(rule).as_proto();
674 AddRules(request, std::forward<Args>(rules_and_options)...);
675 auto opts = google::cloud::internal::GroupOptions(
676 std::forward<Args>(rules_and_options)...);
677 return AsyncReadModifyWriteRowImpl(std::move(request), std::move(opts));
678 }
679
680 /**
681 * Asynchronously reads a set of rows from the table.
682 *
683 * @param on_row the callback to be invoked on each successfully read row; it
684 * should be invocable with `Row` and return a future<bool>; the returned
685 * `future<bool>` should be satisfied with `true` when the user is ready
686 * to receive the next callback and with `false` when the user doesn't
687 * want any more rows; if `on_row` throws, the results are undefined
688 * @param on_finish the callback to be invoked when the stream is closed; it
689 * should be invocable with `Status` and not return anything; it will
690 * always be called as the last callback; if `on_finish` throws, the
691 * results are undefined
692 * @param row_set the rows to read from.
693 * @param filter is applied on the server-side to data in the rows.
694 * @param opts (Optional) Override the class-level options, such as retry,
695 * backoff, and idempotency policies.
696 *
697 * @tparam RowFunctor the type of the @p on_row callback.
698 * @tparam FinishFunctor the type of the @p on_finish callback.
699 *
700 * @par Thread-safety
701 * Two threads concurrently calling this member function on the same instance
702 * of this class are **not** guaranteed to work. Consider copying the object
703 * and using different copies in each thread.
704 *
705 * @par Example
706 * @snippet data_async_snippets.cc async read rows
707 */
708 template <typename RowFunctor, typename FinishFunctor>
709 void AsyncReadRows(RowFunctor on_row, FinishFunctor on_finish, RowSet row_set,
710 Filter filter, Options opts = {}) {
711 AsyncReadRows(std::move(on_row), std::move(on_finish), std::move(row_set),
712 RowReader::NO_ROWS_LIMIT, std::move(filter), std::move(opts));
713 }
714
715 /**
716 * Asynchronously reads a set of rows from the table.
717 *
718 * @param on_row the callback to be invoked on each successfully read row; it
719 * should be invocable with `Row` and return a future<bool>; the returned
720 * `future<bool>` should be satisfied with `true` when the user is ready
721 * to receive the next callback and with `false` when the user doesn't
722 * want any more rows; if `on_row` throws, the results are undefined
723 * @param on_finish the callback to be invoked when the stream is closed; it
724 * should be invocable with `Status` and not return anything; it will
725 * always be called as the last callback; if `on_finish` throws, the
726 * results are undefined
727 * @param row_set the rows to read from.
728 * @param rows_limit the maximum number of rows to read. Cannot be a negative
729 * number or zero. Use `AsyncReadRows(RowSet, Filter)` to
730 * read all matching rows.
731 * @param filter is applied on the server-side to data in the rows.
732 * @param opts (Optional) Override the class-level options, such as retry,
733 * backoff, and idempotency policies.
734 *
735 * @tparam RowFunctor the type of the @p on_row callback.
736 * @tparam FinishFunctor the type of the @p on_finish callback.
737 *
738 * @par Thread-safety
739 * Two threads concurrently calling this member function on the same instance
740 * of this class are **not** guaranteed to work. Consider copying the object
741 * and using different copies in each thread. The callbacks passed to this
742 * function may be executed on any thread running the provided completion
743 * queue.
744 *
745 * @par Example
746 * @snippet data_async_snippets.cc async read rows with limit
747 */
748 template <typename RowFunctor, typename FinishFunctor>
749 void AsyncReadRows(RowFunctor on_row, FinishFunctor on_finish,
750 // NOLINTNEXTLINE(performance-unnecessary-value-param)
751 RowSet row_set, std::int64_t rows_limit, Filter filter,
752 Options opts = {}) {
753 static_assert(
754 google::cloud::internal::is_invocable<RowFunctor, bigtable::Row>::value,
755 "RowFunctor must be invocable with Row.");
756 static_assert(
757 google::cloud::internal::is_invocable<FinishFunctor, Status>::value,
758 "FinishFunctor must be invocable with Status.");
759 static_assert(
760 std::is_same<
761 google::cloud::internal::invoke_result_t<RowFunctor, bigtable::Row>,
762 future<bool>>::value,
763 "RowFunctor should return a future<bool>.");
764
765 auto on_row_ptr = std::make_shared<RowFunctor>(std::move(on_row));
766 // NOLINTNEXTLINE(performance-unnecessary-value-param)
767 auto on_row_fn = [on_row_ptr](Row row) {
768 return (*on_row_ptr)(std::move(row));
769 };
770
771 auto on_finish_ptr = std::make_shared<FinishFunctor>(std::move(on_finish));
772 // NOLINTNEXTLINE(performance-unnecessary-value-param)
773 auto on_finish_fn = [on_finish_ptr](Status status) {
774 return (*on_finish_ptr)(std::move(status));
775 };
776
777 if (connection_) {
778 google::cloud::internal::OptionsSpan span(
779 google::cloud::internal::MergeOptions(std::move(opts), options_));
780 connection_->AsyncReadRows(table_name_, std::move(on_row_fn),
781 std::move(on_finish_fn), std::move(row_set),
782 rows_limit, std::move(filter));
783 return;
784 }
785 if (!google::cloud::internal::IsEmpty(opts)) {
786 on_finish_fn(
787 Status(StatusCode::kInvalidArgument,
788 "Per-operation options only apply to `Table`s constructed "
789 "with a `DataConnection`."));
790 return;
791 }
792
793 bigtable_internal::LegacyAsyncRowReader::Create(
794 background_threads_->cq(), client_, app_profile_id(), table_name_,
795 std::move(on_row_fn), std::move(on_finish_fn), std::move(row_set),
796 rows_limit, std::move(filter), clone_rpc_retry_policy(),
797 clone_rpc_backoff_policy(), metadata_update_policy_,
798 std::make_unique<bigtable::internal::ReadRowsParserFactory>());
799 }
800
801 /**
802 * Asynchronously read and return a single row from the table.
803 *
804 * @param row_key the row to read.
805 * @param filter a filter expression, can be used to select a subset of the
806 * column families and columns in the row.
807 * @param opts (Optional) Override the class-level options, such as retry,
808 * backoff, and idempotency policies.
809 * @returns a future satisfied when the operation completes, fails
810 * permanently or keeps failing transiently, but the retry policy has been
811 * exhausted. The future will return a tuple. The first element is a
812 * boolean, with value `false` if the row does not exist. If the first
813 * element is `true` the second element has the contents of the Row. Note
814 * that the contents may be empty if the filter expression removes all
815 * column families and columns.
816 *
817 * @par Idempotency
818 * This is a read-only operation and therefore it is always idempotent.
819 *
820 * @par Thread-safety
821 * Two threads concurrently calling this member function on the same instance
822 * of this class are **not** guaranteed to work. Consider copying the object
823 * and using different copies in each thread.
824 *
825 * @par Example
826 * @snippet data_async_snippets.cc async read row
827 */
828 future<StatusOr<std::pair<bool, Row>>> AsyncReadRow(std::string row_key,
829 Filter filter,
830 Options opts = {});
831
832 /**
833 * Constructor with default policies.
834 *
835 * @param client how to communicate with Cloud Bigtable, including
836 * credentials, the project id, and the instance id.
837 * @param table_id the table id within the instance defined by client. The
838 * full table name is `client->instance_name() + "/tables/" + table_id`.
839 *
840 * @deprecated #google::cloud::bigtable::DataConnection is the preferred way
841 * to communicate with the Bigtable Data API. To migrate existing code,
842 * see @ref migrating-from-dataclient "Migrating from DataClient".
843 */
844 Table(std::shared_ptr<DataClient> client, std::string const& table_id)
845 : Table(std::move(client), std::string{}, table_id) {}
846
847 /**
848 * Constructor with default policies.
849 *
850 * @param client how to communicate with Cloud Bigtable, including
851 * credentials, the project id, and the instance id.
852 * @param app_profile_id the app_profile_id needed for using the replication
853 * API.
854 * @param table_id the table id within the instance defined by client. The
855 * full table name is `client->instance_name() + "/tables/" + table_id`.
856 *
857 * @deprecated #google::cloud::bigtable::DataConnection is the preferred way
858 * to communicate with the Bigtable Data API. To migrate existing code,
859 * see @ref migrating-from-dataclient "Migrating from DataClient".
860 */
861 Table(std::shared_ptr<DataClient> client, std::string app_profile_id,
862 std::string const& table_id)
863 : client_(std::move(client)),
864 table_(client_->project_id(), client_->instance_id(), table_id),
865 table_name_(table_.FullName()),
866 rpc_retry_policy_prototype_(
867 bigtable::DefaultRPCRetryPolicy(internal::kBigtableLimits)),
868 rpc_backoff_policy_prototype_(
869 bigtable::DefaultRPCBackoffPolicy(internal::kBigtableLimits)),
870 idempotent_mutation_policy_(
872 background_threads_(client_->BackgroundThreadsFactory()()),
873 options_(Options{}.set<AppProfileIdOption>(std::move(app_profile_id))),
874 metadata_update_policy_(bigtable_internal::MakeMetadataUpdatePolicy(
875 table_name_, this->app_profile_id())) {}
876
877 /**
878 * Constructor with explicit policies.
879 *
880 * The policies are passed by value, because this makes it easy for
881 * applications to create them.
882 *
883 * @par Example
884 * @code
885 * using namespace std::chrono_literals; // assuming C++14.
886 * auto client = bigtable::MakeClient(...); // details omitted
887 * bigtable::Table table(client, "my-table",
888 * // Allow up to 20 minutes to retry operations
889 * bigtable::LimitedTimeRetryPolicy(20min),
890 * // Start with 50 milliseconds backoff, grow
891 * // exponentially to 5 minutes.
892 * bigtable::ExponentialBackoffPolicy(50ms, 5min),
893 * // Only retry idempotent mutations.
894 * bigtable::SafeIdempotentMutationPolicy());
895 * @endcode
896 *
897 * @param client how to communicate with Cloud Bigtable, including
898 * credentials, the project id, and the instance id.
899 * @param table_id the table id within the instance defined by client. The
900 * full table name is `client->instance_name() + "/tables/" + table_id`.
901 * @param policies the set of policy overrides for this object.
902 * @tparam Policies the types of the policies to override, the types must
903 * derive from one of the following types:
904 *
905 * - `IdempotentMutationPolicy` which mutations are retried. Use
906 * `SafeIdempotentMutationPolicy` to only retry idempotent operations,
907 * use `AlwaysRetryMutationPolicy` to retry all operations. Read the
908 * caveats in the class definition to understand the downsides of the
909 * latter. You can also create your own policies that decide which
910 * mutations to retry.
911 * - `RPCBackoffPolicy` how to backoff from a failed RPC. Currently only
912 * `ExponentialBackoffPolicy` is implemented. You can also create your
913 * own policies that backoff using a different algorithm.
914 * - `RPCRetryPolicy` for how long to retry failed RPCs. Use
915 * `LimitedErrorCountRetryPolicy` to limit the number of failures
916 * allowed. Use `LimitedTimeRetryPolicy` to bound the time for any
917 * request. You can also create your own policies that combine time and
918 * error counts.
919 *
920 * @see SafeIdempotentMutationPolicy, AlwaysRetryMutationPolicy,
921 * ExponentialBackoffPolicy, LimitedErrorCountRetryPolicy,
922 * LimitedTimeRetryPolicy.
923 *
924 * @deprecated #google::cloud::bigtable::DataConnection is the preferred way
925 * to communicate with the Bigtable Data API. To migrate existing code,
926 * see @ref migrating-from-dataclient "Migrating from DataClient".
927 */
928 template <
929 typename... Policies,
930 /// @cond implementation_details
931 typename std::enable_if<ValidPolicies<Policies...>::value, int>::type = 0
932 /// @endcond
933 >
934 Table(std::shared_ptr<DataClient> client, std::string const& table_id,
935 Policies&&... policies)
936 : Table(std::move(client), table_id) {
937 ChangePolicies(std::forward<Policies>(policies)...);
938 }
939
940 /**
941 * Constructor with explicit policies.
942 *
943 * The policies are passed by value, because this makes it easy for
944 * applications to create them.
945 *
946 * @par Example
947 * @code
948 * using namespace std::chrono_literals; // assuming C++14.
949 * auto client = bigtable::MakeClient(...); // details omitted
950 * bigtable::Table table(client, "app_id", "my-table",
951 * // Allow up to 20 minutes to retry operations
952 * bigtable::LimitedTimeRetryPolicy(20min),
953 * // Start with 50 milliseconds backoff, grow
954 * // exponentially to 5 minutes.
955 * bigtable::ExponentialBackoffPolicy(50ms, 5min),
956 * // Only retry idempotent mutations.
957 * bigtable::SafeIdempotentMutationPolicy());
958 * @endcode
959 *
960 * @param client how to communicate with Cloud Bigtable, including
961 * credentials, the project id, and the instance id.
962 * @param app_profile_id the app_profile_id needed for using the replication
963 * API.
964 * @param table_id the table id within the instance defined by client. The
965 * full table name is `client->instance_name() + "/tables/" + table_id`.
966 * @param policies the set of policy overrides for this object.
967 * @tparam Policies the types of the policies to override, the types must
968 * derive from one of the following types:
969 * - `IdempotentMutationPolicy` which mutations are retried. Use
970 * `SafeIdempotentMutationPolicy` to only retry idempotent operations,
971 * use `AlwaysRetryMutationPolicy` to retry all operations. Read the
972 * caveats in the class definition to understand the downsides of the
973 * latter. You can also create your own policies that decide which
974 * mutations to retry.
975 * - `RPCBackoffPolicy` how to backoff from a failed RPC. Currently only
976 * `ExponentialBackoffPolicy` is implemented. You can also create your
977 * own policies that backoff using a different algorithm.
978 * - `RPCRetryPolicy` for how long to retry failed RPCs. Use
979 * `LimitedErrorCountRetryPolicy` to limit the number of failures
980 * allowed. Use `LimitedTimeRetryPolicy` to bound the time for any
981 * request. You can also create your own policies that combine time and
982 * error counts.
983 *
984 * @see SafeIdempotentMutationPolicy, AlwaysRetryMutationPolicy,
985 * ExponentialBackoffPolicy, LimitedErrorCountRetryPolicy,
986 * LimitedTimeRetryPolicy.
987 *
988 * @deprecated #google::cloud::bigtable::DataConnection is the preferred way
989 * to communicate with the Bigtable Data API. To migrate existing code,
990 * see @ref migrating-from-dataclient "Migrating from DataClient".
991 */
992 template <
993 typename... Policies,
994 /// @cond implementation_details
995 typename std::enable_if<ValidPolicies<Policies...>::value, int>::type = 0
996 /// @endcond
997 >
998 Table(std::shared_ptr<DataClient> client, std::string app_profile_id,
999 std::string const& table_id, Policies&&... policies)
1000 : Table(std::move(client), std::move(app_profile_id), table_id) {
1001 ChangePolicies(std::forward<Policies>(policies)...);
1002 }
1003
1004 private:
1005 /**
1006 * Send request ReadModifyWriteRowRequest to modify the row and get it back
1007 */
1008 StatusOr<Row> ReadModifyWriteRowImpl(
1009 ::google::bigtable::v2::ReadModifyWriteRowRequest request, Options opts);
1010
1011 future<StatusOr<Row>> AsyncReadModifyWriteRowImpl(
1012 ::google::bigtable::v2::ReadModifyWriteRowRequest request, Options opts);
1013
1014 void AddRules(google::bigtable::v2::ReadModifyWriteRowRequest&) {
1015 // no-op for empty list
1016 }
1017
1018 template <typename... Args>
1019 void AddRules(google::bigtable::v2::ReadModifyWriteRowRequest& request,
1020 bigtable::ReadModifyWriteRule rule, Args&&... args) {
1021 *request.add_rules() = std::move(rule).as_proto();
1022 AddRules(request, std::forward<Args>(args)...);
1023 }
1024
1025 template <typename... Args>
1026 void AddRules(google::bigtable::v2::ReadModifyWriteRowRequest& request,
1027 Options const&, Args&&... args) {
1028 AddRules(request, std::forward<Args>(args)...);
1029 }
1030
1031 std::unique_ptr<RPCRetryPolicy> clone_rpc_retry_policy() {
1032 return rpc_retry_policy_prototype_->clone();
1033 }
1034
1035 std::unique_ptr<RPCBackoffPolicy> clone_rpc_backoff_policy() {
1036 return rpc_backoff_policy_prototype_->clone();
1037 }
1038
1039 MetadataUpdatePolicy clone_metadata_update_policy() {
1040 return metadata_update_policy_;
1041 }
1042
1043 std::unique_ptr<IdempotentMutationPolicy> clone_idempotent_mutation_policy() {
1044 return idempotent_mutation_policy_->clone();
1045 }
1046
1047 ///@{
1048 /// @name Helper functions to implement constructors with changed policies.
1049 void ChangePolicy(RPCRetryPolicy const& policy) {
1050 rpc_retry_policy_prototype_ = policy.clone();
1051 }
1052
1053 void ChangePolicy(RPCBackoffPolicy const& policy) {
1054 rpc_backoff_policy_prototype_ = policy.clone();
1055 }
1056
1057 void ChangePolicy(IdempotentMutationPolicy const& policy) {
1058 idempotent_mutation_policy_ = policy.clone();
1059 }
1060
1061 template <typename Policy, typename... Policies>
1062 void ChangePolicies(Policy&& policy, Policies&&... policies) {
1063 ChangePolicy(policy);
1064 ChangePolicies(std::forward<Policies>(policies)...);
1065 }
1066 void ChangePolicies() {}
1067 ///@}
1068
1069 friend class MutationBatcher;
1070 std::shared_ptr<DataClient> client_;
1071 TableResource table_;
1072 std::string table_name_;
1073 std::shared_ptr<RPCRetryPolicy const> rpc_retry_policy_prototype_;
1074 std::shared_ptr<RPCBackoffPolicy const> rpc_backoff_policy_prototype_;
1075 std::shared_ptr<IdempotentMutationPolicy> idempotent_mutation_policy_;
1076 std::shared_ptr<BackgroundThreads> background_threads_;
1077 std::shared_ptr<DataConnection> connection_;
1078 Options options_;
1079 MetadataUpdatePolicy metadata_update_policy_;
1080};
1081
1082GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
1083} // namespace bigtable
1084} // namespace cloud
1085} // namespace google
1086
1087#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_TABLE_H
virtual CompletionQueue cq() const=0
ValueTypeT< T > const & get() const
Options & set(ValueTypeT< T > v)
Options(Options const &rhs)
Status(StatusCode code, std::string message, ErrorInfo info={})
Represent a set of mutations across multiple rows.
Definition: mutations.h:492
Connects to Cloud Bigtable's data manipulation APIs.
Definition: data_client.h:66
virtual std::string const & instance_id() const =0
virtual std::string const & project_id() const =0
virtual google::cloud::BackgroundThreadsFactory BackgroundThreadsFactory()=0
The thread factory this client was created with.
A connection to the Cloud Bigtable Data API.
Definition: data_connection.h:88
virtual Options options()
Definition: data_connection.h:92
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)
A SingleRowMutation that failed.
Definition: mutations.h:409
Define the interfaces to create filter expressions.
Definition: filters.h:52
Defines the interface to control which mutations are idempotent and therefore can be re-tried.
Definition: idempotent_mutation_policy.h:31
virtual std::unique_ptr< IdempotentMutationPolicy > clone() const =0
Return a copy of the policy.
std::string const & instance_id() const
Returns the Instance ID.
Definition: instance_resource.h:58
std::string const & project_id() const
Definition: instance_resource.h:55
MetadataUpdatePolicy holds supported metadata and setup ClientContext.
Definition: metadata_update_policy.h:76
MetadataUpdatePolicy & operator=(MetadataUpdatePolicy &&)=default
Objects of this class pack single row mutations into bulk mutations.
Definition: mutation_batcher.h:56
Define the interface for controlling how the Bigtable client backsoff from failed RPC operations.
Definition: rpc_backoff_policy.h:44
virtual std::unique_ptr< RPCBackoffPolicy > clone() const =0
Return a new copy of this object.
Define the interface for controlling how the Bigtable client retries RPC operations.
Definition: rpc_retry_policy.h:78
virtual std::unique_ptr< RPCRetryPolicy > clone() const =0
Return a new copy of this object.
Define the interfaces to create ReadWriteModifyRule operations.
Definition: read_modify_write_rule.h:37
google::bigtable::v2::ReadModifyWriteRule && as_proto() &&
Move out the underlying protobuf value.
Definition: read_modify_write_rule.h:82
Object returned by Table::ReadRows(), enumerates rows in the response.
Definition: row_reader.h:54
static std::int64_t constexpr NO_ROWS_LIMIT
A constant for the magic value that means "no limit, get all rows".
Definition: row_reader.h:63
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
This class identifies a Cloud Bigtable Table.
Definition: table_resource.h:44
TableResource(std::string project_id, std::string instance_id, std::string table_id)
Constructs a TableResource object identified by the given IDs.
std::string const & table_id() const
Returns the Table ID.
Definition: table_resource.h:66
std::string FullName() const
Returns the fully qualified table name as a string of the form: "projects/<project-id>/instances/<ins...
InstanceResource const & instance() const
Returns the InstanceResource containing this table.
Definition: table_resource.h:63
The main interface to interact with data in a Cloud Bigtable table.
Definition: table.h:166
std::string const & table_name() const
Definition: table.h:216
RowReader ReadRows(RowSet row_set, std::int64_t rows_limit, Filter filter, Options opts={})
Reads a limited set of rows from the table.
Table(std::shared_ptr< DataClient > client, std::string app_profile_id, std::string const &table_id, Policies &&... policies)
Constructor with explicit policies.
Definition: table.h:998
Table(std::shared_ptr< DataClient > client, std::string app_profile_id, std::string const &table_id)
Constructor with default policies.
Definition: table.h:861
Table(std::shared_ptr< DataClient > client, std::string const &table_id, Policies &&... policies)
Constructor with explicit policies.
Definition: table.h:934
future< std::vector< FailedMutation > > AsyncBulkApply(BulkMutation mut, Options opts={})
Makes asynchronous attempts to apply mutations to multiple rows.
RowReader ReadRows(RowSet row_set, Filter filter, Options opts={})
Reads a set of rows from the table.
std::string const & project_id() const
Definition: table.h:220
Table WithNewTarget(std::string project_id, std::string instance_id, std::string app_profile_id, std::string table_id) const
Returns a Table that reuses the connection and configuration of this Table, but with a different reso...
Definition: table.h:249
std::string const & instance_id() const
Definition: table.h:223
StatusOr< std::vector< bigtable::RowKeySample > > SampleRows(Options opts={})
Sample of the row keys in the table, including approximate data sizes.
Table WithNewTarget(std::string project_id, std::string instance_id, std::string table_id) const
Returns a Table that reuses the connection and configuration of this Table, but with a different reso...
Definition: table.h:234
void AsyncReadRows(RowFunctor on_row, FinishFunctor on_finish, RowSet row_set, Filter filter, Options opts={})
Asynchronously reads a set of rows from the table.
Definition: table.h:709
StatusOr< Row > ReadModifyWriteRow(std::string row_key, bigtable::ReadModifyWriteRule rule, Args &&... rules_and_options)
Atomically read and modify the row in the server, returning the resulting row.
Definition: table.h:603
future< Status > AsyncApply(SingleRowMutation mut, Options opts={})
Makes asynchronous attempts to apply the mutation to a row.
future< StatusOr< std::pair< bool, Row > > > AsyncReadRow(std::string row_key, Filter filter, Options opts={})
Asynchronously read and return a single row from the table.
Table(std::shared_ptr< bigtable::DataConnection > conn, TableResource tr, Options options={})
Constructs a Table object.
Definition: table.h:206
StatusOr< std::pair< bool, Row > > ReadRow(std::string row_key, Filter filter, Options opts={})
Read and return a single row from the table.
std::string const & table_id() const
Definition: table.h:226
Table(std::shared_ptr< DataClient > client, std::string const &table_id)
Constructor with default policies.
Definition: table.h:844
future< StatusOr< std::vector< bigtable::RowKeySample > > > AsyncSampleRows(Options opts={})
Asynchronously obtains a sample of the row keys in the table, including approximate data sizes.
StatusOr< MutationBranch > CheckAndMutateRow(std::string row_key, Filter filter, std::vector< Mutation > true_mutations, std::vector< Mutation > false_mutations, Options opts={})
Atomic test-and-set for a row using filter expressions.
std::string const & app_profile_id() const
Definition: table.h:217
void AsyncReadRows(RowFunctor on_row, FinishFunctor on_finish, RowSet row_set, std::int64_t rows_limit, Filter filter, Options opts={})
Asynchronously reads a set of rows from the table.
Definition: table.h:749
future< StatusOr< MutationBranch > > AsyncCheckAndMutateRow(std::string row_key, Filter filter, std::vector< Mutation > true_mutations, std::vector< Mutation > false_mutations, Options opts={})
Make an asynchronous request to conditionally mutate a row.
std::vector< FailedMutation > BulkApply(BulkMutation mut, Options opts={})
Attempts to apply mutations to multiple rows.
Status Apply(SingleRowMutation mut, Options opts={})
Attempts to apply the mutation to a row.
future< StatusOr< Row > > AsyncReadModifyWriteRow(std::string row_key, bigtable::ReadModifyWriteRule rule, Args &&... rules_and_options)
Make an asynchronous request to atomically read and modify a row.
Definition: table.h:657
friend friend class future
Contains all the Cloud Bigtable C++ client APIs.
Definition: admin_client.h:28
std::unique_ptr< RPCBackoffPolicy > DefaultRPCBackoffPolicy(internal::RPCPolicyParameters defaults)
Return an instance of the default RPCBackoffPolicy.
std::string InstanceName(std::shared_ptr< DataClient > const &client)
Return the fully qualified instance name for the client.
Definition: data_client.h:225
std::unique_ptr< RPCRetryPolicy > DefaultRPCRetryPolicy(internal::RPCPolicyParameters defaults)
Return an instance of the default RPCRetryPolicy.
MutationBranch
The branch taken by a Table::CheckAndMutateRow operation.
Definition: mutation_branch.h:26
std::string TableName(std::shared_ptr< DataClient > const &client, std::string const &table_id)
Return the full table name.
Definition: table.h:63
std::unique_ptr< IdempotentMutationPolicy > DefaultIdempotentMutationPolicy()
Return an instance of the default IdempotentMutationPolicy.
The application profile id.
Definition: options.h:75
Represent a single change to a specific row in a Table.
Definition: mutations.h:45
A simple wrapper to represent the response from Table::SampleRowKeys().
Definition: row_key_sample.h:27