Skip to content

Commit 8b06bf3

Browse files
authored
25-1: check that we are not migrating tablets to ourselves (#15477) (#15667)
1 parent 207f337 commit 8b06bf3

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
@@ -1573,6 +1573,27 @@ Y_UNIT_TEST_SUITE(THiveTest) {
15731573
runtime.SetObserverFunc(prevObserverFunc);
15741574
}
15751575

1576+
Y_UNIT_TEST(TestNoMigrationToSelf) {
1577+
TTestBasicRuntime runtime(2, false);
1578+
Setup(runtime, true);
1579+
1580+
const ui64 hiveTablet = MakeDefaultHiveID();
1581+
const ui64 testerTablet = MakeTabletID(false, 1);
1582+
TActorId sender = runtime.AllocateEdgeActor(0);
1583+
CreateTestBootstrapper(runtime, CreateTestTabletInfo(hiveTablet, TTabletTypes::Hive), &CreateDefaultHive);
1584+
MakeSureTabletIsUp(runtime, hiveTablet, 0);
1585+
1586+
THolder<TEvHive::TEvCreateTablet> createTablet = MakeHolder<TEvHive::TEvCreateTablet>(testerTablet, 1, TTabletTypes::Dummy, BINDED_CHANNELS);
1587+
SendCreateTestTablet(runtime, hiveTablet, testerTablet, std::move(createTablet), 0, true);
1588+
1589+
THolder<TEvHive::TEvInitMigration> migration = MakeHolder<TEvHive::TEvInitMigration>();
1590+
runtime.SendToPipe(hiveTablet, sender, migration.Release(), 0, GetPipeConfigWithRetries());
1591+
TAutoPtr<IEventHandle> handle;
1592+
auto initMigrationReply = runtime.GrabEdgeEventRethrow<TEvHive::TEvInitMigrationReply>(handle);
1593+
UNIT_ASSERT(initMigrationReply);
1594+
UNIT_ASSERT(initMigrationReply->Record.GetStatus() == NKikimrProto::ERROR);
1595+
}
1596+
15761597
Y_UNIT_TEST(TestCheckSubHiveMigrationManyTablets) {
15771598
TTestBasicRuntime runtime(2, false);
15781599
Setup(runtime, true);

ydb/core/mind/hive/monitoring.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3028,6 +3028,7 @@ class TTxMonEvent_InitMigration : public TTransactionBase<THive> {
30283028
TAutoPtr<NMon::TEvRemoteHttpInfo> Event;
30293029
const TActorId Source;
30303030
bool Wait = true;
3031+
TString Error;
30313032

30323033
TTxMonEvent_InitMigration(const TActorId& source, NMon::TEvRemoteHttpInfo::TPtr& ev, TSelf* hive)
30333034
: TBase(hive)
@@ -3040,6 +3041,9 @@ class TTxMonEvent_InitMigration : public TTransactionBase<THive> {
30403041
TTxType GetTxType() const override { return NHive::TXTYPE_MON_INIT_MIGRATION; }
30413042

30423043
bool Execute(TTransactionContext&, const TActorContext& ctx) override {
3044+
if (Self->AreWeRootHive()) {
3045+
Error = "Cannot migrate to root hive";
3046+
}
30433047
TActorId waitActorId;
30443048
TInitMigrationWaitActor* waitActor = nullptr;
30453049
if (Wait) {
@@ -3053,8 +3057,12 @@ class TTxMonEvent_InitMigration : public TTransactionBase<THive> {
30533057
}
30543058

30553059
void Complete(const TActorContext& ctx) override {
3056-
if (!Wait) {
3057-
ctx.Send(Source, new NMon::TEvRemoteJsonInfoRes("{}"));
3060+
if (Error) {
3061+
ctx.Send(Source, new NMon::TEvRemoteJsonInfoRes(TStringBuilder() << "{\"error\":\"" << Error << "\"}"));
3062+
} else {
3063+
if (!Wait) {
3064+
ctx.Send(Source, new NMon::TEvRemoteJsonInfoRes("{}"));
3065+
}
30583066
}
30593067
}
30603068
};

0 commit comments

Comments
 (0)