-
Notifications
You must be signed in to change notification settings - Fork 1k
/
yb-backup-cross-feature-test.cc
1485 lines (1271 loc) · 61.9 KB
/
yb-backup-cross-feature-test.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/client/table_info.h"
#include "yb/client/ql-dml-test-base.h"
#include "yb/master/master_client.pb.h"
#include "yb/tools/yb-backup/yb-backup-test_base.h"
#include "yb/util/backoff_waiter.h"
using namespace std::chrono_literals;
using namespace std::literals;
DECLARE_int32(TEST_partitioning_version);
namespace {
const auto kDefaultTimeout = 30s;
template <size_t N>
std::string bytes_to_str(const char (&bytes)[N]) {
// Correctly instantiates std::string if an array conains a zero char and handles the case with
// null-terminated string ignoring the last element.
return std::string(bytes, N - (bytes[N - 1] == '\0' ? 1 : 0));
}
} // anonymous namespace
namespace yb {
namespace tools {
class YBBackupTestNumTablets : public YBBackupTest {
public:
void UpdateMiniClusterOptions(ExternalMiniClusterOptions* options) override {
YBBackupTest::UpdateMiniClusterOptions(options);
// For convenience, rather than create a subclass for tablet splitting tests, add tablet split
// flags here since they shouldn't really affect non-tablet splitting tests.
options->extra_master_flags.push_back("--enable_automatic_tablet_splitting=false");
options->extra_tserver_flags.push_back("--db_filter_block_size_bytes=2048");
options->extra_tserver_flags.push_back("--db_index_block_size_bytes=2048");
options->extra_tserver_flags.push_back("--db_block_size_bytes=1024");
options->extra_tserver_flags.push_back("--ycql_num_tablets=3");
options->extra_tserver_flags.push_back("--ysql_num_tablets=3");
options->extra_tserver_flags.push_back("--cleanup_split_tablets_interval_sec=1");
}
string default_db_ = "yugabyte";
};
// Test backup/restore on table with UNIQUE constraint when default number of tablets differs. When
// creating the table, the default is 3; when restoring, the default is 2. Restore should restore
// the unique constraint index as 3 tablets since the tablet snapshot files are already split into 3
// tablets.
//
// For debugging, run ./yb_build.sh with extra flags:
// - --extra-daemon-flags "--vmodule=client=1,table_creator=1"
// - --test-args "--verbose_yb_backup"
TEST_F_EX(YBBackupTest,
YB_DISABLE_TEST_IN_SANITIZERS(TestYSQLChangeDefaultNumTablets),
YBBackupTestNumTablets) {
const string table_name = "mytbl";
const string index_name = table_name + "_v_key";
ASSERT_NO_FATALS(CreateTable(Format(
"CREATE TABLE $0 (k INT PRIMARY KEY, v TEXT, UNIQUE (v))", table_name)));
auto tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, index_name));
ASSERT_EQ(tablets.size(), 3);
const string backup_dir = GetTempDir("backup");
ASSERT_OK(RunBackupCommand(
{"--backup_location", backup_dir, "--keyspace", "ysql.yugabyte", "create"}));
// Drop the table (and index) so that, on restore, running the ysql_dump file recreates the table
// (and index).
ASSERT_NO_FATALS(RunPsqlCommand(Format("DROP TABLE $0", table_name), "DROP TABLE"));
// When restore runs the CREATE TABLE, make it run in an environment where the default number of
// tablets is different. Namely, run it with new default 2 (previously 3). This won't affect the
// table since the table is generated with SPLIT clause specifying 3, but it will change the way
// the unique index is created because the unique index has no corresponding grammar to specify
// number of splits in ysql_dump file.
for (auto ts : cluster_->tserver_daemons()) {
ts->Shutdown();
ts->mutable_flags()->push_back("--ysql_num_tablets=2");
ASSERT_OK(ts->Restart());
}
// Check that --ysql_num_tablets=2 is working as intended by
// 1. running the CREATE TABLE that is expected to be found in the ysql_dump file and
// 2. finding 2 index tablets
ASSERT_NO_FATALS(CreateTable(Format(
"CREATE TABLE $0 (k INT PRIMARY KEY, v TEXT, UNIQUE (v))", table_name)));
tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, index_name));
ASSERT_EQ(tablets.size(), 2);
ASSERT_NO_FATALS(RunPsqlCommand(Format("DROP TABLE $0", table_name), "DROP TABLE"));
// Restore should notice that the index it creates from ysql_dump file (2 tablets) differs from
// the external snapshot (3 tablets), so it should adjust to match the snapshot (3 tablets).
ASSERT_OK(RunBackupCommand({"--backup_location", backup_dir, "restore"}));
tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, index_name));
ASSERT_EQ(tablets.size(), 3);
LOG(INFO) << "Test finished: " << CURRENT_TEST_CASE_AND_TEST_NAME_STR();
}
// Test delete_snapshot operation, where one of the tablets involved in the delete snapshot
// operation is already deleted (For example: due to tablet splitting).
// 1. create a table with 3 pre-split tablets.
// 2. create a database snapshot
// 3. split one of the tablets to make 4 tablets
// 4. delete the snapshot created at 2
TEST_F(YBBackupTest, DeleteSnapshotAfterTabletSplitting) {
const string table_name = "mytbl";
const string default_db = "yugabyte";
LOG(INFO) << Format("Create table '$0'", table_name);
ASSERT_NO_FATALS(CreateTable(Format("CREATE TABLE $0 (k INT, v INT)", table_name)));
LOG(INFO) << "Insert values";
ASSERT_NO_FATALS(InsertRows(
Format("INSERT INTO $0 (k,v) SELECT i,i FROM generate_series(1,10000) AS i", table_name),
10000));
// Verify tablets count and get table_id
auto tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db, table_name));
LogTabletsInfo(tablets);
ASSERT_EQ(tablets.size(), 3);
constexpr int middle_index = 1;
TableId table_id = tablets[0].table_id();
LOG(INFO) << "Create snapshot";
auto snapshot_id = ASSERT_RESULT(snapshot_util_->CreateSnapshot(table_id));
LOG(INFO) << "Split one tablet Manually and wait for parent tablet to be deleted.";
string tablet_id = tablets[middle_index].tablet_id();
// Split it && Wait for split to complete.
constexpr int num_tablets = 4;
ASSERT_OK(test_admin_client_->SplitTabletAndWait(
default_db, table_name, /* wait_for_parent_deletion */ true, tablet_id));
LOG(INFO) << "Finish tablet splitting";
tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db, table_name));
LogTabletsInfo(tablets);
ASSERT_EQ(tablets.size(), num_tablets);
// Delete the snapshot after the parent tablet has been deleted
LOG(INFO) << "Delete snapshot";
ASSERT_OK(snapshot_util_->DeleteSnapshot(snapshot_id));
// Make sure the snapshot has been deleted
LOG(INFO) << "Wait snapshot to be Deleted";
ASSERT_OK(snapshot_util_->WaitAllSnapshotsDeleted());
}
// Test fixture class for tests that need multiple masters (ex: master failover scenarios)
class YBBackupTestMultipleMasters : public YBBackupTest {
public:
void UpdateMiniClusterOptions(ExternalMiniClusterOptions* options) override {
YBBackupTest::UpdateMiniClusterOptions(options);
options->num_masters = 3;
}
};
// Test delete_snapshot operation completes successfully when one of the tablets involved in the
// delete snapshot operation is already deleted (For example: due to tablet splitting) and a master
// failover happens after that.
// 1. create a table with 3 pre-split tablets.
// 2. create a database snapshot
// 3. split one of the tablets to make 4 tablets and wait for the parent tablet to be deleted
// 4. perform a master leader failover - the new master will not have any state for this deleted
// parent tablet
// 5. delete the snapshot created at 2
TEST_F_EX(
YBBackupTest, DeleteSnapshotAfterTabletSplittingAndMasterFailover,
YBBackupTestMultipleMasters) {
const string table_name = "mytbl";
const string default_db = "yugabyte";
LOG(INFO) << Format("Create table '$0'", table_name);
ASSERT_NO_FATALS(CreateTable(Format("CREATE TABLE $0 (k INT, v INT)", table_name)));
LOG(INFO) << "Insert values";
ASSERT_NO_FATALS(InsertRows(
Format("INSERT INTO $0 (k,v) SELECT i,i FROM generate_series(1,1000) AS i", table_name),
1000));
// Verify tablets count and get table_id
auto tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db, table_name));
LogTabletsInfo(tablets);
ASSERT_EQ(tablets.size(), 3);
TableId table_id = tablets[0].table_id();
LOG(INFO) << "Create snapshot";
auto snapshot_id = ASSERT_RESULT(snapshot_util_->CreateSnapshot(table_id));
LOG(INFO) << "Split one tablet Manually and wait for parent tablet to be deleted.";
constexpr int middle_index = 1;
string tablet_id = tablets[middle_index].tablet_id();
// Split it && Wait for split to complete.
ASSERT_OK(test_admin_client_->SplitTabletAndWait(
default_db, table_name, /* wait_for_parent_deletion */ true, tablet_id));
LOG(INFO) << "Finish tablet splitting";
tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db, table_name));
LogTabletsInfo(tablets);
constexpr int num_tablets = 4;
ASSERT_EQ(tablets.size(), num_tablets);
// Perform a master failover. the new master will not have any state for this deleted parent
// tablet.
LOG(INFO) << "Fail over the master leader";
ASSERT_OK(cluster_->StepDownMasterLeaderAndWaitForNewLeader());
// Delete the snapshot after the parent tablet has been deleted
LOG(INFO) << "Delete snapshot";
ASSERT_OK(snapshot_util_->DeleteSnapshot(snapshot_id));
// Make sure the snapshot has been deleted
LOG(INFO) << "Wait snapshot to be Deleted";
ASSERT_OK(snapshot_util_->WaitAllSnapshotsDeleted());
}
// Test backup/restore when a hash-partitioned table undergoes manual tablet splitting. Most
// often, if tablets are split after creation, the partition boundaries will not be evenly spaced.
// This then differs from the boundaries of a hash table that is pre-split with the same number of
// tablets. Restoring snapshots to a table with differing partition boundaries should be detected
// and handled by repartitioning the table, even if the number of partitions are equal. This test
// exercises that:
// 1. start with 3 pre-split tablets
// 2. split one of them to make 4 tablets
// 3. backup
// 4. drop table
// 5. restore, which will initially create 4 pre-split tablets then realize the partition boundaries
// differ
TEST_F_EX(YBBackupTest,
YB_DISABLE_TEST_IN_SANITIZERS(TestYSQLManualTabletSplit),
YBBackupTestNumTablets) {
const string table_name = "mytbl";
// Create table.
ASSERT_NO_FATALS(CreateTable(Format("CREATE TABLE $0 (k INT PRIMARY KEY)", table_name)));
// Insert rows that hash to each possible partition range for both manual split and even split.
//
// part range | k | hash | manual split part num | even split part num | interesting
// -0x3fff | 1 | 0x1210 | 1 | 1 | N
// 0x3fff-0x5555 | 6 | 0x4e58 | 1 | 2 | Y
// 0x5555-0x7ffe | 9 | 0x5d60 | 2 | 2 | N
// 0x7ffe-0xa6e8 | 23 | 0x986c | 2 | 3 | Y
// 0xa6e8-0xaaaa | 4 | 0x9eaf | 3 | 3 | N
// 0xaaaa-0xbffd | 27 | 0xbd51 | 4 | 3 | Y
// 0xbffd- | 2 | 0xc0c4 | 4 | 4 | N
//
// Split ranges are further discused in comments below.
ASSERT_NO_FATALS(InsertRows(
Format("INSERT INTO $0 VALUES (generate_series(1, 100))", table_name), 100));
string select_query = Format("SELECT k, to_hex(yb_hash_code(k)) AS hash FROM $0"
" WHERE k IN (1, 2, 4, 6, 9, 23, 27) ORDER BY hash",
table_name);
string select_output = R"#(
k | hash
----+------
1 | 1210
6 | 4e58
9 | 5d60
23 | 986c
4 | 9eaf
27 | bd51
2 | c0c4
(7 rows)
)#";
ASSERT_NO_FATALS(RunPsqlCommand(select_query, select_output));
// It has three tablets because of --ysql_num_tablets=3.
auto tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, table_name));
LogTabletsInfo(tablets);
ASSERT_EQ(tablets.size(), 3);
const std::vector<std::string> initial_split_points = {"\x55\x55", "\xaa\xaa"};
ASSERT_EQ(ASSERT_RESULT(GetSplitPoints(tablets)), initial_split_points);
// Choose the middle tablet among
// - -0x5555
// - 0x5555-0xaaaa
// - 0xaaaa-
constexpr int middle_index = 1;
ASSERT_EQ(tablets[middle_index].partition().partition_key_start(), "\x55\x55");
string tablet_id = tablets[middle_index].tablet_id();
// Flush table because it is necessary for manual tablet split.
auto table_id = ASSERT_RESULT(GetTableId(table_name, "pre-split"));
ASSERT_OK(client_->FlushTables({table_id}, false, 30, false));
// Split it && Wait for split to complete.
constexpr int num_tablets = 4;
ASSERT_OK(test_admin_client_->SplitTabletAndWait(
default_db_, table_name, /* wait_for_parent_deletion */ false, tablet_id));
// Verify that it has these four tablets:
// - -0x5555
// - 0x5555-?
// - ?-0xaaaa
// - 0xaaaa-
// Tablet splitting should choose the split point based on the existing data. Don't verify that
// it chose the right split point: that is out of scope of this test. Just trust what it chose.
tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, table_name));
LogTabletsInfo(tablets);
ASSERT_EQ(tablets.size(), num_tablets);
auto three_split_points = ASSERT_RESULT(GetSplitPoints(tablets));
ASSERT_EQ(three_split_points[0], initial_split_points[0]);
ASSERT_EQ(three_split_points[2], initial_split_points[1]);
const string backup_dir = GetTempDir("backup");
ASSERT_OK(RunBackupCommand(
{"--backup_location", backup_dir, "--keyspace", "ysql.yugabyte", "create"}));
// Drop the table so that, on restore, running the ysql_dump file recreates the table. ysql_dump
// should specify SPLIT INTO 4 TABLETS because the table in snapshot has 4 tablets.
ASSERT_NO_FATALS(RunPsqlCommand(Format("DROP TABLE $0", table_name), "DROP TABLE"));
// Before performing restore, demonstrate that the table that would be created by the ysql_dump
// file will have different splits.
ASSERT_NO_FATALS(CreateTable(
Format("CREATE TABLE $0 (k INT PRIMARY KEY) SPLIT INTO 4 TABLETS", table_name)));
tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, table_name));
ASSERT_EQ(tablets.size(), 4);
auto default_table_split_points = ASSERT_RESULT(GetSplitPoints(tablets));
ASSERT_NE(three_split_points, default_table_split_points);
ASSERT_NO_FATALS(RunPsqlCommand(Format("DROP TABLE $0", table_name), "DROP TABLE"));
// Restore should notice that the table it creates from ysql_dump file has different partition
// boundaries from the one in the external snapshot EVEN THOUGH the number of partitions is four
// in both, so it should recreate partitions to match the splits in the snapshot.
ASSERT_OK(RunBackupCommand({"--backup_location", backup_dir, "restore"}));
// Validate.
tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, table_name));
ASSERT_EQ(tablets.size(), 4);
auto post_restore_splits = ASSERT_RESULT(GetSplitPoints(tablets));
ASSERT_EQ(post_restore_splits, three_split_points);
ASSERT_NO_FATALS(RunPsqlCommand(select_query, select_output));
LOG(INFO) << "Test finished: " << CURRENT_TEST_CASE_AND_TEST_NAME_STR();
}
// Test backup/restore of a range-partitioned table
// without tablet splitting happening.
// Note: make sure there is no CatalogManager::RepartitionTable's log.
// This indicates the success of backup/restore of range-partitioned tables
// without the help RepartitionTable.
// This test exercises that:
// 1. start with a table with 3 pre-split tablets
// 2. insert data
// 3. backup
// 4. drop table
// 5. restore
TEST_F_EX(YBBackupTest,
YB_DISABLE_TEST_IN_SANITIZERS(TestPreSplitYSQLRangeSplitTable),
YBBackupTestNumTablets) {
const string table_name = "mytbl";
// Create table
ASSERT_NO_FATALS(CreateTable(Format("CREATE TABLE $0 (k INT, v TEXT, PRIMARY KEY(k ASC, v ASC))"
" SPLIT AT VALUES ((10, 'f'), (20, 'n'))", table_name)));
// Verify table has 3 tablets
auto tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, table_name));
LogTabletsInfo(tablets);
ASSERT_EQ(tablets.size(), 3);
// 'H' represents the KeyEntryType for Int32.
// \x80\x00\x00\x0a = 0x80000000 ^ 10
// \x80\x00\x00\x14 = 0x80000000 ^ 20
// 'S' represents the KeyEntryType for String.
// "f" and "n" are the split point values of column v
// two '\x00' terminate a string value.
// '!' indicates the end of the range group of a key.
ASSERT_TRUE(CheckPartitions(tablets, {"H\x80\x00\x00\x0aSf\x00\x00!"s,
"H\x80\x00\x00\x14Sn\x00\x00!"s}));
// Insert data
ASSERT_NO_FATALS(InsertRows(
Format("INSERT INTO $0 VALUES (1,'a'), (11,'h'), (21,'o')", table_name), 3));
ASSERT_NO_FATALS(RunPsqlCommand(
Format("SELECT * FROM $0 ORDER BY v", table_name),
R"#(
k | v
----+---
1 | a
11 | h
21 | o
(3 rows)
)#"
));
// Backup
const string backup_dir = GetTempDir("backup");
ASSERT_OK(RunBackupCommand(
{"--backup_location", backup_dir, "--keyspace", "ysql.yugabyte", "create"}));
// Drop the table
ASSERT_NO_FATALS(RunPsqlCommand(Format("DROP TABLE $0", table_name), "DROP TABLE"));
// Restore
ASSERT_OK(RunBackupCommand({"--backup_location", backup_dir, "restore"}));
// Validate
tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, table_name));
ASSERT_EQ(tablets.size(), 3);
ASSERT_TRUE(CheckPartitions(tablets, {"H\x80\x00\x00\x0aSf\x00\x00!"s,
"H\x80\x00\x00\x14Sn\x00\x00!"s}));
ASSERT_NO_FATALS(RunPsqlCommand(
Format("SELECT * FROM $0 ORDER BY v", table_name),
R"#(
k | v
----+---
1 | a
11 | h
21 | o
(3 rows)
)#"
));
LOG(INFO) << "Test finished: " << CURRENT_TEST_CASE_AND_TEST_NAME_STR();
}
// Test backup/restore of a range-partitioned table with a range-partitioned index
// without tablet splitting happening.
// Note: make sure there is no CatalogManager::RepartitionTable's log.
// This indicates the success of backup/restore of range-partitioned tables
// without the help RepartitionTable.
// This test exercises that:
// 1. start with a table with 3 pre-split tablets
// 2. create an index with 3 pre-split tablets
// 3. insert data
// 4. backup
// 5. drop table
// 6. restore
TEST_F_EX(YBBackupTest,
YB_DISABLE_TEST_IN_SANITIZERS(TestPreSplitYSQLRangeSplitTableAndIndex),
YBBackupTestNumTablets) {
const string table_name = "mytbl";
const string index_name = "myidx";
// Create table and index
ASSERT_NO_FATALS(CreateTable(Format("CREATE TABLE $0 (k INT, v TEXT, PRIMARY KEY(k ASC))"
" SPLIT AT VALUES ((10), (20))", table_name)));
ASSERT_NO_FATALS(CreateIndex(Format("CREATE INDEX $0 ON $1 (v ASC)"
" SPLIT AT VALUES (('f'), ('n'))", index_name, table_name)));
// Verify both table and index have 3 tablets
auto tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, table_name));
LogTabletsInfo(tablets);
ASSERT_EQ(tablets.size(), 3);
// 'H' represents the KeyEntryType for Int32.
// \x80\x00\x00\x0a = 0x80000000 ^ 10
// \x80\x00\x00\x14 = 0x80000000 ^ 20
// '!' indicates the end of the range group of a key.
ASSERT_TRUE(CheckPartitions(tablets, {"H\x80\x00\x00\x0a!"s,
"H\x80\x00\x00\x14!"s}));
tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, index_name));
LogTabletsInfo(tablets);
ASSERT_EQ(tablets.size(), 3);
// 'S' represents the KeyEntryType for String.
// "f" and "n" are the split point values.
// one '\0' is the default split point value of an index's hidden column.
// two '\0' terminate a string value.
// '!' indicates the end of the range group of a key.
ASSERT_TRUE(CheckPartitions(tablets, {"Sf\0\0\0!"s, "Sn\0\0\0!"s}));
// Insert data
ASSERT_NO_FATALS(InsertRows(
Format("INSERT INTO $0 VALUES (1,'a'), (11,'h'), (21,'o')", table_name), 3));
ASSERT_NO_FATALS(RunPsqlCommand(
Format("SELECT * FROM $0 ORDER BY v", table_name),
R"#(
k | v
----+---
1 | a
11 | h
21 | o
(3 rows)
)#"
));
// Backup
const string backup_dir = GetTempDir("backup");
ASSERT_OK(RunBackupCommand(
{"--backup_location", backup_dir, "--keyspace", "ysql.yugabyte", "create"}));
// Drop the table
ASSERT_NO_FATALS(RunPsqlCommand(Format("DROP TABLE $0", table_name), "DROP TABLE"));
// Restore
ASSERT_OK(RunBackupCommand({"--backup_location", backup_dir, "restore"}));
// Validate
tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, table_name));
ASSERT_EQ(tablets.size(), 3);
ASSERT_TRUE(CheckPartitions(tablets, {"H\x80\x00\x00\x0a!"s,
"H\x80\x00\x00\x14!"s}));
tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, index_name));
ASSERT_EQ(tablets.size(), 3);
ASSERT_TRUE(CheckPartitions(tablets, {"Sf\0\0\0!"s, "Sn\0\0\0!"s}));
ASSERT_NO_FATALS(RunPsqlCommand(
Format("SELECT * FROM $0 ORDER BY v", table_name),
R"#(
k | v
----+---
1 | a
11 | h
21 | o
(3 rows)
)#"
));
LOG(INFO) << "Test finished: " << CURRENT_TEST_CASE_AND_TEST_NAME_STR();
}
// Test backup/restore when a range-partitioned table undergoes automatic tablet splitting.
// Note: after #12631 is fixed, make sure there is no CatalogManager::RepartitionTable's log.
// This indicates the success of backup/restore of range-partitioned tables
// without the help RepartitionTable.
// This test exercises that:
// 1. start with a table with 2 pre-split tablets
// 2. insert data into the table to trigger automatic tablet splitting
// 3. backup
// 4. drop table
// 5. restore
TEST_F_EX(YBBackupTest,
YB_DISABLE_TEST_IN_SANITIZERS(TestYSQLAutomaticTabletSplitRangeTable),
YBBackupTestNumTablets) {
constexpr int expected_num_tablets = 4;
ASSERT_OK(cluster_->SetFlagOnMasters("tablet_split_low_phase_size_threshold_bytes", "2500"));
// Enable automatic tablet splitting (overriden by YBBackupTestNumTablets).
ASSERT_OK(cluster_->SetFlagOnMasters("enable_automatic_tablet_splitting", "true"));
ASSERT_OK(cluster_->SetFlagOnMasters("tablet_split_limit_per_table",
IntToString(expected_num_tablets)));
const string table_name = "mytbl";
// Create table.
ASSERT_NO_FATALS(CreateTable(Format("CREATE TABLE $0 (k TEXT, PRIMARY KEY(k ASC))"
" SPLIT AT VALUES (('4a'))", table_name)));
auto tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, table_name));
LogTabletsInfo(tablets);
ASSERT_EQ(tablets.size(), 2);
// 'S' represents the KeyEntryType for String.
// "4a" is the split point value.
// two '\0' terminate a string value.
// '!' indicates the end of the range group of a key.
ASSERT_TRUE(CheckPartitions(tablets, {"S4a\0\0!"s}));
// Insert data.
ASSERT_NO_FATALS(InsertRows(
Format("INSERT INTO $0 SELECT i||'a' FROM generate_series(101, 150) i", table_name), 50));
// Flush table so SST file size is accurate.
auto table_id = ASSERT_RESULT(GetTableId(table_name, "pre-split"));
ASSERT_OK(client_->FlushTables({table_id}, false, 30, false));
// Wait for automatic split to complete.
ASSERT_OK(WaitFor(
[&]() -> Result<bool> {
auto res = VERIFY_RESULT(test_admin_client_->GetTabletLocations(default_db_, table_name));
return res.size() == expected_num_tablets;
}, 30s * kTimeMultiplier, Format("Waiting for tablet count: $0", expected_num_tablets)));
// Backup.
const string backup_dir = GetTempDir("backup");
ASSERT_OK(RunBackupCommand(
{"--backup_location", backup_dir, "--keyspace", "ysql.yugabyte", "create"}));
// Drop the table.
ASSERT_NO_FATALS(RunPsqlCommand(Format("DROP TABLE $0", table_name), "DROP TABLE"));
// Restore.
ASSERT_OK(RunBackupCommand({"--backup_location", backup_dir, "restore"}));
// Validate number of tablets after restore.
tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, table_name));
ASSERT_EQ(tablets.size(), expected_num_tablets);
LOG(INFO) << "Test finished: " << CURRENT_TEST_CASE_AND_TEST_NAME_STR();
}
// Test backup/restore when a range-partitioned table undergoes manual tablet splitting.
// Note: after #12631 is fixed, make sure there is no CatalogManager::RepartitionTable's log.
// This indicates the success of backup/restore of range-partitioned tables
// without the help of RepartitionTable.
// This test exercises that:
// 1. start with 2 pre-split tablets
// 2. split one of them (3 tablets)
// 3. further split one of newly created tablets (4 tablets)
// 4. backup
// 5. drop table
// 6. restore
TEST_F_EX(YBBackupTest,
YB_DISABLE_TEST_IN_SANITIZERS(TestYSQLManualTabletSplitRangeTable),
YBBackupTestNumTablets) {
const string table_name = "mytbl";
// Create table
ASSERT_NO_FATALS(CreateTable(Format("CREATE TABLE $0 (k TEXT, PRIMARY KEY(k ASC))"
" SPLIT AT VALUES (('4a'))", table_name)));
auto tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, table_name));
LogTabletsInfo(tablets);
ASSERT_EQ(tablets.size(), 2);
// 'S' represents the KeyEntryType for String.
// "4a" is the split point value.
// two '\0' terminate a string value.
// '!' indicates the end of the range group of a key.
const std::string initial_split_point = "S4a\0\0!"s;
ASSERT_TRUE(CheckPartitions(tablets, {initial_split_point}));
// Insert data
ASSERT_NO_FATALS(InsertRows(
Format("INSERT INTO $0 SELECT i||'a' FROM generate_series(101, 150) i", table_name), 50));
// Flush table
auto table_id = ASSERT_RESULT(GetTableId(table_name, "pre-split"));
ASSERT_OK(client_->FlushTables({table_id}, false, 30, false));
// Split at split depth 0
// Choose the first tablet among tablets: "" --- "4a" and "4a" --- ""
int split_index = 0;
ASSERT_EQ(tablets[split_index].partition().partition_key_start(), "");
ASSERT_EQ(tablets[split_index].partition().partition_key_end(), initial_split_point);
string tablet_id = tablets[split_index].tablet_id();
// Split it && Wait for split to complete.
int num_tablets = 3;
ASSERT_OK(test_admin_client_->SplitTabletAndWait(
default_db_, table_name, /* wait_for_parent_deletion */ true, tablet_id));
// Verify that it has these three tablets:
tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, table_name));
LogTabletsInfo(tablets);
ASSERT_EQ(tablets.size(), num_tablets);
auto two_split_points = ASSERT_RESULT(GetSplitPoints(tablets));
ASSERT_EQ(two_split_points[1], initial_split_point);
// Further split at split depth 1
split_index = 0;
tablet_id = tablets[split_index].tablet_id();
// Split it && wait for split to complete.
num_tablets = 4;
ASSERT_OK(test_admin_client_->SplitTabletAndWait(
default_db_, table_name, /* wait_for_parent_deletion */ false, tablet_id));
// Verify that it has these four tablets:
tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, table_name));
LogTabletsInfo(tablets);
ASSERT_EQ(tablets.size(), num_tablets);
auto three_split_points = ASSERT_RESULT(GetSplitPoints(tablets));
// Verify the 3 split points contain as suffix the earlier 2 split points.
ASSERT_TRUE(std::equal(three_split_points.begin() + 1,
three_split_points.end(),
two_split_points.begin(),
two_split_points.end()));
// Backup
const string backup_dir = GetTempDir("backup");
ASSERT_OK(RunBackupCommand(
{"--backup_location", backup_dir, "--keyspace", "ysql.yugabyte", "create"}));
// Drop the table
ASSERT_NO_FATALS(RunPsqlCommand(Format("DROP TABLE $0", table_name), "DROP TABLE"));
// Restore
ASSERT_OK(RunBackupCommand({"--backup_location", backup_dir, "restore"}));
// Validate
tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, table_name));
ASSERT_EQ(tablets.size(), 4);
auto post_restore_split_points = ASSERT_RESULT(GetSplitPoints(tablets));
ASSERT_EQ(post_restore_split_points,
three_split_points);
LOG(INFO) << "Test finished: " << CURRENT_TEST_CASE_AND_TEST_NAME_STR();
}
// Test backup/restore when a range-partitioned unique index undergoes manual tablet splitting
// on its hidden column: ybuniqueidxkeysuffix.
// This test exercises that:
// 1. create a table and a unique index
// 2. insert data into the table
// 3. split the index on its hidden column into 3 tablets
// 4. backup
// 5. drop table
// 6. restore
TEST_F_EX(YBBackupTest,
YB_DISABLE_TEST_IN_SANITIZERS(TestYSQLTabletSplitRangeUniqueIndexOnHiddenColumn),
YBBackupTestNumTablets) {
const string table_name = "mytbl";
const string index_name = "myidx";
// Create table and index
ASSERT_NO_FATALS(CreateTable(Format("CREATE TABLE $0 (k INT PRIMARY KEY, v INT)", table_name)));
ASSERT_NO_FATALS(CreateIndex(Format("CREATE UNIQUE INDEX $0 ON $1 (v ASC)",
index_name, table_name)));
// Verify the index has only one tablet
auto tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, index_name));
LogTabletsInfo(tablets);
ASSERT_EQ(tablets.size(), 1);
// Use this function for side effects. It validates the begin and end partitions are empty.
ASSERT_RESULT(GetSplitPoints(tablets));
// Insert data
ASSERT_NO_FATALS(InsertRows(
Format("INSERT INTO $0 SELECT *, null FROM generate_series(1, 100)", table_name), 100));
// Flush index
auto index_id = ASSERT_RESULT(GetTableId(index_name, "pre-split"));
ASSERT_OK(client_->FlushTables({index_id}, false, 30, false));
// Split the unique index into three tablets on its hidden column:
// tablet-1 boundaries: [ "", (null, <ybctid-1>) )
// tablet-2 boundaries: [ (null, <ybctid-1>), (null, <ybctid-2>) )
// tablet-3 boundaries: [ (null, <ybctid-2>), "" )
// Split at split depth 0
int split_index = 0;
ASSERT_EQ(tablets[split_index].partition().partition_key_start(), "");
ASSERT_EQ(tablets[split_index].partition().partition_key_end(), "");
string tablet_id = tablets[split_index].tablet_id();
// Split it && Wait for split to complete.
int num_tablets = 2;
ASSERT_OK(test_admin_client_->SplitTabletAndWait(
default_db_, index_name, /* wait_for_parent_deletion */ true, tablet_id));
// Verify that it has these two tablets:
tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, index_name));
LogTabletsInfo(tablets);
ASSERT_EQ(tablets.size(), num_tablets);
auto one_split_point = ASSERT_RESULT(GetSplitPoints(tablets));
// Further split at split depth 1
split_index = 0;
tablet_id = tablets[split_index].tablet_id();
// Split it && Wait for split to complete.
num_tablets = 3;
ASSERT_OK(test_admin_client_->SplitTabletAndWait(
default_db_, index_name, /* wait_for_parent_deletion */ true, tablet_id));
// Verify that it has these three tablets:
tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, index_name));
LogTabletsInfo(tablets);
ASSERT_EQ(tablets.size(), num_tablets);
auto two_split_points = ASSERT_RESULT(GetSplitPoints(tablets));
ASSERT_EQ(two_split_points[1], one_split_point[0]);
// Verify yb_get_range_split_clause returns an empty string because null values are present
// in split points.
ASSERT_NO_FATALS(RunPsqlCommand(
Format("SELECT yb_get_range_split_clause('$0'::regclass)", index_name),
R"#(
yb_get_range_split_clause
---------------------------
(1 row)
)#"
));
// Backup
const string backup_dir = GetTempDir("backup");
ASSERT_OK(RunBackupCommand(
{"--backup_location", backup_dir, "--keyspace", "ysql.yugabyte", "create"}));
// Drop the table
ASSERT_NO_FATALS(RunPsqlCommand(Format("DROP TABLE $0", table_name), "DROP TABLE"));
// Restore
ASSERT_OK(RunBackupCommand({"--backup_location", backup_dir, "restore"}));
// Validate
tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, index_name));
ASSERT_EQ(tablets.size(), 3);
auto post_restore_split_points = ASSERT_RESULT(GetSplitPoints(tablets));
ASSERT_EQ(post_restore_split_points, two_split_points);
// Verify yb_get_range_split_clause returns an empty string because null values are present
// in split points.
ASSERT_NO_FATALS(RunPsqlCommand(
Format("SELECT yb_get_range_split_clause('$0'::regclass)", index_name),
R"#(
yb_get_range_split_clause
---------------------------
(1 row)
)#"
));
LOG(INFO) << "Test finished: " << CURRENT_TEST_CASE_AND_TEST_NAME_STR();
}
// Test backup/restore when a range-partitioned regular index undergoes manual tablet splitting
// on its hidden column: ybidxbasectid.
// This test exercises that:
// 1. create a table and a regular index
// 2. insert data into the table
// 3. split the index on its hidden column into 3 tablets
// 4. backup
// 5. drop table
// 6. restore
TEST_F_EX(YBBackupTest,
YB_DISABLE_TEST_IN_SANITIZERS(TestYSQLTabletSplitRangeIndexOnHiddenColumn),
YBBackupTestNumTablets) {
const string table_name = "mytbl";
const string index_name = "myidx";
// Create table and index
ASSERT_NO_FATALS(CreateTable(Format("CREATE TABLE $0 (k INT PRIMARY KEY, v INT)", table_name)));
ASSERT_NO_FATALS(CreateIndex(Format("CREATE INDEX $0 ON $1 (v ASC)", index_name, table_name)));
// Verify the index has only one tablet
auto tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, index_name));
LogTabletsInfo(tablets);
ASSERT_EQ(tablets.size(), 1);
// Use this function for side effects. It validates the begin and end partitions are empty.
ASSERT_RESULT(GetSplitPoints(tablets));
// Insert data
ASSERT_NO_FATALS(InsertRows(
Format("INSERT INTO $0 SELECT *, 200 FROM generate_series(1, 100)", table_name), 100));
// Flush index
auto index_id = ASSERT_RESULT(GetTableId(index_name, "pre-split"));
ASSERT_OK(client_->FlushTables({index_id}, false, 30, false));
// Split the index into three tablets on its hidden column:
// tablet-1 boundaries: [ "", (200, <ybctid-1>) )
// tablet-2 boundaries: [ (200, <ybctid-1>), (200, <ybctid-2>) )
// tablet-3 boundaries: [ (200, <ybctid-2>), "" )
// Split at split depth 0
int split_index = 0;
ASSERT_EQ(tablets[split_index].partition().partition_key_start(), "");
ASSERT_EQ(tablets[split_index].partition().partition_key_end(), "");
string tablet_id = tablets[split_index].tablet_id();
// Split it && Wait for split to complete.
int num_tablets = 2;
ASSERT_OK(test_admin_client_->SplitTabletAndWait(
default_db_, index_name, /* wait_for_parent_deletion */ true, tablet_id));
// Verify that it has these two tablets:
tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, index_name));
LogTabletsInfo(tablets);
ASSERT_EQ(tablets.size(), num_tablets);
auto one_split_point = ASSERT_RESULT(GetSplitPoints(tablets));
// Further split at split depth 1
split_index = 0;
tablet_id = tablets[split_index].tablet_id();
// Split it && Wait for split to complete.
num_tablets = 3;
ASSERT_OK(test_admin_client_->SplitTabletAndWait(
default_db_, index_name, /* wait_for_parent_deletion */ false, tablet_id));
// Verify that it has these three tablets:
tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, index_name));
LogTabletsInfo(tablets);
ASSERT_EQ(tablets.size(), num_tablets);
auto two_split_points = ASSERT_RESULT(GetSplitPoints(tablets));
ASSERT_EQ(two_split_points[1], one_split_point[0]);
// Backup
const string backup_dir = GetTempDir("backup");
ASSERT_OK(RunBackupCommand(
{"--backup_location", backup_dir, "--keyspace", "ysql.yugabyte", "create"}));
// Drop the table
ASSERT_NO_FATALS(RunPsqlCommand(Format("DROP TABLE $0", table_name), "DROP TABLE"));
// Restore
ASSERT_OK(RunBackupCommand({"--backup_location", backup_dir, "restore"}));
// Validate
tablets = ASSERT_RESULT(test_admin_client_->GetTabletLocations(default_db_, index_name));
ASSERT_EQ(tablets.size(), 3);
auto post_restore_split_points = ASSERT_RESULT(GetSplitPoints(tablets));
ASSERT_EQ(two_split_points,
post_restore_split_points);
LOG(INFO) << "Test finished: " << CURRENT_TEST_CASE_AND_TEST_NAME_STR();
}
class YBBackupAfterFailedMatviewRefresh : public YBBackupTest {
public:
void UpdateMiniClusterOptions(ExternalMiniClusterOptions* options) override {
YBBackupTest::UpdateMiniClusterOptions(options);
options->extra_master_flags.push_back(
"--enable_transactional_ddl_gc=false");
options->extra_tserver_flags.push_back(
"--TEST_yb_test_fail_matview_refresh_after_creation=true");
}
};
// Test that backup and restore succeed when an orphaned table is left behind
// after a failed refresh on a materialized view.
TEST_F_EX(YBBackupTest,
YB_DISABLE_TEST_IN_SANITIZERS(TestYSQLBackupAfterFailedMatviewRefresh),
YBBackupAfterFailedMatviewRefresh) {
const string kDatabaseName = "yugabyte";
const string kNewDatabaseName = "yugabyte_new";
const string base_table = "base";
const string materialized_view = "mv";
ASSERT_NO_FATALS(CreateTable(Format("CREATE TABLE $0 (t int)", base_table)));
ASSERT_NO_FATALS(InsertOneRow(Format("INSERT INTO $0 (t) VALUES (1)", base_table)));
ASSERT_NO_FATALS(RunPsqlCommand(Format("CREATE MATERIALIZED VIEW $0 AS SELECT * FROM $1",
materialized_view,
base_table),
"SELECT 1"));
ASSERT_NO_FATALS(InsertOneRow(Format("INSERT INTO $0 (t) VALUES (1)", base_table)));
ASSERT_NO_FATALS(RunPsqlCommand(Format("REFRESH MATERIALIZED VIEW $0", materialized_view), ""));
const auto matview_table_id = ASSERT_RESULT(GetTableId(materialized_view, "pre-backup"));
const auto matview_table_pg_oid = ASSERT_RESULT(GetPgsqlTableOid(TableId(matview_table_id)));
// Naming convention in PG for the relation created as part of the REFRESH is
// "pg_temp_<OID of matview>".
const auto orphaned_mv = "pg_temp_" + std::to_string(matview_table_pg_oid);
// Verify that the table created as a part of REFRESH still exists.
ASSERT_TRUE(ASSERT_RESULT(client_->TableExists(
client::YBTableName(YQL_DATABASE_PGSQL, kDatabaseName, orphaned_mv))));
// Take a backup, ensure that this passes despite the state of the orphaned_mv.
const string backup_dir = GetTempDir("backup");
ASSERT_OK(RunBackupCommand(
{"--backup_location", backup_dir, "--keyspace", "ysql." + kDatabaseName, "create"}));
// Now try to restore the backup and ensure that only the original materialized view
// was restored.
ASSERT_OK(RunBackupCommand(
{"--backup_location", backup_dir, "--keyspace", "ysql." + kNewDatabaseName, "restore"}));
SetDbName(kNewDatabaseName); // Connecting to the second DB.
ASSERT_NO_FATALS(RunPsqlCommand(
Format("SELECT * FROM $0", materialized_view),
R"#(
t
---
1
(1 row)
)#"
));
ASSERT_FALSE(ASSERT_RESULT(client_->TableExists(client::YBTableName(YQL_DATABASE_PGSQL,
kNewDatabaseName, orphaned_mv))));
}
class YBBackupPartitioningVersionTest : public YBBackupTest {
protected:
Result<uint32_t> GetTablePartitioningVersion(const client::YBTableName& yb_table_name) {
const auto table_info = VERIFY_RESULT(client_->GetYBTableInfo(yb_table_name));
return table_info.schema.table_properties().partitioning_version();
}
Result<uint32_t> GetTablePartitioningVersion(const std::string& table_name,
const std::string& log_prefix, const std::string& ns = std::string()) {
const auto yb_table_name = VERIFY_RESULT(GetTableName(table_name, log_prefix, ns));
return GetTablePartitioningVersion(yb_table_name);
}
Status ForceSetPartitioningVersion(const int32_t version) {
ANNOTATE_UNPROTECTED_WRITE(FLAGS_TEST_partitioning_version) = version;
for (auto ms : cluster_->master_daemons()) {
ms->Shutdown();
ms->mutable_flags()->push_back(Format("--TEST_partitioning_version=$0", version));
RETURN_NOT_OK(ms->Restart());
}
for (auto ts : cluster_->tserver_daemons()) {
ts->Shutdown();
ts->mutable_flags()->push_back(Format("--TEST_partitioning_version=$0", version));
RETURN_NOT_OK(ts->Restart());
}
return cluster_->WaitForTabletServerCount(GetNumTabletServers(), kDefaultTimeout);
}
string default_db_ = "yugabyte";
};
TEST_F_EX(YBBackupTest, YB_DISABLE_TEST_IN_SANITIZERS(TestYCQLPartitioningVersion),
YBBackupPartitioningVersionTest) {
// The test checks that partitioning_version is restored correctly for the tables backuped before
// the next increment of the partitioning_version.
constexpr auto kKeyspace0 = "keyspace0";
constexpr auto kKeyspace1 = "keyspace1";
// 1) Create a table with partitioning_version == 0.
ASSERT_OK(ForceSetPartitioningVersion(0));
const client::YBTableName kTableNameV0(YQL_DATABASE_CQL, kKeyspace0, "mytbl0");