Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions ydb/core/mind/hive/hive_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8229,6 +8229,69 @@ Y_UNIT_TEST_SUITE(THiveTest) {
}
}

Y_UNIT_TEST(TestReassignNonexistentTablet) {
TTestBasicRuntime runtime(1, false);
Setup(runtime, true);

const ui64 hiveTablet = MakeDefaultHiveID();
const ui64 testerTablet = MakeTabletID(false, 1);
const TActorId hiveActor = CreateTestBootstrapper(runtime, CreateTestTabletInfo(hiveTablet, TTabletTypes::Hive), &CreateDefaultHive);
runtime.EnableScheduleForActor(hiveActor);
MakeSureTabletIsUp(runtime, hiveTablet, 0);
TActorId sender = runtime.AllocateEdgeActor(0);

{
TDispatchOptions options;
options.FinalEvents.emplace_back(TEvLocal::EvSyncTablets);
runtime.DispatchEvents(options);
}

THolder<TEvHive::TEvCreateTablet> createTablet = MakeHolder<TEvHive::TEvCreateTablet>(testerTablet, 1, TTabletTypes::Dummy, BINDED_CHANNELS);
ui64 tablet = SendCreateTestTablet(runtime, hiveTablet, testerTablet, std::move(createTablet), 0, true);

MakeSureTabletIsUp(runtime, tablet, 0);

{
NActorsProto::TRemoteHttpInfo pb;
pb.SetMethod(HTTP_METHOD_POST);
pb.SetPath("/app");
auto* p1 = pb.AddQueryParams();
p1->SetKey("TabletID");
p1->SetValue(TStringBuilder() << hiveTablet);
auto* p2 = pb.AddQueryParams();
p2->SetKey("page");
p2->SetValue("ReassignTablet");
auto* p3 = pb.AddQueryParams();
p3->SetKey("tablet");
p3->SetValue("52");
runtime.SendToPipe(hiveTablet, sender, new NMon::TEvRemoteHttpInfo(std::move(pb)), 0, GetPipeConfigWithRetries());

TAutoPtr<IEventHandle> handle;
auto resp = runtime.GrabEdgeEventRethrow<NMon::TEvRemoteJsonInfoRes>(handle);
Ctest << "Hive response: " << resp->Json << Endl;
NJson::TJsonValue value;
ReadJsonTree(resp->Json, &value, false);
UNIT_ASSERT_VALUES_EQUAL(value["total"].GetIntegerSafe(), 0);
}

// this must not block balancer

{
THolder<TEvHive::TEvTabletMetrics> metrics = MakeHolder<TEvHive::TEvTabletMetrics>();
NKikimrHive::TTabletMetrics* metric = metrics->Record.AddTabletMetrics();
metric->SetTabletID(tablet);
metric->MutableResourceUsage()->SetNetwork(9000);

runtime.SendToPipe(hiveTablet, sender, metrics.Release());
}

{
TDispatchOptions options;
options.FinalEvents.push_back(NHive::TEvPrivate::EvBalancerOut);
runtime.DispatchEvents(options);
}
}

Y_UNIT_TEST(TestTabletsStartingCounter) {
TTestBasicRuntime runtime(1, false);
Setup(runtime, true);
Expand Down
19 changes: 14 additions & 5 deletions ydb/core/mind/hive/monitoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2880,7 +2880,7 @@ class TTxMonEvent_RebalanceFromScratch : public TTransactionBase<THive> {
class TReassignTabletWaitActor : public TActor<TReassignTabletWaitActor>, public ISubActor {
public:
TActorId Source;
ui32 TabletsTotal = std::numeric_limits<ui32>::max();
ui32 TabletsTotal = 0;
ui32 TabletsDone = 0;
THive* Hive;

Expand All @@ -2907,14 +2907,23 @@ class TReassignTabletWaitActor : public TActor<TReassignTabletWaitActor>, public
return SelfId().LocalId();
}

void Handle(TEvPrivate::TEvRestartComplete::TPtr&) {
++TabletsDone;
void AddTablet(TLeaderTabletInfo* tablet) {
tablet->ActorsToNotifyOnRestart.push_back(SelfId());
++TabletsTotal;
}

void CheckCompletion() {
if (TabletsDone >= TabletsTotal) {
Send(Source, new NMon::TEvRemoteJsonInfoRes(TStringBuilder() << "{\"total\":" << TabletsDone << "}"));
PassAway();
}
}

void Handle(TEvPrivate::TEvRestartComplete::TPtr&) {
++TabletsDone;
CheckCompletion();
}

STATEFN(StateWork) {
switch (ev->GetTypeRewrite()) {
cFunc(TEvents::TSystem::PoisonPill, PassAway);
Expand Down Expand Up @@ -3042,12 +3051,12 @@ class TTxMonEvent_ReassignTablet : public TTransactionBase<THive> {
continue;
}
if (Wait) {
tablet->ActorsToNotifyOnRestart.emplace_back(waitActorId); // volatile settings, will not persist upon restart
waitActor->AddTablet(tablet);
}
operations.emplace_back(new TEvHive::TEvReassignTablet(tablet->Id, channels, forcedGroupIds, Async));
}
if (Wait) {
waitActor->TabletsTotal = operations.size();
waitActor->CheckCompletion();
}
for (auto& op : operations) {
ctx.Send(Self->SelfId(), op.Release());
Expand Down
Loading