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
4 changes: 4 additions & 0 deletions ydb/core/mind/hive/hive_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,10 @@ void THive::Handle(TEvPrivate::TEvBootTablets::TPtr&) {

void THive::Handle(TEvHive::TEvInitMigration::TPtr& ev) {
BLOG_D("Handle InitMigration " << ev->Get()->Record);
if (AreWeRootHive()) {
Send(ev->Sender, new TEvHive::TEvInitMigrationReply(NKikimrProto::ERROR));
return;
}
if (MigrationState == NKikimrHive::EMigrationState::MIGRATION_READY || MigrationState == NKikimrHive::EMigrationState::MIGRATION_COMPLETE) {
if (ev->Get()->Record.GetMigrationFilter().GetFilterDomain().GetSchemeShard() == 0 && GetMySubDomainKey().GetSchemeShard() == 0) {
BLOG_ERROR("Migration ignored - unknown domain");
Expand Down
21 changes: 21 additions & 0 deletions ydb/core/mind/hive/hive_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,27 @@ Y_UNIT_TEST_SUITE(THiveTest) {
runtime.SetObserverFunc(prevObserverFunc);
}

Y_UNIT_TEST(TestNoMigrationToSelf) {
TTestBasicRuntime runtime(2, false);
Setup(runtime, true);

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

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

THolder<TEvHive::TEvInitMigration> migration = MakeHolder<TEvHive::TEvInitMigration>();
runtime.SendToPipe(hiveTablet, sender, migration.Release(), 0, GetPipeConfigWithRetries());
TAutoPtr<IEventHandle> handle;
auto initMigrationReply = runtime.GrabEdgeEventRethrow<TEvHive::TEvInitMigrationReply>(handle);
UNIT_ASSERT(initMigrationReply);
UNIT_ASSERT(initMigrationReply->Record.GetStatus() == NKikimrProto::ERROR);
}

Y_UNIT_TEST(TestCheckSubHiveMigrationManyTablets) {
TTestBasicRuntime runtime(2, false);
Setup(runtime, true);
Expand Down
12 changes: 10 additions & 2 deletions ydb/core/mind/hive/monitoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3081,6 +3081,7 @@ class TTxMonEvent_InitMigration : public TTransactionBase<THive> {
TAutoPtr<NMon::TEvRemoteHttpInfo> Event;
const TActorId Source;
bool Wait = true;
TString Error;

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

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

void Complete(const TActorContext& ctx) override {
if (!Wait) {
ctx.Send(Source, new NMon::TEvRemoteJsonInfoRes("{}"));
if (Error) {
ctx.Send(Source, new NMon::TEvRemoteJsonInfoRes(TStringBuilder() << "{\"error\":\"" << Error << "\"}"));
} else {
if (!Wait) {
ctx.Send(Source, new NMon::TEvRemoteJsonInfoRes("{}"));
}
}
}
};
Expand Down
Loading