|
21 | 21 | #include <ydb/core/testlib/basics/helpers.h>
|
22 | 22 | #include <ydb/core/testlib/tablet_helpers.h>
|
23 | 23 | #include <ydb/core/testlib/tenant_runtime.h>
|
| 24 | +#include <ydb/core/tx/columnshard/columnshard.h> |
24 | 25 | #include <ydb/core/tx/schemeshard/schemeshard.h>
|
25 | 26 | #include <ydb/core/tx/mediator/mediator.h>
|
26 | 27 | #include <ydb/core/util/random.h>
|
@@ -92,6 +93,7 @@ namespace {
|
92 | 93 | runtime.SetLogPriority(NKikimrServices::TABLET_RESOLVER, otherPriority);
|
93 | 94 | runtime.SetLogPriority(NKikimrServices::STATESTORAGE, otherPriority);
|
94 | 95 | runtime.SetLogPriority(NKikimrServices::BOOTSTRAPPER, otherPriority);
|
| 96 | + runtime.SetLogPriority(NKikimrServices::TX_COLUMNSHARD, otherPriority); |
95 | 97 | }
|
96 | 98 |
|
97 | 99 | THashMap<ui32, TIntrusivePtr<TNodeWardenConfig>> NodeWardenConfigs;
|
@@ -215,25 +217,34 @@ namespace {
|
215 | 217 | false);
|
216 | 218 | }
|
217 | 219 |
|
| 220 | + TLocalConfig::TPtr MakeDefaultLocalConfig() { |
| 221 | + TLocalConfig::TPtr localConfig(new TLocalConfig()); |
| 222 | + localConfig->TabletClassInfo[TTabletTypes::Dummy].SetupInfo = new TTabletSetupInfo( |
| 223 | + &CreateFlatDummyTablet, |
| 224 | + TMailboxType::Simple, 0, |
| 225 | + TMailboxType::Simple, 0); |
| 226 | + localConfig->TabletClassInfo[TTabletTypes::Hive].SetupInfo = new TTabletSetupInfo( |
| 227 | + &CreateDefaultHive, |
| 228 | + TMailboxType::Simple, 0, |
| 229 | + TMailboxType::Simple, 0); |
| 230 | + localConfig->TabletClassInfo[TTabletTypes::Mediator].SetupInfo = new TTabletSetupInfo( |
| 231 | + &CreateTxMediator, |
| 232 | + TMailboxType::Simple, 0, |
| 233 | + TMailboxType::Simple, 0); |
| 234 | + localConfig->TabletClassInfo[TTabletTypes::ColumnShard].SetupInfo = new TTabletSetupInfo( |
| 235 | + &CreateColumnShard, |
| 236 | + TMailboxType::Simple, 0, |
| 237 | + TMailboxType::Simple, 0); |
| 238 | + return localConfig; |
| 239 | + } |
| 240 | + |
218 | 241 | void SetupLocals(TTestActorRuntime &runtime, bool isLocalEnabled) {
|
219 | 242 | if (!isLocalEnabled) {
|
220 | 243 | return;
|
221 | 244 | }
|
222 | 245 |
|
223 | 246 | for (ui32 nodeIndex = 0; nodeIndex < runtime.GetNodeCount(); ++nodeIndex) {
|
224 |
| - TLocalConfig::TPtr localConfig(new TLocalConfig()); |
225 |
| - localConfig->TabletClassInfo[TTabletTypes::Dummy].SetupInfo = new TTabletSetupInfo( |
226 |
| - &CreateFlatDummyTablet, |
227 |
| - TMailboxType::Simple, 0, |
228 |
| - TMailboxType::Simple, 0); |
229 |
| - localConfig->TabletClassInfo[TTabletTypes::Hive].SetupInfo = new TTabletSetupInfo( |
230 |
| - &CreateDefaultHive, |
231 |
| - TMailboxType::Simple, 0, |
232 |
| - TMailboxType::Simple, 0); |
233 |
| - localConfig->TabletClassInfo[TTabletTypes::Mediator].SetupInfo = new TTabletSetupInfo( |
234 |
| - &CreateTxMediator, |
235 |
| - TMailboxType::Simple, 0, |
236 |
| - TMailboxType::Simple, 0); |
| 247 | + auto localConfig = MakeDefaultLocalConfig(); |
237 | 248 | TTenantPoolConfig::TPtr tenantPoolConfig = new TTenantPoolConfig(localConfig);
|
238 | 249 | tenantPoolConfig->AddStaticSlot(DOMAIN_NAME);
|
239 | 250 |
|
@@ -653,10 +664,7 @@ Y_UNIT_TEST_SUITE(THiveTest) {
|
653 | 664 |
|
654 | 665 | void CreateLocal(TTestActorRuntime &runtime, ui32 nodeIndex, TLocalConfig::TPtr localConfig = {}) {
|
655 | 666 | if (localConfig == nullptr) {
|
656 |
| - localConfig = new TLocalConfig(); |
657 |
| - localConfig->TabletClassInfo[TTabletTypes::Dummy].SetupInfo = new TTabletSetupInfo(&CreateFlatDummyTablet, |
658 |
| - TMailboxType::Simple, 0, |
659 |
| - TMailboxType::Simple, 0); |
| 667 | + localConfig = MakeDefaultLocalConfig(); |
660 | 668 | }
|
661 | 669 | TTenantPoolConfig::TPtr tenantPoolConfig = new TTenantPoolConfig(localConfig);
|
662 | 670 | tenantPoolConfig->AddStaticSlot(DOMAIN_NAME);
|
@@ -5329,6 +5337,72 @@ Y_UNIT_TEST_SUITE(THiveTest) {
|
5329 | 5337 | UNIT_ASSERT_EQUAL(initialDistribution, newDistribution);
|
5330 | 5338 | }
|
5331 | 5339 |
|
| 5340 | + Y_UNIT_TEST(TestHiveBalancerHighUsageAndColumnShards) { |
| 5341 | + static constexpr ui64 NUM_NODES = 2; |
| 5342 | + TTestBasicRuntime runtime(2, false); |
| 5343 | + Setup(runtime, true, 1, [](TAppPrepare& app) { |
| 5344 | + app.HiveConfig.SetTabletKickCooldownPeriod(0); |
| 5345 | + app.HiveConfig.SetResourceChangeReactionPeriod(0); |
| 5346 | + }); |
| 5347 | + const int nodeBase = runtime.GetNodeId(0); |
| 5348 | + TActorId senderA = runtime.AllocateEdgeActor(); |
| 5349 | + const ui64 hiveTablet = MakeDefaultHiveID(); |
| 5350 | + const ui64 testerTablet = MakeTabletID(false, 1); |
| 5351 | + |
| 5352 | + auto getDistribution = [hiveTablet, nodeBase, senderA, &runtime]() -> std::array<std::vector<ui64>, NUM_NODES> { |
| 5353 | + std::array<std::vector<ui64>, NUM_NODES> nodeTablets = {}; |
| 5354 | + { |
| 5355 | + runtime.SendToPipe(hiveTablet, senderA, new TEvHive::TEvRequestHiveInfo()); |
| 5356 | + TAutoPtr<IEventHandle> handle; |
| 5357 | + TEvHive::TEvResponseHiveInfo* response = runtime.GrabEdgeEventRethrow<TEvHive::TEvResponseHiveInfo>(handle); |
| 5358 | + for (const NKikimrHive::TTabletInfo& tablet : response->Record.GetTablets()) { |
| 5359 | + UNIT_ASSERT_C(((int)tablet.GetNodeID() - nodeBase >= 0) && (tablet.GetNodeID() - nodeBase < NUM_NODES), |
| 5360 | + "nodeId# " << tablet.GetNodeID() << " nodeBase# " << nodeBase); |
| 5361 | + nodeTablets[tablet.GetNodeID() - nodeBase].push_back(tablet.GetTabletID()); |
| 5362 | + } |
| 5363 | + } |
| 5364 | + return nodeTablets; |
| 5365 | + }; |
| 5366 | + |
| 5367 | + CreateTestBootstrapper(runtime, CreateTestTabletInfo(hiveTablet, TTabletTypes::Hive), &CreateDefaultHive); |
| 5368 | + |
| 5369 | + // wait for creation of nodes |
| 5370 | + { |
| 5371 | + TDispatchOptions options; |
| 5372 | + options.FinalEvents.emplace_back(TEvLocal::EvStatus, NUM_NODES); |
| 5373 | + runtime.DispatchEvents(options); |
| 5374 | + } |
| 5375 | + SendKillLocal(runtime, 1); |
| 5376 | + |
| 5377 | + TTabletTypes::EType tabletType = TTabletTypes::ColumnShard; |
| 5378 | + for (size_t i = 0; i < 2; ++i) { |
| 5379 | + THolder<TEvHive::TEvCreateTablet> ev(new TEvHive::TEvCreateTablet(testerTablet, 100500 + i, tabletType, BINDED_CHANNELS)); |
| 5380 | + ev->Record.SetObjectId(i); |
| 5381 | + ui64 tabletId = SendCreateTestTablet(runtime, hiveTablet, testerTablet, std::move(ev), 0, true); |
| 5382 | + MakeSureTabletIsUp(runtime, tabletId, 0); |
| 5383 | + } |
| 5384 | + |
| 5385 | + { |
| 5386 | + TActorId sender = runtime.AllocateEdgeActor(0); |
| 5387 | + THolder<TEvHive::TEvTabletMetrics> metrics = MakeHolder<TEvHive::TEvTabletMetrics>(); |
| 5388 | + metrics->Record.SetTotalNodeUsage(.95); |
| 5389 | + |
| 5390 | + runtime.SendToPipe(hiveTablet, sender, metrics.Release(), 0); |
| 5391 | + } |
| 5392 | + CreateLocal(runtime, 1); |
| 5393 | + |
| 5394 | + { |
| 5395 | + TDispatchOptions options; |
| 5396 | + options.FinalEvents.emplace_back(NHive::TEvPrivate::EvBalancerOut, 2); |
| 5397 | + runtime.DispatchEvents(options, TDuration::Seconds(10)); |
| 5398 | + } |
| 5399 | + |
| 5400 | + // Check that balancer moved a tablet |
| 5401 | + auto newDistribution = getDistribution(); |
| 5402 | + |
| 5403 | + UNIT_ASSERT_VALUES_EQUAL(newDistribution[0].size(), newDistribution[1].size()); |
| 5404 | + } |
| 5405 | + |
5332 | 5406 | Y_UNIT_TEST(TestUpdateTabletsObjectUpdatesMetrics) {
|
5333 | 5407 | TTestBasicRuntime runtime(1, false);
|
5334 | 5408 | Setup(runtime, true);
|
|
0 commit comments