forked from googleapis/google-cloud-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable_admin.h
1766 lines (1682 loc) · 72.1 KB
/
table_admin.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2017 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_TABLE_ADMIN_H
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_TABLE_ADMIN_H
#include "google/cloud/bigtable/admin_client.h"
#include "google/cloud/bigtable/column_family.h"
#include "google/cloud/bigtable/completion_queue.h"
#include "google/cloud/bigtable/iam_policy.h"
#include "google/cloud/bigtable/metadata_update_policy.h"
#include "google/cloud/bigtable/polling_policy.h"
#include "google/cloud/bigtable/resource_names.h"
#include "google/cloud/bigtable/table_config.h"
#include "google/cloud/bigtable/version.h"
#include "google/cloud/future.h"
#include "google/cloud/grpc_error_delegate.h"
#include "google/cloud/iam_policy.h"
#include "google/cloud/internal/attributes.h"
#include "google/cloud/status_or.h"
#include "absl/types/optional.h"
#include <chrono>
#include <future>
#include <memory>
#include <string>
#include <vector>
namespace google {
namespace cloud {
namespace bigtable {
inline namespace BIGTABLE_CLIENT_NS {
/// The result of checking replication against a given token.
enum class Consistency {
/// Some of the mutations created before the consistency token have not been
/// received by all the table replicas.
kInconsistent,
/// All mutations created before the consistency token have been received by
/// all the table replicas.
kConsistent,
};
/**
* Implements the API to administer tables in a Cloud Bigtable instance.
*
* @par Thread-safety
* Instances of this class created via copy-construction or copy-assignment
* share the underlying pool of connections. Access to these copies via multiple
* threads is guaranteed to work. Two threads operating concurrently on the same
* instance of this class is not guaranteed to work.
*
* @par Cost
* Creating a new object of type `TableAdmin` is comparable to creating a few
* objects of type `std::string` or a few objects of type
* `std::shared_ptr<int>`. The class represents a shallow handle to a remote
* object.
*
* @par Error Handling
* This class uses `StatusOr<T>` to report errors. When an operation fails to
* perform its work the returned `StatusOr<T>` contains the error details. If
* the `ok()` member function in the `StatusOr<T>` returns `true` then it
* contains the expected result. Operations that do not return a value simply
* return a `google::cloud::Status` indicating success or the details of the
* error Please consult the
* [`StatusOr<T>` documentation](#google::cloud::v1::StatusOr) for more details.
*
* @code
* namespace cbt = google::cloud::bigtable;
* namespace btadmin = google::bigtable::admin::v2;
* cbt::TableAdmin admin = ...;
* google::cloud::StatusOr<btadmin::Table> metadata = admin.GetTable(...);
*
* if (!metadata) {
* std::cerr << "Error fetching table metadata\n";
* return;
* }
*
* // Use "metadata" as a smart pointer here, e.g.:
* std::cout << "The full table name is " << table->name() << " the table has "
* << table->column_families_size() << " column families\n";
* @endcode
*
* In addition, the @ref index "main page" contains examples using `StatusOr<T>`
* to handle errors.
*
* @par Retry, Backoff, and Idempotency Policies
* The library automatically retries requests that fail with transient errors,
* and uses [truncated exponential backoff][backoff-link] to backoff between
* retries. The default policies are to continue retrying for up to 10 minutes.
* On each transient failure the backoff period is doubled, starting with an
* initial backoff of 100 milliseconds. The backoff period growth is truncated
* at 60 seconds. The default idempotency policy is to only retry idempotent
* operations. Note that most operations that change state are **not**
* idempotent.
*
* The application can override these policies when constructing objects of this
* class. The documentation for the constructors show examples of this in
* action.
*
* [backoff-link]: https://cloud.google.com/storage/docs/exponential-backoff
*
* @see https://cloud.google.com/bigtable/ for an overview of Cloud Bigtable.
*
* @see https://cloud.google.com/bigtable/docs/overview for an overview of the
* Cloud Bigtable data model.
*
* @see https://cloud.google.com/bigtable/docs/instances-clusters-nodes for an
* introduction of the main APIs into Cloud Bigtable.
*
* @see https://cloud.google.com/bigtable/docs/reference/service-apis-overview
* for an overview of the underlying Cloud Bigtable API.
*
* @see #google::cloud::v1::StatusOr for a description of the error reporting
* class used by this library.
*
* @see `LimitedTimeRetryPolicy` and `LimitedErrorCountRetryPolicy` for
* alternative retry policies.
*
* @see `ExponentialBackoffPolicy` to configure different parameters for the
* exponential backoff policy.
*
* @see `SafeIdempotentMutationPolicy` and `AlwaysRetryMutationPolicy` for
* alternative idempotency policies.
*/
class TableAdmin {
public:
/**
* @param client the interface to create grpc stubs, report errors, etc.
* @param instance_id the id of the instance, e.g., "my-instance", the full
* name (e.g. '/projects/my-project/instances/my-instance') is built using
* the project id in the @p client parameter.
*/
TableAdmin(std::shared_ptr<AdminClient> client, std::string instance_id)
: client_(std::move(client)),
instance_id_(std::move(instance_id)),
instance_name_(InstanceName()),
rpc_retry_policy_prototype_(
DefaultRPCRetryPolicy(internal::kBigtableTableAdminLimits)),
rpc_backoff_policy_prototype_(
DefaultRPCBackoffPolicy(internal::kBigtableTableAdminLimits)),
metadata_update_policy_(instance_name(), MetadataParamTypes::PARENT),
polling_policy_prototype_(
DefaultPollingPolicy(internal::kBigtableTableAdminLimits)) {}
/**
* Create a new TableAdmin using explicit policies to handle RPC errors.
*
* @param client the interface to create grpc stubs, report errors, etc.
* @param instance_id the id of the instance, e.g., "my-instance", the full
* name (e.g. '/projects/my-project/instances/my-instance') is built using
* the project id in the @p client parameter.
* @param policies the set of policy overrides for this object.
* @tparam Policies the types of the policies to override, the types must
* derive from one of the following types:
* - `RPCBackoffPolicy` how to backoff from a failed RPC. Currently only
* `ExponentialBackoffPolicy` is implemented. You can also create your
* own policies that backoff using a different algorithm.
* - `RPCRetryPolicy` for how long to retry failed RPCs. Use
* `LimitedErrorCountRetryPolicy` to limit the number of failures
* allowed. Use `LimitedTimeRetryPolicy` to bound the time for any
* request. You can also create your own policies that combine time and
* error counts.
* - `PollingPolicy` for how long will the class wait for
* `google.longrunning.Operation` to complete. This class combines both
* the backoff policy for checking long running operations and the
* retry policy.
*
* @see GenericPollingPolicy, ExponentialBackoffPolicy,
* LimitedErrorCountRetryPolicy, LimitedTimeRetryPolicy.
*/
template <typename... Policies>
// NOLINTNEXTLINE(performance-unnecessary-value-param) TODO(#4112)
TableAdmin(std::shared_ptr<AdminClient> client, std::string instance_id,
Policies&&... policies)
: TableAdmin(std::move(client), std::move(instance_id)) {
ChangePolicies(std::forward<Policies>(policies)...);
}
TableAdmin(TableAdmin const&) = default;
TableAdmin& operator=(TableAdmin const&) = default;
//@{
/// @name Convenience shorthands for the schema views.
using TableView = google::bigtable::admin::v2::Table::View;
/// Only populate 'name' and fields related to the table's encryption state.
static auto constexpr ENCRYPTION_VIEW = // NOLINT(readability-identifier-naming)
google::bigtable::admin::v2::Table::ENCRYPTION_VIEW;
/// Populate all the fields in the response.
static auto constexpr FULL = // NOLINT(readability-identifier-naming)
google::bigtable::admin::v2::Table::FULL;
/// Populate only the name in the responses.
static auto constexpr NAME_ONLY = // NOLINT(readability-identifier-naming)
google::bigtable::admin::v2::Table::NAME_ONLY;
/// Populate only the name and the fields related to the table replication
/// state.
static auto constexpr REPLICATION_VIEW = // NOLINT(readability-identifier-naming)
google::bigtable::admin::v2::Table::REPLICATION_VIEW;
/// Populate only the name and the fields related to the table schema.
static auto constexpr SCHEMA_VIEW = // NOLINT(readability-identifier-naming)
google::bigtable::admin::v2::Table::SCHEMA_VIEW;
/// Use the default view as defined for each function.
static auto constexpr VIEW_UNSPECIFIED = // NOLINT(readability-identifier-naming)
google::bigtable::admin::v2::Table::VIEW_UNSPECIFIED;
//@}
std::string const& project() const { return client_->project(); }
std::string const& instance_id() const { return instance_id_; }
std::string const& instance_name() const { return instance_name_; }
/**
* Create a new table in the instance.
*
* @param table_id the name of the table relative to the instance managed by
* this object. The full table name is
* `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/tables/<table_id>`
* where PROJECT_ID is obtained from the associated AdminClient and
* INSTANCE_ID is the instance_id() of this object.
* @param config the initial schema for the table.
* @return the attributes of the newly created table. Notice that the server
* only populates the table_name() field at this time.
*
* @par Idempotency
* This operation is always treated as non-idempotent.
*
* @par Thread-safety
* Two threads concurrently calling this member function on the same instance
* of this class are **not** guaranteed to work. Consider copying the object
* and using different copies in each thread.
*
* @par Example
* @snippet table_admin_snippets.cc create table
*/
StatusOr<::google::bigtable::admin::v2::Table> CreateTable(
std::string table_id, TableConfig config);
/**
* Sends an asynchronous request to create a new table in the instance.
*
* @warning This is an early version of the asynchronous APIs for Cloud
* Bigtable. These APIs might be changed in backward-incompatible ways. It
* is not subject to any SLA or deprecation policy.
*
* @param table_id the name of the table relative to the instance managed by
* this object. The full table name is
* `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/tables/<table_id>`
* where PROJECT_ID is obtained from the associated AdminClient and
* INSTANCE_ID is the instance_id() of this object.
* @param config the initial schema for the table.
* @param cq the completion queue that will execute the asynchronous calls,
* the application must ensure that one or more threads are blocked on
* `cq.Run()`.
*
* @return a future that will be satisfied when the request succeeds or the
* retry policy expires. In the first case, the future will contain the
* response from the service. In the second the future is satisfied with
* an exception. Note that the service only fills out the `table_name` field
* for this request.
*
* @par Idempotency
* This operation is always treated as non-idempotent.
*
* @par Thread-safety
* Two threads concurrently calling this member function on the same instance
* of this class are **not** guaranteed to work. Consider copying the object
* and using different copies in each thread.
*
* @par Example
* Use #CreateTable()
*/
GOOGLE_CLOUD_CPP_BIGTABLE_ADMIN_ASYNC_DEPRECATED
future<StatusOr<google::bigtable::admin::v2::Table>> AsyncCreateTable(
CompletionQueue& cq, std::string table_id, TableConfig config);
/**
* Return all the tables in the instance.
*
* @param view define what information about the tables is retrieved.
* - `VIEW_UNSPECIFIED`: equivalent to `VIEW_SCHEMA`.
* - `NAME`: return only the name of the table.
* - `VIEW_SCHEMA`: return the name and the schema.
* - `FULL`: return all the information about the table.
*
* @par Idempotency
* This operation is read-only and therefore it is always idempotent.
*
* @par Thread-safety
* Two threads concurrently calling this member function on the same instance
* of this class are **not** guaranteed to work. Consider copying the object
* and using different copies in each thread.
*
* @par Example
* @snippet table_admin_snippets.cc list tables
*/
StatusOr<std::vector<::google::bigtable::admin::v2::Table>> ListTables(
::google::bigtable::admin::v2::Table::View view);
/**
* Sends an asynchronous request to get all the tables in the instance.
*
* @warning This is an early version of the asynchronous APIs for Cloud
* Bigtable. These APIs might be changed in backward-incompatible ways. It
* is not subject to any SLA or deprecation policy.
*
* @param cq the completion queue that will execute the asynchronous calls,
* the application must ensure that one or more threads are blocked on
* `cq.Run()`.
* @param view describes how much information to get about the name.
* - VIEW_UNSPECIFIED: equivalent to VIEW_SCHEMA.
* - NAME: return only the name of the table.
* - VIEW_SCHEMA: return the name and the schema.
* - FULL: return all the information about the table.
*
* @return a future that will be satisfied when the request succeeds or the
* retry policy expires. In the first case, the future will contain the
* response from the service. In the second the future is satisfied with
* an exception.
*
* @par Idempotency
* This operation is read-only and therefore it is always idempotent.
*
* @par Thread-safety
* Two threads concurrently calling this member function on the same instance
* of this class are **not** guaranteed to work. Consider copying the object
* and using different copies in each thread.
*
* @par Example
* Use #ListTables()
*/
GOOGLE_CLOUD_CPP_BIGTABLE_ADMIN_ASYNC_DEPRECATED
future<StatusOr<std::vector<::google::bigtable::admin::v2::Table>>>
AsyncListTables(CompletionQueue& cq,
google::bigtable::admin::v2::Table::View view);
/**
* Get information about a single table.
*
* @param table_id the id of the table within the instance associated with
* this object. The full name of the table is
* `this->instance_name() + "/tables/" + table_id`
* @param view describes how much information to get about the name.
* - VIEW_UNSPECIFIED: equivalent to VIEW_SCHEMA.
* - NAME: return only the name of the table.
* - VIEW_SCHEMA: return the name and the schema.
* - FULL: return all the information about the table.
* @return the information about the table or status.
*
* @par Idempotency
* This operation is read-only and therefore it is always idempotent.
*
* @par Thread-safety
* Two threads concurrently calling this member function on the same instance
* of this class are **not** guaranteed to work. Consider copying the object
* and using different copies in each thread.
*
* @par Example
* @snippet table_admin_snippets.cc get table
*/
StatusOr<::google::bigtable::admin::v2::Table> GetTable(
std::string const& table_id, TableView view = SCHEMA_VIEW);
/**
* Sends an asynchronous request to get information about an existing table.
*
* @warning This is an early version of the asynchronous APIs for Cloud
* Bigtable. These APIs might be changed in backward-incompatible ways. It
* is not subject to any SLA or deprecation policy.
*
* @param table_id the id of the table within the instance associated with
* this object. The full name of the table is
* `this->instance_name() + "/tables/" + table_id`
* @param view describes how much information to get about the name.
* - VIEW_UNSPECIFIED: equivalent to VIEW_SCHEMA.
* - NAME: return only the name of the table.
* - VIEW_SCHEMA: return the name and the schema.
* - FULL: return all the information about the table.
* @param cq the completion queue that will execute the asynchronous calls,
* the application must ensure that one or more threads are blocked on
* `cq.Run()`.
*
* @return a future that will be satisfied when the request succeeds or the
* retry policy expires. In the first case, the future will contain the
* response from the service. In the second the future is satisfied with
* an exception.
*
* @par Idempotency
* This operation is read-only and therefore it is always idempotent.
*
* @par Thread-safety
* Two threads concurrently calling this member function on the same instance
* of this class are **not** guaranteed to work. Consider copying the object
* and using different copies in each thread.
*
* @par Example
* Use #GetTable()
*/
GOOGLE_CLOUD_CPP_BIGTABLE_ADMIN_ASYNC_DEPRECATED
future<StatusOr<google::bigtable::admin::v2::Table>> AsyncGetTable(
CompletionQueue& cq, std::string const& table_id,
google::bigtable::admin::v2::Table::View view);
/**
* Delete a table.
*
* @param table_id the id of the table within the instance associated with
* this object. The full name of the table is
* `this->instance_name() + "/tables/" + table_id`
*
* @return status of the operation.
*
* @par Idempotency
* This operation is always treated as non-idempotent.
*
* @par Thread-safety
* Two threads concurrently calling this member function on the same instance
* of this class are **not** guaranteed to work. Consider copying the object
* and using different copies in each thread.
*
* @par Example
* @snippet table_admin_snippets.cc delete table
*/
Status DeleteTable(std::string const& table_id);
/**
* Start a request to asynchronously delete a table.
*
* @warning This is an early version of the asynchronous APIs for Cloud
* Bigtable. These APIs might be changed in backward-incompatible ways. It
* is not subject to any SLA or deprecation policy.
*
* @param cq the completion queue that will execute the asynchronous calls,
* the application must ensure that one or more threads are blocked on
* `cq.Run()`.
* @param table_id the id of the table within the instance associated with
* this object. The full name of the table is
* `this->instance_name() + "/tables/" + table_id`
*
* @return status of the operation.
*
* @par Idempotency
* This operation is always treated as non-idempotent.
*
* @par Thread-safety
* Two threads concurrently calling this member function on the same instance
* of this class are **not** guaranteed to work. Consider copying the object
* and using different copies in each thread.
*
* @par Example
* Use #DeleteTable()
*/
GOOGLE_CLOUD_CPP_BIGTABLE_ADMIN_ASYNC_DEPRECATED
future<Status> AsyncDeleteTable(CompletionQueue& cq,
std::string const& table_id);
/**
* Parameters for `CreateBackup` and `AsyncCreateBackup`.
*
* @param cluster_id the name of the cluster relative to the instance managed
* by the `TableAdmin` object. The full cluster name is
* `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<cluster_id>`
* where PROJECT_ID is obtained from the associated AdminClient and
* INSTANCE_ID is the instance_id() of the `TableAdmin` object.
* @param backup_id the name of the backup relative to the cluster specified.
* The full backup name is
* `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<CLUSTER_ID>/backups/<backup_id>`
* where PROJECT_ID is obtained from the associated AdminClient,
* INSTANCE_ID is the instance_id() of the `TableAdmin` object, and
* CLUSTER_ID is the cluster_id specified for this object.
* @param table_id the id of the table within the instance to be backed up.
* The full name of the table is
* `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/tables/<table_id>`
* where PROJECT_ID is obtained from the associated AdminClient and
* INSTANCE_ID is the instance_id() of the `TableAdmin` object.
* @param expire_time the date and time when the created backup will expire.
*/
struct CreateBackupParams {
CreateBackupParams() = default;
CreateBackupParams(std::string cluster_id, std::string backup_id,
std::string table_id,
std::chrono::system_clock::time_point expire_time)
: cluster_id(std::move(cluster_id)),
backup_id(std::move(backup_id)),
table_name(std::move(table_id)),
expire_time(std::move(expire_time)) {}
google::bigtable::admin::v2::CreateBackupRequest AsProto(
std::string instance_name) const;
std::string cluster_id;
std::string backup_id;
std::string table_name;
std::chrono::system_clock::time_point expire_time;
};
/**
* Create a new backup of a table in the instance.
*
* @param params instance of `CreateBackupParams`.
*
* @par Idempotency
* This operation is always treated as non-idempotent.
*
* @par Thread-safety
* Two threads concurrently calling this member function on the same instance
* of this class are **not** guaranteed to work. Consider copying the object
* and using different copies in each thread.
*
* @par Example
* @snippet bigtable_table_admin_backup_snippets.cc create backup
*/
StatusOr<google::bigtable::admin::v2::Backup> CreateBackup(
CreateBackupParams const& params);
/**
* Sends an asynchronous request to create a new backup of a table in the
* instance.
*
* @warning This is an early version of the asynchronous APIs for Cloud
* Bigtable. These APIs might be changed in backward-incompatible ways. It
* is not subject to any SLA or deprecation policy.
*
* @param cq the completion queue that will execute the asynchronous calls,
* the application must ensure that one or more threads are blocked on
* `cq.Run()`.
* @param params instance of `CreateBackupParams`.
*
* @return a future that will be satisfied when the request succeeds or the
* retry policy expires. In the first case, the future will contain the
* response from the service. In the second case, the future is satisfied
* with an exception.
*
* @par Idempotency
* This operation is always treated as non-idempotent.
*
* @par Thread-safety
* Two threads concurrently calling this member function on the same instance
* of this class are **not** guaranteed to work. Consider copying the object
* and using different copies in each thread.
*
* @par Example
* Use #CreateBackup()
*/
GOOGLE_CLOUD_CPP_BIGTABLE_ADMIN_ASYNC_DEPRECATED
future<StatusOr<google::bigtable::admin::v2::Backup>> AsyncCreateBackup(
CompletionQueue& cq, CreateBackupParams const& params);
/**
* Get information about a single backup.
*
* @param cluster_id the name of the cluster relative to the instance managed
* by the `TableAdmin` object. The full cluster name is
* `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<cluster_id>`
* where PROJECT_ID is obtained from the associated AdminClient and
* INSTANCE_ID is the instance_id() of the `TableAdmin` object.
* @param backup_id the name of the backup relative to the cluster specified.
* The full backup name is
* `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<CLUSTER_ID>/backups/<backup_id>`
* where PROJECT_ID is obtained from the associated AdminClient,
* INSTANCE_ID is the instance_id() of the `TableAdmin` object, and
* CLUSTER_ID is the cluster_id previously specified.
*
* @par Idempotency
* This operation is read-only and therefore it is always idempotent.
*
* @par Thread-safety
* Two threads concurrently calling this member function on the same instance
* of this class are **not** guaranteed to work. Consider copying the object
* and using different copies in each thread.
*
* @par Example
* @snippet bigtable_table_admin_backup_snippets.cc get backup
*/
StatusOr<google::bigtable::admin::v2::Backup> GetBackup(
std::string const& cluster_id, std::string const& backup_id);
/**
* Sends an asynchronous request to get information about a single backup.
*
* @warning This is an early version of the asynchronous APIs for Cloud
* Bigtable. These APIs might be changed in backward-incompatible ways. It
* is not subject to any SLA or deprecation policy.
*
* @param cq the completion queue that will execute the asynchronous calls,
* the application must ensure that one or more threads are blocked on
* `cq.Run()`.
* @param cluster_id the name of the cluster relative to the instance managed
* by the `TableAdmin` object. The full cluster name is
* `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<cluster_id>`
* where PROJECT_ID is obtained from the associated AdminClient and
* INSTANCE_ID is the instance_id() of the `TableAdmin` object.
* @param backup_id the name of the backup relative to the cluster specified.
* The full backup name is
* `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<CLUSTER_ID>/backups/<backup_id>`
* where PROJECT_ID is obtained from the associated AdminClient,
* INSTANCE_ID is the instance_id() of the `TableAdmin` object, and
* CLUSTER_ID is the cluster_id previously specified.
* @return a future that will be satisfied when the request succeeds or the
* retry policy expires. In the first case, the future will contain the
* response from the service. In the second case, the future is satisfied
* with an exception.
*
* @par Idempotency
* This operation is read-only and therefore it is always idempotent.
*
* @par Thread-safety
* Two threads concurrently calling this member function on the same instance
* of this class are **not** guaranteed to work. Consider copying the object
* and using different copies in each thread.
*
* @par Example
* Use #GetBackup()
*/
GOOGLE_CLOUD_CPP_BIGTABLE_ADMIN_ASYNC_DEPRECATED
future<StatusOr<google::bigtable::admin::v2::Backup>> AsyncGetBackup(
CompletionQueue& cq, std::string const& cluster_id,
std::string const& backup_id);
/**
* Parameters for `UpdateBackup` and `AsyncUpdateBackup`.
*
* @param cluster_id the name of the cluster relative to the instance managed
* by the `TableAdmin` object. The full cluster name is
* `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<cluster_id>`
* where PROJECT_ID is obtained from the associated AdminClient and
* INSTANCE_ID is the instance_id() of the `TableAdmin` object.
* @param backup_id the name of the backup relative to the cluster specified.
* The full backup name is
* `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<CLUSTER_ID>/backups/<backup_id>`
* where PROJECT_ID is obtained from the associated AdminClient,
* INSTANCE_ID is the instance_id() of the `TableAdmin` object, and
* CLUSTER_ID is the cluster_id specified for this object.
* @param expire_time the date and time when the created backup will expire.
*/
struct UpdateBackupParams {
UpdateBackupParams() = default;
UpdateBackupParams(std::string cluster_id, std::string backup_id,
std::chrono::system_clock::time_point expire_time)
: cluster_id(std::move(cluster_id)),
backup_name(std::move(backup_id)),
expire_time(std::move(expire_time)) {}
google::bigtable::admin::v2::UpdateBackupRequest AsProto(
std::string const& instance_name) const;
std::string cluster_id;
std::string backup_name;
std::chrono::system_clock::time_point expire_time;
};
/**
* Updates a backup of a table in the instance.
*
* @param params instance of `UpdateBackupParams`.
*
* @par Idempotency
* This operation is always treated as non-idempotent.
*
* @par Thread-safety
* Two threads concurrently calling this member function on the same instance
* of this class are **not** guaranteed to work. Consider copying the object
* and using different copies in each thread.
*
* @par Example
* @snippet bigtable_table_admin_backup_snippets.cc update backup
*/
StatusOr<google::bigtable::admin::v2::Backup> UpdateBackup(
UpdateBackupParams const& params);
/**
* Sends an asynchronous request to update a backup of a table in the
* instance.
*
* @warning This is an early version of the asynchronous APIs for Cloud
* Bigtable. These APIs might be changed in backward-incompatible ways. It
* is not subject to any SLA or deprecation policy.
*
* @param cq the completion queue that will execute the asynchronous calls,
* the application must ensure that one or more threads are blocked on
* `cq.Run()`.
* @param params instance of `UpdateBackupParams`.
*
* @return a future that will be satisfied when the request succeeds or the
* retry policy expires. In the first case, the future will contain the
* response from the service. In the second case, the future is satisfied
* with an exception.
*
* @par Idempotency
* This operation is always treated as non-idempotent.
*
* @par Thread-safety
* Two threads concurrently calling this member function on the same instance
* of this class are **not** guaranteed to work. Consider copying the object
* and using different copies in each thread.
*
* @par Example
* Use #UpdateBackup()
*/
GOOGLE_CLOUD_CPP_BIGTABLE_ADMIN_ASYNC_DEPRECATED
future<StatusOr<google::bigtable::admin::v2::Backup>> AsyncUpdateBackup(
CompletionQueue& cq, UpdateBackupParams const& params);
/**
* Delete a backup.
*
* @param cluster_id the name of the cluster relative to the instance managed
* by the `TableAdmin` object. The full cluster name is
* `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<cluster_id>`
* where PROJECT_ID is obtained from the associated AdminClient and
* INSTANCE_ID is the instance_id() of the `TableAdmin` object.
* @param backup_id the name of the backup relative to the cluster specified.
* The full backup name is
* `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<CLUSTER_ID>/backups/<backup_id>`
* where PROJECT_ID is obtained from the associated AdminClient,
* INSTANCE_ID is the instance_id() of the `TableAdmin` object, and
* CLUSTER_ID is the cluster_id previously specified.
*
* @par Idempotency
* This operation is always treated as non-idempotent.
*
* @par Thread-safety
* Two threads concurrently calling this member function on the same instance
* of this class are **not** guaranteed to work. Consider copying the object
* and using different copies in each thread.
*
* @par Example
* @snippet bigtable_table_admin_backup_snippets.cc delete backup
*/
Status DeleteBackup(std::string const& cluster_id,
std::string const& backup_id);
/**
* Delete a backup.
*
* @param backup typically returned by a call to `GetBackup` or `ListBackups`.
*
* @par Idempotency
* This operation is always treated as non-idempotent.
*
* @par Thread-safety
* Two threads concurrently calling this member function on the same instance
* of this class are **not** guaranteed to work. Consider copying the object
* and using different copies in each thread.
*
* @par Example
* @snippet bigtable_table_admin_backup_snippets.cc delete backup
*/
Status DeleteBackup(google::bigtable::admin::v2::Backup const& backup);
/**
* Sends an asynchronous request to delete a backup.
*
* @warning This is an early version of the asynchronous APIs for Cloud
* Bigtable. These APIs might be changed in backward-incompatible ways. It
* is not subject to any SLA or deprecation policy.
*
* @param cq the completion queue that will execute the asynchronous calls,
* the application must ensure that one or more threads are blocked on
* `cq.Run()`.
* @param cluster_id the name of the cluster relative to the instance managed
* by the `TableAdmin` object. The full cluster name is
* `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<cluster_id>`
* where PROJECT_ID is obtained from the associated AdminClient and
* INSTANCE_ID is the instance_id() of the `TableAdmin` object.
* @param backup_id the name of the backup relative to the cluster specified.
* The full backup name is
* `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<CLUSTER_ID>/backups/<backup_id>`
* where PROJECT_ID is obtained from the associated AdminClient,
* INSTANCE_ID is the instance_id() of the `TableAdmin` object, and
* CLUSTER_ID is the cluster_id previously specified.
* @return a future that will be satisfied when the request succeeds or the
* retry policy expires. In the first case, the future will contain the
* response from the service. In the second case, the future is satisfied
* with an exception.
*
* @par Idempotency
* This operation is always treated as non-idempotent.
*
* @par Thread-safety
* Two threads concurrently calling this member function on the same instance
* of this class are **not** guaranteed to work. Consider copying the object
* and using different copies in each thread.
*
* @par Example
* Use #DeleteBackup()
*/
GOOGLE_CLOUD_CPP_BIGTABLE_ADMIN_ASYNC_DEPRECATED
future<Status> AsyncDeleteBackup(CompletionQueue& cq,
std::string const& cluster_id,
std::string const& backup_id);
/**
* Sends an asynchronous request to delete a backup.
*
* @warning This is an early version of the asynchronous APIs for Cloud
* Bigtable. These APIs might be changed in backward-incompatible ways. It
* is not subject to any SLA or deprecation policy.
*
* @param cq the completion queue that will execute the asynchronous calls,
* the application must ensure that one or more threads are blocked on
* `cq.Run()`.
* @param backup typically returned by a call to `GetBackup` or `ListBackups`.
*
* @return a future that will be satisfied when the request succeeds or the
* retry policy expires. In the first case, the future will contain the
* response from the service. In the second case, the future is satisfied
* with an exception.
*
* @par Idempotency
* This operation is always treated as non-idempotent.
*
* @par Thread-safety
* Two threads concurrently calling this member function on the same instance
* of this class are **not** guaranteed to work. Consider copying the object
* and using different copies in each thread.
*
* @par Example
* Use #DeleteBackup()
*/
GOOGLE_CLOUD_CPP_BIGTABLE_ADMIN_ASYNC_DEPRECATED
future<Status> AsyncDeleteBackup(
CompletionQueue& cq, google::bigtable::admin::v2::Backup const& backup);
/**
* Parameters for `ListBackups` and `AsyncListBackups`.
*/
struct ListBackupsParams {
ListBackupsParams() = default;
/**
* Sets the cluster_id.
*
* @param c the name of the cluster relative to the instance
* managed by the `TableAdmin` object. If no cluster_id is specified,
* the all backups in all clusters are listed. The full cluster name is
* `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<cluster_id>`
* where PROJECT_ID is obtained from the associated AdminClient and
* INSTANCE_ID is the instance_id() of the `TableAdmin` object.
*/
ListBackupsParams& set_cluster(std::string c) {
this->cluster_id = std::move(c);
return *this;
}
/**
* Sets the filtering expression.
*
* @param f expression that filters backups listed in the response.
* The expression must specify the field name, a comparison operator,
* and the value that you want to use for filtering. The value must be a
* string, a number, or a boolean. The comparison operator must be
* <, >, <=, >=, !=, =, or :. Colon ‘:’ represents a HAS operator which
* is roughly synonymous with equality. Filter rules are case
* insensitive.
*
* The fields eligible for filtering are:
* * `name`
* * `table`
* * `state`
* * `start_time` (and values are of the format
* `YYYY-MM-DDTHH:MM:SSZ`)
* * `end_time` (and values are of the format `YYYY-MM-DDTHH:MM:SSZ`)
* * `expire_time` (and values are of the format
* `YYYY-MM-DDTHH:MM:SSZ`)
* * `size_bytes`
*
* To filter on multiple expressions, provide each separate expression
* within parentheses. By default, each expression is an AND expression.
* However, you can include AND, OR, and NOT expressions explicitly.
*
* Some examples of using filters are:
* * `name:"exact"` --> The backup's name is the string "exact".
* * `name:howl` --> The backup's name contains the string "howl".
* * `table:prod` --> The table's name contains the string "prod".
* * `state:CREATING` --> The backup is pending creation.
* * `state:READY` --> The backup is fully created and ready for use.
* * `(name:howl) AND (start_time < \"2018-03-28T14:50:00Z\")`
* --> The backup name contains the string "howl" and start_time
* of the backup is before `2018-03-28T14:50:00Z`.
* * `size_bytes > 10000000000` --> The backup's size is greater than
* 10GB
*/
ListBackupsParams& set_filter(std::string f) {
this->filter = std::move(f);
return *this;
}
/**
* Sets the ordering expression.
*
* @param o expression for specifying the sort order of the results
* of the request. The string value should specify only one field in
* `google::bigtable::admin::v2::Backup`.
* The following field names are supported:
* * name
* * table
* * expire_time
* * start_time
* * end_time
* * size_bytes
* * state
*
* For example, "start_time". The default sorting order is ascending.
* Append the " desc" suffix to the field name to sort descending, e.g.
* "start_time desc". Redundant space characters in the syntax are
* insignificant.
*
* If order_by is empty, results will be sorted by `start_time` in
* descending order starting from the most recently created backup.
*/
ListBackupsParams& set_order_by(std::string o) {
this->order_by = std::move(o);
return *this;
}
google::bigtable::admin::v2::ListBackupsRequest AsProto(
std::string const& instance_name) const;
absl::optional<std::string> cluster_id;
absl::optional<std::string> filter;
absl::optional<std::string> order_by;
};
/**
* Retrieves a list of backups.
*
* @param params instance of `ListBackupsParams`.
*
* @par Idempotency
* This operation is read-only and therefore it is always idempotent.
*
* @par Thread-safety
* Two threads concurrently calling this member function on the same instance
* of this class are **not** guaranteed to work. Consider copying the object
* and using different copies in each thread.
*
* @par Example
* @snippet bigtable_table_admin_backup_snippets.cc list backups
*/
StatusOr<std::vector<google::bigtable::admin::v2::Backup>> ListBackups(
ListBackupsParams const& params);
/**
* Sends an asynchronous request to retrieve a list of backups.
*
* @warning This is an early version of the asynchronous APIs for Cloud
* Bigtable. These APIs might be changed in backward-incompatible ways. It
* is not subject to any SLA or deprecation policy.
*
* @param cq the completion queue that will execute the asynchronous calls,
* the application must ensure that one or more threads are blocked on
* `cq.Run()`.
* @param params instance of `ListBackupsParams`.
*
* @return a future that will be satisfied when the request succeeds or the
* retry policy expires. In the first case, the future will contain the
* response from the service. In the second case, the future is satisfied
* with an exception.
*
* @par Idempotency
* This operation is read-only and therefore it is always idempotent.
*
* @par Thread-safety
* Two threads concurrently calling this member function on the same instance
* of this class are **not** guaranteed to work. Consider copying the object
* and using different copies in each thread.
*
* @par Example
* Use #ListBackups()
*/
GOOGLE_CLOUD_CPP_BIGTABLE_ADMIN_ASYNC_DEPRECATED
future<StatusOr<std::vector<google::bigtable::admin::v2::Backup>>>
AsyncListBackups(CompletionQueue& cq, ListBackupsParams const& params);
/**
* Parameters for `RestoreTable` and `AsyncRestoreTable`.
*
* @param table_id the name of the table relative to the instance managed by
* this object. The full table name is
* `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/tables/<table_id>`
* where PROJECT_ID is obtained from the associated AdminClient and
* INSTANCE_ID is the instance_id() of this object.
* @param cluster_id the name of the cluster relative to the instance managed
* by the `TableAdmin` object. The full cluster name is
* `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<cluster_id>`
* where PROJECT_ID is obtained from the associated AdminClient and
* INSTANCE_ID is the instance_id() of the `TableAdmin` object.
* @param backup_id the name of the backup relative to the cluster specified.
* The full backup name is
* `projects/<PROJECT_ID>/instances/<INSTANCE_ID>/clusters/<CLUSTER_ID>/backups/<backup_id>`
* where PROJECT_ID is obtained from the associated AdminClient,
* INSTANCE_ID is the instance_id() of the `TableAdmin` object, and