-
Notifications
You must be signed in to change notification settings - Fork 1k
/
cdcsdk_ysql_test_base.cc
3115 lines (2721 loc) · 128 KB
/
cdcsdk_ysql_test_base.cc
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 (c) YugaByte, 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.
#include "yb/integration-tests/cdcsdk_ysql_test_base.h"
#include "yb/cdc/cdc_state_table.h"
namespace yb {
namespace cdc {
Result<string> CDCSDKYsqlTest::GetUniverseId(Cluster* cluster) {
yb::master::GetMasterClusterConfigRequestPB req;
yb::master::GetMasterClusterConfigResponsePB resp;
master::MasterClusterProxy master_proxy(
&cluster->client_->proxy_cache(),
VERIFY_RESULT(cluster->mini_cluster_->GetLeaderMasterBoundRpcAddr()));
rpc::RpcController rpc;
rpc.set_timeout(MonoDelta::FromSeconds(kRpcTimeout));
RETURN_NOT_OK(master_proxy.GetMasterClusterConfig(req, &resp, &rpc));
if (resp.has_error()) {
return STATUS(IllegalState, "Error getting cluster config");
}
return resp.cluster_config().cluster_uuid();
}
void CDCSDKYsqlTest::VerifyCdcStateMatches(
client::YBClient* client, const xrepl::StreamId& stream_id, const TabletId& tablet_id,
const uint64_t term, const uint64_t index) {
CDCStateTable cdc_state_table(client);
auto row = ASSERT_RESULT(cdc_state_table.TryFetchEntry(
{tablet_id, stream_id}, CDCStateTableEntrySelector().IncludeCheckpoint()));
ASSERT_TRUE(row);
LOG(INFO) << Format(
"Verifying tablet: $0, stream: $1, op_id: $2", tablet_id, stream_id,
OpId(term, index).ToString());
OpId op_id = *row->checkpoint;
ASSERT_EQ(op_id.term, term);
ASSERT_EQ(op_id.index, index);
}
Status CDCSDKYsqlTest::WriteRowsToTwoTables(
uint32_t start, uint32_t end, Cluster* cluster, bool flag, const char* const first_table_name,
const char* const second_table_name, uint32_t num_cols) {
auto conn = VERIFY_RESULT(cluster->ConnectToDB(kNamespaceName));
LOG(INFO) << "Writing " << end - start << " row(s) within transaction";
RETURN_NOT_OK(conn.Execute("BEGIN"));
for (uint32_t i = start; i < end; ++i) {
uint32_t value = i;
std::stringstream statement_buff;
statement_buff << "INSERT INTO $0 VALUES (";
for (uint32_t iter = 0; iter < num_cols; ++value, ++iter) {
statement_buff << value << ",";
}
std::string statement(statement_buff.str());
statement.at(statement.size() - 1) = ')';
RETURN_NOT_OK(conn.ExecuteFormat(statement, first_table_name));
RETURN_NOT_OK(conn.ExecuteFormat(statement, second_table_name));
}
if (flag) {
RETURN_NOT_OK(conn.Execute("COMMIT"));
} else {
RETURN_NOT_OK(conn.Execute("ABORT"));
}
return Status::OK();
}
void CDCSDKYsqlTest::VerifyStreamDeletedFromCdcState(
client::YBClient* client, const xrepl::StreamId& stream_id, const TabletId& tablet_id,
int timeout_secs) {
CDCStateTable cdc_state_table(client);
// The deletion of cdc_state rows for the specified stream happen in an asynchronous thread,
// so even if the request has returned, it doesn't mean that the rows have been deleted yet.
ASSERT_OK(WaitFor(
[&]() -> Result<bool> {
auto row = VERIFY_RESULT(cdc_state_table.TryFetchEntry({tablet_id, stream_id}));
return !row;
},
MonoDelta::FromSeconds(timeout_secs),
"Failed to delete stream rows from cdc_state table."));
}
Result<OpId> CDCSDKYsqlTest::GetStreamCheckpointInCdcState(
client::YBClient* client, const xrepl::StreamId& stream_id, const TabletId& tablet_id) {
CDCStateTable cdc_state_table(client);
auto row = VERIFY_RESULT(cdc_state_table.TryFetchEntry(
{tablet_id, stream_id}, CDCStateTableEntrySelector().IncludeCheckpoint()));
SCHECK(row, IllegalState, "Row not found in cdc_state table");
return *row->checkpoint;
}
void CDCSDKYsqlTest::VerifyStreamCheckpointInCdcState(
client::YBClient* client, const xrepl::StreamId& stream_id, const TabletId& tablet_id,
OpIdExpectedValue op_id_expected_value, int timeout_secs) {
CDCStateTable cdc_state_table(client);
ASSERT_OK(WaitFor(
[&]() -> Result<bool> {
auto row = VERIFY_RESULT(cdc_state_table.TryFetchEntry(
{tablet_id, stream_id}, CDCStateTableEntrySelector().IncludeCheckpoint()));
if (!row) {
return false;
}
SCHECK(
row->checkpoint, IllegalState, "Checkpoint not set in cdc_state table row: $0",
row->ToString());
auto& op_id = *row->checkpoint;
switch (op_id_expected_value) {
case OpIdExpectedValue::MaxOpId:
if (op_id == OpId::Max()) return true;
break;
case (OpIdExpectedValue::InvalidOpId):
if (op_id == OpId::Invalid()) return true;
break;
case (OpIdExpectedValue::ValidNonMaxOpId):
if (op_id.valid() && op_id != OpId::Max()) return true;
break;
default:
break;
}
return false;
},
MonoDelta::FromSeconds(timeout_secs),
"Checkpoint not OpId::Max in cdc_state table."));
}
void CDCSDKYsqlTest::VerifyTransactionParticipant(const TabletId& tablet_id, const OpId& opid) {
ASSERT_OK(WaitFor(
[&]() -> Result<bool> {
for (size_t i = 0; i < test_cluster()->num_tablet_servers(); ++i) {
for (const auto& peer : test_cluster()->GetTabletPeers(i)) {
if (peer->tablet_id() == tablet_id) {
LOG(INFO) << "Tablet peer cdc_sdk_min_checkpoint_op_id: "
<< peer->cdc_sdk_min_checkpoint_op_id();
if (peer->cdc_sdk_min_checkpoint_op_id() == opid) {
return true;
}
}
}
}
return false;
},
MonoDelta::FromSeconds(60),
"The cdc_sdk_min_checkpoint_op_id doesn't match with expected op_id."));
}
Status CDCSDKYsqlTest::DropDB(Cluster* cluster) {
const std::string db_name = "testdatabase";
RETURN_NOT_OK(CreateDatabase(&test_cluster_, db_name, true));
auto conn = VERIFY_RESULT(cluster->ConnectToDB(db_name));
RETURN_NOT_OK(conn.ExecuteFormat("DROP DATABASE $0", kNamespaceName));
return Status::OK();
}
Status CDCSDKYsqlTest::TruncateTable(Cluster* cluster, const std::vector<string>& table_ids) {
RETURN_NOT_OK(cluster->client_->TruncateTables(table_ids));
return Status::OK();
}
// The range is exclusive of end i.e. [start, end)
Status CDCSDKYsqlTest::WriteRows(
uint32_t start, uint32_t end, Cluster* cluster,
const vector<string>& optional_cols_name) {
auto conn = VERIFY_RESULT(cluster->ConnectToDB(kNamespaceName));
LOG(INFO) << "Writing " << end - start << " row(s)";
for (uint32_t i = start; i < end; ++i) {
if (!optional_cols_name.empty()) {
std::stringstream columns_name;
std::stringstream columns_value;
columns_name << "( " << kKeyColumnName << "," << kValueColumnName;
columns_value << "( " << i << "," << i + 1;
for (const auto& optional_col_name : optional_cols_name) {
columns_name << ", " << optional_col_name;
columns_value << "," << i + 1;
}
columns_name << " )";
columns_value << " )";
RETURN_NOT_OK(conn.ExecuteFormat(
"INSERT INTO $0 $1 VALUES $2", kTableName, columns_name.str(), columns_value.str()));
} else {
RETURN_NOT_OK(conn.ExecuteFormat(
"INSERT INTO $0($1, $2) VALUES ($3, $4)", kTableName, kKeyColumnName, kValueColumnName,
i, i + 1));
}
}
return Status::OK();
}
// The range is exclusive of end i.e. [start, end)
Status CDCSDKYsqlTest::WriteRows(uint32_t start, uint32_t end, Cluster* cluster,
uint32_t num_cols) {
auto conn = VERIFY_RESULT(cluster->ConnectToDB(kNamespaceName));
LOG(INFO) << "Writing " << end - start << " row(s)";
for (uint32_t i = start; i < end; ++i) {
uint32_t value = i;
std::stringstream statement_buff;
statement_buff << "INSERT INTO $0 VALUES (";
for (uint32_t iter = 0; iter < num_cols; ++value, ++iter) {
statement_buff << value << ",";
}
std::string statement(statement_buff.str());
statement.at(statement.size() - 1) = ')';
RETURN_NOT_OK(conn.ExecuteFormat(statement, kTableName));
}
return Status::OK();
}
void CDCSDKYsqlTest::DropTable(Cluster* cluster, const char* table_name) {
auto conn = EXPECT_RESULT(cluster->ConnectToDB(kNamespaceName));
ASSERT_OK(conn.ExecuteFormat("DROP TABLE $0", table_name));
}
Status CDCSDKYsqlTest::WriteRowsHelper(
uint32_t start, uint32_t end, Cluster* cluster, bool flag, uint32_t num_cols,
const char* const table_name, const vector<string>& optional_cols_name) {
auto conn = VERIFY_RESULT(cluster->ConnectToDB(kNamespaceName));
LOG(INFO) << "Writing " << end - start << " row(s) within transaction";
RETURN_NOT_OK(conn.Execute("BEGIN"));
for (uint32_t i = start; i < end; ++i) {
if (!optional_cols_name.empty()) {
std::stringstream columns_name;
std::stringstream columns_value;
columns_name << "( " << kKeyColumnName << "," << kValueColumnName;
columns_value << "( " << i << "," << i + 1;
for (const auto& optional_col_name : optional_cols_name) {
columns_name << ", " << optional_col_name;
columns_value << "," << i + 1;
}
columns_name << " )";
columns_value << " )";
RETURN_NOT_OK(conn.ExecuteFormat(
"INSERT INTO $0 $1 VALUES $2", table_name, columns_name.str(), columns_value.str()));
} else {
uint32_t value = i;
std::stringstream statement_buff;
statement_buff << "INSERT INTO $0 VALUES (";
for (uint32_t iter = 0; iter < num_cols; ++value, ++iter) {
statement_buff << value << ",";
}
std::string statement(statement_buff.str());
statement.at(statement.size() - 1) = ')';
RETURN_NOT_OK(conn.ExecuteFormat(statement, table_name));
}
}
if (flag) {
RETURN_NOT_OK(conn.Execute("COMMIT"));
} else {
RETURN_NOT_OK(conn.Execute("ABORT"));
}
return Status::OK();
}
Status CDCSDKYsqlTest::CreateTableWithoutPK(Cluster* cluster) {
auto conn = VERIFY_RESULT(cluster->ConnectToDB(kNamespaceName));
RETURN_NOT_OK(conn.ExecuteFormat("CREATE TABLE test1_no_pk(id1 int, id2 int)"));
return Status::OK();
}
Status CDCSDKYsqlTest::WriteAndUpdateRowsHelper(
uint32_t start, uint32_t end, Cluster* cluster, bool flag,
const std::multimap<uint32_t, uint32_t>& col_val_map, const std::string& table_id) {
auto conn = VERIFY_RESULT(cluster->ConnectToDB(kNamespaceName));
LOG(INFO) << "Writing " << end - start << " row(s) within transaction";
for (uint32_t i = start; i < end; ++i) {
RETURN_NOT_OK(conn.ExecuteFormat(
"INSERT INTO $0($1, $2) VALUES ($3, $4)", kTableName, kKeyColumnName, kValueColumnName, i,
i + 1));
}
RETURN_NOT_OK(test_client()->FlushTables(
{table_id}, /* add_indexes = */ false,
/* timeout_secs = */ 30, /* is_compaction = */ false));
RETURN_NOT_OK(conn.Execute("BEGIN"));
for (auto& col_value_pair : col_val_map) {
LOG(INFO) << "Updating row for key " << col_value_pair.first << " with value "
<< col_value_pair.second;
RETURN_NOT_OK(conn.ExecuteFormat(
"UPDATE $0 SET $1 = $2 WHERE $3 = $4", kTableName, kValueColumnName,
col_value_pair.second, kKeyColumnName, col_value_pair.first));
}
RETURN_NOT_OK(test_client()->FlushTables(
{table_id}, /* add_indexes = */ false,
/* timeout_secs = */ 30, /* is_compaction = */ false));
if (flag) {
RETURN_NOT_OK(conn.Execute("COMMIT"));
} else {
RETURN_NOT_OK(conn.Execute("ABORT"));
}
return Status::OK();
}
Status CDCSDKYsqlTest::CreateColocatedObjects(Cluster* cluster) {
auto conn = VERIFY_RESULT(cluster->ConnectToDB(kNamespaceName));
RETURN_NOT_OK(conn.ExecuteFormat("CREATE TABLEGROUP tg1"));
RETURN_NOT_OK(conn.ExecuteFormat("CREATE TABLE test1(id1 int primary key) TABLEGROUP tg1;"));
RETURN_NOT_OK(conn.ExecuteFormat("CREATE TABLE test2(id2 text primary key) TABLEGROUP tg1;"));
return Status::OK();
}
Status CDCSDKYsqlTest::AddColocatedTable(
Cluster* cluster, const TableName& table_name, const std::string& table_group_name) {
auto conn = VERIFY_RESULT(cluster->ConnectToDB(kNamespaceName));
RETURN_NOT_OK(conn.ExecuteFormat(
"CREATE TABLE $0(id2 text primary key) TABLEGROUP $1;", table_name, table_group_name));
return Status::OK();
}
Status CDCSDKYsqlTest::PopulateColocatedData(Cluster* cluster, int insert_count,
bool transaction) {
auto conn = VERIFY_RESULT(cluster->ConnectToDB(kNamespaceName));
if (transaction) {
RETURN_NOT_OK(conn.Execute("BEGIN"));
}
for (int i = 0; i < insert_count; ++i) {
LOG(INFO) << "Inserting entry " << i;
RETURN_NOT_OK(conn.ExecuteFormat("INSERT INTO test1 VALUES ($0)", i));
RETURN_NOT_OK(conn.ExecuteFormat("INSERT INTO test2 VALUES ('$0')", i));
}
if (transaction) {
RETURN_NOT_OK(conn.Execute("COMMIT"));
}
return Status::OK();
}
Status CDCSDKYsqlTest::WriteEnumsRows(
uint32_t start, uint32_t end, Cluster* cluster, const string& enum_suffix,
string database_name, string table_name,
string schema_name) {
auto conn = VERIFY_RESULT(cluster->ConnectToDB(database_name));
LOG(INFO) << "Writing " << end - start << " row(s) within transaction";
RETURN_NOT_OK(conn.Execute("BEGIN"));
for (uint32_t i = start; i < end; ++i) {
RETURN_NOT_OK(conn.ExecuteFormat(
"INSERT INTO $0.$1($2, $3) VALUES ($4, '$5')", schema_name, table_name + enum_suffix,
kKeyColumnName, kValueColumnName, i,
std::string(i % 2 ? "FIXED" : "PERCENTAGE") + enum_suffix));
}
RETURN_NOT_OK(conn.Execute("COMMIT"));
return Status::OK();
}
Result<YBTableName> CDCSDKYsqlTest::CreateCompositeTable(
Cluster* cluster, const uint32_t num_tablets, const std::string& type_suffix) {
auto conn = VERIFY_RESULT(cluster->ConnectToDB(kNamespaceName));
RETURN_NOT_OK(conn.ExecuteFormat(
"CREATE TYPE composite_name$0 AS (first text, last text);", type_suffix));
RETURN_NOT_OK(conn.ExecuteFormat(
"CREATE TABLE emp(id int primary key, name composite_name) "
"SPLIT INTO $0 TABLETS",
num_tablets));
return GetTable(cluster, kNamespaceName, "emp");
}
Status CDCSDKYsqlTest::WriteCompositeRows(uint32_t start, uint32_t end, Cluster* cluster) {
auto conn = VERIFY_RESULT(cluster->ConnectToDB(kNamespaceName));
LOG(INFO) << "Writing " << end - start << " row(s) within transaction";
RETURN_NOT_OK(conn.Execute("BEGIN"));
for (uint32_t i = start; i < end; ++i) {
RETURN_NOT_OK(
conn.ExecuteFormat("INSERT INTO emp(id, name) VALUES ($0, ('John', 'Doe'))", i));
}
RETURN_NOT_OK(conn.Execute("COMMIT"));
return Status::OK();
}
Result<YBTableName> CDCSDKYsqlTest::CreateNestedCompositeTable(
Cluster* cluster, const uint32_t num_tablets, const std::string& type_suffix) {
auto conn = VERIFY_RESULT(cluster->ConnectToDB(kNamespaceName));
RETURN_NOT_OK(
conn.ExecuteFormat("CREATE TYPE part_name$0 AS (first text, middle text);", type_suffix));
RETURN_NOT_OK(conn.ExecuteFormat(
"CREATE TYPE full_name$0 AS (part part_name$0, last text);", type_suffix));
RETURN_NOT_OK(conn.ExecuteFormat(
"CREATE TABLE emp_nested(id int primary key, name full_name$0) "
"SPLIT INTO $1 TABLETS",
type_suffix, num_tablets));
return GetTable(cluster, kNamespaceName, "emp_nested");
}
Status CDCSDKYsqlTest::WriteNestedCompositeRows(uint32_t start, uint32_t end, Cluster* cluster) {
auto conn = VERIFY_RESULT(cluster->ConnectToDB(kNamespaceName));
LOG(INFO) << "Writing " << end - start << " row(s) within transaction";
RETURN_NOT_OK(conn.Execute("BEGIN"));
for (uint32_t i = start; i < end; ++i) {
RETURN_NOT_OK(conn.ExecuteFormat(
"INSERT INTO emp_nested(id, name) VALUES ($0, (('John', 'Middle'), 'Doe'))", i));
}
RETURN_NOT_OK(conn.Execute("COMMIT"));
return Status::OK();
}
Result<YBTableName> CDCSDKYsqlTest::CreateArrayCompositeTable(
Cluster* cluster, const uint32_t num_tablets, const std::string& type_suffix) {
auto conn = VERIFY_RESULT(cluster->ConnectToDB(kNamespaceName));
RETURN_NOT_OK(
conn.ExecuteFormat("CREATE TYPE emp_data$0 AS (name text[], phone int[]);", type_suffix));
RETURN_NOT_OK(conn.ExecuteFormat(
"CREATE TABLE emp_array(id int primary key, data emp_data$0) "
"SPLIT INTO $1 TABLETS",
type_suffix, num_tablets));
return GetTable(cluster, kNamespaceName, "emp_array");
}
Status CDCSDKYsqlTest::WriteArrayCompositeRows(uint32_t start, uint32_t end, Cluster* cluster) {
auto conn = VERIFY_RESULT(cluster->ConnectToDB(kNamespaceName));
LOG(INFO) << "Writing " << end - start << " row(s) within transaction";
RETURN_NOT_OK(conn.Execute("BEGIN"));
for (uint32_t i = start; i < end; ++i) {
RETURN_NOT_OK(conn.ExecuteFormat(
"INSERT INTO emp_array(id, data) VALUES ($0, ('{\"John\", \"Middle\", \"Doe\"}', '{123, "
"456}'))",
i));
}
RETURN_NOT_OK(conn.Execute("COMMIT"));
return Status::OK();
}
Result<YBTableName> CDCSDKYsqlTest::CreateRangeCompositeTable(
Cluster* cluster, const uint32_t num_tablets, const std::string& type_suffix) {
auto conn = VERIFY_RESULT(cluster->ConnectToDB(kNamespaceName));
RETURN_NOT_OK(conn.ExecuteFormat(
"CREATE type range_composite$0 AS (r1 numrange, r2 int4range);", type_suffix));
RETURN_NOT_OK(conn.ExecuteFormat(
"CREATE TABLE range_composite_table(id int primary key, data range_composite$0) "
"SPLIT INTO $1 TABLETS",
type_suffix, num_tablets));
return GetTable(cluster, kNamespaceName, "range_composite_table");
}
Status CDCSDKYsqlTest::WriteRangeCompositeRows(uint32_t start, uint32_t end, Cluster* cluster) {
auto conn = VERIFY_RESULT(cluster->ConnectToDB(kNamespaceName));
LOG(INFO) << "Writing " << end - start << " row(s) within transaction";
RETURN_NOT_OK(conn.Execute("BEGIN"));
for (uint32_t i = start; i < end; ++i) {
RETURN_NOT_OK(conn.ExecuteFormat(
"INSERT INTO range_composite_table(id, data) VALUES ($0, ('[$1, $2]', '[$3, $4]'))", i, i,
i + 10, i + 11, i + 20));
}
RETURN_NOT_OK(conn.Execute("COMMIT"));
return Status::OK();
}
Result<YBTableName> CDCSDKYsqlTest::CreateRangeArrayCompositeTable(
Cluster* cluster, const uint32_t num_tablets, const std::string& type_suffix) {
auto conn = VERIFY_RESULT(cluster->ConnectToDB(kNamespaceName));
RETURN_NOT_OK(conn.ExecuteFormat(
"CREATE type range_array_composite$0 AS (r1 numrange[], r2 int4range[]);", type_suffix));
RETURN_NOT_OK(conn.ExecuteFormat(
"CREATE TABLE range_array_composite_table(id int primary key, data "
"range_array_composite$0) "
"SPLIT INTO $1 TABLETS",
type_suffix, num_tablets));
return GetTable(cluster, kNamespaceName, "range_array_composite_table");
}
Status CDCSDKYsqlTest::WriteRangeArrayCompositeRows(uint32_t start, uint32_t end,
Cluster* cluster) {
auto conn = VERIFY_RESULT(cluster->ConnectToDB(kNamespaceName));
LOG(INFO) << "Writing " << end - start << " row(s) within transaction";
RETURN_NOT_OK(conn.Execute("BEGIN"));
for (uint32_t i = start; i < end; ++i) {
RETURN_NOT_OK(conn.ExecuteFormat(
"INSERT INTO range_array_composite_table(id, data) VALUES ($0, ('{\"[$1, $2]\", \"[$3, "
"$4]\"}', '{\"[$5, $6]\"}'))",
i, i, i + 10, i + 11, i + 20, i + 21, i + 30));
}
RETURN_NOT_OK(conn.Execute("COMMIT"));
return Status::OK();
}
Status CDCSDKYsqlTest::UpdateRows(uint32_t key, uint32_t value, Cluster* cluster) {
auto conn = VERIFY_RESULT(cluster->ConnectToDB(kNamespaceName));
LOG(INFO) << "Updating row for key " << key << " with value " << value;
RETURN_NOT_OK(conn.ExecuteFormat(
"UPDATE $0 SET $1 = $2 WHERE $3 = $4", kTableName, kValueColumnName, value, kKeyColumnName,
key));
return Status::OK();
}
Status CDCSDKYsqlTest::UpdatePrimaryKey(uint32_t key, uint32_t value, Cluster* cluster) {
auto conn = VERIFY_RESULT(cluster->ConnectToDB(kNamespaceName));
LOG(INFO) << "Updating primary key " << key << " with value " << value;
RETURN_NOT_OK(conn.ExecuteFormat(
"UPDATE $0 SET $1 = $2 WHERE $3 = $4", kTableName, kKeyColumnName, value, kKeyColumnName,
key));
return Status::OK();
}
Status CDCSDKYsqlTest::UpdateRows(
uint32_t key, const std::map<std::string, uint32_t>& col_val_map, Cluster* cluster) {
auto conn = VERIFY_RESULT(cluster->ConnectToDB(kNamespaceName));
std::stringstream log_buff;
log_buff << "Updating row for key " << key << " with";
for (auto& col_value_pair : col_val_map) {
log_buff << " (" << col_value_pair.first << ":" << col_value_pair.second << ")";
}
LOG(INFO) << log_buff.str();
std::stringstream statement_buff;
statement_buff << "UPDATE $0 SET ";
for (auto col_value_pair : col_val_map) {
statement_buff << col_value_pair.first << "=" << col_value_pair.second << ",";
}
std::string statement(statement_buff.str());
statement.at(statement.size() - 1) = ' ';
std::string where_clause("WHERE $1 = $2");
statement += where_clause;
RETURN_NOT_OK(conn.ExecuteFormat(statement, kTableName, "col1", key));
return Status::OK();
}
Status CDCSDKYsqlTest::UpdateRowsHelper(
uint32_t start, uint32_t end, Cluster* cluster, bool flag, uint32_t key,
const std::map<std::string, uint32_t>& col_val_map1,
const std::map<std::string, uint32_t>& col_val_map2, uint32_t num_cols) {
auto conn = VERIFY_RESULT(cluster->ConnectToDB(kNamespaceName));
std::stringstream log_buff1, log_buff2;
LOG(INFO) << "Writing " << end - start << " row(s) within transaction";
RETURN_NOT_OK(conn.Execute("BEGIN"));
for (uint32_t i = start; i < end; ++i) {
uint32_t value = i;
std::stringstream statement_buff;
statement_buff << "INSERT INTO $0 VALUES (";
for (uint32_t iter = 0; iter < num_cols; ++value, ++iter) {
statement_buff << value << ",";
}
std::string statement(statement_buff.str());
statement.at(statement.size() - 1) = ')';
RETURN_NOT_OK(conn.ExecuteFormat(statement, kTableName));
}
log_buff1 << "Updating row for key " << key << " with";
for (auto& col_value_pair : col_val_map1) {
log_buff1 << " (" << col_value_pair.first << ":" << col_value_pair.second << ")";
}
LOG(INFO) << log_buff1.str();
std::stringstream statement_buff1, statement_buff2;
statement_buff1 << "UPDATE $0 SET ";
for (auto& col_value_pair : col_val_map1) {
statement_buff1 << col_value_pair.first << "=" << col_value_pair.second << ",";
}
std::string statement1(statement_buff1.str());
statement1.at(statement1.size() - 1) = ' ';
std::string where_clause("WHERE $1 = $2");
statement1 += where_clause;
RETURN_NOT_OK(conn.ExecuteFormat(statement1, kTableName, "col1", key));
log_buff2 << "Updating row for key " << key << " with";
for (auto& col_value_pair : col_val_map2) {
log_buff2 << " (" << col_value_pair.first << ":" << col_value_pair.second << ")";
}
LOG(INFO) << log_buff2.str();
statement_buff2 << "UPDATE $0 SET ";
for (auto& col_value_pair : col_val_map2) {
statement_buff2 << col_value_pair.first << "=" << col_value_pair.second << ",";
}
std::string statement2(statement_buff2.str());
statement2.at(statement2.size() - 1) = ' ';
statement2 += where_clause;
RETURN_NOT_OK(conn.ExecuteFormat(statement2, kTableName, "col1", key));
if (flag) {
RETURN_NOT_OK(conn.Execute("COMMIT"));
} else {
RETURN_NOT_OK(conn.Execute("ABORT"));
}
return Status::OK();
}
Status CDCSDKYsqlTest::UpdateDeleteRowsHelper(
uint32_t start, uint32_t end, Cluster* cluster, bool flag, uint32_t key,
const std::map<std::string, uint32_t>& col_val_map, uint32_t num_cols) {
auto conn = VERIFY_RESULT(cluster->ConnectToDB(kNamespaceName));
std::stringstream log_buff1, log_buff2;
LOG(INFO) << "Writing " << end - start << " row(s) within transaction";
RETURN_NOT_OK(conn.Execute("BEGIN"));
for (uint32_t i = start; i < end; ++i) {
uint32_t value = i;
std::stringstream statement_buff;
statement_buff << "INSERT INTO $0 VALUES (";
for (uint32_t iter = 0; iter < num_cols; ++value, ++iter) {
statement_buff << value << ",";
}
std::string statement(statement_buff.str());
statement.at(statement.size() - 1) = ')';
RETURN_NOT_OK(conn.ExecuteFormat(statement, kTableName));
}
log_buff1 << "Updating row for key " << key << " with";
for (auto col_value_pair : col_val_map) {
log_buff1 << " (" << col_value_pair.first << ":" << col_value_pair.second << ")";
}
LOG(INFO) << log_buff1.str();
std::stringstream statement_buff1, statement_buff2;
statement_buff1 << "UPDATE $0 SET ";
for (auto col_value_pair : col_val_map) {
statement_buff1 << col_value_pair.first << "=" << col_value_pair.second << ",";
}
std::string statement1(statement_buff1.str());
statement1.at(statement1.size() - 1) = ' ';
std::string where_clause("WHERE $1 = $2");
statement1 += where_clause;
RETURN_NOT_OK(conn.ExecuteFormat(statement1, kTableName, "col1", key));
log_buff2 << "Updating row for key " << key << " with";
for (auto& col_value_pair : col_val_map) {
log_buff2 << " (" << col_value_pair.first << ":" << col_value_pair.second << ")";
}
LOG(INFO) << log_buff2.str();
statement_buff2 << "DELETE FROM $0 ";
std::string statement2(statement_buff2.str());
statement2.at(statement2.size() - 1) = ' ';
statement2 += where_clause;
RETURN_NOT_OK(conn.ExecuteFormat(statement2, kTableName, "col1", key));
if (flag) {
RETURN_NOT_OK(conn.Execute("COMMIT"));
} else {
RETURN_NOT_OK(conn.Execute("ABORT"));
}
return Status::OK();
}
Status CDCSDKYsqlTest::DeleteRows(uint32_t key, Cluster* cluster) {
auto conn = VERIFY_RESULT(cluster->ConnectToDB(kNamespaceName));
LOG(INFO) << "Deleting row for key " << key;
RETURN_NOT_OK(
conn.ExecuteFormat("DELETE FROM $0 WHERE $1 = $2", kTableName, kKeyColumnName, key));
return Status::OK();
}
Status CDCSDKYsqlTest::SplitTablet(const TabletId& tablet_id, Cluster* cluster) {
yb::master::SplitTabletRequestPB req;
req.set_tablet_id(tablet_id);
yb::master::SplitTabletResponsePB resp;
rpc::RpcController rpc;
rpc.set_timeout(MonoDelta::FromSeconds(30.0) * kTimeMultiplier);
auto& cm = cluster->mini_cluster_->mini_master()->catalog_manager();
RETURN_NOT_OK(cm.SplitTablet(
tablet_id, master::ManualSplit::kTrue,
cm.GetLeaderEpochInternal()));
if (resp.has_error()) {
RETURN_NOT_OK(StatusFromPB(resp.error().status()));
}
return Status::OK();
}
Result<google::protobuf::RepeatedPtrField<master::TabletLocationsPB>>
CDCSDKYsqlTest::SetUpCluster() {
ANNOTATE_UNPROTECTED_WRITE(FLAGS_enable_single_record_update) = false;
RETURN_NOT_OK(SetUpWithParams(3, 1, false));
auto table = EXPECT_RESULT(CreateTable(&test_cluster_, kNamespaceName, kTableName));
google::protobuf::RepeatedPtrField<master::TabletLocationsPB> tablets;
RETURN_NOT_OK(test_client()->GetTablets(table, 0, &tablets, nullptr));
return tablets;
}
Result<google::protobuf::RepeatedPtrField<master::TabletLocationsPB>>
CDCSDKYsqlTest::SetUpClusterMultiColumnUsecase(uint32_t num_cols) {
ANNOTATE_UNPROTECTED_WRITE(FLAGS_enable_single_record_update) = true;
RETURN_NOT_OK(SetUpWithParams(3, 1, false));
auto table = EXPECT_RESULT(CreateTable(
&test_cluster_, kNamespaceName, kTableName, 1, true, false, 0, false, "", "public",
num_cols));
google::protobuf::RepeatedPtrField<master::TabletLocationsPB> tablets;
RETURN_NOT_OK(test_client()->GetTablets(table, 0, &tablets, nullptr));
return tablets;
}
Result<GetChangesResponsePB> CDCSDKYsqlTest::UpdateSnapshotDone(
const xrepl::StreamId& stream_id,
const google::protobuf::RepeatedPtrField<master::TabletLocationsPB>& tablets,
const TableId table_id) {
GetChangesRequestPB change_req2;
GetChangesResponsePB change_resp2;
PrepareChangeRequest(
&change_req2, stream_id, tablets, 0, -1, -1, kCDCSDKSnapshotDoneKey, 0, 0, table_id);
RpcController get_changes_rpc;
RETURN_NOT_OK(cdc_proxy_->GetChanges(change_req2, &change_resp2, &get_changes_rpc));
if (change_resp2.has_error()) {
return StatusFromPB(change_resp2.error().status());
}
return change_resp2;
}
Result<GetChangesResponsePB> CDCSDKYsqlTest::UpdateCheckpoint(
const xrepl::StreamId& stream_id,
const google::protobuf::RepeatedPtrField<master::TabletLocationsPB>& tablets,
const GetChangesResponsePB* change_resp,
const TableId table_id) {
GetChangesRequestPB change_req2;
GetChangesResponsePB change_resp2;
PrepareChangeRequest(
&change_req2, stream_id, tablets, 0, change_resp->cdc_sdk_checkpoint().index(),
change_resp->cdc_sdk_checkpoint().term(), change_resp->cdc_sdk_checkpoint().key(),
change_resp->cdc_sdk_checkpoint().write_id(),
change_resp->cdc_sdk_checkpoint().snapshot_time(), table_id);
RpcController get_changes_rpc;
RETURN_NOT_OK(cdc_proxy_->GetChanges(change_req2, &change_resp2, &get_changes_rpc));
if (change_resp2.has_error()) {
return StatusFromPB(change_resp2.error().status());
}
return change_resp2;
}
std::unique_ptr<tserver::TabletServerAdminServiceProxy> CDCSDKYsqlTest::GetTServerAdminProxy(
const uint32_t tserver_index) {
auto tserver = test_cluster()->mini_tablet_server(tserver_index);
return std::make_unique<tserver::TabletServerAdminServiceProxy>(
&tserver->server()->proxy_cache(), HostPort::FromBoundEndpoint(tserver->bound_rpc_addr()));
}
Status CDCSDKYsqlTest::GetIntentCounts(const uint32_t tserver_index, int64* num_intents) {
tserver::CountIntentsRequestPB req;
tserver::CountIntentsResponsePB resp;
RpcController rpc;
auto ts_admin_service_proxy = GetTServerAdminProxy(tserver_index);
rpc.set_timeout(MonoDelta::FromSeconds(kRpcTimeout));
RETURN_NOT_OK(ts_admin_service_proxy->CountIntents(req, &resp, &rpc));
*num_intents = resp.num_intents();
return Status::OK();
}
void CDCSDKYsqlTest::PrepareChangeRequest(
GetChangesRequestPB* change_req, const xrepl::StreamId& stream_id,
const google::protobuf::RepeatedPtrField<master::TabletLocationsPB>& tablets,
const int tablet_idx, int64 index, int64 term, std::string key, int32_t write_id,
int64 snapshot_time, const TableId table_id, int64 safe_hybrid_time,
int32_t wal_segment_index, const bool populate_checkpoint) {
change_req->set_stream_id(stream_id.ToString());
change_req->set_tablet_id(tablets.Get(tablet_idx).tablet_id());
if (populate_checkpoint) {
change_req->mutable_from_cdc_sdk_checkpoint()->set_index(index);
change_req->mutable_from_cdc_sdk_checkpoint()->set_term(term);
change_req->mutable_from_cdc_sdk_checkpoint()->set_key(key);
change_req->mutable_from_cdc_sdk_checkpoint()->set_write_id(write_id);
change_req->mutable_from_cdc_sdk_checkpoint()->set_snapshot_time(snapshot_time);
}
change_req->set_wal_segment_index(wal_segment_index);
if (!table_id.empty()) {
change_req->set_table_id(table_id);
}
change_req->set_safe_hybrid_time(safe_hybrid_time);
}
void CDCSDKYsqlTest::PrepareChangeRequest(
GetChangesRequestPB* change_req, const xrepl::StreamId& stream_id, const TabletId& tablet_id,
const int tablet_idx, int64 index, int64 term, std::string key, int32_t write_id,
int64 snapshot_time) {
change_req->set_stream_id(stream_id.ToString());
change_req->set_tablet_id(tablet_id);
change_req->mutable_from_cdc_sdk_checkpoint()->set_index(index);
change_req->mutable_from_cdc_sdk_checkpoint()->set_term(term);
change_req->mutable_from_cdc_sdk_checkpoint()->set_key(key);
change_req->mutable_from_cdc_sdk_checkpoint()->set_write_id(write_id);
change_req->mutable_from_cdc_sdk_checkpoint()->set_snapshot_time(snapshot_time);
}
void CDCSDKYsqlTest::PrepareChangeRequest(
GetChangesRequestPB* change_req, const xrepl::StreamId& stream_id,
const google::protobuf::RepeatedPtrField<master::TabletLocationsPB>& tablets,
const CDCSDKCheckpointPB& cp, const int tablet_idx, const TableId table_id,
int64 safe_hybrid_time, int32_t wal_segment_index) {
change_req->set_stream_id(stream_id.ToString());
change_req->set_tablet_id(tablets.Get(tablet_idx).tablet_id());
change_req->mutable_from_cdc_sdk_checkpoint()->set_term(cp.term());
change_req->mutable_from_cdc_sdk_checkpoint()->set_index(cp.index());
change_req->mutable_from_cdc_sdk_checkpoint()->set_key(cp.key());
change_req->mutable_from_cdc_sdk_checkpoint()->set_write_id(cp.write_id());
if (!table_id.empty()) {
change_req->set_table_id(table_id);
}
change_req->set_safe_hybrid_time(safe_hybrid_time);
change_req->set_wal_segment_index(wal_segment_index);
}
void CDCSDKYsqlTest::PrepareChangeRequest(
GetChangesRequestPB* change_req, const xrepl::StreamId& stream_id, const TabletId& tablet_id,
const CDCSDKCheckpointPB& cp, const int tablet_idx) {
change_req->set_stream_id(stream_id.ToString());
change_req->set_tablet_id(tablet_id);
change_req->mutable_from_cdc_sdk_checkpoint()->set_term(cp.term());
change_req->mutable_from_cdc_sdk_checkpoint()->set_index(cp.index());
change_req->mutable_from_cdc_sdk_checkpoint()->set_key(cp.key());
change_req->mutable_from_cdc_sdk_checkpoint()->set_write_id(cp.write_id());
}
void CDCSDKYsqlTest::PrepareChangeRequestWithExplicitCheckpoint(
GetChangesRequestPB* change_req, const xrepl::StreamId& stream_id,
const google::protobuf::RepeatedPtrField<master::TabletLocationsPB>& tablets,
const CDCSDKCheckpointPB& cp, const int tablet_idx) {
change_req->set_stream_id(stream_id.ToString());
change_req->set_tablet_id(tablets.Get(tablet_idx).tablet_id());
change_req->mutable_from_cdc_sdk_checkpoint()->set_term(cp.term());
change_req->mutable_from_cdc_sdk_checkpoint()->set_index(cp.index());
change_req->mutable_from_cdc_sdk_checkpoint()->set_key(cp.key());
change_req->mutable_from_cdc_sdk_checkpoint()->set_write_id(cp.write_id());
change_req->mutable_explicit_cdc_sdk_checkpoint()->set_term(cp.term());
change_req->mutable_explicit_cdc_sdk_checkpoint()->set_index(cp.index());
change_req->mutable_explicit_cdc_sdk_checkpoint()->set_key(cp.key());
change_req->mutable_explicit_cdc_sdk_checkpoint()->set_write_id(cp.write_id());
}
void CDCSDKYsqlTest::PrepareSetCheckpointRequest(
SetCDCCheckpointRequestPB* set_checkpoint_req,
const xrepl::StreamId stream_id,
google::protobuf::RepeatedPtrField<master::TabletLocationsPB>
tablets,
const int tablet_idx,
const OpId& op_id,
bool initial_checkpoint,
const uint64_t cdc_sdk_safe_time,
bool bootstrap) {
set_checkpoint_req->set_stream_id(stream_id.ToString());
set_checkpoint_req->set_initial_checkpoint(initial_checkpoint);
set_checkpoint_req->set_cdc_sdk_safe_time(cdc_sdk_safe_time);
set_checkpoint_req->set_bootstrap(bootstrap);
set_checkpoint_req->set_tablet_id(tablets.Get(tablet_idx).tablet_id());
set_checkpoint_req->mutable_checkpoint()->mutable_op_id()->set_term(op_id.term);
set_checkpoint_req->mutable_checkpoint()->mutable_op_id()->set_index(op_id.index);
}
Result<SetCDCCheckpointResponsePB> CDCSDKYsqlTest::SetCDCCheckpoint(
const xrepl::StreamId& stream_id,
const google::protobuf::RepeatedPtrField<master::TabletLocationsPB>& tablets,
const OpId& op_id, const uint64_t cdc_sdk_safe_time, bool initial_checkpoint,
const int tablet_idx, bool bootstrap) {
Status st;
SetCDCCheckpointResponsePB set_checkpoint_resp_final;
RETURN_NOT_OK(WaitFor(
[&]() -> Result<bool> {
RpcController set_checkpoint_rpc;
SetCDCCheckpointRequestPB set_checkpoint_req;
SetCDCCheckpointResponsePB set_checkpoint_resp;
auto deadline = CoarseMonoClock::now() + test_client()->default_rpc_timeout();
set_checkpoint_rpc.set_deadline(deadline);
PrepareSetCheckpointRequest(
&set_checkpoint_req, stream_id, tablets, tablet_idx, op_id, initial_checkpoint,
cdc_sdk_safe_time, bootstrap);
st = cdc_proxy_->SetCDCCheckpoint(
set_checkpoint_req, &set_checkpoint_resp, &set_checkpoint_rpc);
if (set_checkpoint_resp.has_error() &&
set_checkpoint_resp.error().code() != CDCErrorPB::TABLET_NOT_FOUND &&
set_checkpoint_resp.error().code() != CDCErrorPB::LEADER_NOT_READY) {
return STATUS_FORMAT(
InternalError, "Response had error: $0", set_checkpoint_resp.DebugString());
}
if (st.ok() && !set_checkpoint_resp.has_error()) {
set_checkpoint_resp_final.CopyFrom(set_checkpoint_resp);
return true;
}
return false;
},
MonoDelta::FromSeconds(kRpcTimeout),
"GetChanges timed out waiting for Leader to get ready"));
return set_checkpoint_resp_final;
}
Result<std::vector<OpId>> CDCSDKYsqlTest::GetCDCCheckpoint(
const xrepl::StreamId& stream_id,
const google::protobuf::RepeatedPtrField<master::TabletLocationsPB>& tablets) {
GetCheckpointRequestPB get_checkpoint_req;
std::vector<OpId> op_ids;
op_ids.reserve(tablets.size());
for (const auto& tablet : tablets) {
get_checkpoint_req.set_stream_id(stream_id.ToString());
get_checkpoint_req.set_tablet_id(tablet.tablet_id());
RETURN_NOT_OK(WaitFor(
[&]() -> Result<bool> {
GetCheckpointResponsePB get_checkpoint_resp;
RpcController get_checkpoint_rpc;
RETURN_NOT_OK(cdc_proxy_->GetCheckpoint(
get_checkpoint_req, &get_checkpoint_resp, &get_checkpoint_rpc));
if (get_checkpoint_resp.has_error() &&
get_checkpoint_resp.error().code() != CDCErrorPB::TABLET_NOT_FOUND &&
get_checkpoint_resp.error().code() != CDCErrorPB::LEADER_NOT_READY) {
return STATUS_FORMAT(
InternalError, "Response had error: $0", get_checkpoint_resp.DebugString());
}
if (!get_checkpoint_resp.has_error()) {
op_ids.push_back(OpId::FromPB(get_checkpoint_resp.checkpoint().op_id()));
return true;
}
return false;
},
MonoDelta::FromSeconds(kRpcTimeout),
"GetChanges timed out waiting for Leader to get ready"));
}
return op_ids;
}
Result<GetCheckpointResponsePB> CDCSDKYsqlTest::GetCDCSnapshotCheckpoint(
const xrepl::StreamId& stream_id, const TabletId& tablet_id, const TableId& table_id) {
RpcController get_checkpoint_rpc;
GetCheckpointRequestPB get_checkpoint_req;
GetCheckpointResponsePB get_checkpoint_resp;
auto deadline = CoarseMonoClock::now() + test_client()->default_rpc_timeout();
get_checkpoint_rpc.set_deadline(deadline);
get_checkpoint_req.set_stream_id(stream_id.ToString());
if (!table_id.empty()) {
get_checkpoint_req.set_table_id(table_id);
}
get_checkpoint_req.set_tablet_id(tablet_id);
RETURN_NOT_OK(
cdc_proxy_->GetCheckpoint(get_checkpoint_req, &get_checkpoint_resp, &get_checkpoint_rpc));
return get_checkpoint_resp;
}
Result<GetTabletListToPollForCDCResponsePB> CDCSDKYsqlTest::GetTabletListToPollForCDC(
const xrepl::StreamId& stream_id, const TableId& table_id, const TabletId& tablet_id) {
RpcController rpc;
GetTabletListToPollForCDCRequestPB get_tablet_list_req;
GetTabletListToPollForCDCResponsePB get_tablet_list_resp;
auto deadline = CoarseMonoClock::now() + test_client()->default_rpc_timeout();
rpc.set_deadline(deadline);
TableInfo table_info;
table_info.set_table_id(table_id);
table_info.set_stream_id(stream_id.ToString());
get_tablet_list_req.mutable_table_info()->set_table_id(table_id);