Skip to content

Commit 69ccf6c

Browse files
committed
correctly handle follower count = 0
1 parent 0f0d954 commit 69ccf6c

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

ydb/core/mind/hive/hive_ut.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5920,7 +5920,7 @@ Y_UNIT_TEST_SUITE(THiveTest) {
59205920
}
59215921
}
59225922

5923-
Y_UNIT_TEST(TestFollowerCompatability1) {
5923+
void TestAncientFollowers(unsigned followerCount) {
59245924
static constexpr ui32 NUM_NODES = 3;
59255925
TTestBasicRuntime runtime(NUM_NODES, NUM_NODES); // num nodes = num dcs
59265926
Setup(runtime, true);
@@ -5940,7 +5940,7 @@ Y_UNIT_TEST_SUITE(THiveTest) {
59405940
THolder<TEvHive::TEvCreateTablet> ev(new TEvHive::TEvCreateTablet(testerTablet, 100500, tabletType, BINDED_CHANNELS));
59415941
ev->Record.SetObjectId(1);
59425942
auto* followerGroup = ev->Record.AddFollowerGroups();
5943-
followerGroup->SetFollowerCount(NUM_NODES);
5943+
followerGroup->SetFollowerCount(followerCount);
59445944
followerGroup->SetFollowerCountPerDataCenter(false);
59455945
followerGroup->SetRequireAllDataCenters(true);
59465946
ui64 tabletId = SendCreateTestTablet(runtime, hiveTablet, testerTablet, std::move(ev), 0, true);
@@ -5959,17 +5959,24 @@ Y_UNIT_TEST_SUITE(THiveTest) {
59595959
}
59605960
{
59615961
TDispatchOptions options;
5962-
options.FinalEvents.emplace_back(TEvLocal::EvTabletStatus, 3);
5962+
options.FinalEvents.emplace_back(TEvLocal::EvTabletStatus, followerCount);
59635963
runtime.DispatchEvents(options, TDuration::Seconds(1));
59645964
}
5965-
// test every node has a follower running
59665965
NTabletPipe::TClientConfig pipeConfig;
59675966
pipeConfig.ForceLocal = true;
59685967
pipeConfig.AllowFollower = true;
59695968
pipeConfig.ForceFollower = true;
5969+
unsigned actualFollowers = 0;
59705970
for (ui32 node = 0; node < NUM_NODES; ++node) {
5971-
MakeSureTabletIsUp(runtime, tabletId, node, &pipeConfig);
5971+
if (CheckTabletIsUp(runtime, tabletId, node, &pipeConfig)) {
5972+
++actualFollowers;
5973+
}
59725974
}
5975+
UNIT_ASSERT_VALUES_EQUAL(followerCount, actualFollowers);
5976+
}
5977+
5978+
Y_UNIT_TEST(TestFollowerCompatability1) {
5979+
TestAncientFollowers(3);
59735980
}
59745981

59755982
Y_UNIT_TEST(TestFollowerCompatability2) {
@@ -6033,6 +6040,10 @@ Y_UNIT_TEST_SUITE(THiveTest) {
60336040
UNIT_ASSERT_VALUES_EQUAL(followers, 2);
60346041
}
60356042

6043+
Y_UNIT_TEST(TestFollowerCompatability3) {
6044+
TestAncientFollowers(0);
6045+
}
6046+
60366047
Y_UNIT_TEST(TestCreateExternalTablet) {
60376048
TTestBasicRuntime runtime(1, false);
60386049
Setup(runtime, true);

ydb/core/mind/hive/tx__load_everything.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,8 @@ class TTxLoadEverything : public TTransactionBase<THive> {
611611

612612
if (followerGroup.RequireAllDataCenters && !followerGroup.FollowerCountPerDataCenter) {
613613
followerGroup.FollowerCountPerDataCenter = true;
614-
followerGroup.SetFollowerCount((followerGroup.GetRawFollowerCount() - 1) / Self->DataCenters.size() + 1);
614+
auto dataCenters = Self->DataCenters.size() ? Self->DataCenters.size() : 3ull;
615+
followerGroup.SetFollowerCount((followerGroup.GetRawFollowerCount() + dataCenters - 1) / dataCenters); // round up
615616
}
616617
} else {
617618
++numMissingTablets;

0 commit comments

Comments
 (0)