diff options
| author | Dan Engelbrecht <[email protected]> | 2022-04-01 15:20:42 +0200 |
|---|---|---|
| committer | Dan Engelbrecht <[email protected]> | 2022-04-01 15:20:42 +0200 |
| commit | ef8cb5f11168183be77b1c121a9171b2ea9fbaab (patch) | |
| tree | fc9abc4f409ce05a6f290e9857659e72f6aee3f8 /zenstore/compactcas.cpp | |
| parent | fix entry validation (diff) | |
| download | zen-ef8cb5f11168183be77b1c121a9171b2ea9fbaab.tar.xz zen-ef8cb5f11168183be77b1c121a9171b2ea9fbaab.zip | |
Make gc reserve a global resource
Diffstat (limited to 'zenstore/compactcas.cpp')
| -rw-r--r-- | zenstore/compactcas.cpp | 103 |
1 files changed, 3 insertions, 100 deletions
diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp index 2a4f3c012..c424cde74 100644 --- a/zenstore/compactcas.cpp +++ b/zenstore/compactcas.cpp @@ -112,11 +112,6 @@ namespace { return Path.ToPath(); } - std::filesystem::path GetGCReservePath(const std::filesystem::path& RootPath, const std::string& ContainerBaseName) - { - return GetBasePath(RootPath, ContainerBaseName) / (ContainerBaseName + ".gc.reserve" + DataExtension); - } - std::filesystem::path GetLegacyLogPath(const std::filesystem::path& RootPath, const std::string& ContainerBaseName) { return RootPath / (ContainerBaseName + LogExtension); @@ -352,7 +347,6 @@ namespace { BasicFile BlockFile; BlockFile.Open(LegacySobsPath, BasicFile::EMode::kRead); - uint64_t FileSize = BlockFile.FileSize(); std::unordered_map<IoHash, LegacyCasDiskIndexEntry, IoHash::Hasher> LegacyDiskIndex; @@ -1223,8 +1217,8 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx) } if (Space.Free < m_MaxBlockSize) { - std::filesystem::path GCReservePath = GetGCReservePath(m_Config.RootDirectory, m_ContainerBaseName); - if (!std::filesystem::is_regular_file(GCReservePath)) + uint64_t ReclaimedSpace = GcCtx.ClaimGCReserve(); + if (ReclaimedSpace == 0) { ZEN_INFO("garbage collect for '{}' FAILED, required disk space {}, free {}", m_Config.RootDirectory / m_ContainerBaseName, @@ -1244,14 +1238,8 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx) ZEN_INFO("using gc reserve for '{}', disk free {}", m_Config.RootDirectory / m_ContainerBaseName, NiceBytes(Space.Free)); - std::filesystem::path NewBlockPath = GetBlockPath(m_BlocksBasePath, NextBlockIndex); - std::filesystem::rename(GCReservePath, NewBlockPath); - NewBlockFile->Open(); - } - else - { - NewBlockFile->Create(m_MaxBlockSize); } + NewBlockFile->Create(m_MaxBlockSize); NewBlockIndex = NextBlockIndex; WriteOffset = 0; } @@ -1305,34 +1293,6 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx) } GcCtx.DeletedCas(DeletedChunks); - - std::filesystem::path GCReservePath = GetGCReservePath(m_Config.RootDirectory, m_ContainerBaseName); - if (std::filesystem::is_regular_file(GCReservePath)) - { - return; - } - - std::error_code Error; - DiskSpace Space = DiskSpaceInfo(m_Config.RootDirectory, Error); - if (Error) - { - ZEN_ERROR("get disk space in {} FAILED, reason '{}'", m_ContainerBaseName, Error.message()); - return; - } - if (Space.Free < m_MaxBlockSize) - { - ZEN_INFO("not enough space for garbage collect reserve for '{}' FAILED, required disk space {}, free {}", - m_Config.RootDirectory / m_ContainerBaseName, - m_MaxBlockSize, - NiceBytes(Space.Free)); - return; - } - BasicFile GCReserveFile; - CreateDirectories(GCReservePath.parent_path()); - GCReserveFile.Open(GCReservePath, BasicFile::EMode::kTruncate); - GCReserveFile.SetFileSize(m_MaxBlockSize); - - ZEN_DEBUG("recreated garbage collect reserve for '{}', {} bytes", m_Config.RootDirectory / m_ContainerBaseName, NiceBytes(Space.Free)); } void @@ -1608,59 +1568,6 @@ CasContainerStrategy::OpenContainer(bool IsNewStore) CreateDirectories(m_BlocksBasePath); } - // Create GC reserve file if possible - std::filesystem::path GCReservePath = GetGCReservePath(m_Config.RootDirectory, m_ContainerBaseName); - - std::error_code Error; - DiskSpace Space = DiskSpaceInfo(m_Config.RootDirectory, Error); - if (Error) - { - ZEN_ERROR("get disk space in {} FAILED, reason '{}'", m_Config.RootDirectory, Error.message()); - return; - } - - BasicFile GCReserveFile; - if (std::filesystem::is_regular_file(GCReservePath)) - { - GCReserveFile.Open(GCReservePath, BasicFile::EMode::kWrite); - std::uint64_t CurrentSize = GCReserveFile.FileSize(); - if ((Space.Free - CurrentSize) >= m_MaxBlockSize) - { - GCReserveFile.SetFileSize(m_MaxBlockSize); - } - else - { - // We need it to be the proper size if we are to use it - ZEN_WARN("removing gc reserve for '{}', not enough space free on drive, need {}, have {} ", - m_Config.RootDirectory / m_ContainerBaseName, - NiceBytes(m_MaxBlockSize), - NiceBytes(Space.Free)); - - std::error_code Ec; - std::filesystem::remove(GCReservePath, Ec); - if (Ec) - { - ZEN_WARN("Failed to delete gc reserve file '{}' reason: '{}'", GCReservePath, Ec.message()); - } - } - } - else - { - if (Space.Free >= m_MaxBlockSize) - { - CreateDirectories(GCReservePath.parent_path()); - GCReserveFile.Open(GCReservePath, BasicFile::EMode::kTruncate); - GCReserveFile.SetFileSize(m_MaxBlockSize); - } - else - { - ZEN_WARN("can't create gc reserve for '{}', not enough space free on drive, need {}, have {} ", - m_Config.RootDirectory / m_ContainerBaseName, - NiceBytes(m_MaxBlockSize), - NiceBytes(Space.Free)); - } - } - if (MakeSnapshot) { MakeIndexSnapshot(); @@ -2342,10 +2249,6 @@ TEST_CASE("compactcas.legacyconversion") std::filesystem::path SLegacylogPath = GetLegacyLogPath(CasConfig.RootDirectory, "test"); LegacyCasLog.Open(SLegacylogPath, CasLogFile::EMode::kTruncate); - BasicFile UCasFile; - UCasFile.Open(LegacyCasPath, BasicFile::EMode::kRead); - uint64_t FileSize = UCasFile.FileSize(); - for (const CasDiskIndexEntry& Entry : LogEntries) { BlockStoreLocation Location = Entry.Location.Get(16); |