1
1
#include " ydb_common_ut.h"
2
2
3
+ #include < ydb/core/tx/datashard/datashard.h>
3
4
#include < ydb/core/wrappers/ut_helpers/s3_mock.h>
4
5
5
6
#include < ydb/public/lib/ydb_cli/dump/dump.h>
13
14
#include < ydb/library/backup/backup.h>
14
15
15
16
#include < library/cpp/testing/hook/hook.h>
17
+ #include < library/cpp/testing/unittest/registar.h>
16
18
17
19
#include < aws/core/Aws.h>
18
20
@@ -21,6 +23,8 @@ using namespace NYdb::NTable;
21
23
22
24
namespace {
23
25
26
+ #define DEBUG_HINT (TStringBuilder() << " at line " << __LINE__)
27
+
24
28
void ExecuteDataDefinitionQuery (TSession& session, const TString& script) {
25
29
const auto result = session.ExecuteSchemeQuery (script).ExtractValueSync ();
26
30
UNIT_ASSERT_C (result.IsSuccess (), " script:\n " << script << " \n issues:\n " << result.GetIssues ().ToString ());
@@ -50,15 +54,19 @@ ui64 GetUint64(const TValue& value) {
50
54
return TValueParser (value).GetUint64 ();
51
55
}
52
56
53
- auto CreateMinPartitionsChecker (ui64 expectedMinPartitions) {
57
+ auto CreateMinPartitionsChecker (ui64 expectedMinPartitions, const TString& debugHint = " " ) {
54
58
return [=](const TTableDescription& tableDescription) {
55
- return tableDescription.GetPartitioningSettings ().GetMinPartitionsCount () == expectedMinPartitions;
59
+ UNIT_ASSERT_VALUES_EQUAL_C (
60
+ tableDescription.GetPartitioningSettings ().GetMinPartitionsCount (),
61
+ expectedMinPartitions,
62
+ debugHint
63
+ );
56
64
};
57
65
}
58
66
59
- auto CreatePartitionCountChecker (ui64 expectedPartitionCount) {
67
+ auto CreatePartitionCountChecker (ui64 expectedPartitionCount, const TString& debugHint = " " ) {
60
68
return [=](const TTableDescription& tableDescription) {
61
- return tableDescription.GetPartitionsCount () == expectedPartitionCount;
69
+ UNIT_ASSERT_VALUES_EQUAL_C ( tableDescription.GetPartitionsCount (), expectedPartitionCount, debugHint) ;
62
70
};
63
71
}
64
72
@@ -68,13 +76,7 @@ void CheckTableDescription(TSession& session, const TString& path, auto&& checke
68
76
auto describeResult = session.DescribeTable (path, settings).ExtractValueSync ();
69
77
UNIT_ASSERT_C (describeResult.IsSuccess (), describeResult.GetIssues ().ToString ());
70
78
auto tableDescription = describeResult.GetTableDescription ();
71
- Ydb::Table::CreateTableRequest descriptionProto;
72
- // The purpose of translating to CreateTableRequest is solely to produce a clearer error message.
73
- tableDescription.SerializeTo (descriptionProto);
74
- UNIT_ASSERT_C (
75
- checker (tableDescription),
76
- descriptionProto.DebugString ()
77
- );
79
+ checker (tableDescription);
78
80
}
79
81
80
82
}
@@ -175,7 +177,7 @@ Y_UNIT_TEST_SUITE(BackupRestore) {
175
177
table, minPartitions
176
178
));
177
179
178
- CheckTableDescription (session, table, CreateMinPartitionsChecker (minPartitions));
180
+ CheckTableDescription (session, table, CreateMinPartitionsChecker (minPartitions, DEBUG_HINT ));
179
181
180
182
TTempDir tempDir;
181
183
const auto & pathToBackup = tempDir.Path ();
@@ -190,7 +192,7 @@ Y_UNIT_TEST_SUITE(BackupRestore) {
190
192
)" , table
191
193
));
192
194
Restore (backupClient, pathToBackup, " /Root" );
193
- CheckTableDescription (session, table, CreateMinPartitionsChecker (minPartitions));
195
+ CheckTableDescription (session, table, CreateMinPartitionsChecker (minPartitions, DEBUG_HINT ));
194
196
}
195
197
196
198
Y_UNIT_TEST (RestoreIndexTablePartitioningSettings) {
@@ -221,7 +223,7 @@ Y_UNIT_TEST_SUITE(BackupRestore) {
221
223
)" , table, index , minPartitions
222
224
));
223
225
224
- CheckTableDescription (session, indexTablePath, CreateMinPartitionsChecker (minPartitions));
226
+ CheckTableDescription (session, indexTablePath, CreateMinPartitionsChecker (minPartitions, DEBUG_HINT ));
225
227
226
228
TTempDir tempDir;
227
229
const auto & pathToBackup = tempDir.Path ();
@@ -236,7 +238,7 @@ Y_UNIT_TEST_SUITE(BackupRestore) {
236
238
)" , table
237
239
));
238
240
Restore (backupClient, pathToBackup, " /Root" );
239
- CheckTableDescription (session, indexTablePath, CreateMinPartitionsChecker (minPartitions));
241
+ CheckTableDescription (session, indexTablePath, CreateMinPartitionsChecker (minPartitions, DEBUG_HINT ));
240
242
}
241
243
242
244
}
@@ -295,6 +297,10 @@ Y_UNIT_TEST_SUITE(BackupRestoreS3) {
295
297
ui16 GetS3Port () const {
296
298
return s3Port;
297
299
}
300
+
301
+ const THashMap<TString, TString>& GetS3Data () const {
302
+ return s3Mock.GetData ();
303
+ }
298
304
};
299
305
300
306
template <typename TOperation>
@@ -426,7 +432,7 @@ Y_UNIT_TEST_SUITE(BackupRestoreS3) {
426
432
table, minPartitions
427
433
));
428
434
429
- CheckTableDescription (testEnv.GetSession (), table, CreateMinPartitionsChecker (minPartitions));
435
+ CheckTableDescription (testEnv.GetSession (), table, CreateMinPartitionsChecker (minPartitions, DEBUG_HINT ));
430
436
431
437
NExport::TExportClient exportClient (testEnv.GetDriver ());
432
438
NImport::TImportClient importClient (testEnv.GetDriver ());
@@ -441,7 +447,7 @@ Y_UNIT_TEST_SUITE(BackupRestoreS3) {
441
447
));
442
448
443
449
ImportFromS3 (importClient, testEnv.GetS3Port (), operationClient, " table" , table);
444
- CheckTableDescription (testEnv.GetSession (), table, CreateMinPartitionsChecker (minPartitions));
450
+ CheckTableDescription (testEnv.GetSession (), table, CreateMinPartitionsChecker (minPartitions, DEBUG_HINT ));
445
451
}
446
452
447
453
Y_UNIT_TEST (RestoreIndexTablePartitioningSettings) {
@@ -469,7 +475,7 @@ Y_UNIT_TEST_SUITE(BackupRestoreS3) {
469
475
)" , table, index , minPartitions
470
476
));
471
477
472
- CheckTableDescription (testEnv.GetSession (), indexTablePath, CreateMinPartitionsChecker (minPartitions));
478
+ CheckTableDescription (testEnv.GetSession (), indexTablePath, CreateMinPartitionsChecker (minPartitions, DEBUG_HINT ));
473
479
474
480
NExport::TExportClient exportClient (testEnv.GetDriver ());
475
481
NImport::TImportClient importClient (testEnv.GetDriver ());
@@ -484,7 +490,7 @@ Y_UNIT_TEST_SUITE(BackupRestoreS3) {
484
490
));
485
491
486
492
ImportFromS3 (importClient, testEnv.GetS3Port (), operationClient, " table" , table);
487
- CheckTableDescription (testEnv.GetSession (), indexTablePath, CreateMinPartitionsChecker (minPartitions));
493
+ CheckTableDescription (testEnv.GetSession (), indexTablePath, CreateMinPartitionsChecker (minPartitions, DEBUG_HINT ));
488
494
}
489
495
490
496
Y_UNIT_TEST (RestoreTableSplitBoundaries) {
@@ -505,7 +511,7 @@ Y_UNIT_TEST_SUITE(BackupRestoreS3) {
505
511
table, partitions
506
512
));
507
513
508
- CheckTableDescription (testEnv.GetSession (), table, CreatePartitionCountChecker (partitions),
514
+ CheckTableDescription (testEnv.GetSession (), table, CreatePartitionCountChecker (partitions, DEBUG_HINT ),
509
515
TDescribeTableSettings ().WithTableStatistics (true )
510
516
);
511
517
@@ -522,7 +528,166 @@ Y_UNIT_TEST_SUITE(BackupRestoreS3) {
522
528
));
523
529
524
530
ImportFromS3 (importClient, testEnv.GetS3Port (), operationClient, " table" , table);
525
- CheckTableDescription (testEnv.GetSession (), table, CreatePartitionCountChecker (partitions),
531
+ CheckTableDescription (testEnv.GetSession (), table, CreatePartitionCountChecker (partitions, DEBUG_HINT),
532
+ TDescribeTableSettings ().WithTableStatistics (true )
533
+ );
534
+ }
535
+
536
+ Y_UNIT_TEST (RestoreIndexTableSplitBoundaries) {
537
+ TS3TestEnv testEnv;
538
+
539
+ NDataShard::gDbStatsReportInterval = TDuration::Zero ();
540
+ NDataShard::gDbStatsDataSizeResolution = 1 ; // to do: try to remove
541
+ NDataShard::gDbStatsRowCountResolution = 1 ; // to do: try to remove
542
+
543
+ constexpr const char * table = " /Root/table" ;
544
+ constexpr const char * index = " byValue" ;
545
+ const TString indexTablePath = JoinFsPaths (table, index , " indexImplTable" );
546
+ constexpr int partitions = 5 ;
547
+
548
+ constexpr const char * textDescription = R"(
549
+ Name: "table"
550
+ Columns { Name: "Key" Type: "Uint32"}
551
+ Columns { Name: "Value" Type: "Uint32"}
552
+ Columns { Name: "Payload" Type: "Utf8"}
553
+ KeyColumnNames: ["Key"]
554
+ )" ;
555
+ NKikimrSchemeOp::TTableDescription protoDescription;
556
+ UNIT_ASSERT (google::protobuf::TextFormat::ParseFromString (textDescription, &protoDescription));
557
+ TClient client (*testEnv.GetServer ().ServerSettings );
558
+ // const auto status = client.CreateTable("/Root", tableDescr);
559
+ const auto status = client.CreateTableWithUniformShardedIndex (
560
+ " /Root" , protoDescription, index , {" Value" }, NKikimrSchemeOp::EIndexTypeGlobal, {" Payload" }, partitions
561
+ );
562
+ UNIT_ASSERT_VALUES_EQUAL (status, NMsgBusProxy::EResponseStatus::MSTATUS_OK);
563
+ /*
564
+ ExecuteDataDefinitionQuery(testEnv.GetSession(), Sprintf(R"(
565
+ CREATE TABLE `%s` (
566
+ Key Uint32,
567
+ Value Utf8,
568
+ PRIMARY KEY (Key),
569
+ INDEX %s GLOBAL ON (Value)
570
+ );
571
+ )",
572
+ table, index
573
+ ));
574
+
575
+ ExecuteDataDefinitionQuery(testEnv.GetSession(), Sprintf(R"(
576
+ ALTER TABLE `%s` ALTER INDEX %s SET (
577
+ AUTO_PARTITIONING_PARTITION_SIZE_MB = 1,
578
+ AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = %d,
579
+ AUTO_PARTITIONING_MAX_PARTITIONS_COUNT = %d
580
+ );
581
+ )", table, index, partitions, partitions
582
+ ));
583
+ const auto oneMegabyteValue = TString(100'000, 'a');
584
+ ExecuteDataModificationQuery(testEnv.GetSession(), Sprintf(R"(
585
+ UPSERT INTO `%s` (
586
+ Key,
587
+ Value
588
+ )
589
+ VALUES
590
+ (1, "%s"),
591
+ (2, "%s"),
592
+ (3, "%s"),
593
+ (4, "%s"),
594
+ (5, "%s"),
595
+ (6, "%s"),
596
+ (7, "%s"),
597
+ (8, "%s"),
598
+ (9, "%s"),
599
+ (10, "%s"),
600
+ (11, "%s"),
601
+ (12, "%s"),
602
+ (13, "%s"),
603
+ (14, "%s"),
604
+ (15, "%s"),
605
+ (16, "%s"),
606
+ (17, "%s"),
607
+ (18, "%s"),
608
+ (19, "%s"),
609
+ (20, "%s"),
610
+ (21, "%s"),
611
+ (22, "%s"),
612
+ (23, "%s"),
613
+ (24, "%s"),
614
+ (25, "%s"),
615
+ (26, "%s"),
616
+ (27, "%s"),
617
+ (28, "%s"),
618
+ (29, "%s"),
619
+ (30, "%s"),
620
+ (31, "%s"),
621
+ (32, "%s"),
622
+ (33, "%s");
623
+ )",
624
+ table,
625
+ oneMegabyteValue.c_str(),
626
+ oneMegabyteValue.c_str(),
627
+ oneMegabyteValue.c_str(),
628
+ oneMegabyteValue.c_str(),
629
+ oneMegabyteValue.c_str(),
630
+ oneMegabyteValue.c_str(),
631
+ oneMegabyteValue.c_str(),
632
+ oneMegabyteValue.c_str(),
633
+ oneMegabyteValue.c_str(),
634
+ oneMegabyteValue.c_str(),
635
+ oneMegabyteValue.c_str(),
636
+ oneMegabyteValue.c_str(),
637
+ oneMegabyteValue.c_str(),
638
+ oneMegabyteValue.c_str(),
639
+ oneMegabyteValue.c_str(),
640
+ oneMegabyteValue.c_str(),
641
+ oneMegabyteValue.c_str(),
642
+ oneMegabyteValue.c_str(),
643
+ oneMegabyteValue.c_str(),
644
+ oneMegabyteValue.c_str(),
645
+ oneMegabyteValue.c_str(),
646
+ oneMegabyteValue.c_str(),
647
+ oneMegabyteValue.c_str(),
648
+ oneMegabyteValue.c_str(),
649
+ oneMegabyteValue.c_str(),
650
+ oneMegabyteValue.c_str(),
651
+ oneMegabyteValue.c_str(),
652
+ oneMegabyteValue.c_str(),
653
+ oneMegabyteValue.c_str(),
654
+ oneMegabyteValue.c_str(),
655
+ oneMegabyteValue.c_str(),
656
+ oneMegabyteValue.c_str(),
657
+ oneMegabyteValue.c_str()
658
+ ));
659
+ Sleep(TDuration::Seconds(60));
660
+ */
661
+
662
+ CheckTableDescription (testEnv.GetSession (), indexTablePath, CreatePartitionCountChecker (partitions, DEBUG_HINT),
663
+ TDescribeTableSettings ().WithTableStatistics (true )
664
+ );
665
+
666
+ NExport::TExportClient exportClient (testEnv.GetDriver ());
667
+ NImport::TImportClient importClient (testEnv.GetDriver ());
668
+ NOperation::TOperationClient operationClient (testEnv.GetDriver ());
669
+
670
+ ExportToS3 (exportClient, testEnv.GetS3Port (), operationClient, table, " table" );
671
+ // debug begin
672
+ const auto & exportedData = testEnv.GetS3Data ();
673
+ const auto * scheme = exportedData.FindPtr (" /test_bucket/table/scheme.pb" );
674
+ if (!scheme) {
675
+ for (const auto & [name, content] : exportedData) {
676
+ Cerr << " --- name: " << name << " , content: " << content << ' \n ' ;
677
+ }
678
+ } else {
679
+ Cerr << " --- scheme:\n " << *scheme << ' \n ' ;
680
+ }
681
+ // debug end
682
+
683
+ // The table needs to be dropped before importing from S3 can proceed successfully.
684
+ ExecuteDataDefinitionQuery (testEnv.GetSession (), Sprintf (R"(
685
+ DROP TABLE `%s`;
686
+ )" , table
687
+ ));
688
+
689
+ ImportFromS3 (importClient, testEnv.GetS3Port (), operationClient, " table" , table);
690
+ CheckTableDescription (testEnv.GetSession (), indexTablePath, CreatePartitionCountChecker (partitions, DEBUG_HINT),
526
691
TDescribeTableSettings ().WithTableStatistics (true )
527
692
);
528
693
}
0 commit comments