Skip to content

Commit 55a88ca

Browse files
authored
Fix PDisk drive size estimation code (#11098)
1 parent ec5b47e commit 55a88ca

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

ydb/core/blobstorage/pdisk/blobstorage_pdisk_impl_metadata.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,15 @@ namespace NKikimr::NPDisk {
620620
true, fmt.DataKey, 0, 0, 1);
621621
const size_t bytesToWrite = payload.size();
622622

623-
const ui64 deviceSizeInBytes = DriveData.Size & ~ui64(DefaultSectorSize - 1);
623+
ui64 rawDeviceSize = 0;
624+
try {
625+
bool isBlockDevice = false;
626+
DetectFileParameters(Cfg->Path, rawDeviceSize, isBlockDevice);
627+
} catch (const std::exception&) {
628+
rawDeviceSize = 0;
629+
}
630+
631+
const ui64 deviceSizeInBytes = rawDeviceSize & ~ui64(DefaultSectorSize - 1);
624632
auto& cur = unformatted.Format;
625633
const ui64 endOffset = !cur || cur->Offset + cur->Length + bytesToWrite <= deviceSizeInBytes
626634
? deviceSizeInBytes
@@ -629,7 +637,7 @@ namespace NKikimr::NPDisk {
629637
if (endOffset < bytesToWrite + FormatSectorSize * ReplicationFactor) { // way too large metadata
630638
P_LOG(PRI_ERROR, BPD01, "ProcessWriteMetadata (unformatted): not enough free space",
631639
(EndOffset, endOffset),
632-
(RawDeviceSize, DriveData.Size),
640+
(RawDeviceSize, rawDeviceSize),
633641
(DeviceSizeInBytes, deviceSizeInBytes),
634642
(BytesToWrite, bytesToWrite));
635643
PCtx->ActorSystem->Send(write.Sender, new TEvWriteMetadataResult(EPDiskMetadataOutcome::ERROR, std::nullopt));

0 commit comments

Comments
 (0)