Google Cloud Bigtable C++ Client  1.1.0
A C++ Client Library for Google Cloud Bigtable
table_admin.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_TABLE_ADMIN_H_
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_TABLE_ADMIN_H_
17 
18 #include "google/cloud/bigtable/admin_client.h"
19 #include "google/cloud/bigtable/column_family.h"
20 #include "google/cloud/bigtable/completion_queue.h"
21 #include "google/cloud/bigtable/metadata_update_policy.h"
22 #include "google/cloud/bigtable/polling_policy.h"
23 #include "google/cloud/bigtable/table_config.h"
24 #include "google/cloud/bigtable/version.h"
25 #include "google/cloud/future.h"
26 #include "google/cloud/grpc_utils/grpc_error_delegate.h"
27 #include "google/cloud/status_or.h"
28 #include <future>
29 #include <memory>
30 
31 namespace google {
32 namespace cloud {
33 namespace bigtable {
34 inline namespace BIGTABLE_CLIENT_NS {
35 /// The result of checking replication against a given token.
36 enum class Consistency {
37  /// Some of the mutations created before the consistency token have not been
38  /// received by all the table replicas.
39  kInconsistent,
40  /// All mutations created before the consistency token have been received by
41  /// all the table replicas.
42  kConsistent,
43 };
44 
45 /**
46  * Implements the API to administer tables in a Cloud Bigtable instance.
47  *
48  * @par Thread-safety
49  * Instances of this class created via copy-construction or copy-assignment
50  * share the underlying pool of connections. Access to these copies via multiple
51  * threads is guaranteed to work. Two threads operating on the same instance of
52  * this class is not guaranteed to work.
53  *
54  * @par Cost
55  * Creating a new object of type `TableAdmin` is comparable to creating a few
56  * objects of type `std::string` or a few objects of type
57  * `std::shared_ptr<int>`. The class represents a shallow handle to a remote
58  * object.
59  *
60  * @par Error Handling
61  * This class uses `StatusOr<T>` to report errors. When an operation fails to
62  * perform its work the returned `StatusOr<T>` contains the error details. If
63  * the `ok()` member function in the `StatusOr<T>` returns `true` then it
64  * contains the expected result. Operations that do not return a value simply
65  * return a `google::cloud::Status` indicating success or the details of the
66  * error Please consult the
67  * [`StatusOr<T>` documentation](#google::cloud::v0::StatusOr) for more details.
68  *
69  * @code
70  * namespace cbt = google::cloud::bigtable;
71  * namespace btadmin = google::bigtable::admin::v2;
72  * cbt::TableAdmin admin = ...;
73  * google::cloud::StatusOr<btadmin::Table> metadata = admin.GetTable(...);
74  *
75  * if (!metadata) {
76  * std::cerr << "Error fetching table metadata\n";
77  * return;
78  * }
79  *
80  * // Use "metadata" as a smart pointer here, e.g.:
81  * std::cout << "The full table name is " << table->name() << " the table has "
82  * << table->column_families_size() << " column families\n";
83  * @endcode
84  *
85  * In addition, the @ref index "main page" contains examples using `StatusOr<T>`
86  * to handle errors.
87  *
88  * @par Retry, Backoff, and Idempotency Policies
89  * The library automatically retries requests that fail with transient errors,
90  * and uses [truncated exponential backoff][backoff-link] to backoff between
91  * retries. The default policies are to continue retrying for up to 10 minutes.
92  * On each transient failure the backoff period is doubled, starting with an
93  * initial backoff of 100 milliseconds. The backoff period growth is truncated
94  * at 60 seconds. The default idempotency policy is to only retry idempotent
95  * operations. Note that most operations that change state are **not**
96  * idempotent.
97  *
98  * The application can override these policies when constructing objects of this
99  * class. The documentation for the constructors show examples of this in
100  * action.
101  *
102  * [backoff-link]: https://cloud.google.com/storage/docs/exponential-backoff
103  *
104  * @see https://cloud.google.com/bigtable/ for an overview of Cloud Bigtable.
105  *
106  * @see https://cloud.google.com/bigtable/docs/overview for an overview of the
107  * Cloud Bigtable data model.
108  *
109  * @see https://cloud.google.com/bigtable/docs/instances-clusters-nodes for an
110  * introduction of the main APIs into Cloud Bigtable.
111  *
112  * @see https://cloud.google.com/bigtable/docs/reference/service-apis-overview
113  * for an overview of the underlying Cloud Bigtable API.
114  *
115  * @see #google::cloud::v0::StatusOr for a description of the error reporting
116  * class used by this library.
117  *
118  * @see `LimitedTimeRetryPolicy` and `LimitedErrorCountRetryPolicy` for
119  * alternative retry policies.
120  *
121  * @see `ExponentialBackoffPolicy` to configure different parameters for the
122  * exponential backoff policy.
123  *
124  * @see `SafeIdempotentMutationPolicy` and `AlwaysRetryMutationPolicy` for
125  * alternative idempotency policies.
126  */
127 class TableAdmin {
128  public:
129  /**
130  * @param client the interface to create grpc stubs, report errors, etc.
131  * @param instance_id the id of the instance, e.g., "my-instance", the full
132  * name (e.g. '/projects/my-project/instances/my-instance') is built using
133  * the project id in the @p client parameter.
134  */
135  TableAdmin(std::shared_ptr<AdminClient> client, std::string instance_id)
136  : client_(std::move(client)),
137  instance_id_(std::move(instance_id)),
138  instance_name_(InstanceName()),
139  rpc_retry_policy_(
140  DefaultRPCRetryPolicy(internal::kBigtableTableAdminLimits)),
141  rpc_backoff_policy_(
142  DefaultRPCBackoffPolicy(internal::kBigtableTableAdminLimits)),
143  metadata_update_policy_(instance_name(), MetadataParamTypes::PARENT),
144  polling_policy_(
145  DefaultPollingPolicy(internal::kBigtableTableAdminLimits)) {}
146 
147  /**
148  * Create a new TableAdmin using explicit policies to handle RPC errors.
149  *
150  * @param client the interface to create grpc stubs, report errors, etc.
151  * @param instance_id the id of the instance, e.g., "my-instance", the full
152  * name (e.g. '/projects/my-project/instances/my-instance') is built using
153  * the project id in the @p client parameter.
154  * @param policies the set of policy overrides for this object.
155  * @tparam Policies the types of the policies to override, the types must
156  * derive from one of the following types:
157  * - `RPCBackoffPolicy` how to backoff from a failed RPC. Currently only
158  * `ExponentialBackoffPolicy` is implemented. You can also create your
159  * own policies that backoff using a different algorithm.
160  * - `RPCRetryPolicy` for how long to retry failed RPCs. Use
161  * `LimitedErrorCountRetryPolicy` to limit the number of failures
162  * allowed. Use `LimitedTimeRetryPolicy` to bound the time for any
163  * request. You can also create your own policies that combine time and
164  * error counts.
165  * - `PollingPolicy` for how long will the class wait for
166  * `google.longrunning.Operation` to complete. This class combines both
167  * the backoff policy for checking long running operations and the
168  * retry policy.
169  *
170  * @see GenericPollingPolicy, ExponentialBackoffPolicy,
171  * LimitedErrorCountRetryPolicy, LimitedTimeRetryPolicy.
172  */
173  template <typename... Policies>
174  TableAdmin(std::shared_ptr<AdminClient> client, std::string instance_id,
175  Policies&&... policies)
176  : TableAdmin(std::move(client), std::move(instance_id)) {
177  ChangePolicies(std::forward<Policies>(policies)...);
178  }
179 
180  TableAdmin(TableAdmin const&) = default;
181  TableAdmin& operator=(TableAdmin const&) = default;
182 
183  //@{
184  /// @name Convenience shorthands for the schema views.
185  using TableView = google::bigtable::admin::v2::Table::View;
186  /// Use the default view as defined for each function.
187  constexpr static TableView VIEW_UNSPECIFIED =
188  google::bigtable::admin::v2::Table::VIEW_UNSPECIFIED;
189  /// Populate only the name in the responses.
190  constexpr static TableView NAME_ONLY =
191  google::bigtable::admin::v2::Table::NAME_ONLY;
192  /// Populate only the name and the fields related to the table schema.
193  constexpr static TableView SCHEMA_VIEW =
194  google::bigtable::admin::v2::Table::SCHEMA_VIEW;
195  /// Populate only the name and the fields related to the table replication
196  /// state.
197  constexpr static TableView REPLICATION_VIEW =
198  google::bigtable::admin::v2::Table::REPLICATION_VIEW;
199  /// Populate all the fields in the response.
200  constexpr static TableView FULL = google::bigtable::admin::v2::Table::FULL;
201  //@}
202 
203  std::string const& project() const { return client_->project(); }
204  std::string const& instance_id() const { return instance_id_; }
205  std::string const& instance_name() const { return instance_name_; }
206 
207  /**
208  * Create a new table in the instance.
209  *
210  * @param table_id the name of the table relative to the instance managed by
211  * this object. The full table name is
212  * `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/tables/<table_id>`
213  * where PROJECT_ID is obtained from the associated AdminClient and
214  * INSTANCE_ID is the instance_id() of this object.
215  * @param config the initial schema for the table.
216  * @return the attributes of the newly created table. Notice that the server
217  * only populates the table_name() field at this time.
218  *
219  * @par Idempotency
220  * This operation is always treated as non-idempotent.
221  *
222  * @par Example
223  * @snippet table_admin_snippets.cc create table
224  */
225  StatusOr<::google::bigtable::admin::v2::Table> CreateTable(
226  std::string table_id, TableConfig config);
227 
228  /**
229  * Sends an asynchronous request to create a new table in the instance.
230  *
231  * @warning This is an early version of the asynchronous APIs for Cloud
232  * Bigtable. These APIs might be changed in backward-incompatible ways. It
233  * is not subject to any SLA or deprecation policy.
234  *
235  * @param table_id the name of the table relative to the instance managed by
236  * this object. The full table name is
237  * `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/tables/<table_id>`
238  * where PROJECT_ID is obtained from the associated AdminClient and
239  * INSTANCE_ID is the instance_id() of this object.
240  * @param config the initial schema for the table.
241  * @param cq the completion queue that will execute the asynchronous calls,
242  * the application must ensure that one or more threads are blocked on
243  * `cq.Run()`.
244  *
245  * @return a future that will be satisfied when the request succeeds or the
246  * retry policy expires. In the first case, the future will contain the
247  * response from the service. In the second the future is satisfied with
248  * an exception. Note that the service only fills out the `table_name` field
249  * for this request.
250  *
251  * @par Idempotency
252  * This operation is always treated as non-idempotent.
253  *
254  * @par Example
255  * @snippet table_admin_async_snippets.cc async create table
256  */
257  future<StatusOr<google::bigtable::admin::v2::Table>> AsyncCreateTable(
258  CompletionQueue& cq, std::string table_id, TableConfig config);
259 
260  /**
261  * Return all the tables in the instance.
262  *
263  * @param view define what information about the tables is retrieved.
264  * - `VIEW_UNSPECIFIED`: equivalent to `VIEW_SCHEMA`.
265  * - `NAME`: return only the name of the table.
266  * - `VIEW_SCHEMA`: return the name and the schema.
267  * - `FULL`: return all the information about the table.
268  *
269  * @par Idempotency
270  * This operation is read-only and therefore it is always idempotent.
271  *
272  * @par Example
273  * @snippet table_admin_snippets.cc list tables
274  */
275  StatusOr<std::vector<::google::bigtable::admin::v2::Table>> ListTables(
276  ::google::bigtable::admin::v2::Table::View view);
277 
278  /**
279  * Sends an asynchronous request to get all the tables in the instance.
280  *
281  * @warning This is an early version of the asynchronous APIs for Cloud
282  * Bigtable. These APIs might be changed in backward-incompatible ways. It
283  * is not subject to any SLA or deprecation policy.
284  *
285  * @param cq the completion queue that will execute the asynchronous calls,
286  * the application must ensure that one or more threads are blocked on
287  * `cq.Run()`.
288  * @param view describes how much information to get about the name.
289  * - VIEW_UNSPECIFIED: equivalent to VIEW_SCHEMA.
290  * - NAME: return only the name of the table.
291  * - VIEW_SCHEMA: return the name and the schema.
292  * - FULL: return all the information about the table.
293  *
294  * @return a future that will be satisfied when the request succeeds or the
295  * retry policy expires. In the first case, the future will contain the
296  * response from the service. In the second the future is satisfied with
297  * an exception.
298  *
299  * @par Idempotency
300  * This operation is read-only and therefore it is always idempotent.
301  *
302  * @par Example
303  * @snippet table_admin_async_snippets.cc async list tables
304  */
305  future<StatusOr<std::vector<::google::bigtable::admin::v2::Table>>>
306  AsyncListTables(CompletionQueue& cq,
307  google::bigtable::admin::v2::Table::View view);
308 
309  /**
310  * Get information about a single table.
311  *
312  * @param table_id the id of the table within the instance associated with
313  * this object. The full name of the table is
314  * `this->instance_name() + "/tables/" + table_id`
315  * @param view describes how much information to get about the name.
316  * - VIEW_UNSPECIFIED: equivalent to VIEW_SCHEMA.
317  * - NAME: return only the name of the table.
318  * - VIEW_SCHEMA: return the name and the schema.
319  * - FULL: return all the information about the table.
320  * @return the information about the table or status.
321  *
322  * @par Idempotency
323  * This operation is read-only and therefore it is always idempotent.
324  *
325  * @par Example
326  * @snippet table_admin_snippets.cc get table
327  */
328  StatusOr<::google::bigtable::admin::v2::Table> GetTable(
329  std::string const& table_id, TableView view = SCHEMA_VIEW);
330 
331  /**
332  * Sends an asynchronous request to get information about an existing table.
333  *
334  * @warning This is an early version of the asynchronous APIs for Cloud
335  * Bigtable. These APIs might be changed in backward-incompatible ways. It
336  * is not subject to any SLA or deprecation policy.
337  *
338  * @param table_id the id of the table within the instance associated with
339  * this object. The full name of the table is
340  * `this->instance_name() + "/tables/" + table_id`
341  * @param view describes how much information to get about the name.
342  * - VIEW_UNSPECIFIED: equivalent to VIEW_SCHEMA.
343  * - NAME: return only the name of the table.
344  * - VIEW_SCHEMA: return the name and the schema.
345  * - FULL: return all the information about the table.
346  * @param cq the completion queue that will execute the asynchronous calls,
347  * the application must ensure that one or more threads are blocked on
348  * `cq.Run()`.
349  *
350  * @return a future that will be satisfied when the request succeeds or the
351  * retry policy expires. In the first case, the future will contain the
352  * response from the service. In the second the future is satisfied with
353  * an exception.
354  *
355  * @par Idempotency
356  * This operation is read-only and therefore it is always idempotent.
357  *
358  * @par Example
359  * @snippet table_admin_async_snippets.cc async get table
360  */
361  future<StatusOr<google::bigtable::admin::v2::Table>> AsyncGetTable(
362  CompletionQueue& cq, std::string const& table_id,
363  google::bigtable::admin::v2::Table::View view);
364 
365  /**
366  * Delete a table.
367  *
368  * @param table_id the id of the table within the instance associated with
369  * this object. The full name of the table is
370  * `this->instance_name() + "/tables/" + table_id`
371  *
372  * @return status of the operation.
373  *
374  * @par Idempotency
375  * This operation is always treated as non-idempotent.
376  *
377  * @par Example
378  * @snippet table_admin_snippets.cc delete table
379  */
380  Status DeleteTable(std::string const& table_id);
381 
382  /**
383  * Start a request to asynchronously delete a table.
384  *
385  * @warning This is an early version of the asynchronous APIs for Cloud
386  * Bigtable. These APIs might be changed in backward-incompatible ways. It
387  * is not subject to any SLA or deprecation policy.
388  *
389  * @param cq the completion queue that will execute the asynchronous calls,
390  * the application must ensure that one or more threads are blocked on
391  * `cq.Run()`.
392  * @param table_id the id of the table within the instance associated with
393  * this object. The full name of the table is
394  * `this->instance_name() + "/tables/" + table_id`
395  *
396  * @return status of the operation.
397  *
398  * @par Idempotency
399  * This operation is always treated as non-idempotent.
400  *
401  * @par Example
402  * @snippet table_admin_async_snippets.cc async delete table
403  */
404  future<Status> AsyncDeleteTable(CompletionQueue& cq,
405  std::string const& table_id);
406 
407  /**
408  * Modify the schema for an existing table.
409  *
410  * @param table_id the id of the table within the instance associated with
411  * this object. The full name of the table is
412  * `this->instance_name() + "/tables/" + table_id`
413  * @param modifications the list of modifications to the schema.
414  *
415  * @par Idempotency
416  * This operation is always treated as non-idempotent.
417  *
418  * @par Example
419  * @snippet table_admin_snippets.cc modify table
420  */
421  StatusOr<::google::bigtable::admin::v2::Table> ModifyColumnFamilies(
422  std::string const& table_id,
423  std::vector<ColumnFamilyModification> modifications);
424 
425  /**
426  * Make an asynchronous request to modify the column families of a table.
427  *
428  * @warning This is an early version of the asynchronous APIs for Cloud
429  * Bigtable. These APIs might be changed in backward-incompatible ways. It
430  * is not subject to any SLA or deprecation policy.
431  *
432  * @param cq the completion queue that will execute the asynchronous calls,
433  * the application must ensure that one or more threads are blocked on
434  * `cq.Run()`.
435  * @param table_id the name of the table relative to the instance managed by
436  * this object. The full table name is
437  * `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/tables/<table_id>`
438  * where PROJECT_ID is obtained from the associated AdminClient and
439  * INSTANCE_ID is the instance_id() of this object.
440  * @param modifications the list of modifications to the schema.
441  * @return the information about table or status.
442  *
443  * @par Idempotency
444  * This operation is always treated as non-idempotent.
445  *
446  * @par Example
447  * @snippet table_admin_async_snippets.cc async modify table
448  */
449  future<StatusOr<::google::bigtable::admin::v2::Table>>
450  AsyncModifyColumnFamilies(
451  CompletionQueue& cq, std::string const& table_id,
452  std::vector<ColumnFamilyModification> modifications);
453 
454  /**
455  * Delete all the rows that start with a given prefix.
456  *
457  * @param table_id the id of the table within the instance associated with
458  * this object. The full name of the table is
459  * `this->instance_name() + "/tables/" + table_id`
460  * @param row_key_prefix drop any rows that start with this prefix.
461  *
462  * @par Idempotency
463  * This operation is always treated as non-idempotent.
464  *
465  * @par Example
466  * @snippet table_admin_snippets.cc drop rows by prefix
467  */
468  Status DropRowsByPrefix(std::string const& table_id,
469  std::string row_key_prefix);
470 
471  /**
472  * Make an asynchronous request to delete all the rows that start with a given
473  * prefix.
474  *
475  * @warning This is an early version of the asynchronous APIs for Cloud
476  * Bigtable. These APIs might be changed in backward-incompatible ways. It
477  * is not subject to any SLA or deprecation policy.
478  *
479  * @param cq the completion queue that will execute the asynchronous calls,
480  * the application must ensure that one or more threads are blocked on
481  * `cq.Run()`.
482  * @param table_id the id of the table within the instance associated with
483  * this object. The full name of the table is
484  * `this->instance_name() + "/tables/" + table_id`
485  * @param row_key_prefix drop any rows that start with this prefix.
486  * @return status of the operation.
487  *
488  * @par Idempotency
489  * This operation is always treated as non-idempotent.
490  *
491  * @par Example
492  * @snippet table_admin_async_snippets.cc async drop rows by prefix
493  */
494  future<Status> AsyncDropRowsByPrefix(CompletionQueue& cq,
495  std::string const& table_id,
496  std::string row_key_prefix);
497 
498  /**
499  * Generates consistency token for a table.
500  *
501  * @param table_id the id of the table for which we want to generate
502  * consistency token.
503  * @return the consistency token for table.
504  *
505  * @par Idempotency
506  * This operation is read-only and therefore it is always idempotent.
507  *
508  * @par Example
509  * @snippet table_admin_snippets.cc generate consistency token
510  */
511  StatusOr<std::string> GenerateConsistencyToken(std::string const& table_id);
512 
513  /**
514  * Make an asynchronous request to generates consistency token for a table.
515  *
516  * @warning This is an early version of the asynchronous APIs for Cloud
517  * Bigtable. These APIs might be changed in backward-incompatible ways. It
518  * is not subject to any SLA or deprecation policy.
519  *
520  * @param cq the completion queue that will execute the asynchronous calls,
521  * the application must ensure that one or more threads are blocked on
522  * `cq.Run()`.
523  * @param table_id the id of the table within the instance associated with
524  * this object. The full name of the table is
525  * `this->instance_name() + "/tables/" + table_id`
526  * @return consistency token or status of the operation.
527  *
528  * @par Idempotency
529  * This operation is read-only and therefore it is always idempotent.
530  *
531  * @par Example
532  * @snippet table_admin_async_snippets.cc async generate consistency token
533  */
534  future<StatusOr<std::string>> AsyncGenerateConsistencyToken(
535  CompletionQueue& cq, std::string const& table_id);
536 
537  /**
538  * Checks consistency of a table.
539  *
540  * @param table_id the id of the table for which we want to check
541  * consistency.
542  * @param consistency_token the consistency token of the table.
543  * @return the consistency status for the table.
544  *
545  * @par Idempotency
546  * This operation is read-only and therefore it is always idempotent.
547  *
548  * @par Example
549  * @snippet table_admin_snippets.cc check consistency
550  */
551  StatusOr<Consistency> CheckConsistency(std::string const& table_id,
552  std::string const& consistency_token);
553 
554  /**
555  * Make an asynchronous request to check consistency of a table.
556  *
557  * @warning This is an early version of the asynchronous APIs for Cloud
558  * Bigtable. These APIs might be changed in backward-incompatible ways. It
559  * is not subject to any SLA or deprecation policy.
560  *
561  * @param cq the completion queue that will execute the asynchronous calls,
562  * the application must ensure that one or more threads are blocked on
563  * `cq.Run()`.
564  * @param table_id the id of the table for which we want to check
565  * consistency.
566  * @param consistency_token the consistency token of the table.
567  * @return consistency status or status of the operation.
568  *
569  * @par Idempotency
570  * This operation is read-only and therefore it is always idempotent.
571  *
572  * @par Example
573  * @snippet table_admin_async_snippets.cc async check consistency
574  */
575  future<StatusOr<Consistency>> AsyncCheckConsistency(
576  CompletionQueue& cq, std::string const& table_id,
577  std::string const& consistency_token);
578 
579  /**
580  * Checks consistency of a table with multiple calls using a separate thread
581  *
582  * @param table_id the id of the table for which we want to check
583  * consistency.
584  * @param consistency_token the consistency token of the table.
585  * @return the consistency status for the table.
586  * @throws std::exception if the operation cannot be completed.
587  *
588  * @par Idempotency
589  * This operation is read-only and therefore it is always idempotent.
590  *
591  * @par Example
592  * @snippet table_admin_snippets.cc wait for consistency check
593  */
594  google::cloud::future<StatusOr<Consistency>> WaitForConsistency(
595  std::string const& table_id, std::string const& consistency_token);
596 
597  /**
598  * Asynchronously wait until a table is consistent with the given @p token.
599  *
600  * @warning This is an early version of the asynchronous APIs for Cloud
601  * Bigtable. These APIs might be changed in backward-incompatible ways. It
602  * is not subject to any SLA or deprecation policy.
603  *
604  * @param cq the completion queue that will execute the asynchronous calls,
605  * the application must ensure that one or more threads are blocked on
606  * `cq.Run()`.
607  * @param table_id the id of the table for which we want to check
608  * consistency.
609  * @param consistency_token the consistency token of the table.
610  * @return the consistency status for the table.
611  *
612  * @par Idempotency
613  * This operation is read-only and therefore it is always idempotent.
614  *
615  * @par Example
616  * @snippet table_admin_async_snippets.cc async wait for consistency
617  */
618  google::cloud::future<StatusOr<Consistency>> AsyncWaitForConsistency(
619  CompletionQueue& cq, std::string const& table_id,
620  std::string const& consistency_token);
621 
622  /**
623  * Delete all the rows in a table.
624  *
625  * @param table_id the id of the table within the instance associated with
626  * this object. The full name of the table is
627  * `this->instance_name() + "/tables/" + table_id`
628  *
629  * @par Idempotency
630  * This operation is always treated as non-idempotent.
631  *
632  * @par Example
633  * @snippet table_admin_snippets.cc drop all rows
634  */
635  Status DropAllRows(std::string const& table_id);
636 
637  /**
638  * Make an asynchronous request to delete all the rows in a table.
639  *
640  * @warning This is an early version of the asynchronous APIs for Cloud
641  * Bigtable. These APIs might be changed in backward-incompatible ways. It
642  * is not subject to any SLA or deprecation policy.
643  *
644  * @param cq the completion queue that will execute the asynchronous calls,
645  * the application must ensure that one or more threads are blocked on
646  * `cq.Run()`.
647  * @param table_id the id of the table within the instance associated with
648  * this object. The full name of the table is
649  * `this->instance_name() + "/tables/" + table_id`
650  *
651  * @par Idempotency
652  * This operation is always treated as non-idempotent.
653  *
654  * @par Example
655  * @snippet table_admin_async_snippets.cc async drop all rows
656  */
657  future<Status> AsyncDropAllRows(CompletionQueue& cq,
658  std::string const& table_id);
659 
660  /// Return the fully qualified name of a table in this object's instance.
661  std::string TableName(std::string const& table_id) const {
662  return instance_name() + "/tables/" + table_id;
663  }
664 
665  /// Return the fully qualified name of a Cluster.
666  std::string ClusterName(std::string const& cluster_id) {
667  return instance_name() + "/clusters/" + cluster_id;
668  }
669 
670  private:
671  //@{
672  /// @name Helper functions to implement constructors with changed policies.
673  void ChangePolicy(RPCRetryPolicy& policy) {
674  rpc_retry_policy_ = policy.clone();
675  }
676 
677  void ChangePolicy(RPCBackoffPolicy& policy) {
678  rpc_backoff_policy_ = policy.clone();
679  }
680 
681  void ChangePolicy(PollingPolicy& policy) { polling_policy_ = policy.clone(); }
682 
683  template <typename Policy, typename... Policies>
684  void ChangePolicies(Policy&& policy, Policies&&... policies) {
685  ChangePolicy(policy);
686  ChangePolicies(std::forward<Policies>(policies)...);
687  }
688  void ChangePolicies() {}
689  //@}
690 
691  std::unique_ptr<RPCRetryPolicy> clone_rpc_retry_policy() {
692  return rpc_retry_policy_->clone();
693  }
694 
695  std::unique_ptr<RPCBackoffPolicy> clone_rpc_backoff_policy() {
696  return rpc_backoff_policy_->clone();
697  }
698 
699  MetadataUpdatePolicy clone_metadata_update_policy() {
700  return metadata_update_policy_;
701  }
702 
703  std::unique_ptr<PollingPolicy> clone_polling_policy() {
704  return polling_policy_->clone();
705  }
706 
707  /// Compute the fully qualified instance name.
708  std::string InstanceName() const;
709 
710  std::shared_ptr<AdminClient> client_;
711  std::string instance_id_;
712  std::string instance_name_;
713  std::shared_ptr<RPCRetryPolicy> rpc_retry_policy_;
714  std::shared_ptr<RPCBackoffPolicy> rpc_backoff_policy_;
715  bigtable::MetadataUpdatePolicy metadata_update_policy_;
716  std::shared_ptr<PollingPolicy> polling_policy_;
717 };
718 
719 } // namespace BIGTABLE_CLIENT_NS
720 } // namespace bigtable
721 } // namespace cloud
722 } // namespace google
723 
724 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_TABLE_ADMIN_H_
#define BIGTABLE_CLIENT_NS
Definition: version.h:22