Skip to content

Commit 22600a9

Browse files
authored
Add decimal split boundaries backup / restore test (#10790)
1 parent eebeb70 commit 22600a9

File tree

1 file changed

+94
-41
lines changed

1 file changed

+94
-41
lines changed

ydb/services/ydb/backup_ut/ydb_backup_ut.cpp

Lines changed: 94 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ namespace {
6969
}; \
7070
static TTestRegistration##N testRegistration##N; \
7171
template <ENUM_TYPE Value> \
72-
void TTestCase##N<Value>::Execute_(NUnitTest::TTestContext& ut_context Y_DECLARE_UNUSED)
72+
void TTestCase##N<Value>::Execute_(NUnitTest::TTestContext& ut_context Y_DECLARE_UNUSED)
7373

7474
#define DEBUG_HINT (TStringBuilder() << "at line " << __LINE__)
7575

@@ -316,48 +316,24 @@ void TestTableSplitBoundariesArePreserved(
316316
}
317317

318318
void TestIndexTableSplitBoundariesArePreserved(
319-
const char* table, const char* index, ui64 indexPartitions, TSession& session,
319+
const char* table, const char* index, ui64 indexPartitions, TSession& session, TTableBuilder& tableBuilder,
320320
TBackupFunction&& backup, TRestoreFunction&& restore
321321
) {
322-
const TString indexTablePath = JoinFsPaths(table, index, "indexImplTable");
323-
324322
{
325-
TExplicitPartitions indexPartitionBoundaries;
326-
for (ui32 boundary : {1, 2, 4, 8, 16, 32, 64, 128, 256}) {
327-
indexPartitionBoundaries.AppendSplitPoints(
328-
// split boundary is technically always a tuple
329-
TValueBuilder().BeginTuple().AddElement().OptionalUint32(boundary).EndTuple().Build()
330-
);
331-
}
332-
// By default indexImplTable has auto partitioning by size enabled,
333-
// so you must set min partition count for partitions to not merge immediately after indexImplTable is built.
334-
TPartitioningSettingsBuilder partitioningSettingsBuilder;
335-
partitioningSettingsBuilder
336-
.SetMinPartitionsCount(indexPartitions)
337-
.SetMaxPartitionsCount(indexPartitions);
338-
339-
const auto indexSettings = TGlobalIndexSettings{
340-
.PartitioningSettings = partitioningSettingsBuilder.Build(),
341-
.Partitions = std::move(indexPartitionBoundaries)
342-
};
343-
344-
auto tableBuilder = TTableBuilder()
345-
.AddNullableColumn("Key", EPrimitiveType::Uint32)
346-
.AddNullableColumn("Value", EPrimitiveType::Uint32)
347-
.SetPrimaryKeyColumn("Key")
348-
.AddSecondaryIndex(TIndexDescription("byValue", EIndexType::GlobalSync, { "Value" }, {}, { indexSettings }));
349-
350323
const auto result = session.CreateTable(table, tableBuilder.Build()).ExtractValueSync();
351324
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());
352325
}
326+
327+
const TString indexTablePath = JoinFsPaths(table, index, "indexImplTable");
353328
const auto describeSettings = TDescribeTableSettings()
354329
.WithTableStatistics(true)
355330
.WithKeyShardBoundary(true);
356-
const auto originalIndexTableDescription = GetTableDescription(
331+
332+
const auto originalDescription = GetTableDescription(
357333
session, indexTablePath, describeSettings
358334
);
359-
UNIT_ASSERT_VALUES_EQUAL(originalIndexTableDescription.GetPartitionsCount(), indexPartitions);
360-
const auto& originalKeyRanges = originalIndexTableDescription.GetKeyRanges();
335+
UNIT_ASSERT_VALUES_EQUAL(originalDescription.GetPartitionsCount(), indexPartitions);
336+
const auto& originalKeyRanges = originalDescription.GetKeyRanges();
361337
UNIT_ASSERT_VALUES_EQUAL(originalKeyRanges.size(), indexPartitions);
362338

363339
backup(table);
@@ -368,11 +344,11 @@ void TestIndexTableSplitBoundariesArePreserved(
368344
));
369345

370346
restore(table);
371-
const auto restoredIndexTableDescription = GetTableDescription(
347+
const auto restoredDescription = GetTableDescription(
372348
session, indexTablePath, describeSettings
373349
);
374-
UNIT_ASSERT_VALUES_EQUAL(restoredIndexTableDescription.GetPartitionsCount(), indexPartitions);
375-
const auto& restoredKeyRanges = restoredIndexTableDescription.GetKeyRanges();
350+
UNIT_ASSERT_VALUES_EQUAL(restoredDescription.GetPartitionsCount(), indexPartitions);
351+
const auto& restoredKeyRanges = restoredDescription.GetKeyRanges();
376352
UNIT_ASSERT_VALUES_EQUAL(restoredKeyRanges.size(), indexPartitions);
377353
UNIT_ASSERT_EQUAL(restoredKeyRanges, originalKeyRanges);
378354
}
@@ -464,7 +440,7 @@ void TestRestoreTableWithIndex(
464440
DROP TABLE `%s`;
465441
)", table
466442
));
467-
443+
468444
restore(table);
469445

