Skip to content

Commit add786e

Browse files
authored
check that we are not migrating tablets to ourselves (#15477)
1 parent f71a74a commit add786e

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

ydb/core/mind/hive/hive_impl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,10 @@ void THive::Handle(TEvPrivate::TEvBootTablets::TPtr&) {
581581

582582
void THive::Handle(TEvHive::TEvInitMigration::TPtr& ev) {
583583
BLOG_D("Handle InitMigration " << ev->Get()->Record);
584+
if (AreWeRootHive()) {
585+
Send(ev->Sender, new TEvHive::TEvInitMigrationReply(NKikimrProto::ERROR));
586+
return;
587+
}
584588
if (MigrationState == NKikimrHive::EMigrationState::MIGRATION_READY || MigrationState == NKikimrHive::EMigrationState::MIGRATION_COMPLETE) {
585589
if (ev->Get()->Record.GetMigrationFilter().GetFilterDomain().GetSchemeShard() == 0 && GetMySubDomainKey().GetSchemeShard() == 0) {
586590
BLOG_ERROR("Migration ignored - unknown domain");

ydb/core/mind/hive/hive_ut.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,27 @@ Y_UNIT_TEST_SUITE(THiveTest) {
15811581
runtime.SetObserverFunc(prevObserverFunc);
15821582
}
15831583

1584+
Y_UNIT_TEST(TestNoMigrationToSelf) {
1585+
TTestBasicRuntime runtime(2, false);
1586+
Setup(runtime, true);
1587+
1588+
const ui64 hiveTablet = MakeDefaultHiveID();
1589+
const ui64 testerTablet = MakeTabletID(false, 1);
1590+
TActorId sender = runtime.AllocateEdgeActor(0);
1591+
CreateTestBootstrapper(runtime, CreateTestTabletInfo(hiveTablet, TTabletTypes::Hive), &CreateDefaultHive);
1592+
MakeSureTabletIsUp(runtime, hiveTablet, 0);
1593+
1594+
THolder<TEvHive::TEvCreateTablet> createTablet = MakeHolder<TEvHive::TEvCreateTablet>(testerTablet, 1, TTabletTypes::Dummy, BINDED_CHANNELS);
1595+
SendCreateTestTablet(runtime, hiveTablet, testerTablet, std::move(createTablet), 0, true);
1596+
1597+
THolder<TEvHive::TEvInitMigration> migration = MakeHolder<TEvHive::TEvInitMigration>();
1598+
runtime.SendToPipe(hiveTablet, sender, migration.Release(), 0, GetPipeConfigWithRetries());
1599+
TAutoPtr<IEventHandle> handle;
1600+
auto initMigrationReply = runtime.GrabEdgeEventRethrow<TEvHive::TEvInitMigrationReply>(handle);
1601+
UNIT_ASSERT(initMigrationReply);
1602+
UNIT_ASSERT(initMigrationReply->Record.GetStatus() == NKikimrProto::ERROR);
1603+
}
1604+
15841605
Y_UNIT_TEST(TestCheckSubHiveMigrationManyTablets) {
15851606
TTestBasicRuntime runtime(2, false);
15861607
Setup(runtime, true);

ydb/core/mind/hive/monitoring.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3081,6 +3081,7 @@ class TTxMonEvent_InitMigration : public TTransactionBase<THive> {
30813081
TAutoPtr<NMon::TEvRemoteHttpInfo> Event;
30823082
const TActorId Source;
30833083
bool Wait = true;
3084+
TString Error;
30843085

30853086
TTxMonEvent_InitMigration(const TActorId& source, NMon::TEvRemoteHttpInfo::TPtr& ev, TSelf* hive)
30863087
: TBase(hive)
@@ -3093,6 +3094,9 @@ class TTxMonEvent_InitMigration : public TTransactionBase<THive> {
30933094
TTxType GetTxType() const override { return NHive::TXTYPE_MON_INIT_MIGRATION; }
30943095

30953096
bool Execute(TTransactionContext&, const TActorContext& ctx) override {
3097+
if (Self->AreWeRootHive()) {
3098+
Error = "Cannot migrate to root hive";
3099+
}
30963100
TActorId waitActorId;
30973101
TInitMigrationWaitActor* waitActor = nullptr;
30983102
if (Wait) {
@@ -3106,8 +3110,12 @@ class TTxMonEvent_InitMigration : public TTransactionBase<THive> {
31063110
}
31073111

31083112
void Complete(const TActorContext& ctx) override {
3109-
if (!Wait) {
3110-
ctx.Send(Source, new NMon::TEvRemoteJsonInfoRes("{}"));
3113+
if (Error) {
3114+
ctx.Send(Source, new NMon::TEvRemoteJsonInfoRes(TStringBuilder() << "{\"error\":\"" << Error << "\"}"));
3115+
} else {
3116+
if (!Wait) {
3117+
ctx.Send(Source, new NMon::TEvRemoteJsonInfoRes("{}"));
3118+
}
31113119
}
31123120
}
31133121
};

0 commit comments

Comments
 (0)