15#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_TABLE_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_TABLE_H
18#include "google/cloud/bigtable/completion_queue.h"
19#include "google/cloud/bigtable/data_client.h"
20#include "google/cloud/bigtable/data_connection.h"
21#include "google/cloud/bigtable/filters.h"
22#include "google/cloud/bigtable/idempotent_mutation_policy.h"
23#include "google/cloud/bigtable/internal/defaults.h"
24#include "google/cloud/bigtable/internal/legacy_async_row_reader.h"
25#include "google/cloud/bigtable/mutation_branch.h"
26#include "google/cloud/bigtable/mutations.h"
27#include "google/cloud/bigtable/options.h"
28#include "google/cloud/bigtable/read_modify_write_rule.h"
29#include "google/cloud/bigtable/resource_names.h"
30#include "google/cloud/bigtable/row_key_sample.h"
31#include "google/cloud/bigtable/row_reader.h"
32#include "google/cloud/bigtable/row_set.h"
33#include "google/cloud/bigtable/rpc_backoff_policy.h"
34#include "google/cloud/bigtable/rpc_retry_policy.h"
35#include "google/cloud/bigtable/table_resource.h"
36#include "google/cloud/bigtable/version.h"
37#include "google/cloud/future.h"
38#include "google/cloud/grpc_error_delegate.h"
39#include "google/cloud/internal/group_options.h"
40#include "google/cloud/options.h"
41#include "google/cloud/status.h"
42#include "google/cloud/status_or.h"
43#include "absl/meta/type_traits.h"
50GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
55
56
57
58
59
60
61
62
64 std::string
const& table_id) {
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
172 template <
typename P>
179 template <
typename... Policies>
180 struct ValidPolicies : absl::conjunction<ValidPolicy<Policies>...> {};
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
208 : table_(std::move(tr)),
210 connection_(std::move(conn)),
211 options_(
google::
cloud::internal::MergeOptions(std::move(options),
213 metadata_update_policy_(bigtable_internal::MakeMetadataUpdatePolicy(
216 std::string
const&
table_name()
const {
return table_name_; }
229
230
231
232
233
235 std::string table_id)
const {
238 std::move(table_id)
);
240 table.metadata_update_policy_
= bigtable_internal::MakeMetadataUpdatePolicy(
246
247
248
250 std::string app_profile_id, std::string table_id)
const {
253 std::move(table_id)
);
256 table.metadata_update_policy_
= bigtable_internal::MakeMetadataUpdatePolicy(
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
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
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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
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
495 std::string row_key,
Filter filter, std::vector<
Mutation> true_mutations,
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
524 std::string row_key,
Filter filter, std::vector<
Mutation> true_mutations,
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
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 template <
typename... Args>
605 Args&&... rules_and_options) {
606 ::
google::bigtable::v2::ReadModifyWriteRowRequest request;
607 request.set_row_key(std::move(row_key));
612 absl::conjunction<absl::disjunction<
614 std::is_same<
typename std::decay<Args>::type,
Options>>...>::value,
615 "The arguments passed to ReadModifyWriteRow(row_key,...) must be "
616 "convertible to bigtable::ReadModifyWriteRule, or of type "
617 "google::cloud::Options");
620 AddRules(request, std::forward<Args>(rules_and_options)...);
622 std::forward<Args>(rules_and_options)...);
623 return ReadModifyWriteRowImpl(std::move(request), std::move(opts));
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 template <
typename... Args>
659 Args&&... rules_and_options) {
660 ::
google::bigtable::v2::ReadModifyWriteRowRequest request;
661 request.set_row_key(std::move(row_key));
666 absl::conjunction<absl::disjunction<
668 std::is_same<
typename std::decay<Args>::type,
Options>>...>::value,
669 "The arguments passed to AsyncReadModifyWriteRow(row_key,...) must be "
670 "convertible to bigtable::ReadModifyWriteRule, or of type "
671 "google::cloud::Options");
674 AddRules(request, std::forward<Args>(rules_and_options)...);
676 std::forward<Args>(rules_and_options)...);
677 return AsyncReadModifyWriteRowImpl(std::move(request), std::move(opts));
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 template <
typename RowFunctor,
typename FinishFunctor>
711 AsyncReadRows(std::move(on_row), std::move(on_finish), std::move(row_set),
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 template <
typename RowFunctor,
typename FinishFunctor>
749 void AsyncReadRows(RowFunctor on_row, FinishFunctor on_finish,
755 "RowFunctor must be invocable with Row.");
758 "FinishFunctor must be invocable with Status.");
763 "RowFunctor should return a future<bool>.");
765 auto on_row_ptr = std::make_shared<RowFunctor>(std::move(on_row));
767 auto on_row_fn = [on_row_ptr](
Row row) {
768 return (*on_row_ptr)(std::move(row));
771 auto on_finish_ptr = std::make_shared<FinishFunctor>(std::move(on_finish));
773 auto on_finish_fn = [on_finish_ptr](
Status status) {
774 return (*on_finish_ptr)(std::move(status));
779 google::
cloud::internal::MergeOptions(std::move(opts), options_));
781 std::move(on_finish_fn)
, std::move(row_set)
,
782 rows_limit
, std::move(filter)
);
788 "Per-operation options only apply to `Table`s constructed "
789 "with a `DataConnection`."));
793 bigtable_internal::LegacyAsyncRowReader::Create(
795 std::move(on_row_fn), std::move(on_finish_fn), std::move(row_set),
796 rows_limit, std::move(filter), clone_rpc_retry_policy(),
797 clone_rpc_backoff_policy(), metadata_update_policy_,
798 std::make_unique<
bigtable::internal::ReadRowsParserFactory>());
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
833
834
835
836
837
838
839
840
841
842
843
845 :
Table(std::move(client)
, std::string{}
, table_id
) {}
848
849
850
851
852
853
854
855
856
857
858
859
860
862 std::string
const& table_id)
863 : client_(std::move(client)),
866 rpc_retry_policy_prototype_(
868 rpc_backoff_policy_prototype_(
870 idempotent_mutation_policy_(
874 metadata_update_policy_(bigtable_internal::MakeMetadataUpdatePolicy(
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
929 typename... Policies,
931 typename std::enable_if<ValidPolicies<Policies...>::value,
int>::type = 0
935 Policies&&... policies)
936 :
Table(std::move(client), table_id) {
937 ChangePolicies(std::forward<Policies>(policies)...);
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
993 typename... Policies,
995 typename std::enable_if<ValidPolicies<Policies...>::value,
int>::type = 0
999 std::string
const& table_id, Policies&&... policies)
1000 :
Table(std::move(client), std::move(app_profile_id), table_id) {
1001 ChangePolicies(std::forward<Policies>(policies)...);
1006
1007
1008 StatusOr<
Row> ReadModifyWriteRowImpl(
1009 ::
google::bigtable::v2::ReadModifyWriteRowRequest request,
Options opts);
1011 future<StatusOr<
Row>> AsyncReadModifyWriteRowImpl(
1012 ::
google::bigtable::v2::ReadModifyWriteRowRequest request,
Options opts);
1014 void AddRules(
google::bigtable::v2::ReadModifyWriteRowRequest&) {
1018 template <
typename... Args>
1019 void AddRules(
google::bigtable::v2::ReadModifyWriteRowRequest& request,
1021 *request.add_rules() = std::move(rule)
.as_proto();
1022 AddRules(request, std::forward<Args>(args)...);
1025 template <
typename... Args>
1026 void AddRules(
google::bigtable::v2::ReadModifyWriteRowRequest& request,
1027 Options const&, Args&&... args) {
1028 AddRules(request, std::forward<Args>(args)...);
1032 return rpc_retry_policy_prototype_->
clone();
1036 return rpc_backoff_policy_prototype_->
clone();
1040 return metadata_update_policy_;
1044 return idempotent_mutation_policy_->
clone();
1050 rpc_retry_policy_prototype_ = policy
.clone();
1054 rpc_backoff_policy_prototype_ = policy
.clone();
1058 idempotent_mutation_policy_ = policy
.clone();
1061 template <
typename Policy,
typename... Policies>
1062 void ChangePolicies(Policy&& policy, Policies&&... policies) {
1063 ChangePolicy(policy);
1064 ChangePolicies(std::forward<Policies>(policies)...);
1066 void ChangePolicies() {}
1072 std::string table_name_;
1073 std::shared_ptr<
RPCRetryPolicy const> rpc_retry_policy_prototype_;
1082GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
virtual CompletionQueue cq() const=0
ValueTypeT< T > const & get() const
Options & set(ValueTypeT< T > v)
Options(Options const &rhs)
Status(StatusCode code, std::string message, ErrorInfo info={})
Represent a set of mutations across multiple rows.
Definition: mutations.h:492
Connects to Cloud Bigtable's data manipulation APIs.
Definition: data_client.h:66
virtual std::string const & instance_id() const =0
virtual std::string const & project_id() const =0
virtual google::cloud::BackgroundThreadsFactory BackgroundThreadsFactory()=0
The thread factory this client was created with.
A connection to the Cloud Bigtable Data API.
Definition: data_connection.h:88
virtual Options options()
Definition: data_connection.h:92
virtual void AsyncReadRows(std::string const &table_name, std::function< future< bool >(Row)> on_row, std::function< void(Status)> on_finish, RowSet row_set, std::int64_t rows_limit, Filter filter)
A SingleRowMutation that failed.
Definition: mutations.h:409
Define the interfaces to create filter expressions.
Definition: filters.h:52
Defines the interface to control which mutations are idempotent and therefore can be re-tried.
Definition: idempotent_mutation_policy.h:31
virtual std::unique_ptr< IdempotentMutationPolicy > clone() const =0
Return a copy of the policy.
std::string const & instance_id() const
Returns the Instance ID.
Definition: instance_resource.h:58
std::string const & project_id() const
Definition: instance_resource.h:55
Objects of this class pack single row mutations into bulk mutations.
Definition: mutation_batcher.h:56
Define the interface for controlling how the Bigtable client backsoff from failed RPC operations.
Definition: rpc_backoff_policy.h:44
virtual std::unique_ptr< RPCBackoffPolicy > clone() const =0
Return a new copy of this object.
Define the interface for controlling how the Bigtable client retries RPC operations.
Definition: rpc_retry_policy.h:78
virtual std::unique_ptr< RPCRetryPolicy > clone() const =0
Return a new copy of this object.
Define the interfaces to create ReadWriteModifyRule operations.
Definition: read_modify_write_rule.h:37
google::bigtable::v2::ReadModifyWriteRule && as_proto() &&
Move out the underlying protobuf value.
Definition: read_modify_write_rule.h:82
Object returned by Table::ReadRows(), enumerates rows in the response.
Definition: row_reader.h:54
static std::int64_t constexpr NO_ROWS_LIMIT
A constant for the magic value that means "no limit, get all rows".
Definition: row_reader.h:63
Represent a (possibly non-continuous) set of row keys.
Definition: row_set.h:33
The in-memory representation of a Bigtable row.
Definition: row.h:34
Represent a single row mutation.
Definition: mutations.h:296
This class identifies a Cloud Bigtable Table.
Definition: table_resource.h:44
TableResource(std::string project_id, std::string instance_id, std::string table_id)
Constructs a TableResource object identified by the given IDs.
std::string const & table_id() const
Returns the Table ID.
Definition: table_resource.h:66
std::string FullName() const
Returns the fully qualified table name as a string of the form: "projects/<project-id>/instances/<ins...
InstanceResource const & instance() const
Returns the InstanceResource containing this table.
Definition: table_resource.h:63
The main interface to interact with data in a Cloud Bigtable table.
Definition: table.h:166
std::string const & table_name() const
Definition: table.h:216
RowReader ReadRows(RowSet row_set, std::int64_t rows_limit, Filter filter, Options opts={})
Reads a limited set of rows from the table.
Table(std::shared_ptr< DataClient > client, std::string app_profile_id, std::string const &table_id, Policies &&... policies)
Constructor with explicit policies.
Definition: table.h:998
Table(std::shared_ptr< DataClient > client, std::string app_profile_id, std::string const &table_id)
Constructor with default policies.
Definition: table.h:861
Table(std::shared_ptr< DataClient > client, std::string const &table_id, Policies &&... policies)
Constructor with explicit policies.
Definition: table.h:934
future< std::vector< FailedMutation > > AsyncBulkApply(BulkMutation mut, Options opts={})
Makes asynchronous attempts to apply mutations to multiple rows.
RowReader ReadRows(RowSet row_set, Filter filter, Options opts={})
Reads a set of rows from the table.
std::string const & project_id() const
Definition: table.h:220
Table WithNewTarget(std::string project_id, std::string instance_id, std::string app_profile_id, std::string table_id) const
Returns a Table that reuses the connection and configuration of this Table, but with a different reso...
Definition: table.h:249
std::string const & instance_id() const
Definition: table.h:223
StatusOr< std::vector< bigtable::RowKeySample > > SampleRows(Options opts={})
Sample of the row keys in the table, including approximate data sizes.
Table WithNewTarget(std::string project_id, std::string instance_id, std::string table_id) const
Returns a Table that reuses the connection and configuration of this Table, but with a different reso...
Definition: table.h:234
void AsyncReadRows(RowFunctor on_row, FinishFunctor on_finish, RowSet row_set, Filter filter, Options opts={})
Asynchronously reads a set of rows from the table.
Definition: table.h:709
StatusOr< Row > ReadModifyWriteRow(std::string row_key, bigtable::ReadModifyWriteRule rule, Args &&... rules_and_options)
Atomically read and modify the row in the server, returning the resulting row.
Definition: table.h:603
future< Status > AsyncApply(SingleRowMutation mut, Options opts={})
Makes asynchronous attempts to apply the mutation to a row.
future< StatusOr< std::pair< bool, Row > > > AsyncReadRow(std::string row_key, Filter filter, Options opts={})
Asynchronously read and return a single row from the table.
Table(std::shared_ptr< bigtable::DataConnection > conn, TableResource tr, Options options={})
Constructs a Table object.
Definition: table.h:206
StatusOr< std::pair< bool, Row > > ReadRow(std::string row_key, Filter filter, Options opts={})
Read and return a single row from the table.
std::string const & table_id() const
Definition: table.h:226
Table(std::shared_ptr< DataClient > client, std::string const &table_id)
Constructor with default policies.
Definition: table.h:844
future< StatusOr< std::vector< bigtable::RowKeySample > > > AsyncSampleRows(Options opts={})
Asynchronously obtains a sample of the row keys in the table, including approximate data sizes.
StatusOr< MutationBranch > CheckAndMutateRow(std::string row_key, Filter filter, std::vector< Mutation > true_mutations, std::vector< Mutation > false_mutations, Options opts={})
Atomic test-and-set for a row using filter expressions.
std::string const & app_profile_id() const
Definition: table.h:217
void AsyncReadRows(RowFunctor on_row, FinishFunctor on_finish, RowSet row_set, std::int64_t rows_limit, Filter filter, Options opts={})
Asynchronously reads a set of rows from the table.
Definition: table.h:749
future< StatusOr< MutationBranch > > AsyncCheckAndMutateRow(std::string row_key, Filter filter, std::vector< Mutation > true_mutations, std::vector< Mutation > false_mutations, Options opts={})
Make an asynchronous request to conditionally mutate a row.
std::vector< FailedMutation > BulkApply(BulkMutation mut, Options opts={})
Attempts to apply mutations to multiple rows.
Status Apply(SingleRowMutation mut, Options opts={})
Attempts to apply the mutation to a row.
future< StatusOr< Row > > AsyncReadModifyWriteRow(std::string row_key, bigtable::ReadModifyWriteRule rule, Args &&... rules_and_options)
Make an asynchronous request to atomically read and modify a row.
Definition: table.h:657
friend friend class future
Contains all the Cloud Bigtable C++ client APIs.
Definition: admin_client.h:28
std::unique_ptr< RPCBackoffPolicy > DefaultRPCBackoffPolicy(internal::RPCPolicyParameters defaults)
Return an instance of the default RPCBackoffPolicy.
std::string InstanceName(std::shared_ptr< DataClient > const &client)
Return the fully qualified instance name for the client.
Definition: data_client.h:225
std::unique_ptr< RPCRetryPolicy > DefaultRPCRetryPolicy(internal::RPCPolicyParameters defaults)
Return an instance of the default RPCRetryPolicy.
MutationBranch
The branch taken by a Table::CheckAndMutateRow operation.
Definition: mutation_branch.h:26
std::string TableName(std::shared_ptr< DataClient > const &client, std::string const &table_id)
Return the full table name.
Definition: table.h:63
std::unique_ptr< IdempotentMutationPolicy > DefaultIdempotentMutationPolicy()
Return an instance of the default IdempotentMutationPolicy.
The application profile id.
Definition: options.h:75
Represent a single change to a specific row in a Table.
Definition: mutations.h:45
A simple wrapper to represent the response from Table::SampleRowKeys().
Definition: row_key_sample.h:27