Skip to content

Commit ff5b388

Browse files
adameatblinkov
authored andcommitted
fix segfault in storage/groups handler (#14623)
1 parent 227c6b2 commit ff5b388

File tree

1 file changed

+29
-44
lines changed

1 file changed

+29
-44
lines changed

ydb/core/viewer/storage_groups.h

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,7 +1579,7 @@ class TStorageGroups : public TViewerPipeClient {
15791579
}
15801580
}
15811581

1582-
void RequestNodesList() {
1582+
void RequestNodesListForStorageGroups() {
15831583
if (!NodesInfo.has_value()) {
15841584
NodesInfo = MakeRequest<TEvInterconnect::TEvNodesInfo>(GetNameserviceActorId(), new TEvInterconnect::TEvListNodes());
15851585
}
@@ -1628,34 +1628,30 @@ class TStorageGroups : public TViewerPipeClient {
16281628
}
16291629

16301630
void ProcessWhiteboardGroups() {
1631-
std::unordered_map<ui32, const NKikimrWhiteboard::TBSGroupStateInfo*> latestGroupInfo;
1632-
for (const auto& [nodeId, bsGroupStateResponse] : BSGroupStateResponse) {
1633-
if (bsGroupStateResponse.IsOk()) {
1634-
for (const NKikimrWhiteboard::TBSGroupStateInfo& info : bsGroupStateResponse->Record.GetBSGroupStateInfo()) {
1635-
TString storagePoolName = info.GetStoragePoolName();
1636-
if (storagePoolName.empty()) {
1637-
continue;
1638-
}
1639-
if (info.VDiskNodeIdsSize() == 0) {
1640-
continue;
1641-
}
1642-
auto itLatest = latestGroupInfo.find(info.GetGroupID());
1643-
if (itLatest == latestGroupInfo.end()) {
1644-
latestGroupInfo.emplace(info.GetGroupID(), &info);
1645-
} else {
1646-
if (info.GetGroupGeneration() > itLatest->second->GetGroupGeneration()) {
1647-
itLatest->second = &info;
1631+
if (GroupData.empty()) {
1632+
std::unordered_map<ui32, const NKikimrWhiteboard::TBSGroupStateInfo*> latestGroupInfo;
1633+
for (const auto& [nodeId, bsGroupStateResponse] : BSGroupStateResponse) {
1634+
if (bsGroupStateResponse.IsOk()) {
1635+
for (const NKikimrWhiteboard::TBSGroupStateInfo& info : bsGroupStateResponse->Record.GetBSGroupStateInfo()) {
1636+
TString storagePoolName = info.GetStoragePoolName();
1637+
if (storagePoolName.empty()) {
1638+
continue;
1639+
}
1640+
if (info.VDiskNodeIdsSize() == 0) {
1641+
continue;
1642+
}
1643+
auto itLatest = latestGroupInfo.find(info.GetGroupID());
1644+
if (itLatest == latestGroupInfo.end()) {
1645+
latestGroupInfo.emplace(info.GetGroupID(), &info);
1646+
} else {
1647+
if (info.GetGroupGeneration() > itLatest->second->GetGroupGeneration()) {
1648+
itLatest->second = &info;
1649+
}
16481650
}
16491651
}
16501652
}
16511653
}
1652-
}
1653-
GroupData.reserve(latestGroupInfo.size()); // to keep cache stable after emplace
1654-
RebuildGroupsByGroupId();
1655-
size_t capacity = GroupData.capacity();
1656-
for (const auto& [groupId, info] : latestGroupInfo) {
1657-
auto itGroup = GroupsByGroupId.find(groupId);
1658-
if (itGroup == GroupsByGroupId.end()) {
1654+
for (const auto& [groupId, info] : latestGroupInfo) {
16591655
TGroup& group = GroupData.emplace_back();
16601656
group.GroupId = groupId;
16611657
group.GroupGeneration = info->GetGroupGeneration();
@@ -1670,26 +1666,15 @@ class TStorageGroups : public TViewerPipeClient {
16701666
TVDisk& vDisk = group.VDisks.emplace_back();
16711667
vDisk.VDiskId = VDiskIDFromVDiskID(vDiskId);
16721668
}
1673-
if (capacity != GroupData.capacity()) {
1674-
// we expect to never do this
1675-
RebuildGroupsByGroupId();
1676-
capacity = GroupData.capacity();
1677-
}
1678-
} else {
1679-
TGroup& group = *itGroup->second;
1680-
if (group.VDiskNodeIds.empty()) {
1681-
for (auto nodeId : info->GetVDiskNodeIds()) {
1682-
group.VDiskNodeIds.push_back(nodeId);
1683-
}
1684-
}
16851669
}
1670+
GroupView.clear();
1671+
for (TGroup& group : GroupData) {
1672+
GroupView.emplace_back(&group);
1673+
}
1674+
FieldsAvailable |= FieldsWbGroups;
1675+
FoundGroups = TotalGroups = GroupView.size();
1676+
ApplyEverything();
16861677
}
1687-
for (TGroup& group : GroupData) {
1688-
GroupView.emplace_back(&group);
1689-
}
1690-
FieldsAvailable |= FieldsWbGroups;
1691-
FoundGroups = TotalGroups = GroupView.size();
1692-
ApplyEverything();
16931678
if (FieldsNeeded(FieldsWbDisks)) {
16941679
std::unordered_set<TNodeId> nodeIds;
16951680
for (const TGroup* group : GroupView) {
@@ -1907,7 +1892,7 @@ class TStorageGroups : public TViewerPipeClient {
19071892

19081893
void RequestWhiteboard() {
19091894
FallbackToWhiteboard = true;
1910-
RequestNodesList();
1895+
RequestNodesListForStorageGroups();
19111896
}
19121897

19131898
void OnBscError(const TString& error) {

0 commit comments

Comments
 (0)