Skip to content

fix segfault in storage/groups handler #14623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2025
Merged
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
73 changes: 29 additions & 44 deletions ydb/core/viewer/storage_groups.h
Original file line number Diff line number Diff line change
Expand Up @@ -1579,7 +1579,7 @@ class TStorageGroups : public TViewerPipeClient {
}
}

void RequestNodesList() {
void RequestNodesListForStorageGroups() {
if (!NodesInfo.has_value()) {
NodesInfo = MakeRequest<TEvInterconnect::TEvNodesInfo>(GetNameserviceActorId(), new TEvInterconnect::TEvListNodes());
}
Expand Down Expand Up @@ -1628,34 +1628,30 @@ class TStorageGroups : public TViewerPipeClient {
}

void ProcessWhiteboardGroups() {
std::unordered_map<ui32, const NKikimrWhiteboard::TBSGroupStateInfo*> latestGroupInfo;
for (const auto& [nodeId, bsGroupStateResponse] : BSGroupStateResponse) {
if (bsGroupStateResponse.IsOk()) {
for (const NKikimrWhiteboard::TBSGroupStateInfo& info : bsGroupStateResponse->Record.GetBSGroupStateInfo()) {
TString storagePoolName = info.GetStoragePoolName();
if (storagePoolName.empty()) {
continue;
}
if (info.VDiskNodeIdsSize() == 0) {
continue;
}
auto itLatest = latestGroupInfo.find(info.GetGroupID());
if (itLatest == latestGroupInfo.end()) {
latestGroupInfo.emplace(info.GetGroupID(), &info);
} else {
if (info.GetGroupGeneration() > itLatest->second->GetGroupGeneration()) {
itLatest->second = &info;
if (GroupData.empty()) {
std::unordered_map<ui32, const NKikimrWhiteboard::TBSGroupStateInfo*> latestGroupInfo;
for (const auto& [nodeId, bsGroupStateResponse] : BSGroupStateResponse) {
if (bsGroupStateResponse.IsOk()) {
for (const NKikimrWhiteboard::TBSGroupStateInfo& info : bsGroupStateResponse->Record.GetBSGroupStateInfo()) {
TString storagePoolName = info.GetStoragePoolName();
if (storagePoolName.empty()) {
continue;
}
if (info.VDiskNodeIdsSize() == 0) {
continue;
}
auto itLatest = latestGroupInfo.find(info.GetGroupID());
if (itLatest == latestGroupInfo.end()) {
latestGroupInfo.emplace(info.GetGroupID(), &info);
} else {
if (info.GetGroupGeneration() > itLatest->second->GetGroupGeneration()) {
itLatest->second = &info;
}
}
}
}
}
}
GroupData.reserve(latestGroupInfo.size()); // to keep cache stable after emplace
RebuildGroupsByGroupId();
size_t capacity = GroupData.capacity();
for (const auto& [groupId, info] : latestGroupInfo) {
auto itGroup = GroupsByGroupId.find(groupId);
if (itGroup == GroupsByGroupId.end()) {
for (const auto& [groupId, info] : latestGroupInfo) {
TGroup& group = GroupData.emplace_back();
group.GroupId = groupId;
group.GroupGeneration = info->GetGroupGeneration();
Expand All @@ -1670,26 +1666,15 @@ class TStorageGroups : public TViewerPipeClient {
TVDisk& vDisk = group.VDisks.emplace_back();
vDisk.VDiskId = VDiskIDFromVDiskID(vDiskId);
}
if (capacity != GroupData.capacity()) {
// we expect to never do this
RebuildGroupsByGroupId();
capacity = GroupData.capacity();
}
} else {
TGroup& group = *itGroup->second;
if (group.VDiskNodeIds.empty()) {
for (auto nodeId : info->GetVDiskNodeIds()) {
group.VDiskNodeIds.push_back(nodeId);
}
}
}
GroupView.clear();
for (TGroup& group : GroupData) {
GroupView.emplace_back(&group);
}
FieldsAvailable |= FieldsWbGroups;
FoundGroups = TotalGroups = GroupView.size();
ApplyEverything();
}
for (TGroup& group : GroupData) {
GroupView.emplace_back(&group);
}
FieldsAvailable |= FieldsWbGroups;
FoundGroups = TotalGroups = GroupView.size();
ApplyEverything();
if (FieldsNeeded(FieldsWbDisks)) {
std::unordered_set<TNodeId> nodeIds;
for (const TGroup* group : GroupView) {
Expand Down Expand Up @@ -1907,7 +1892,7 @@ class TStorageGroups : public TViewerPipeClient {

void RequestWhiteboard() {
FallbackToWhiteboard = true;
RequestNodesList();
RequestNodesListForStorageGroups();
}

void OnBscError(const TString& error) {
Expand Down
Loading