|
1 | 1 | #include "helpers/typed_local.h" |
| 2 | +#include "helpers/local.h" |
| 3 | +#include "helpers/writer.h" |
2 | 4 | #include <ydb/core/tx/columnshard/data_sharing/initiator/controller/abstract.h> |
3 | 5 | #include <ydb/core/tx/columnshard/hooks/testing/controller.h> |
4 | 6 | #include <ydb/core/tx/columnshard/common/snapshot.h> |
|
7 | 9 | #include <ydb/core/tx/columnshard/data_sharing/destination/session/destination.h> |
8 | 10 | #include <ydb/core/tx/columnshard/data_sharing/destination/events/control.h> |
9 | 11 | #include <ydb/core/base/tablet_pipecache.h> |
| 12 | +#include <ydb/public/sdk/cpp/client/ydb_operation/operation.h> |
| 13 | +#include <ydb/public/sdk/cpp/client/ydb_ss_tasks/task.h> |
10 | 14 |
|
11 | 15 | namespace NKikimr::NKqp { |
12 | 16 |
|
@@ -261,6 +265,151 @@ Y_UNIT_TEST_SUITE(KqpOlapBlobsSharing) { |
261 | 265 | tester.Execute(0, {1, 2}, false, NOlap::TSnapshot(TInstant::Now().MilliSeconds(), 1232123), {0}); |
262 | 266 | tester.WaitNormalization(); |
263 | 267 | } |
| 268 | + |
| 269 | + class TReshardingTest { |
| 270 | + private: |
| 271 | + YDB_ACCESSOR(TString, ShardingType, "HASH_FUNCTION_CONSISTENCY_64"); |
| 272 | + |
| 273 | + void WaitResharding() { |
| 274 | + const TInstant start = TInstant::Now(); |
| 275 | + bool clean = false; |
| 276 | + while (TInstant::Now() - start < TDuration::Seconds(200)) { |
| 277 | + NYdb::NOperation::TOperationClient operationClient(Kikimr.GetDriver()); |
| 278 | + auto result = operationClient.List<NYdb::NSchemeShard::TBackgroundProcessesResponse>().GetValueSync(); |
| 279 | + UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), NYdb::EStatus::SUCCESS, result.GetIssues().ToString()); |
| 280 | + if (result.GetList().size() == 0) { |
| 281 | + Cerr << "RESHARDING_FINISHED" << Endl; |
| 282 | + clean = true; |
| 283 | + break; |
| 284 | + } |
| 285 | + UNIT_ASSERT_VALUES_EQUAL(result.GetList().size(), 1); |
| 286 | + Sleep(TDuration::Seconds(1)); |
| 287 | + Cerr << "WAIT_FINISHED..." << Endl; |
| 288 | + } |
| 289 | + AFL_VERIFY(clean); |
| 290 | + } |
| 291 | + |
| 292 | + void CheckCount(const ui32 expectation) { |
| 293 | + auto it = Kikimr.GetTableClient().StreamExecuteScanQuery(R"( |
| 294 | + --!syntax_v1 |
| 295 | +
|
| 296 | + SELECT |
| 297 | + COUNT(*) |
| 298 | + FROM `/Root/olapStore/olapTable` |
| 299 | + )").GetValueSync(); |
| 300 | + |
| 301 | + UNIT_ASSERT_C(it.IsSuccess(), it.GetIssues().ToString()); |
| 302 | + TString result = StreamResultToYson(it); |
| 303 | + Cerr << result << Endl; |
| 304 | + CompareYson(result, "[[" + ::ToString(expectation) + "u;]]"); |
| 305 | + } |
| 306 | + |
| 307 | + TKikimrRunner Kikimr; |
| 308 | + public: |
| 309 | + |
| 310 | + TReshardingTest() |
| 311 | + : Kikimr(TKikimrSettings().SetWithSampleTables(false)) |
| 312 | + { |
| 313 | + |
| 314 | + } |
| 315 | + |
| 316 | + void Execute() { |
| 317 | + auto csController = NYDBTest::TControllers::RegisterCSControllerGuard<NYDBTest::NColumnShard::TController>(); |
| 318 | + csController->SetPeriodicWakeupActivationPeriod(TDuration::Seconds(1)); |
| 319 | + csController->SetLagForCompactionBeforeTierings(TDuration::Seconds(1)); |
| 320 | + csController->SetOverrideReduceMemoryIntervalLimit(1LLU << 30); |
| 321 | + |
| 322 | + TLocalHelper(Kikimr).SetShardingMethod(ShardingType).CreateTestOlapTable("olapTable", "olapStore", 16, 4); |
| 323 | + auto tableClient = Kikimr.GetTableClient(); |
| 324 | + |
| 325 | + Tests::NCommon::TLoggerInit(Kikimr).SetComponents({ NKikimrServices::TX_COLUMNSHARD }, "CS").SetPriority(NActors::NLog::PRI_DEBUG).Initialize(); |
| 326 | + |
| 327 | + std::vector<TString> uids; |
| 328 | + std::vector<TString> resourceIds; |
| 329 | + std::vector<ui32> levels; |
| 330 | + |
| 331 | + { |
| 332 | + WriteTestData(Kikimr, "/Root/olapStore/olapTable", 1000000, 300000000, 10000); |
| 333 | + WriteTestData(Kikimr, "/Root/olapStore/olapTable", 1100000, 300100000, 10000); |
| 334 | + WriteTestData(Kikimr, "/Root/olapStore/olapTable", 1200000, 300200000, 10000); |
| 335 | + WriteTestData(Kikimr, "/Root/olapStore/olapTable", 1300000, 300300000, 10000); |
| 336 | + WriteTestData(Kikimr, "/Root/olapStore/olapTable", 1400000, 300400000, 10000); |
| 337 | + WriteTestData(Kikimr, "/Root/olapStore/olapTable", 2000000, 200000000, 70000); |
| 338 | + WriteTestData(Kikimr, "/Root/olapStore/olapTable", 3000000, 100000000, 110000); |
| 339 | + |
| 340 | + const auto filler = [&](const ui32 startRes, const ui32 startUid, const ui32 count) { |
| 341 | + for (ui32 i = 0; i < count; ++i) { |
| 342 | + uids.emplace_back("uid_" + ::ToString(startUid + i)); |
| 343 | + resourceIds.emplace_back(::ToString(startRes + i)); |
| 344 | + levels.emplace_back(i % 5); |
| 345 | + } |
| 346 | + }; |
| 347 | + |
| 348 | + filler(1000000, 300000000, 10000); |
| 349 | + filler(1100000, 300100000, 10000); |
| 350 | + filler(1200000, 300200000, 10000); |
| 351 | + filler(1300000, 300300000, 10000); |
| 352 | + filler(1400000, 300400000, 10000); |
| 353 | + filler(2000000, 200000000, 70000); |
| 354 | + filler(3000000, 100000000, 110000); |
| 355 | + |
| 356 | + } |
| 357 | + |
| 358 | + CheckCount(230000); |
| 359 | + { |
| 360 | + auto alterQuery = TStringBuilder() << R"(ALTER OBJECT `/Root/olapStore/olapTable` (TYPE TABLESTORE) SET (ACTION=ALTER_SHARDING, MODIFICATION=SPLIT);)"; |
| 361 | + auto session = tableClient.CreateSession().GetValueSync().GetSession(); |
| 362 | + auto alterResult = session.ExecuteSchemeQuery(alterQuery).GetValueSync(); |
| 363 | + UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), NYdb::EStatus::SUCCESS, alterResult.GetIssues().ToString()); |
| 364 | + } |
| 365 | + |
| 366 | + WaitResharding(); |
| 367 | + AFL_VERIFY(csController->GetShardingFiltersCount().Val() == 0); |
| 368 | + CheckCount(230000); |
| 369 | + |
| 370 | + i64 count = csController->GetShardingFiltersCount().Val(); |
| 371 | + AFL_VERIFY(count == 16)("count", count); |
| 372 | + WriteTestData(Kikimr, "/Root/olapStore/olapTable", 1000000, 300000000, 10000); |
| 373 | + csController->WaitIndexation(TDuration::Seconds(5)); |
| 374 | + csController->WaitCompactions(TDuration::Seconds(5)); |
| 375 | + |
| 376 | + csController->SetCompactionControl(NYDBTest::EOptimizerCompactionWeightControl::Disable); |
| 377 | + |
| 378 | + CheckCount(230000); |
| 379 | + |
| 380 | + AFL_VERIFY(count == csController->GetShardingFiltersCount().Val())("count", count)("val", csController->GetShardingFiltersCount().Val()); |
| 381 | + const ui32 portionsCount = 8; |
| 382 | + for (ui32 i = 0; i < 3; ++i) { |
| 383 | + { |
| 384 | + auto alterQuery = TStringBuilder() << R"(ALTER OBJECT `/Root/olapStore/olapTable` (TYPE TABLESTORE) SET (ACTION=ALTER_SHARDING, MODIFICATION=MERGE);)"; |
| 385 | + auto session = tableClient.CreateSession().GetValueSync().GetSession(); |
| 386 | + auto alterResult = session.ExecuteSchemeQuery(alterQuery).GetValueSync(); |
| 387 | + UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), NYdb::EStatus::SUCCESS, alterResult.GetIssues().ToString()); |
| 388 | + } |
| 389 | + WaitResharding(); |
| 390 | + csController->WaitCleaning(TDuration::Seconds(5)); |
| 391 | + |
| 392 | + CheckCount(230000); |
| 393 | + AFL_VERIFY(count + portionsCount == csController->GetShardingFiltersCount().Val())("count", count)("val", csController->GetShardingFiltersCount().Val()); |
| 394 | + count += portionsCount; |
| 395 | + } |
| 396 | + { |
| 397 | + auto alterQuery = TStringBuilder() << R"(ALTER OBJECT `/Root/olapStore/olapTable` (TYPE TABLESTORE) SET (ACTION=ALTER_SHARDING, MODIFICATION=MERGE);)"; |
| 398 | + auto session = tableClient.CreateSession().GetValueSync().GetSession(); |
| 399 | + auto alterResult = session.ExecuteSchemeQuery(alterQuery).GetValueSync(); |
| 400 | + UNIT_ASSERT_VALUES_UNEQUAL_C(alterResult.GetStatus(), NYdb::EStatus::SUCCESS, alterResult.GetIssues().ToString()); |
| 401 | + } |
| 402 | + } |
| 403 | + }; |
| 404 | + |
| 405 | + Y_UNIT_TEST(TableReshardingConsistency64) { |
| 406 | + TReshardingTest().SetShardingType("HASH_FUNCTION_CONSISTENCY_64").Execute(); |
| 407 | + } |
| 408 | + |
| 409 | + Y_UNIT_TEST(TableReshardingModuloN) { |
| 410 | + TReshardingTest().SetShardingType("HASH_FUNCTION_MODULO_N").Execute(); |
| 411 | + } |
| 412 | + |
264 | 413 | } |
265 | 414 |
|
266 | 415 | } |
0 commit comments