Skip to content

Commit 0f8727a

Browse files
authored
Merge 0af8ca8 into 8b8059d
2 parents 8b8059d + 0af8ca8 commit 0f8727a

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

ydb/core/mind/hive/hive_ut.cpp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <ydb/core/mind/tenant_pool.h>
1717
#include <ydb/core/tablet_flat/tablet_flat_executed.h>
1818
#include <ydb/core/tablet/tablet_impl.h>
19+
#include <ydb/core/testlib/actors/block_events.h>
1920
#include <ydb/core/testlib/basics/appdata.h>
2021
#include <ydb/core/testlib/basics/helpers.h>
2122
#include <ydb/core/testlib/tablet_helpers.h>
@@ -6154,13 +6155,14 @@ Y_UNIT_TEST_SUITE(THiveTest) {
61546155
ActorIdToProto(owner, event->Record.MutableOwnerActor());
61556156
}
61566157
TActorId senderB = runtime.AllocateEdgeActor(nodeIndex);
6158+
Ctest << "Send UnlockTablet\n";
61576159
runtime.SendToPipe(hiveTablet, senderB, event.Release(), nodeIndex, GetPipeConfigWithRetries());
61586160

61596161
TAutoPtr<IEventHandle> handle;
61606162
auto result = runtime.GrabEdgeEventRethrow<TEvHive::TEvUnlockTabletExecutionResult>(handle);
61616163
UNIT_ASSERT(result);
61626164
UNIT_ASSERT_VALUES_EQUAL(result->Record.GetTabletID(), tabletId);
6163-
UNIT_ASSERT_VALUES_EQUAL(result->Record.GetStatus(), expectedStatus);
6165+
UNIT_ASSERT_C(result->Record.GetStatus() == expectedStatus, "Expected status " << expectedStatus << ", got reply " << result->Record.ShortDebugString());
61646166
}
61656167

61666168
Y_UNIT_TEST(TestLockTabletExecutionBadUnlock) {
@@ -6237,6 +6239,44 @@ Y_UNIT_TEST_SUITE(THiveTest) {
62376239
VerifyLockTabletExecutionLost(runtime, tabletId, owner);
62386240
}
62396241

6242+
Y_UNIT_TEST(TestLockTabletExecutionLocalGone) {
6243+
TTestBasicRuntime runtime(3, false);
6244+
Setup(runtime, false);
6245+
CreateLocal(runtime, 0); // only the 1st node has local running
6246+
const ui64 hiveTablet = MakeDefaultHiveID();
6247+
const ui64 testerTablet = MakeTabletID(false, 1);
6248+
const TActorId hiveActor = CreateTestBootstrapper(runtime, CreateTestTabletInfo(hiveTablet, TTabletTypes::Hive), &CreateDefaultHive);
6249+
const TActorId senderA = runtime.AllocateEdgeActor(0);
6250+
runtime.EnableScheduleForActor(hiveActor);
6251+
6252+
TTabletTypes::EType tabletType = TTabletTypes::Dummy;
6253+
THolder<TEvHive::TEvCreateTablet> ev(new TEvHive::TEvCreateTablet(testerTablet, 0, tabletType, BINDED_CHANNELS));
6254+
ui64 tabletId = SendCreateTestTablet(runtime, hiveTablet, testerTablet, std::move(ev), 0, true);
6255+
MakeSureTabletIsUp(runtime, tabletId, 0);
6256+
6257+
TActorId owner = runtime.AllocateEdgeActor(1);
6258+
SendLockTabletExecution(runtime, hiveTablet, tabletId, 1, NKikimrProto::OK, owner, 100500);
6259+
MakeSureTabletIsDown(runtime, tabletId, 0);
6260+
6261+
// Block events related to node disconnect
6262+
// TEvents::TEvUndelivered - actor system does not guarantee that this event will be sent
6263+
// TEvLocal::TEvStatus - we cannot expect that the disconnecting node will always be able to send this
6264+
// TEvInterconnect::TEvNodeDisconnected - we will send this one, but follow it up with NodeConnected
6265+
// This is simulating a case when a new host is using the old node id and that new host does not run Local
6266+
TBlockEvents<TEvents::TEvUndelivered> blockUndleivered(runtime, [](auto&& ev) { return ev->Get()->SourceType == TEvLocal::EvPing; });
6267+
TBlockEvents<TEvLocal::TEvStatus> blockStatus(runtime, [](auto&& ev) { return ev->Get()->Record.GetStatus() != NKikimrProto::OK; });
6268+
SendKillLocal(runtime, 0);
6269+
runtime.SendToPipe(hiveTablet, senderA, new TEvInterconnect::TEvNodeDisconnected(runtime.GetNodeId(0)), 0, GetPipeConfigWithRetries());
6270+
CreateLocal(runtime, 2);
6271+
runtime.Register(CreateTabletKiller(hiveTablet));
6272+
runtime.SendToPipe(hiveTablet, senderA, new TEvInterconnect::TEvNodeConnected(runtime.GetNodeId(0)), 0, GetPipeConfigWithRetries());
6273+
6274+
// Unlocking with the same owner should succeed and boot the tablet
6275+
SendUnlockTabletExecution(runtime, hiveTablet, tabletId, 1, NKikimrProto::OK, owner);
6276+
WaitForTabletIsUp(runtime, tabletId, 0);
6277+
6278+
}
6279+
62406280
Y_UNIT_TEST(TestExternalBoot) {
62416281
TTestBasicRuntime runtime(1, false);
62426282
Setup(runtime, true);

ydb/core/mind/hive/tx__lock_tablet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class TTxLockTabletExecution : public TTransactionBase<THive> {
9595
follower.InitiateStop(SideEffects);
9696
}
9797
tablet->InitiateStop(SideEffects);
98+
db.Table<Schema::Tablet>().Key(TabletId).Update<Schema::Tablet::LeaderNode>(0);
9899
}
99100
if (tablet->LockedToActor == OwnerActor && tablet->PendingUnlockSeqNo == 0) {
100101
// Lock is still valid, watch for node disconnections

0 commit comments

Comments
 (0)