Skip to content

Commit 062fa7b

Browse files
authored
Add node interlace to GroupMapper's TScore (#13458)
1 parent 8b9a7e5 commit 062fa7b

File tree

3 files changed

+50
-9
lines changed

3 files changed

+50
-9
lines changed

ydb/core/mind/bscontroller/group_layout_checker.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,15 @@ namespace NKikimr::NBsController {
7272
TEntityId RealmGroup;
7373
TEntityId Realm;
7474
TEntityId Domain;
75+
TEntityId Node;
7576

7677
TPDiskLayoutPosition() = default;
7778

78-
TPDiskLayoutPosition(TEntityId realmGroup, TEntityId realm, TEntityId domain)
79+
TPDiskLayoutPosition(TEntityId realmGroup, TEntityId realm, TEntityId domain, TEntityId node)
7980
: RealmGroup(realmGroup)
8081
, Realm(realm)
8182
, Domain(domain)
83+
, Node(node)
8284
{}
8385

8486
TPDiskLayoutPosition(TDomainMapper& mapper, const TNodeLocation& location, TPDiskId pdiskId, const TGroupGeometryInfo& geom) {
@@ -102,6 +104,7 @@ namespace NKikimr::NBsController {
102104
RealmGroup = mapper(realmGroup.Str());
103105
Realm = mapper(realm.Str());
104106
Domain = mapper(domain.Str());
107+
Node.Value = pdiskId.NodeId;
105108
}
106109

107110
TString ToString() const {
@@ -124,12 +127,13 @@ namespace NKikimr::NBsController {
124127
struct TScore {
125128
ui32 RealmInterlace = 0;
126129
ui32 DomainInterlace = 0;
130+
ui32 NodeInterlace = 0;
127131
ui32 RealmGroupScatter = 0;
128132
ui32 RealmScatter = 0;
129133
ui32 DomainScatter = 0;
130134

131135
auto AsTuple() const {
132-
return std::make_tuple(RealmInterlace, DomainInterlace, RealmGroupScatter, RealmScatter, DomainScatter);
136+
return std::make_tuple(RealmInterlace, DomainInterlace, NodeInterlace, RealmGroupScatter, RealmScatter, DomainScatter);
133137
}
134138

135139
bool BetterThan(const TScore& other) const {
@@ -141,12 +145,13 @@ namespace NKikimr::NBsController {
141145
}
142146

143147
static TScore Max() {
144-
return {::Max<ui32>(), ::Max<ui32>(), ::Max<ui32>(), ::Max<ui32>(), ::Max<ui32>()};
148+
return {::Max<ui32>(), ::Max<ui32>(), ::Max<ui32>(), ::Max<ui32>(), ::Max<ui32>(), ::Max<ui32>()};
145149
}
146150

147151
TString ToString() const {
148152
return TStringBuilder() << "{RealmInterlace# " << RealmInterlace
149153
<< " DomainInterlace# " << DomainInterlace
154+
<< " NodeInterlace# " << NodeInterlace
150155
<< " RealmGroupScatter# " << RealmGroupScatter
151156
<< " RealmScatter# " << RealmScatter
152157
<< " DomainScatter# " << DomainScatter
@@ -168,6 +173,8 @@ namespace NKikimr::NBsController {
168173
TStackVec<THashMap<TEntityId, ui32>, 32> NumDisksPerDomain;
169174
THashMap<TEntityId, ui32> NumDisksPerDomainTotal;
170175

176+
THashMap<TEntityId, ui32> NumDisksPerNode;
177+
171178
TGroupLayout(const TBlobStorageGroupInfo::TTopology& topology)
172179
: Topology(topology)
173180
, NumDisksInRealm(Topology.GetTotalFailRealmsNum())
@@ -187,6 +194,8 @@ namespace NKikimr::NBsController {
187194
NumDisksInDomain[domainIdx] += value;
188195
NumDisksPerDomain[domainIdx][pos.Domain] += value;
189196
NumDisksPerDomainTotal[pos.Domain] += value;
197+
198+
NumDisksPerNode[pos.Node] += value;
190199
}
191200

192201
void AddDisk(const TPDiskLayoutPosition& pos, ui32 orderNumber) {
@@ -204,9 +213,12 @@ namespace NKikimr::NBsController {
204213
const auto& disksPerRealm = NumDisksPerRealm[vdisk.FailRealm][pos.Realm];
205214
const auto& disksPerDomain = NumDisksPerDomain[domainIdx][pos.Domain];
206215

216+
const ui32 disksOnNode = NumDisksPerNode[pos.Node];
217+
207218
return {
208219
.RealmInterlace = NumDisksPerRealmTotal[pos.Realm] - disksPerRealm,
209220
.DomainInterlace = NumDisksPerDomainTotal[pos.Domain] - disksPerDomain,
221+
.NodeInterlace = disksOnNode,
210222
.RealmGroupScatter = NumDisks - NumDisksPerRealmGroup[pos.RealmGroup],
211223
.RealmScatter = NumDisksInRealm[vdisk.FailRealm] - disksPerRealm,
212224
.DomainScatter = NumDisksInDomain[domainIdx] - disksPerDomain,

ydb/core/mind/bscontroller/group_mapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ namespace NKikimr::NBsController {
405405

406406
static std::pair<TPDiskLayoutPosition, TPDiskLayoutPosition> MakeRange(const TPDiskLayoutPosition& x, TEntityId& scope) {
407407
scope = x.Realm;
408-
return {{x.RealmGroup, x.Realm, TEntityId::Min()}, {x.RealmGroup, x.Realm, TEntityId::Max()}};
408+
return {{x.RealmGroup, x.Realm, TEntityId::Min(), TEntityId::Min()}, {x.RealmGroup, x.Realm, TEntityId::Max(), TEntityId::Max()}};
409409
}
410410
};
411411

@@ -415,7 +415,7 @@ namespace NKikimr::NBsController {
415415

416416
static std::pair<TPDiskLayoutPosition, TPDiskLayoutPosition> MakeRange(const TPDiskLayoutPosition& x, TEntityId& scope) {
417417
scope = x.RealmGroup;
418-
return {{x.RealmGroup, TEntityId::Min(), TEntityId::Min()}, {x.RealmGroup, TEntityId::Max(), TEntityId::Max()}};
418+
return {{x.RealmGroup, TEntityId::Min(), TEntityId::Min(), TEntityId::Min()}, {x.RealmGroup, TEntityId::Max(), TEntityId::Max(), TEntityId::Max()}};
419419
}
420420
};
421421

ydb/core/mind/bscontroller/group_mapper_ut.cpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -593,10 +593,6 @@ Y_UNIT_TEST_SUITE(TGroupMapperTest) {
593593
TestBlock42(1);
594594
}
595595

596-
Y_UNIT_TEST(Block42_2disk) {
597-
TestBlock42(2);
598-
}
599-
600596
Y_UNIT_TEST(Mirror3dc) {
601597
TTestContext context(6, 3, 3, 3, 3);
602598
TGroupMapper mapper(TTestContext::CreateGroupGeometry(TBlobStorageGroupType::ErasureMirror3dc));
@@ -638,6 +634,39 @@ Y_UNIT_TEST_SUITE(TGroupMapperTest) {
638634
}
639635
}
640636

637+
Y_UNIT_TEST(InterlacedRacksWithoutInterlacedNodes) {
638+
TTestContext context(
639+
{
640+
{1, 1, 1, 1, 1}, // node 1
641+
{1, 1, 2, 1, 1},
642+
{1, 1, 3, 1, 2}, // node 3 has two disks
643+
{1, 1, 4, 1, 1},
644+
{1, 1, 5, 1, 1},
645+
{1, 1, 6, 1, 1},
646+
{1, 1, 2, 1, 1}, // node 7 is in the same rack as node 2
647+
{1, 1, 8, 1, 1},
648+
{1, 1, 3, 1, 1}, // node 9 is in the same rack as node 3
649+
}
650+
);
651+
652+
TGroupMapper mapper(TTestContext::CreateGroupGeometry(TBlobStorageGroupType::Erasure4Plus2Block));
653+
context.PopulateGroupMapper(mapper, 8);
654+
655+
TGroupMapper::TGroupDefinition group;
656+
group.emplace_back(TVector<TVector<TPDiskId>>(8));
657+
auto& g = group[0];
658+
659+
for (int i = 0; i < 8; i++) {
660+
g[i].emplace_back(TPDiskId(i + 1, 1));
661+
}
662+
663+
context.SetGroup(1, group);
664+
665+
TGroupMapper::TGroupDefinition newGroup = context.ReallocateGroup(mapper, 1, {TPDiskId(8, 1)});
666+
667+
UNIT_ASSERT_EQUAL_C(TPDiskId(9, 1), newGroup[0][7][0], context.FormatGroup(newGroup));
668+
}
669+
641670
Y_UNIT_TEST(NonUniformClusterDifferentSlotsPerDisk) {
642671
std::vector<std::tuple<ui32, ui32, ui32, ui32, ui32>> disks;
643672
for (ui32 rack = 0; rack < 12; ++rack) {

0 commit comments

Comments
 (0)