Skip to content

Commit 521c1b0

Browse files
authored
Allow shorter drive listing in config.yaml (#6024)
1 parent 27ff0b3 commit 521c1b0

File tree

6 files changed

+80
-44
lines changed

6 files changed

+80
-44
lines changed

ydb/core/blobstorage/nodewarden/distconf.h

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ namespace NKikimr::NStorage {
418418

419419
template<typename T>
420420
void EnumerateConfigDrives(const NKikimrBlobStorage::TStorageConfig& config, ui32 nodeId, T&& callback,
421-
THashMap<ui32, const NKikimrBlobStorage::TNodeIdentifier*> *nodeMap = nullptr) {
421+
THashMap<ui32, const NKikimrBlobStorage::TNodeIdentifier*> *nodeMap = nullptr, bool fillInPDiskConfig = false) {
422422
if (!config.HasBlobStorageConfig()) {
423423
return;
424424
}
@@ -458,9 +458,30 @@ namespace NKikimr::NStorage {
458458
const auto& node = *it->second;
459459
if (const auto it = defineHostConfigMap.find(host.GetHostConfigId()); it != defineHostConfigMap.end()) {
460460
const auto& hostConfig = *it->second;
461+
auto processDrive = [&](const auto& drive) {
462+
if (fillInPDiskConfig && !drive.HasPDiskConfig() && hostConfig.HasDefaultHostPDiskConfig()) {
463+
NKikimrBlobStorage::THostConfigDrive temp;
464+
temp.CopyFrom(drive);
465+
temp.MutablePDiskConfig()->CopyFrom(hostConfig.GetDefaultHostPDiskConfig());
466+
callback(node, temp);
467+
} else {
468+
callback(node, drive);
469+
}
470+
};
461471
for (const auto& drive : hostConfig.GetDrive()) {
462-
callback(node, drive);
472+
processDrive(drive);
463473
}
474+
auto processTypedDrive = [&](const auto& field, NKikimrBlobStorage::EPDiskType type) {
475+
for (const auto& path : field) {
476+
NKikimrBlobStorage::THostConfigDrive drive;
477+
drive.SetType(type);
478+
drive.SetPath(path);
479+
processDrive(drive);
480+
}
481+
};
482+
processTypedDrive(hostConfig.GetRot(), NKikimrBlobStorage::EPDiskType::ROT);
483+
processTypedDrive(hostConfig.GetSsd(), NKikimrBlobStorage::EPDiskType::SSD);
484+
processTypedDrive(hostConfig.GetNvme(), NKikimrBlobStorage::EPDiskType::NVME);
464485
}
465486
}
466487
}

ydb/core/blobstorage/nodewarden/distconf_fsm.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ namespace NKikimr::NStorage {
112112
invoke(disk);
113113
}
114114
}
115+
for (const auto& item : res->GetProposedConfigs()) {
116+
for (const auto& disk : item.GetDisks()) {
117+
invoke(disk);
118+
}
119+
}
115120
for (const auto& disk : res->GetNoMetadata()) {
116121
invoke(disk);
117122
}

ydb/core/blobstorage/nodewarden/distconf_generate.cpp

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ namespace NKikimr::NStorage {
5858
using TPDiskId = NBsController::TPDiskId;
5959

6060
NKikimrConfig::TBlobStorageConfig *bsConfig = config->MutableBlobStorageConfig();
61-
const auto& settings = bsConfig->GetAutoconfigSettings();
6261

6362
// build node location map
6463
THashMap<ui32, TNodeLocation> nodeLocations;
@@ -301,50 +300,30 @@ namespace NKikimr::NStorage {
301300
}
302301

303302
// build host config map
304-
THashMap<ui64, const NKikimrBlobStorage::TDefineHostConfig*> hostConfigs;
305-
for (const auto& hc : settings.GetDefineHostConfig()) {
306-
const bool inserted = hostConfigs.try_emplace(hc.GetHostConfigId(), &hc).second;
307-
Y_ABORT_UNLESS(inserted);
308-
}
309-
310-
// find all drives
311-
const auto& defineBox = settings.GetDefineBox();
312-
for (const auto& host : defineBox.GetHost()) {
313-
const ui32 nodeId = host.GetEnforcedNodeId();
314-
if (!nodeId) {
315-
throw TExConfigError() << "EnforcedNodeId is not specified in DefineBox";
316-
}
317-
318-
const auto it = hostConfigs.find(host.GetHostConfigId());
319-
if (it == hostConfigs.end()) {
320-
throw TExConfigError() << "no matching DefineHostConfig"
321-
<< " HostConfigId# " << host.GetHostConfigId();
303+
auto processDrive = [&](const auto& node, const auto& drive) {
304+
const ui32 nodeId = node.GetNodeId();
305+
if (pdiskLocations.contains(std::make_tuple(nodeId, drive.GetPath()))) {
306+
return;
322307
}
323-
const auto& defineHostConfig = *it->second;
324-
325-
for (const auto& drive : defineHostConfig.GetDrive()) {
326-
if (pdiskLocations.contains(std::make_tuple(nodeId, drive.GetPath()))) {
327-
continue;
328-
}
329-
if (checkMatch(drive.GetType(), drive.GetSharedWithOs(), drive.GetReadCentric(), drive.GetKind())) {
330-
const TPDiskId pdiskId(nodeId, ++maxPDiskId[nodeId]);
331-
if (const auto [it, inserted] = pdisks.try_emplace(pdiskId); inserted) {
332-
auto& r = it->second.Record;
333-
r.SetNodeID(pdiskId.NodeId);
334-
r.SetPDiskID(pdiskId.PDiskId);
335-
r.SetPath(drive.GetPath());
336-
r.SetPDiskGuid(RandomNumber<ui64>());
337-
r.SetPDiskCategory(TPDiskCategory(static_cast<NPDisk::EDeviceType>(drive.GetType()),
338-
drive.GetKind()).GetRaw());
339-
if (drive.HasPDiskConfig()) {
340-
r.MutablePDiskConfig()->CopyFrom(drive.GetPDiskConfig());
341-
}
342-
} else {
343-
Y_ABORT("duplicate PDiskId");
308+
if (checkMatch(drive.GetType(), drive.GetSharedWithOs(), drive.GetReadCentric(), drive.GetKind())) {
309+
const TPDiskId pdiskId(nodeId, ++maxPDiskId[nodeId]);
310+
if (const auto [it, inserted] = pdisks.try_emplace(pdiskId); inserted) {
311+
auto& r = it->second.Record;
312+
r.SetNodeID(pdiskId.NodeId);
313+
r.SetPDiskID(pdiskId.PDiskId);
314+
r.SetPath(drive.GetPath());
315+
r.SetPDiskGuid(RandomNumber<ui64>());
316+
r.SetPDiskCategory(TPDiskCategory(static_cast<NPDisk::EDeviceType>(drive.GetType()),
317+
drive.GetKind()));
318+
if (drive.HasPDiskConfig()) {
319+
r.MutablePDiskConfig()->CopyFrom(drive.GetPDiskConfig());
344320
}
321+
} else {
322+
Y_ABORT("duplicate PDiskId");
345323
}
346324
}
347-
}
325+
};
326+
EnumerateConfigDrives(*config, 0, processDrive, nullptr, true);
348327

349328
// group mapper
350329
NBsController::TGroupGeometryInfo geom(gtype.GetErasure(), geometry);

ydb/core/mind/bscontroller/cmds_host_config.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,31 @@ namespace NKikimr::NBsController {
3434
}
3535

3636
Schema::HostConfigDrive::TKey::Type key(id, drive.GetPath());
37-
config.Drives.emplace(std::move(key), std::move(driveInfo));
37+
const auto [it, inserted] = config.Drives.emplace(std::move(key), std::move(driveInfo));
38+
if (!inserted) {
39+
throw TExError() << "duplicate path# " << drive.GetPath();
40+
}
3841
}
3942

43+
auto addDrives = [&](const auto& field, NKikimrBlobStorage::EPDiskType type) {
44+
THostConfigInfo::TDriveInfo driveInfo;
45+
driveInfo.Type = type;
46+
driveInfo.SharedWithOs = false;
47+
driveInfo.ReadCentric = false;
48+
driveInfo.Kind = 0;
49+
driveInfo.PDiskConfig = defaultPDiskConfig;
50+
51+
for (const auto& path : field) {
52+
const auto [it, inserted] = config.Drives.emplace(Schema::HostConfigDrive::TKey::Type(id, path), driveInfo);
53+
if (!inserted) {
54+
throw TExError() << "duplicate path# " << path;
55+
}
56+
}
57+
};
58+
addDrives(cmd.GetRot(), NKikimrBlobStorage::EPDiskType::ROT);
59+
addDrives(cmd.GetSsd(), NKikimrBlobStorage::EPDiskType::SSD);
60+
addDrives(cmd.GetNvme(), NKikimrBlobStorage::EPDiskType::NVME);
61+
4062
auto &hostConfigs = HostConfigs.Unshare();
4163
hostConfigs[id] = std::move(config);
4264

ydb/core/protos/blobstorage_config.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ message TDefineHostConfig {
3535
// host-wide default configuration for every PDisk
3636
NKikimrBlobStorage.TPDiskConfig DefaultHostPDiskConfig = 4;
3737

38+
// some syntactic sugar -- one drive type per path
39+
repeated string Rot = 5;
40+
repeated string Ssd = 6;
41+
repeated string Nvme = 7;
42+
3843
// item's generation to prevent concurrent modification
3944
uint64 ItemConfigGeneration = 100;
4045
}

ydb/library/yaml_config/protos/config.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ message TExtendedDefineHostConfig {
134134

135135
optional NKikimrBlobStorage.TPDiskConfig DefaultHostPDiskConfig = 4 [(NMarkers.CopyTo) = "TDefineHostConfig"];
136136

137+
repeated string Rot = 5 [(NMarkers.CopyTo) = "TDefineHostConfig"];
138+
repeated string Ssd = 6 [(NMarkers.CopyTo) = "TDefineHostConfig"];
139+
repeated string Nvme = 7 [(NMarkers.CopyTo) = "TDefineHostConfig"];
140+
137141
optional uint64 ItemConfigGeneration = 100 [(NMarkers.CopyTo) = "TDefineHostConfig"];
138142
}
139143

0 commit comments

Comments
 (0)