From 805e8edbb2ae5fd333c6558d524d34e0b30c71e6 Mon Sep 17 00:00:00 2001 From: azevaykin Date: Fri, 7 Feb 2025 19:54:10 +0300 Subject: [PATCH] Test: split shard with decimal PK --- .../tx/schemeshard/ut_helpers/helpers.cpp | 31 +++++- ydb/core/tx/schemeshard/ut_helpers/helpers.h | 1 + .../ut_split_merge/ut_split_merge.cpp | 100 ++++++++++-------- 3 files changed, 85 insertions(+), 47 deletions(-) diff --git a/ydb/core/tx/schemeshard/ut_helpers/helpers.cpp b/ydb/core/tx/schemeshard/ut_helpers/helpers.cpp index f7b04092c3e3..0a2c53de42b0 100644 --- a/ydb/core/tx/schemeshard/ut_helpers/helpers.cpp +++ b/ydb/core/tx/schemeshard/ut_helpers/helpers.cpp @@ -2487,7 +2487,8 @@ namespace NSchemeShardUT_Private { const auto& sender = runtime.AllocateEdgeActor(); ForwardToTablet(runtime, datashardTabletId, sender, ev.Release()); - runtime.GrabEdgeEvent(sender); + auto evResponse = runtime.GrabEdgeEventRethrow(sender); + UNIT_ASSERT_C(evResponse->Get()->Record.GetStatus() == NKikimrTxDataShard::TError::OK, "Status: " << evResponse->Get()->Record.GetStatus() << " Issues: " << evResponse->Get()->Record.GetErrorDescription()); } void WriteRow(TTestActorRuntime& runtime, const ui64 txId, const TString& tablePath, int partitionIdx, const ui32 key, const TString& value, bool successIsExpected) { @@ -2537,4 +2538,32 @@ namespace NSchemeShardUT_Private { SendNextValRequest(runtime, sender, path); return WaitNextValResult(runtime, sender, expectedStatus); } + + void WaitForTableSplit(TTestActorRuntime& runtime, const TString& path) { + while (true) { + TVector> suppressed; + auto prevObserver = SetSuppressObserver(runtime, suppressed, TEvDataShard::TEvGetTableStatsResult::EventType); + + WaitForSuppressed(runtime, suppressed, 1, prevObserver); + for (auto &msg : suppressed) { + runtime.Send(msg.Release()); + } + suppressed.clear(); + + bool itIsEnough = false; + + NLs::TCheckFunc checkPartitionCount = [&] (const NKikimrScheme::TEvDescribeSchemeResult& record) { + if (record.GetPathDescription().TablePartitionsSize() >= 10) { + itIsEnough = true; + } + }; + + TestDescribeResult(DescribePath(runtime, path, true), + {checkPartitionCount}); + + if (itIsEnough) { + return; + } + } + } } diff --git a/ydb/core/tx/schemeshard/ut_helpers/helpers.h b/ydb/core/tx/schemeshard/ut_helpers/helpers.h index bcca433cc1cc..78138030a376 100644 --- a/ydb/core/tx/schemeshard/ut_helpers/helpers.h +++ b/ydb/core/tx/schemeshard/ut_helpers/helpers.h @@ -636,4 +636,5 @@ namespace NSchemeShardUT_Private { TTestActorRuntime& runtime, const TString& path, Ydb::StatusIds::StatusCode expectedStatus = Ydb::StatusIds::SUCCESS); + void WaitForTableSplit(TTestActorRuntime& runtime, const TString& path); } //NSchemeShardUT_Private diff --git a/ydb/core/tx/schemeshard/ut_split_merge/ut_split_merge.cpp b/ydb/core/tx/schemeshard/ut_split_merge/ut_split_merge.cpp index 953526ad7eff..b8e9b246c401 100644 --- a/ydb/core/tx/schemeshard/ut_split_merge/ut_split_merge.cpp +++ b/ydb/core/tx/schemeshard/ut_split_merge/ut_split_merge.cpp @@ -132,34 +132,66 @@ Y_UNIT_TEST_SUITE(TSchemeShardSplitBySizeTest) { )"); env.TestWaitNotification(runtime, txId); - while (true) { - TVector> suppressed; - auto prevObserver = SetSuppressObserver(runtime, suppressed, TEvDataShard::TEvGetTableStatsResult::EventType); + WaitForTableSplit(runtime, "/MyRoot/Table"); + } - WaitForSuppressed(runtime, suppressed, 1, prevObserver); - for (auto &msg : suppressed) { - runtime.Send(msg.Release()); - } - suppressed.clear(); + Y_UNIT_TEST(SplitShardsWithDecimalKey) { + TTestBasicRuntime runtime; - bool itIsEnough = false; + TTestEnvOptions opts; + opts.EnableBackgroundCompaction(false); - NLs::TCheckFunc checkPartitionCount = [&] (const NKikimrScheme::TEvDescribeSchemeResult& record) { - if (record.GetPathDescription().TablePartitionsSize() >= 10) { - itIsEnough = true; - } - }; + TTestEnv env(runtime, opts); - TestDescribeResult(DescribePath(runtime, "/MyRoot/Table", true), - {checkPartitionCount}); + ui64 txId = 100; - if (itIsEnough) { - return; - } + NDataShard::gDbStatsReportInterval = TDuration::Seconds(1); + NDataShard::gDbStatsDataSizeResolution = 10; + NDataShard::gDbStatsRowCountResolution = 10; + + runtime.SetLogPriority(NKikimrServices::TX_DATASHARD, NActors::NLog::PRI_ERROR); + runtime.SetLogPriority(NKikimrServices::FLAT_TX_SCHEMESHARD, NActors::NLog::PRI_ERROR); + + TestCreateTable(runtime, ++txId, "/MyRoot", R"_( + Name: "Table" + Columns { Name: "key" Type: "Decimal(35, 10)"} + Columns { Name: "decimal_value" Type: "Decimal(2, 1)"} + Columns { Name: "string_value" Type: "Utf8"} + KeyColumnNames: ["key"] + )_"); + env.TestWaitNotification(runtime, txId); + + const std::pair decimalValue = NYql::NDecimal::MakePair( + NYql::NDecimal::FromString("32.1", 2, 1)); + TString stringValue(1000, 'A'); + + for (ui64 key = 0; key < 1000; ++key) { + const std::pair decimalKey = NYql::NDecimal::MakePair( + NYql::NDecimal::FromString(Sprintf("%d.123456789", key * 1'000'000), 35, 10)); + UploadRow(runtime, "/MyRoot/Table", 0, {1}, {2, 3}, + {TCell::Make>(decimalKey)}, + {TCell::Make>(decimalValue), TCell(stringValue)}); } + + TestDescribeResult(DescribePath(runtime, "/MyRoot/Table", true), + {NLs::PartitionCount(1)}); + + TestAlterTable(runtime, ++txId, "/MyRoot", R"( + Name: "Table" + PartitionConfig { + PartitioningPolicy { + MinPartitionsCount: 100 + MaxPartitionsCount: 100 + SizeToSplit: 1 + } + } + )"); + env.TestWaitNotification(runtime, txId); + + WaitForTableSplit(runtime, "/MyRoot/Table"); } - Y_UNIT_TEST(SplitShardsWhithPgKey) { + Y_UNIT_TEST(SplitShardsWithPgKey) { TTestBasicRuntime runtime; TTestEnvOptions opts; @@ -185,7 +217,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardSplitBySizeTest) { )"); env.TestWaitNotification(runtime, txId); - TString valueString = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; + TString valueString(1000, 'A');; for (ui64 key = 0; key < 1000; ++key) { auto pgKey = NPg::PgNativeBinaryFromNativeText(ToString(key * 1'000'000), NPg::TypeDescFromPgTypeName("pgint8")).Str; UploadRow(runtime, "/MyRoot/Table", 0, {1}, {2}, {TCell(pgKey)}, {TCell(valueString)}); @@ -206,31 +238,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardSplitBySizeTest) { )"); env.TestWaitNotification(runtime, txId); - while (true) { - TVector> suppressed; - auto prevObserver = SetSuppressObserver(runtime, suppressed, TEvDataShard::TEvGetTableStatsResult::EventType); - - WaitForSuppressed(runtime, suppressed, 1, prevObserver); - for (auto &msg : suppressed) { - runtime.Send(msg.Release()); - } - suppressed.clear(); - - bool itIsEnough = false; - - NLs::TCheckFunc checkPartitionCount = [&] (const NKikimrScheme::TEvDescribeSchemeResult& record) { - if (record.GetPathDescription().TablePartitionsSize() >= 10) { - itIsEnough = true; - } - }; - - TestDescribeResult(DescribePath(runtime, "/MyRoot/Table", true), - {checkPartitionCount}); - - if (itIsEnough) { - return; - } - } + WaitForTableSplit(runtime, "/MyRoot/Table"); } Y_UNIT_TEST(Merge1KShards) {