470446
CheckTableDescription(session, table, CreateHasIndexChecker(index, ConvertIndexTypeToAPI(indexType)));
@@ -608,7 +584,7 @@ Y_UNIT_TEST_SUITE(BackupRestore) {
608584
const auto& pathToBackup = tempDir.Path();
609585
constexpr const char* table = "/Root/table";
610586
constexpr const char* index = "byValue";
611-
587+
612588
TestRestoreTableWithIndex(
613589
table,
614590
index,
@@ -655,7 +631,7 @@ Y_UNIT_TEST_SUITE(BackupRestore) {
655631

656632
Y_UNIT_TEST_ALL_PROTO_ENUM_VALUES(TestAllSchemeObjectTypes, NKikimrSchemeOp::EPathType) {
657633
using namespace NKikimrSchemeOp;
658-
634+
659635
switch (Value) {
660636
case EPathTypeTable:
661637
TestTableBackupRestore();
@@ -707,7 +683,7 @@ Y_UNIT_TEST_SUITE(BackupRestore) {
707683

708684
Y_UNIT_TEST_ALL_PROTO_ENUM_VALUES(TestAllIndexTypes, NKikimrSchemeOp::EIndexType) {
709685
using namespace NKikimrSchemeOp;
710-
686+
711687
switch (Value) {
712688
case EIndexTypeGlobal:
713689
case EIndexTypeGlobalAsync:
@@ -907,11 +883,88 @@ Y_UNIT_TEST_SUITE(BackupRestoreS3) {
907883
constexpr const char* index = "byValue";
908884
constexpr ui64 indexPartitions = 10;
909885

886+
TExplicitPartitions indexPartitionBoundaries;
887+
for (ui32 i = 1; i < indexPartitions; ++i) {
888+
indexPartitionBoundaries.AppendSplitPoints(
889+
// split boundary is technically always a tuple
890+
TValueBuilder().BeginTuple().AddElement().OptionalUint32(i * 10).EndTuple().Build()
891+
);
892+
}
893+
// By default indexImplTables have auto partitioning by size enabled.
894+
// If you don't want the partitions to merge immediately after the indexImplTable is built,
895+
// you must set the min partition count for the table.
896+
TPartitioningSettingsBuilder partitioningSettingsBuilder;
897+
partitioningSettingsBuilder
898+
.SetMinPartitionsCount(indexPartitions)
899+
.SetMaxPartitionsCount(indexPartitions);
900+
901+
const auto indexSettings = TGlobalIndexSettings{
902+
.PartitioningSettings = partitioningSettingsBuilder.Build(),
903+
.Partitions = std::move(indexPartitionBoundaries)
904+
};
905+
906+
auto tableBuilder = TTableBuilder()
907+
.AddNullableColumn("Key", EPrimitiveType::Uint32)
908+
.AddNullableColumn("Value", EPrimitiveType::Uint32)
909+
.SetPrimaryKeyColumn("Key")
910+
.AddSecondaryIndex(TIndexDescription(index, EIndexType::GlobalSync, { "Value" }, {}, { indexSettings }));
911+
912+
TestIndexTableSplitBoundariesArePreserved(
913+
table,
914+
index,
915+
indexPartitions,
916+
testEnv.GetSession(),
917+
tableBuilder,
918+
CreateBackupLambda(testEnv.GetDriver(), testEnv.GetS3Port()),
919+
CreateRestoreLambda(testEnv.GetDriver(), testEnv.GetS3Port())
920+
);
921+
}
922+
923+
Y_UNIT_TEST(RestoreIndexTableDecimalSplitBoundaries) {
924+
TS3TestEnv testEnv;
925+
constexpr const char* table = "/Root/table";
926+
constexpr const char* index = "byValue";
927+
constexpr ui64 indexPartitions = 10;
928+
929+
constexpr ui8 decimalPrecision = 22;
930+
constexpr ui8 decimalScale = 9;
931+
932+
TExplicitPartitions indexPartitionBoundaries;
933+
for (ui32 i = 1; i < indexPartitions; ++i) {
934+
TDecimalValue boundary(ToString(i * 10), decimalPrecision, decimalScale);
935+
indexPartitionBoundaries.AppendSplitPoints(
936+
// split boundary is technically always a tuple
937+
TValueBuilder()
938+
.BeginTuple().AddElement()
939+
.BeginOptional().Decimal(boundary).EndOptional()
940+
.EndTuple().Build()
941+
);
942+
}
943+
// By default indexImplTables have auto partitioning by size enabled.
944+
// If you don't want the partitions to merge immediately after the indexImplTable is built,
945+
// you must set the min partition count for the table.
946+
TPartitioningSettingsBuilder partitioningSettingsBuilder;
947+
partitioningSettingsBuilder
948+
.SetMinPartitionsCount(indexPartitions)
949+
.SetMaxPartitionsCount(indexPartitions);
950+
951+
const auto indexSettings = TGlobalIndexSettings{
952+
.PartitioningSettings = partitioningSettingsBuilder.Build(),
953+
.Partitions = std::move(indexPartitionBoundaries)
954+
};
955+
956+
auto tableBuilder = TTableBuilder()
957+
.AddNullableColumn("Key", EPrimitiveType::Uint32)
958+
.AddNullableColumn("Value", TDecimalType(decimalPrecision, decimalScale))
959+
.SetPrimaryKeyColumn("Key")
960+
.AddSecondaryIndex(TIndexDescription(index, EIndexType::GlobalSync, { "Value" }, {}, { indexSettings }));
961+
910962
TestIndexTableSplitBoundariesArePreserved(
911963
table,
912964
index,
913965
indexPartitions,
914966
testEnv.GetSession(),
967+
tableBuilder,
915968
CreateBackupLambda(testEnv.GetDriver(), testEnv.GetS3Port()),
916969
CreateRestoreLambda(testEnv.GetDriver(), testEnv.GetS3Port())
917970
);
@@ -958,7 +1011,7 @@ Y_UNIT_TEST_SUITE(BackupRestoreS3) {
9581011

9591012
Y_UNIT_TEST_ALL_PROTO_ENUM_VALUES(TestAllSchemeObjectTypes, NKikimrSchemeOp::EPathType) {
9601013
using namespace NKikimrSchemeOp;
961-
1014+
9621015
switch (Value) {
9631016
case EPathTypeTable:
9641017
TestTableBackupRestore();
@@ -1009,7 +1062,7 @@ Y_UNIT_TEST_SUITE(BackupRestoreS3) {
10091062

10101063
Y_UNIT_TEST_ALL_PROTO_ENUM_VALUES(TestAllIndexTypes, NKikimrSchemeOp::EIndexType) {
10111064
using namespace NKikimrSchemeOp;
1012-
1065+
10131066
switch (Value) {
10141067
case EIndexTypeGlobal:
10151068
case EIndexTypeGlobalAsync:

0 commit comments

Comments
 (0)