@@ -4507,6 +4507,96 @@ Y_UNIT_TEST_SUITE(THiveTest) {
4507
4507
UNIT_ASSERT_LE (movedToFirstNode, TABLETS_PER_NODE / 2 );
4508
4508
}
4509
4509
4510
+ Y_UNIT_TEST (TestHiveNoBalancingWithLowResourceUsage) {
4511
+ static constexpr ui64 NUM_NODES = 5 ;
4512
+ static constexpr ui64 NUM_TABLETS = 100 ;
4513
+ TTestBasicRuntime runtime (NUM_NODES, false );
4514
+ Setup (runtime, true , 1 , [](TAppPrepare& app) {
4515
+ app.HiveConfig .SetTabletKickCooldownPeriod (0 );
4516
+ app.HiveConfig .SetResourceChangeReactionPeriod (0 );
4517
+ app.HiveConfig .SetMetricsWindowSize (1 );
4518
+ });
4519
+ const int nodeBase = runtime.GetNodeId (0 );
4520
+ TActorId senderA = runtime.AllocateEdgeActor ();
4521
+ const ui64 hiveTablet = MakeDefaultHiveID (0 );
4522
+ const ui64 testerTablet = MakeDefaultHiveID (1 );
4523
+
4524
+ auto getDistribution = [hiveTablet, nodeBase, senderA, &runtime]() -> std::array<std::vector<ui64>, NUM_NODES> {
4525
+ std::array<std::vector<ui64>, NUM_NODES> nodeTablets = {};
4526
+ {
4527
+ runtime.SendToPipe (hiveTablet, senderA, new TEvHive::TEvRequestHiveInfo ());
4528
+ TAutoPtr<IEventHandle> handle;
4529
+ TEvHive::TEvResponseHiveInfo* response = runtime.GrabEdgeEventRethrow <TEvHive::TEvResponseHiveInfo>(handle);
4530
+ for (const NKikimrHive::TTabletInfo& tablet : response->Record .GetTablets ()) {
4531
+ UNIT_ASSERT_C (((int )tablet.GetNodeID () - nodeBase >= 0 ) && (tablet.GetNodeID () - nodeBase < NUM_NODES),
4532
+ " nodeId# " << tablet.GetNodeID () << " nodeBase# " << nodeBase);
4533
+ nodeTablets[tablet.GetNodeID () - nodeBase].push_back (tablet.GetTabletID ());
4534
+ }
4535
+ }
4536
+ return nodeTablets;
4537
+ };
4538
+
4539
+ CreateTestBootstrapper (runtime, CreateTestTabletInfo (hiveTablet, TTabletTypes::Hive), &CreateDefaultHive);
4540
+
4541
+ // wait for creation of nodes
4542
+ {
4543
+ TDispatchOptions options;
4544
+ options.FinalEvents .emplace_back (TEvLocal::EvStatus, NUM_NODES);
4545
+ runtime.DispatchEvents (options);
4546
+ }
4547
+
4548
+ TTabletTypes::EType tabletType = TTabletTypes::Dummy;
4549
+ std::vector<ui64> tablets;
4550
+ tablets.reserve (NUM_TABLETS);
4551
+ for (size_t i = 0 ; i < NUM_TABLETS; ++i) {
4552
+ THolder<TEvHive::TEvCreateTablet> ev (new TEvHive::TEvCreateTablet (testerTablet, 100500 + i, tabletType, BINDED_CHANNELS));
4553
+ ev->Record .SetObjectId (i);
4554
+ ui64 tabletId = SendCreateTestTablet (runtime, hiveTablet, testerTablet, std::move (ev), 0 , true );
4555
+ MakeSureTabletIsUp (runtime, tabletId, 0 );
4556
+ tablets.push_back (tabletId);
4557
+ }
4558
+
4559
+ auto initialDistribution = getDistribution ();
4560
+
4561
+ // report small metrics for some tablets
4562
+ auto rand = CreateDeterministicRandomProvider (777 );
4563
+ for (auto tablet : tablets) {
4564
+ THolder<TEvHive::TEvTabletMetrics> metrics = MakeHolder<TEvHive::TEvTabletMetrics>();
4565
+ NKikimrHive::TTabletMetrics* metric = metrics->Record .AddTabletMetrics ();
4566
+ metric->SetTabletID (tablet);
4567
+ if (rand ->GenRand () % 2 ) {
4568
+ metric->MutableResourceUsage ()->SetCPU (1001 ); // 1% core
4569
+ metric->MutableResourceUsage ()->SetMemory (150'000 ); // 150kb
4570
+ } else {
4571
+ metric->MutableResourceUsage ()->SetCPU (999 );
4572
+ metric->MutableResourceUsage ()->SetMemory (100'000 );
4573
+ }
4574
+
4575
+ runtime.SendToPipe (hiveTablet, senderA, metrics.Release ());
4576
+ }
4577
+
4578
+ {
4579
+ TDispatchOptions options;
4580
+ options.FinalEvents .emplace_back (NHive::TEvPrivate::EvBalancerOut);
4581
+ runtime.DispatchEvents (options, TDuration::Seconds (10 ));
4582
+ }
4583
+
4584
+ // Check that balancer moved no tablets
4585
+ auto newDistribution = getDistribution ();
4586
+
4587
+ UNIT_ASSERT_EQUAL (initialDistribution, newDistribution);
4588
+
4589
+ {
4590
+ auto request = std::make_unique<TEvHive::TEvRequestHiveDomainStats>();
4591
+ request->Record .SetReturnMetrics (true );
4592
+ runtime.SendToPipe (hiveTablet, senderA, request.release ());
4593
+ TAutoPtr<IEventHandle> handle;
4594
+ TEvHive::TEvResponseHiveDomainStats* response = runtime.GrabEdgeEventRethrow <TEvHive::TEvResponseHiveDomainStats>(handle);
4595
+ ui64 totalCounter = response->Record .GetDomainStats (0 ).GetMetrics ().GetCounter ();
4596
+ UNIT_ASSERT_VALUES_EQUAL (totalCounter, 0 );
4597
+ }
4598
+ }
4599
+
4510
4600
Y_UNIT_TEST (TestHiveBalancerWithImmovableTablets) {
4511
4601
static constexpr ui64 TABLETS_PER_NODE = 10 ;
4512
4602
TTestBasicRuntime runtime (3 , false );
0 commit comments