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/iam_policy.h"
22 #include "google/cloud/bigtable/metadata_update_policy.h"
23 #include "google/cloud/bigtable/polling_policy.h"
24 #include "google/cloud/bigtable/table_config.h"
25 #include "google/cloud/bigtable/version.h"
26 #include "google/cloud/future.h"
27 #include "google/cloud/grpc_error_delegate.h"
28 #include "google/cloud/iam_policy.h"
29 #include "google/cloud/status_or.h"
30 #include "absl/types/optional.h"
31 #include <future>
32 #include <memory>
33 
34 namespace google {
35 namespace cloud {
36 namespace bigtable {
37 inline namespace BIGTABLE_CLIENT_NS {
38 /// The result of checking replication against a given token.
39 enum class Consistency {
40   /// Some of the mutations created before the consistency token have not been
41   /// received by all the table replicas.
42   kInconsistent,
43   /// All mutations created before the consistency token have been received by
44   /// all the table replicas.
45   kConsistent,
46 };
47 
48 /**
49  * Implements the API to administer tables in a Cloud Bigtable instance.
50  *
51  * @par Thread-safety
52  * Instances of this class created via copy-construction or copy-assignment
53  * share the underlying pool of connections. Access to these copies via multiple
54  * threads is guaranteed to work. Two threads operating on the same instance of
55  * this class is not guaranteed to work.
56  *
57  * @par Cost
58  * Creating a new object of type `TableAdmin` is comparable to creating a few
59  * objects of type `std::string` or a few objects of type
60  * `std::shared_ptr<int>`. The class represents a shallow handle to a remote
61  * object.
62  *
63  * @par Error Handling
64  * This class uses `StatusOr<T>` to report errors. When an operation fails to
65  * perform its work the returned `StatusOr<T>` contains the error details. If
66  * the `ok()` member function in the `StatusOr<T>` returns `true` then it
67  * contains the expected result. Operations that do not return a value simply
68  * return a `google::cloud::Status` indicating success or the details of the
69  * error Please consult the
70  * [`StatusOr<T>` documentation](#google::cloud::v1::StatusOr) for more details.
71  *
72  * @code
73  * namespace cbt = google::cloud::bigtable;
74  * namespace btadmin = google::bigtable::admin::v2;
75  * cbt::TableAdmin admin = ...;
76  * google::cloud::StatusOr<btadmin::Table> metadata = admin.GetTable(...);
77  *
78  * if (!metadata) {
79  *   std::cerr << "Error fetching table metadata\n";
80  *   return;
81  * }
82  *
83  * // Use "metadata" as a smart pointer here, e.g.:
84  * std::cout << "The full table name is " << table->name() << " the table has "
85  *           << table->column_families_size() << " column families\n";
86  * @endcode
87  *
88  * In addition, the @ref index "main page" contains examples using `StatusOr<T>`
89  * to handle errors.
90  *
91  * @par Retry, Backoff, and Idempotency Policies
92  * The library automatically retries requests that fail with transient errors,
93  * and uses [truncated exponential backoff][backoff-link] to backoff between
94  * retries. The default policies are to continue retrying for up to 10 minutes.
95  * On each transient failure the backoff period is doubled, starting with an
96  * initial backoff of 100 milliseconds. The backoff period growth is truncated
97  * at 60 seconds. The default idempotency policy is to only retry idempotent
98  * operations. Note that most operations that change state are **not**
99  * idempotent.
100  *
101  * The application can override these policies when constructing objects of this
102  * class. The documentation for the constructors show examples of this in
103  * action.
104  *
105  * [backoff-link]: https://cloud.google.com/storage/docs/exponential-backoff
106  *
107  * @see https://cloud.google.com/bigtable/ for an overview of Cloud Bigtable.
108  *
109  * @see https://cloud.google.com/bigtable/docs/overview for an overview of the
110  *     Cloud Bigtable data model.
111  *
112  * @see https://cloud.google.com/bigtable/docs/instances-clusters-nodes for an
113  *     introduction of the main APIs into Cloud Bigtable.
114  *
115  * @see https://cloud.google.com/bigtable/docs/reference/service-apis-overview
116  *     for an overview of the underlying Cloud Bigtable API.
117  *
118  * @see #google::cloud::v1::StatusOr for a description of the error reporting
119  *     class used by this library.
120  *
121  * @see `LimitedTimeRetryPolicy` and `LimitedErrorCountRetryPolicy` for
122  *     alternative retry policies.
123  *
124  * @see `ExponentialBackoffPolicy` to configure different parameters for the
125  *     exponential backoff policy.
126  *
127  * @see `SafeIdempotentMutationPolicy` and `AlwaysRetryMutationPolicy` for
128  *     alternative idempotency policies.
129  */
130 class TableAdmin {
131  public:
132   /**
133    * @param client the interface to create grpc stubs, report errors, etc.
134    * @param instance_id the id of the instance, e.g., "my-instance", the full
135    *   name (e.g. '/projects/my-project/instances/my-instance') is built using
136    *   the project id in the @p client parameter.
137    */
TableAdmin(std::shared_ptr<AdminClient> client,std::string instance_id)138   TableAdmin(std::shared_ptr<AdminClient> client, std::string instance_id)
139       : client_(std::move(client)),
140         instance_id_(std::move(instance_id)),
141         instance_name_(InstanceName()),
142         rpc_retry_policy_prototype_(
143             DefaultRPCRetryPolicy(internal::kBigtableTableAdminLimits)),
144         rpc_backoff_policy_prototype_(
145             DefaultRPCBackoffPolicy(internal::kBigtableTableAdminLimits)),
146         metadata_update_policy_(instance_name(), MetadataParamTypes::PARENT),
147         polling_policy_prototype_(
148             DefaultPollingPolicy(internal::kBigtableTableAdminLimits)) {}
149 
150   /**
151    * Create a new TableAdmin using explicit policies to handle RPC errors.
152    *
153    * @param client the interface to create grpc stubs, report errors, etc.
154    * @param instance_id the id of the instance, e.g., "my-instance", the full
155    *   name (e.g. '/projects/my-project/instances/my-instance') is built using
156    *   the project id in the @p client parameter.
157    * @param policies the set of policy overrides for this object.
158    * @tparam Policies the types of the policies to override, the types must
159    *     derive from one of the following types:
160    *     - `RPCBackoffPolicy` how to backoff from a failed RPC. Currently only
161    *       `ExponentialBackoffPolicy` is implemented. You can also create your
162    *       own policies that backoff using a different algorithm.
163    *     - `RPCRetryPolicy` for how long to retry failed RPCs. Use
164    *       `LimitedErrorCountRetryPolicy` to limit the number of failures
165    *       allowed. Use `LimitedTimeRetryPolicy` to bound the time for any
166    *       request. You can also create your own policies that combine time and
167    *       error counts.
168    *     - `PollingPolicy` for how long will the class wait for
169    *       `google.longrunning.Operation` to complete. This class combines both
170    *       the backoff policy for checking long running operations and the
171    *       retry policy.
172    *
173    * @see GenericPollingPolicy, ExponentialBackoffPolicy,
174    *     LimitedErrorCountRetryPolicy, LimitedTimeRetryPolicy.
175    */
176   template <typename... Policies>
177   // NOLINTNEXTLINE(performance-unnecessary-value-param) TODO(#4112)
TableAdmin(std::shared_ptr<AdminClient> client,std::string instance_id,Policies &&...policies)178   TableAdmin(std::shared_ptr<AdminClient> client, std::string instance_id,
179              Policies&&... policies)
180       : TableAdmin(std::move(client), std::move(instance_id)) {
181     ChangePolicies(std::forward<Policies>(policies)...);
182   }
183 
184   TableAdmin(TableAdmin const&) = default;
185   TableAdmin& operator=(TableAdmin const&) = default;
186 
187   //@{
188   /// @name Convenience shorthands for the schema views.
189   using TableView = google::bigtable::admin::v2::Table::View;
190   /// Use the default view as defined for each function.
191   // NOLINTNEXTLINE(readability-identifier-naming)
192   constexpr static TableView VIEW_UNSPECIFIED =
193       google::bigtable::admin::v2::Table::VIEW_UNSPECIFIED;
194   /// Populate only the name in the responses.
195   // NOLINTNEXTLINE(readability-identifier-naming)
196   constexpr static TableView NAME_ONLY =
197       google::bigtable::admin::v2::Table::NAME_ONLY;
198   /// Populate only the name and the fields related to the table schema.
199   // NOLINTNEXTLINE(readability-identifier-naming)
200   constexpr static TableView SCHEMA_VIEW =
201       google::bigtable::admin::v2::Table::SCHEMA_VIEW;
202   /// Populate only the name and the fields related to the table replication
203   /// state.
204   // NOLINTNEXTLINE(readability-identifier-naming)
205   constexpr static TableView REPLICATION_VIEW =
206       google::bigtable::admin::v2::Table::REPLICATION_VIEW;
207   /// Populate all the fields in the response.
208   // NOLINTNEXTLINE(readability-identifier-naming)
209   constexpr static TableView FULL = google::bigtable::admin::v2::Table::FULL;
210   //@}
211 
project()212   std::string const& project() const { return client_->project(); }
instance_id()213   std::string const& instance_id() const { return instance_id_; }
instance_name()214   std::string const& instance_name() const { return instance_name_; }
215 
216   /**
217    * Create a new table in the instance.
218    *
219    * @param table_id the name of the table relative to the instance managed by
220    *     this object.  The full table name is
221    *     `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/tables/<table_id>`
222    *     where PROJECT_ID is obtained from the associated AdminClient and
223    *     INSTANCE_ID is the instance_id() of this object.
224    * @param config the initial schema for the table.
225    * @return the attributes of the newly created table.  Notice that the server
226    *     only populates the table_name() field at this time.
227    *
228    * @par Idempotency
229    * This operation is always treated as non-idempotent.
230    *
231    * @par Example
232    * @snippet table_admin_snippets.cc create table
233    */
234   StatusOr<::google::bigtable::admin::v2::Table> CreateTable(
235       std::string table_id, TableConfig config);
236 
237   /**
238    * Sends an asynchronous request to create a new table in the instance.
239    *
240    * @warning This is an early version of the asynchronous APIs for Cloud
241    *     Bigtable. These APIs might be changed in backward-incompatible ways. It
242    *     is not subject to any SLA or deprecation policy.
243    *
244    * @param table_id the name of the table relative to the instance managed by
245    *     this object.  The full table name is
246    *     `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/tables/<table_id>`
247    *     where PROJECT_ID is obtained from the associated AdminClient and
248    *     INSTANCE_ID is the instance_id() of this object.
249    * @param config the initial schema for the table.
250    * @param cq the completion queue that will execute the asynchronous calls,
251    *     the application must ensure that one or more threads are blocked on
252    *     `cq.Run()`.
253    *
254    * @return a future that will be satisfied when the request succeeds or the
255    *   retry policy expires.  In the first case, the future will contain the
256    *   response from the service. In the second the future is satisfied with
257    *   an exception. Note that the service only fills out the `table_name` field
258    *   for this request.
259    *
260    * @par Idempotency
261    * This operation is always treated as non-idempotent.
262    *
263    * @par Example
264    * @snippet table_admin_async_snippets.cc async create table
265    */
266   future<StatusOr<google::bigtable::admin::v2::Table>> AsyncCreateTable(
267       CompletionQueue& cq, std::string table_id, TableConfig config);
268 
269   /**
270    * Return all the tables in the instance.
271    *
272    * @param view define what information about the tables is retrieved.
273    *   - `VIEW_UNSPECIFIED`: equivalent to `VIEW_SCHEMA`.
274    *   - `NAME`: return only the name of the table.
275    *   - `VIEW_SCHEMA`: return the name and the schema.
276    *   - `FULL`: return all the information about the table.
277    *
278    * @par Idempotency
279    * This operation is read-only and therefore it is always idempotent.
280    *
281    * @par Example
282    * @snippet table_admin_snippets.cc list tables
283    */
284   StatusOr<std::vector<::google::bigtable::admin::v2::Table>> ListTables(
285       ::google::bigtable::admin::v2::Table::View view);
286 
287   /**
288    * Sends an asynchronous request to get all the tables in the instance.
289    *
290    * @warning This is an early version of the asynchronous APIs for Cloud
291    *     Bigtable. These APIs might be changed in backward-incompatible ways. It
292    *     is not subject to any SLA or deprecation policy.
293    *
294    * @param cq the completion queue that will execute the asynchronous calls,
295    *     the application must ensure that one or more threads are blocked on
296    *     `cq.Run()`.
297    * @param view describes how much information to get about the name.
298    *   - VIEW_UNSPECIFIED: equivalent to VIEW_SCHEMA.
299    *   - NAME: return only the name of the table.
300    *   - VIEW_SCHEMA: return the name and the schema.
301    *   - FULL: return all the information about the table.
302    *
303    * @return a future that will be satisfied when the request succeeds or the
304    *   retry policy expires. In the first case, the future will contain the
305    *   response from the service. In the second the future is satisfied with
306    *   an exception.
307    *
308    * @par Idempotency
309    * This operation is read-only and therefore it is always idempotent.
310    *
311    * @par Example
312    * @snippet table_admin_async_snippets.cc async list tables
313    */
314   future<StatusOr<std::vector<::google::bigtable::admin::v2::Table>>>
315   AsyncListTables(CompletionQueue& cq,
316                   google::bigtable::admin::v2::Table::View view);
317 
318   /**
319    * Get information about a single table.
320    *
321    * @param table_id the id of the table within the instance associated with
322    *     this object. The full name of the table is
323    *     `this->instance_name() + "/tables/" + table_id`
324    * @param view describes how much information to get about the name.
325    *   - VIEW_UNSPECIFIED: equivalent to VIEW_SCHEMA.
326    *   - NAME: return only the name of the table.
327    *   - VIEW_SCHEMA: return the name and the schema.
328    *   - FULL: return all the information about the table.
329    * @return the information about the table or status.
330    *
331    * @par Idempotency
332    * This operation is read-only and therefore it is always idempotent.
333    *
334    * @par Example
335    * @snippet table_admin_snippets.cc get table
336    */
337   StatusOr<::google::bigtable::admin::v2::Table> GetTable(
338       std::string const& table_id, TableView view = SCHEMA_VIEW);
339 
340   /**
341    * Sends an asynchronous request to get information about an existing table.
342    *
343    * @warning This is an early version of the asynchronous APIs for Cloud
344    *     Bigtable. These APIs might be changed in backward-incompatible ways. It
345    *     is not subject to any SLA or deprecation policy.
346    *
347    * @param table_id the id of the table within the instance associated with
348    *     this object. The full name of the table is
349    *     `this->instance_name() + "/tables/" + table_id`
350    * @param view describes how much information to get about the name.
351    *   - VIEW_UNSPECIFIED: equivalent to VIEW_SCHEMA.
352    *   - NAME: return only the name of the table.
353    *   - VIEW_SCHEMA: return the name and the schema.
354    *   - FULL: return all the information about the table.
355    * @param cq the completion queue that will execute the asynchronous calls,
356    *     the application must ensure that one or more threads are blocked on
357    *     `cq.Run()`.
358    *
359    * @return a future that will be satisfied when the request succeeds or the
360    *   retry policy expires. In the first case, the future will contain the
361    *   response from the service. In the second the future is satisfied with
362    *   an exception.
363    *
364    * @par Idempotency
365    * This operation is read-only and therefore it is always idempotent.
366    *
367    * @par Example
368    * @snippet table_admin_async_snippets.cc async get table
369    */
370   future<StatusOr<google::bigtable::admin::v2::Table>> AsyncGetTable(
371       CompletionQueue& cq, std::string const& table_id,
372       google::bigtable::admin::v2::Table::View view);
373 
374   /**
375    * Delete a table.
376    *
377    * @param table_id the id of the table within the instance associated with
378    *     this object. The full name of the table is
379    *     `this->instance_name() + "/tables/" + table_id`
380    *
381    * @return status of the operation.
382    *
383    * @par Idempotency
384    * This operation is always treated as non-idempotent.
385    *
386    * @par Example
387    * @snippet table_admin_snippets.cc delete table
388    */
389   Status DeleteTable(std::string const& table_id);
390 
391   /**
392    * Start a request to asynchronously delete a table.
393    *
394    * @warning This is an early version of the asynchronous APIs for Cloud
395    *     Bigtable. These APIs might be changed in backward-incompatible ways. It
396    *     is not subject to any SLA or deprecation policy.
397    *
398    * @param cq the completion queue that will execute the asynchronous calls,
399    *     the application must ensure that one or more threads are blocked on
400    *     `cq.Run()`.
401    * @param table_id the id of the table within the instance associated with
402    *     this object. The full name of the table is
403    *     `this->instance_name() + "/tables/" + table_id`
404    *
405    * @return status of the operation.
406    *
407    * @par Idempotency
408    * This operation is always treated as non-idempotent.
409    *
410    * @par Example
411    * @snippet table_admin_async_snippets.cc async delete table
412    */
413   future<Status> AsyncDeleteTable(CompletionQueue& cq,
414                                   std::string const& table_id);
415 
416   /**
417    * Parameters for `CreateBackup` and `AsyncCreateBackup`.
418    *
419    * @param cluster_id the name of the cluster relative to the instance managed
420    *     by the `TableAdmin` object. The full cluster name is
421    *     `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<cluster_id>`
422    *     where PROJECT_ID is obtained from the associated AdminClient and
423    *     INSTANCE_ID is the instance_id() of the `TableAdmin` object.
424    * @param backup_id the name of the backup relative to the cluster specified.
425    *     The full backup name is
426    *     `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<CLUSTER_ID>/backups/<backup_id>`
427    *     where PROJECT_ID is obtained from the associated AdminClient,
428    *     INSTANCE_ID is the instance_id() of the `TableAdmin` object, and
429    *     CLUSTER_ID is the cluster_id specified for this object.
430    * @param table_id the id of the table within the instance to be backed up.
431    *     The full name of the table is
432    *     `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/tables/<table_id>`
433    *     where PROJECT_ID is obtained from the associated AdminClient and
434    *     INSTANCE_ID is the instance_id() of the `TableAdmin` object.
435    * @param expire_time the date and time when the created backup will expire.
436    */
437   struct CreateBackupParams {
438     CreateBackupParams() = default;
CreateBackupParamsCreateBackupParams439     CreateBackupParams(std::string cluster_id, std::string backup_id,
440                        std::string table_id,
441                        std::chrono::system_clock::time_point expire_time)
442         : cluster_id(std::move(cluster_id)),
443           backup_id(std::move(backup_id)),
444           table_name(std::move(table_id)),
445           expire_time(std::move(expire_time)) {}
446 
447     google::bigtable::admin::v2::CreateBackupRequest AsProto(
448         std::string instance_name) const;
449 
450     std::string cluster_id;
451     std::string backup_id;
452     std::string table_name;
453     std::chrono::system_clock::time_point expire_time;
454   };
455 
456   /**
457    * Create a new backup of a table in the instance.
458    *
459    * @param params instance of `CreateBackupParams`.
460    *
461    * @par Idempotency
462    * This operation is always treated as non-idempotent.
463    *
464    * @par Example
465    * @snippet bigtable_table_admin_backup_snippets.cc create backup
466    */
467   StatusOr<google::bigtable::admin::v2::Backup> CreateBackup(
468       CreateBackupParams const& params);
469 
470   /**
471    * Sends an asynchronous request to create a new backup of a table in the
472    * instance.
473    *
474    * @warning This is an early version of the asynchronous APIs for Cloud
475    *     Bigtable. These APIs might be changed in backward-incompatible ways. It
476    *     is not subject to any SLA or deprecation policy.
477    *
478    * @param cq the completion queue that will execute the asynchronous calls,
479    *     the application must ensure that one or more threads are blocked on
480    *     `cq.Run()`.
481    * @param params instance of `CreateBackupParams`.
482    *
483    * @return a future that will be satisfied when the request succeeds or the
484    *   retry policy expires. In the first case, the future will contain the
485    *   response from the service. In the second case, the future is satisfied
486    *   with an exception.
487    *
488    * @par Idempotency
489    * This operation is always treated as non-idempotent.
490    *
491    * @par Example
492    * @snippet bigtable_table_admin_backup_async_snippets.cc async create backup
493    *
494    */
495   future<StatusOr<google::bigtable::admin::v2::Backup>> AsyncCreateBackup(
496       CompletionQueue& cq, CreateBackupParams const& params);
497 
498   /**
499    * Get information about a single backup.
500    *
501    * @param cluster_id the name of the cluster relative to the instance managed
502    *     by the `TableAdmin` object. The full cluster name is
503    *     `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<cluster_id>`
504    *     where PROJECT_ID is obtained from the associated AdminClient and
505    *     INSTANCE_ID is the instance_id() of the `TableAdmin` object.
506    * @param backup_id the name of the backup relative to the cluster specified.
507    *     The full backup name is
508    *     `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<CLUSTER_ID>/backups/<backup_id>`
509    *     where PROJECT_ID is obtained from the associated AdminClient,
510    *     INSTANCE_ID is the instance_id() of the `TableAdmin` object, and
511    *     CLUSTER_ID is the cluster_id previously specified.
512    *
513    * @par Idempotency
514    * This operation is read-only and therefore it is always idempotent.
515    *
516    * @par Example
517    * @snippet bigtable_table_admin_backup_snippets.cc get backup
518    */
519   StatusOr<google::bigtable::admin::v2::Backup> GetBackup(
520       std::string const& cluster_id, std::string const& backup_id);
521 
522   // clang-format off
523   /**
524    * Sends an asynchronous request to get information about a single backup.
525    *
526    * @warning This is an early version of the asynchronous APIs for Cloud
527    *     Bigtable. These APIs might be changed in backward-incompatible ways. It
528    *     is not subject to any SLA or deprecation policy.
529    *
530    * @param cq the completion queue that will execute the asynchronous calls,
531    *     the application must ensure that one or more threads are blocked on
532    *     `cq.Run()`.
533    * @param cluster_id the name of the cluster relative to the instance managed
534    *     by the `TableAdmin` object. The full cluster name is
535    *     `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<cluster_id>`
536    *     where PROJECT_ID is obtained from the associated AdminClient and
537    *     INSTANCE_ID is the instance_id() of the `TableAdmin` object.
538    * @param backup_id the name of the backup relative to the cluster specified.
539    *     The full backup name is
540    *     `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<CLUSTER_ID>/backups/<backup_id>`
541    *     where PROJECT_ID is obtained from the associated AdminClient,
542    *     INSTANCE_ID is the instance_id() of the `TableAdmin` object, and
543    *     CLUSTER_ID is the cluster_id previously specified.
544    * @return a future that will be satisfied when the request succeeds or the
545    *   retry policy expires. In the first case, the future will contain the
546    *   response from the service. In the second case, the future is satisfied
547    *   with an exception.
548 
549    * @par Idempotency
550    * This operation is read-only and therefore it is always idempotent.
551    *
552    * @par Example
553    * @snippet bigtable_table_admin_backup_async_snippets.cc async get backup
554    */
555   // clang-format on
556   future<StatusOr<google::bigtable::admin::v2::Backup>> AsyncGetBackup(
557       CompletionQueue& cq, std::string const& cluster_id,
558       std::string const& backup_id);
559 
560   /**
561    * Parameters for `UpdateBackup` and `AsyncUpdateBackup`.
562    *
563    * @param cluster_id the name of the cluster relative to the instance managed
564    *     by the `TableAdmin` object. The full cluster name is
565    *     `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<cluster_id>`
566    *     where PROJECT_ID is obtained from the associated AdminClient and
567    *     INSTANCE_ID is the instance_id() of the `TableAdmin` object.
568    * @param backup_id the name of the backup relative to the cluster specified.
569    *     The full backup name is
570    *     `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<CLUSTER_ID>/backups/<backup_id>`
571    *     where PROJECT_ID is obtained from the associated AdminClient,
572    *     INSTANCE_ID is the instance_id() of the `TableAdmin` object, and
573    *     CLUSTER_ID is the cluster_id specified for this object.
574    * @param expire_time the date and time when the created backup will expire.
575    */
576   struct UpdateBackupParams {
577     UpdateBackupParams() = default;
UpdateBackupParamsUpdateBackupParams578     UpdateBackupParams(std::string cluster_id, std::string backup_id,
579                        std::chrono::system_clock::time_point expire_time)
580         : cluster_id(std::move(cluster_id)),
581           backup_name(std::move(backup_id)),
582           expire_time(std::move(expire_time)) {}
583 
584     google::bigtable::admin::v2::UpdateBackupRequest AsProto(
585         std::string const& instance_name) const;
586 
587     std::string cluster_id;
588     std::string backup_name;
589     std::chrono::system_clock::time_point expire_time;
590   };
591 
592   /**
593    * Updates a backup of a table in the instance.
594    *
595    * @param params instance of `UpdateBackupParams`.
596    *
597    * @par Idempotency
598    * This operation is always treated as non-idempotent.
599    *
600    * @par Example
601    * @snippet bigtable_table_admin_backup_snippets.cc update backup
602    */
603   StatusOr<google::bigtable::admin::v2::Backup> UpdateBackup(
604       UpdateBackupParams const& params);
605 
606   /**
607    * Sends an asynchronous request to update a backup of a table in the
608    * instance.
609    *
610    * @warning This is an early version of the asynchronous APIs for Cloud
611    *     Bigtable. These APIs might be changed in backward-incompatible ways. It
612    *     is not subject to any SLA or deprecation policy.
613    *
614    * @param cq the completion queue that will execute the asynchronous calls,
615    *     the application must ensure that one or more threads are blocked on
616    *     `cq.Run()`.
617    * @param params instance of `UpdateBackupParams`.
618    *
619    * @return a future that will be satisfied when the request succeeds or the
620    *   retry policy expires. In the first case, the future will contain the
621    *   response from the service. In the second case, the future is satisfied
622    *   with an exception.
623    *
624    * @par Idempotency
625    * This operation is always treated as non-idempotent.
626    *
627    * @par Example
628    * @snippet bigtable_table_admin_backup_async_snippets.cc async update backup
629    *
630    */
631   future<StatusOr<google::bigtable::admin::v2::Backup>> AsyncUpdateBackup(
632       CompletionQueue& cq, UpdateBackupParams const& params);
633 
634   /**
635    * Delete a backup.
636    *
637    * @param cluster_id the name of the cluster relative to the instance managed
638    *     by the `TableAdmin` object. The full cluster name is
639    *     `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<cluster_id>`
640    *     where PROJECT_ID is obtained from the associated AdminClient and
641    *     INSTANCE_ID is the instance_id() of the `TableAdmin` object.
642    * @param backup_id the name of the backup relative to the cluster specified.
643    *     The full backup name is
644    *     `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<CLUSTER_ID>/backups/<backup_id>`
645    *     where PROJECT_ID is obtained from the associated AdminClient,
646    *     INSTANCE_ID is the instance_id() of the `TableAdmin` object, and
647    *     CLUSTER_ID is the cluster_id previously specified.
648    *
649    * @par Idempotency
650    * This operation is always treated as non-idempotent.
651    *
652    * @par Example
653    * @snippet bigtable_table_admin_backup_snippets.cc delete backup
654    */
655   Status DeleteBackup(std::string const& cluster_id,
656                       std::string const& backup_id);
657 
658   /**
659    * Delete a backup.
660    *
661    * @param backup typically returned by a call to `GetBackup` or `ListBackups`.
662    *
663    * @par Idempotency
664    * This operation is always treated as non-idempotent.
665    *
666    * @par Example
667    * @snippet bigtable_table_admin_backup_snippets.cc delete backup
668    */
669   Status DeleteBackup(google::bigtable::admin::v2::Backup const& backup);
670 
671   /**
672    * Sends an asynchronous request to delete a backup.
673    *
674    * @warning This is an early version of the asynchronous APIs for Cloud
675    *     Bigtable. These APIs might be changed in backward-incompatible ways. It
676    *     is not subject to any SLA or deprecation policy.
677    *
678    * @param cq the completion queue that will execute the asynchronous calls,
679    *     the application must ensure that one or more threads are blocked on
680    *     `cq.Run()`.
681    * @param cluster_id the name of the cluster relative to the instance managed
682    *     by the `TableAdmin` object. The full cluster name is
683    *     `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<cluster_id>`
684    *     where PROJECT_ID is obtained from the associated AdminClient and
685    *     INSTANCE_ID is the instance_id() of the `TableAdmin` object.
686    * @param backup_id the name of the backup relative to the cluster specified.
687    *     The full backup name is
688    *    `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<CLUSTER_ID>/backups/<backup_id>`
689    *     where PROJECT_ID is obtained from the associated AdminClient,
690    *     INSTANCE_ID is the instance_id() of the `TableAdmin` object, and
691    *     CLUSTER_ID is the cluster_id previously specified.
692    * @return a future that will be satisfied when the request succeeds or the
693    *   retry policy expires. In the first case, the future will contain the
694    *   response from the service. In the second case, the future is satisfied
695    *   with an exception.
696    *
697    * @par Idempotency
698    * This operation is always treated as non-idempotent.
699    *
700    * @par Example
701    * @snippet bigtable_table_admin_backup_async_snippets.cc async delete backup
702    */
703   future<Status> AsyncDeleteBackup(CompletionQueue& cq,
704                                    std::string const& cluster_id,
705                                    std::string const& backup_id);
706 
707   /**
708    * Sends an asynchronous request to delete a backup.
709    *
710    * @warning This is an early version of the asynchronous APIs for Cloud
711    *     Bigtable. These APIs might be changed in backward-incompatible ways. It
712    *     is not subject to any SLA or deprecation policy.
713    *
714    * @param cq the completion queue that will execute the asynchronous calls,
715    *     the application must ensure that one or more threads are blocked on
716    *     `cq.Run()`.
717    * @param backup typically returned by a call to `GetBackup` or `ListBackups`.
718    *
719    * @return a future that will be satisfied when the request succeeds or the
720    *   retry policy expires. In the first case, the future will contain the
721    *   response from the service. In the second case, the future is satisfied
722    *   with an exception.
723    *
724    * @par Idempotency
725    * This operation is always treated as non-idempotent.
726    *
727    * @par Example
728    * @snippet bigtable_table_admin_backup_async_snippets.cc async delete backup
729    */
730   future<Status> AsyncDeleteBackup(
731       CompletionQueue& cq, google::bigtable::admin::v2::Backup const& backup);
732 
733   /**
734    * Parameters for `ListBackups` and `AsyncListBackups`.
735    */
736   struct ListBackupsParams {
737     ListBackupsParams() = default;
738 
739     /**
740      * Sets the cluster_id.
741      *
742      * @param cluster_id the name of the cluster relative to the instance
743      *     managed by the `TableAdmin` object. If no cluster_id is specified,
744      *     teh all backups in all clusters are listed. The full cluster name is
745      *     `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<cluster_id>`
746      *     where PROJECT_ID is obtained from the associated AdminClient and
747      *     INSTANCE_ID is the instance_id() of the `TableAdmin` object.
748      */
set_clusterListBackupsParams749     ListBackupsParams& set_cluster(std::string const& cluster_id) {
750       this->cluster_id = cluster_id;
751       return *this;
752     }
753 
754     /**
755      * Sets the filtering expression.
756      *
757      * @param filter expression that filters backups listed in the response.
758      *     The expression must specify the field name, a comparison operator,
759      *     and the value that you want to use for filtering. The value must be a
760      *     string, a number, or a boolean. The comparison operator must be
761      *     <, >, <=, >=, !=, =, or :. Colon ‘:’ represents a HAS operator which
762      *     is roughly synonymous with equality. Filter rules are case
763      *     insensitive.
764      *
765      *     The fields eligible for filtering are:
766      *       * `name`
767      *       * `table`
768      *       * `state`
769      *       * `start_time` (and values are of the format YYYY-MM-DDTHH:MM:SSZ)
770      *       * `end_time` (and values are of the format YYYY-MM-DDTHH:MM:SSZ)
771      *       * `expire_time` (and values are of the format YYYY-MM-DDTHH:MM:SSZ)
772      *       * `size_bytes`
773      *
774      *     To filter on multiple expressions, provide each separate expression
775      *     within parentheses. By default, each expression is an AND expression.
776      *     However, you can include AND, OR, and NOT expressions explicitly.
777      *
778      *     Some examples of using filters are:
779      *       * `name:"exact"` --> The backup's name is the string "exact".
780      *       * `name:howl` --> The backup's name contains the string "howl".
781      *       * `table:prod` --> The table's name contains the string "prod".
782      *       * `state:CREATING` --> The backup is pending creation.
783      *       * `state:READY` --> The backup is fully created and ready for use.
784      *       * `(name:howl) AND (start_time < \"2018-03-28T14:50:00Z\")`
785      *          --> The backup name contains the string "howl" and start_time
786      *              of the backup is before 2018-03-28T14:50:00Z.
787      *       * `size_bytes > 10000000000` --> The backup's size is greater than
788      *          10GB
789      */
set_filterListBackupsParams790     ListBackupsParams& set_filter(std::string const& filter) {
791       this->filter = filter;
792       return *this;
793     }
794 
795     /**
796      * Sets the ordering expression.
797      *
798      * @param order_by expression for specifying the sort order of the results
799      *     of the request. The string value should specify only one field in
800      *     `google::bigtable::admin::v2::Backup`.
801      *     The following field names are supported:
802      *        * name
803      *        * table
804      *        * expire_time
805      *        * start_time
806      *        * end_time
807      *        * size_bytes
808      *        * state
809      *
810      *     For example, "start_time". The default sorting order is ascending.
811      *     Append the " desc" suffix to the field name to sort descending, e.g.
812      *     "start_time desc". Redundant space characters in the syntax are
813      *     insignificant.
814      *
815      *     If order_by is empty, results will be sorted by `start_time` in
816      *     descending order starting from the most recently created backup.
817      */
set_order_byListBackupsParams818     ListBackupsParams& set_order_by(std::string const& order_by) {
819       this->order_by = order_by;
820       return *this;
821     }
822 
823     google::bigtable::admin::v2::ListBackupsRequest AsProto(
824         std::string const& instance_name) const;
825 
826     absl::optional<std::string> cluster_id;
827     absl::optional<std::string> filter;
828     absl::optional<std::string> order_by;
829   };
830 
831   /**
832    * Retrieves a list of backups.
833    *
834    * @param params instance of `ListBackupsParams`.
835    *
836    * @par Idempotency
837    * This operation is read-only and therefore it is always idempotent.
838    *
839    * @par Example
840    * @snippet bigtable_table_admin_backup_snippets.cc list backups
841    */
842   StatusOr<std::vector<google::bigtable::admin::v2::Backup>> ListBackups(
843       ListBackupsParams const& params);
844 
845   /**
846    * Sends an asynchronous request to retrieve a list of backups.
847    *
848    * @warning This is an early version of the asynchronous APIs for Cloud
849    *     Bigtable. These APIs might be changed in backward-incompatible ways. It
850    *     is not subject to any SLA or deprecation policy.
851    *
852    * @param cq the completion queue that will execute the asynchronous calls,
853    *     the application must ensure that one or more threads are blocked on
854    *     `cq.Run()`.
855    * @param params instance of `ListBackupsParams`.
856    *
857    * @return a future that will be satisfied when the request succeeds or the
858    *   retry policy expires. In the first case, the future will contain the
859    *   response from the service. In the second case, the future is satisfied
860    *   with an exception.
861    *
862    * @par Idempotency
863    * This operation is read-only and therefore it is always idempotent.
864    *
865    * @par Example
866    * @snippet bigtable_table_admin_backup_async_snippets.cc async list backups
867    *
868    */
869   future<StatusOr<std::vector<google::bigtable::admin::v2::Backup>>>
870   AsyncListBackups(CompletionQueue& cq, ListBackupsParams const& params);
871 
872   /**
873    * Parameters for `RestoreTable` and `AsyncRestoreTable`.
874    *
875    * @param table_id the name of the table relative to the instance managed by
876    *     this object. The full table name is
877    *     `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/tables/<table_id>`
878    *     where PROJECT_ID is obtained from the associated AdminClient and
879    *     INSTANCE_ID is the instance_id() of this object.
880    * @param cluster_id the name of the cluster relative to the instance managed
881    *     by the `TableAdmin` object. The full cluster name is
882    *     `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<cluster_id>`
883    *     where PROJECT_ID is obtained from the associated AdminClient and
884    *     INSTANCE_ID is the instance_id() of the `TableAdmin` object.
885    * @param backup_id the name of the backup relative to the cluster specified.
886    *     The full backup name is
887    *     `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<CLUSTER_ID>/backups/<backup_id>`
888    *     where PROJECT_ID is obtained from the associated AdminClient,
889    *     INSTANCE_ID is the instance_id() of the `TableAdmin` object, and
890    *     CLUSTER_ID is the cluster_id previously specified.
891    */
892   struct RestoreTableParams {
893     RestoreTableParams() = default;
RestoreTableParamsRestoreTableParams894     RestoreTableParams(std::string table_id, std::string cluster_id,
895                        std::string backup_id)
896         : table_id(std::move(table_id)),
897           cluster_id(std::move(cluster_id)),
898           backup_id(std::move(backup_id)) {}
899 
900     google::bigtable::admin::v2::RestoreTableRequest AsProto(
901         std::string const& instance_name) const;
902 
903     std::string table_id;
904     std::string cluster_id;
905     std::string backup_id;
906   };
907 
908   /**
909    * Restore a backup into a new table in the instance.
910    *
911    * @param params instance of `RestoreTableParams`.
912    *
913    * @par Idempotency
914    * This operation is always treated as non-idempotent.
915    *
916    * @par Example
917    * @snippet bigtable_table_admin_backup_snippets.cc restore table
918    */
919   StatusOr<google::bigtable::admin::v2::Table> RestoreTable(
920       RestoreTableParams const& params);
921 
922   /**
923    * Sends an asynchronous request to restore a backup into a new table in the
924    * instance.
925    *
926    * @warning This is an early version of the asynchronous APIs for Cloud
927    *     Bigtable. These APIs might be changed in backward-incompatible ways. It
928    *     is not subject to any SLA or deprecation policy.
929    *
930    * @param cq the completion queue that will execute the asynchronous calls,
931    *     the application must ensure that one or more threads are blocked on
932    *     `cq.Run()`.
933    * @param params instance of `RestoreTableParams`.
934    *
935    * @return a future that will be satisfied when the request succeeds or the
936    *   retry policy expires. In the first case, the future will contain the
937    *   response from the service. In the second case, the future is satisfied
938    *   with an exception.
939    *
940    * @par Idempotency
941    * This operation is always treated as non-idempotent.
942    *
943    * @par Example
944    * @snippet bigtable_table_admin_backup_async_snippets.cc async restore table
945    *
946    */
947   future<StatusOr<google::bigtable::admin::v2::Table>> AsyncRestoreTable(
948       CompletionQueue& cq, RestoreTableParams const& params);
949 
950   /**
951    * Modify the schema for an existing table.
952    *
953    * @param table_id the id of the table within the instance associated with
954    *     this object. The full name of the table is
955    *     `this->instance_name() + "/tables/" + table_id`
956    * @param modifications the list of modifications to the schema.
957    *
958    * @par Idempotency
959    * This operation is always treated as non-idempotent.
960    *
961    * @par Example
962    * @snippet table_admin_snippets.cc modify table
963    */
964   StatusOr<::google::bigtable::admin::v2::Table> ModifyColumnFamilies(
965       std::string const& table_id,
966       std::vector<ColumnFamilyModification> modifications);
967 
968   /**
969    * Make an asynchronous request to modify the column families of a table.
970    *
971    * @warning This is an early version of the asynchronous APIs for Cloud
972    *     Bigtable. These APIs might be changed in backward-incompatible ways. It
973    *     is not subject to any SLA or deprecation policy.
974    *
975    * @param cq the completion queue that will execute the asynchronous calls,
976    *     the application must ensure that one or more threads are blocked on
977    *     `cq.Run()`.
978    * @param table_id the name of the table relative to the instance managed by
979    *     this object.  The full table name is
980    *     `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/tables/<table_id>`
981    *     where PROJECT_ID is obtained from the associated AdminClient and
982    *     INSTANCE_ID is the instance_id() of this object.
983    * @param modifications the list of modifications to the schema.
984    * @return the information about table or status.
985    *
986    * @par Idempotency
987    * This operation is always treated as non-idempotent.
988    *
989    * @par Example
990    * @snippet table_admin_async_snippets.cc async modify table
991    */
992   future<StatusOr<::google::bigtable::admin::v2::Table>>
993   AsyncModifyColumnFamilies(
994       CompletionQueue& cq, std::string const& table_id,
995       std::vector<ColumnFamilyModification> modifications);
996 
997   /**
998    * Delete all the rows that start with a given prefix.
999    *
1000    * @param table_id the id of the table within the instance associated with
1001    *     this object. The full name of the table is
1002    *     `this->instance_name() + "/tables/" + table_id`
1003    * @param row_key_prefix drop any rows that start with this prefix.
1004    *
1005    * @par Idempotency
1006    * This operation is always treated as non-idempotent.
1007    *
1008    * @par Example
1009    * @snippet table_admin_snippets.cc drop rows by prefix
1010    */
1011   Status DropRowsByPrefix(std::string const& table_id,
1012                           std::string row_key_prefix);
1013 
1014   /**
1015    * Make an asynchronous request to delete all the rows that start with a given
1016    * prefix.
1017    *
1018    * @warning This is an early version of the asynchronous APIs for Cloud
1019    *     Bigtable. These APIs might be changed in backward-incompatible ways. It
1020    *     is not subject to any SLA or deprecation policy.
1021    *
1022    * @param cq the completion queue that will execute the asynchronous calls,
1023    *     the application must ensure that one or more threads are blocked on
1024    *     `cq.Run()`.
1025    * @param table_id the id of the table within the instance associated with
1026    *     this object. The full name of the table is
1027    *     `this->instance_name() + "/tables/" + table_id`
1028    * @param row_key_prefix drop any rows that start with this prefix.
1029    * @return status of the operation.
1030    *
1031    * @par Idempotency
1032    * This operation is always treated as non-idempotent.
1033    *
1034    * @par Example
1035    * @snippet table_admin_async_snippets.cc async drop rows by prefix
1036    */
1037   future<Status> AsyncDropRowsByPrefix(CompletionQueue& cq,
1038                                        std::string const& table_id,
1039                                        std::string row_key_prefix);
1040 
1041   /**
1042    * Generates consistency token for a table.
1043    *
1044    * @param table_id the id of the table for which we want to generate
1045    *     consistency token.
1046    * @return the consistency token for table.
1047    *
1048    * @par Idempotency
1049    * This operation is read-only and therefore it is always idempotent.
1050    *
1051    * @par Example
1052    * @snippet table_admin_snippets.cc generate consistency token
1053    */
1054   StatusOr<std::string> GenerateConsistencyToken(std::string const& table_id);
1055 
1056   /**
1057    * Make an asynchronous request to generates consistency token for a table.
1058    *
1059    * @warning This is an early version of the asynchronous APIs for Cloud
1060    *     Bigtable. These APIs might be changed in backward-incompatible ways. It
1061    *     is not subject to any SLA or deprecation policy.
1062    *
1063    * @param cq the completion queue that will execute the asynchronous calls,
1064    *     the application must ensure that one or more threads are blocked on
1065    *     `cq.Run()`.
1066    * @param table_id the id of the table within the instance associated with
1067    *     this object. The full name of the table is
1068    *     `this->instance_name() + "/tables/" + table_id`
1069    * @return consistency token or status of the operation.
1070    *
1071    * @par Idempotency
1072    * This operation is read-only and therefore it is always idempotent.
1073    *
1074    * @par Example
1075    * @snippet table_admin_async_snippets.cc async generate consistency token
1076    */
1077   future<StatusOr<std::string>> AsyncGenerateConsistencyToken(
1078       CompletionQueue& cq, std::string const& table_id);
1079 
1080   /**
1081    * Checks consistency of a table.
1082    *
1083    * @param table_id  the id of the table for which we want to check
1084    *     consistency.
1085    * @param consistency_token the consistency token of the table.
1086    * @return the consistency status for the table.
1087    *
1088    * @par Idempotency
1089    * This operation is read-only and therefore it is always idempotent.
1090    *
1091    * @par Example
1092    * @snippet table_admin_snippets.cc check consistency
1093    */
1094   StatusOr<Consistency> CheckConsistency(std::string const& table_id,
1095                                          std::string const& consistency_token);
1096 
1097   /**
1098    * Make an asynchronous request to check consistency of a table.
1099    *
1100    * @warning This is an early version of the asynchronous APIs for Cloud
1101    *     Bigtable. These APIs might be changed in backward-incompatible ways. It
1102    *     is not subject to any SLA or deprecation policy.
1103    *
1104    * @param cq the completion queue that will execute the asynchronous calls,
1105    *     the application must ensure that one or more threads are blocked on
1106    *     `cq.Run()`.
1107    * @param table_id  the id of the table for which we want to check
1108    *     consistency.
1109    * @param consistency_token the consistency token of the table.
1110    * @return consistency status or status of the operation.
1111    *
1112    * @par Idempotency
1113    * This operation is read-only and therefore it is always idempotent.
1114    *
1115    * @par Example
1116    * @snippet table_admin_async_snippets.cc async check consistency
1117    */
1118   future<StatusOr<Consistency>> AsyncCheckConsistency(
1119       CompletionQueue& cq, std::string const& table_id,
1120       std::string const& consistency_token);
1121 
1122   /**
1123    * Checks consistency of a table with multiple calls using a separate thread
1124    *
1125    * @param table_id the id of the table for which we want to check
1126    *     consistency.
1127    * @param consistency_token the consistency token of the table.
1128    * @return the consistency status for the table.
1129    * @throws std::exception if the operation cannot be completed.
1130    *
1131    * @par Idempotency
1132    * This operation is read-only and therefore it is always idempotent.
1133    *
1134    * @par Example
1135    * @snippet table_admin_snippets.cc wait for consistency check
1136    */
1137   google::cloud::future<StatusOr<Consistency>> WaitForConsistency(
1138       std::string const& table_id, std::string const& consistency_token);
1139 
1140   /**
1141    * Asynchronously wait until a table is consistent with the given @p token.
1142    *
1143    * @warning This is an early version of the asynchronous APIs for Cloud
1144    *     Bigtable. These APIs might be changed in backward-incompatible ways. It
1145    *     is not subject to any SLA or deprecation policy.
1146    *
1147    * @param cq the completion queue that will execute the asynchronous calls,
1148    *     the application must ensure that one or more threads are blocked on
1149    *     `cq.Run()`.
1150    * @param table_id the id of the table for which we want to check
1151    *     consistency.
1152    * @param consistency_token the consistency token of the table.
1153    * @return the consistency status for the table.
1154    *
1155    * @par Idempotency
1156    * This operation is read-only and therefore it is always idempotent.
1157    *
1158    * @par Example
1159    * @snippet table_admin_async_snippets.cc async wait for consistency
1160    */
1161   google::cloud::future<StatusOr<Consistency>> AsyncWaitForConsistency(
1162       CompletionQueue& cq, std::string const& table_id,
1163       std::string const& consistency_token);
1164 
1165   /**
1166    * Delete all the rows in a table.
1167    *
1168    * @param table_id the id of the table within the instance associated with
1169    *     this object. The full name of the table is
1170    *     `this->instance_name() + "/tables/" + table_id`
1171    *
1172    * @par Idempotency
1173    * This operation is always treated as non-idempotent.
1174    *
1175    * @par Example
1176    * @snippet table_admin_snippets.cc drop all rows
1177    */
1178   Status DropAllRows(std::string const& table_id);
1179 
1180   /**
1181    * Make an asynchronous request to delete all the rows in a table.
1182    *
1183    * @warning This is an early version of the asynchronous APIs for Cloud
1184    *     Bigtable. These APIs might be changed in backward-incompatible ways. It
1185    *     is not subject to any SLA or deprecation policy.
1186    *
1187    * @param cq the completion queue that will execute the asynchronous calls,
1188    *     the application must ensure that one or more threads are blocked on
1189    *     `cq.Run()`.
1190    * @param table_id the id of the table within the instance associated with
1191    *     this object. The full name of the table is
1192    *     `this->instance_name() + "/tables/" + table_id`
1193    *
1194    * @par Idempotency
1195    * This operation is always treated as non-idempotent.
1196    *
1197    * @par Example
1198    * @snippet table_admin_async_snippets.cc async drop all rows
1199    */
1200   future<Status> AsyncDropAllRows(CompletionQueue& cq,
1201                                   std::string const& table_id);
1202 
1203   /**
1204    * Gets the policy for @p table_id.
1205    *
1206    * @param table_id the table to query.
1207    * @return google::iam::v1::Policy the full IAM policy for the table.
1208    *
1209    * @par Idempotency
1210    * This operation is read-only and therefore it is always idempotent.
1211    *
1212    * @par Example
1213    * @snippet table_admin_iam_policy_snippets.cc get iam policy
1214    */
1215   StatusOr<google::iam::v1::Policy> GetIamPolicy(std::string const& table_id);
1216 
1217   /**
1218    * Asynchronously gets the IAM policy for @p table_id.
1219    *
1220    * @param cq the completion queue that will execute the asynchronous calls,
1221    *     the application must ensure that one or more threads are blocked on
1222    *     `cq.Run()`.
1223    * @param table_id the instance to query.
1224    * @return a future satisfied when either (a) the policy is fetched or (b)
1225    *     an unretriable error occurs or (c) retry policy has been exhausted.
1226    *
1227    * @par Idempotency
1228    * This operation is read-only and therefore it is always idempotent.
1229    *
1230    * @par Example
1231    * @snippet table_admin_iam_policy_snippets.cc async get iam policy
1232    */
1233   future<StatusOr<google::iam::v1::Policy>> AsyncGetIamPolicy(
1234       CompletionQueue& cq, std::string const& table_id);
1235 
1236   /**
1237    * Sets the IAM policy for a table.
1238    *
1239    * This is the preferred way to the overload for `IamBindings`. This is more
1240    * closely coupled to the underlying protocol, enable more actions and is more
1241    * likely to tolerate future protocol changes.
1242    *
1243    * @param table_id which table to set the IAM policy for.
1244    * @param iam_policy google::iam::v1::Policy object containing role and
1245    * members.
1246    * @return google::iam::v1::Policy the current IAM policy for the table.
1247    *
1248    * @warning ETags are currently not used by Cloud Bigtable.
1249    *
1250    * @par Idempotency
1251    * This operation is always treated as non-idempotent.
1252    *
1253    * @par Example
1254    * @snippet table_admin_iam_policy_snippets.cc set iam policy
1255    */
1256   StatusOr<google::iam::v1::Policy> SetIamPolicy(
1257       std::string const& table_id, google::iam::v1::Policy const& iam_policy);
1258 
1259   /**
1260    * Asynchronously sets the IAM policy for a table.
1261    *
1262    * @param cq the completion queue that will execute the asynchronous calls,
1263    *     the application must ensure that one or more threads are blocked on
1264    *     `cq.Run()`.
1265    * @param table_id which instance to set the IAM policy for.
1266    * @param iam_policy google::iam::v1::Policy object containing role and
1267    * members.
1268    * @return a future satisfied when either (a) the policy is created or (b)
1269    *     an unretriable error occurs or (c) retry policy has been
1270    *     exhausted.
1271    *
1272    * @warning ETags are currently not used by Cloud Bigtable.
1273    *
1274    * @par Idempotency
1275    * This operation is always treated as non-idempotent.
1276    *
1277    * @par Example
1278    * @snippet table_admin_iam_policy_snippets.cc async set iam policy
1279    */
1280   future<StatusOr<google::iam::v1::Policy>> AsyncSetIamPolicy(
1281       CompletionQueue& cq, std::string const& table_id,
1282       google::iam::v1::Policy const& iam_policy);
1283 
1284   /**
1285    * Returns a permission set that the caller has on the specified table.
1286    *
1287    * @param table_id the ID of the table to query.
1288    * @param permissions set of permissions to check for the resource.
1289    *
1290    * @par Idempotency
1291    * This operation is read-only and therefore it is always idempotent.
1292    *
1293    * @par Example
1294    * @snippet table_admin_iam_policy_snippets.cc test iam permissions
1295    *
1296    * @see https://cloud.google.com/bigtable/docs/access-control for a list of
1297    *     valid permissions on Google Cloud Bigtable.
1298    */
1299   StatusOr<std::vector<std::string>> TestIamPermissions(
1300       std::string const& table_id, std::vector<std::string> const& permissions);
1301 
1302   /**
1303    * Asynchronously obtains a permission set that the caller has on the
1304    * specified table.
1305    *
1306    * @par Idempotency
1307    * This operation is read-only and therefore it is always idempotent.
1308    *
1309    * @param cq the completion queue that will execute the asynchronous calls,
1310    *     the application must ensure that one or more threads are blocked on
1311    *     `cq.Run()`.
1312    * @param table_id the ID of the table to query.
1313    * @param permissions set of permissions to check for the resource.
1314    *
1315    * @par Example
1316    * @snippet table_admin_iam_policy_snippets.cc async test iam permissions
1317    *
1318    * @see https://cloud.google.com/bigtable/docs/access-control for a list of
1319    *     valid permissions on Google Cloud Bigtable.
1320    */
1321   future<StatusOr<std::vector<std::string>>> AsyncTestIamPermissions(
1322       CompletionQueue& cq, std::string const& table_id,
1323       std::vector<std::string> const& permissions);
1324 
1325   /// Return the fully qualified name of a table in this object's instance.
TableName(std::string const & table_id)1326   std::string TableName(std::string const& table_id) const {
1327     return instance_name() + "/tables/" + table_id;
1328   }
1329 
1330   /// Return the fully qualified name of a Cluster.
ClusterName(std::string const & cluster_id)1331   std::string ClusterName(std::string const& cluster_id) {
1332     return instance_name() + "/clusters/" + cluster_id;
1333   }
1334 
1335  private:
1336   //@{
1337   /// @name Helper functions to implement constructors with changed policies.
ChangePolicy(RPCRetryPolicy const & policy)1338   void ChangePolicy(RPCRetryPolicy const& policy) {
1339     rpc_retry_policy_prototype_ = policy.clone();
1340   }
1341 
ChangePolicy(RPCBackoffPolicy const & policy)1342   void ChangePolicy(RPCBackoffPolicy const& policy) {
1343     rpc_backoff_policy_prototype_ = policy.clone();
1344   }
1345 
ChangePolicy(PollingPolicy const & policy)1346   void ChangePolicy(PollingPolicy const& policy) {
1347     polling_policy_prototype_ = policy.clone();
1348   }
1349 
1350   template <typename Policy, typename... Policies>
ChangePolicies(Policy && policy,Policies &&...policies)1351   void ChangePolicies(Policy&& policy, Policies&&... policies) {
1352     ChangePolicy(policy);
1353     ChangePolicies(std::forward<Policies>(policies)...);
1354   }
ChangePolicies()1355   void ChangePolicies() {}
1356   //@}
1357 
clone_rpc_retry_policy()1358   std::unique_ptr<RPCRetryPolicy> clone_rpc_retry_policy() {
1359     return rpc_retry_policy_prototype_->clone();
1360   }
1361 
clone_rpc_backoff_policy()1362   std::unique_ptr<RPCBackoffPolicy> clone_rpc_backoff_policy() {
1363     return rpc_backoff_policy_prototype_->clone();
1364   }
1365 
clone_metadata_update_policy()1366   MetadataUpdatePolicy clone_metadata_update_policy() {
1367     return metadata_update_policy_;
1368   }
1369 
clone_polling_policy()1370   std::unique_ptr<PollingPolicy> clone_polling_policy() {
1371     return polling_policy_prototype_->clone();
1372   }
1373 
1374   /// Compute the fully qualified instance name.
1375   std::string InstanceName() const;
1376 
1377   std::shared_ptr<AdminClient> client_;
1378   std::string instance_id_;
1379   std::string instance_name_;
1380   std::shared_ptr<RPCRetryPolicy const> rpc_retry_policy_prototype_;
1381   std::shared_ptr<RPCBackoffPolicy const> rpc_backoff_policy_prototype_;
1382   bigtable::MetadataUpdatePolicy metadata_update_policy_;
1383   std::shared_ptr<PollingPolicy const> polling_policy_prototype_;
1384 };
1385 
1386 }  // namespace BIGTABLE_CLIENT_NS
1387 }  // namespace bigtable
1388 }  // namespace cloud
1389 }  // namespace google
1390 
1391 #endif  // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_TABLE_ADMIN_H
1392