diff options
| author | Dan Engelbrecht <[email protected]> | 2022-04-06 15:16:26 +0200 |
|---|---|---|
| committer | Dan Engelbrecht <[email protected]> | 2022-04-06 15:39:17 +0200 |
| commit | 3b42300223406b8e14438c95d90d633090d3dbbf (patch) | |
| tree | 4b03eb73f02bf03d1b4671775c1c5277a7d7341a /zenstore/compactcas.cpp | |
| parent | formatting (diff) | |
| download | zen-3b42300223406b8e14438c95d90d633090d3dbbf.tar.xz zen-3b42300223406b8e14438c95d90d633090d3dbbf.zip | |
clean up variable naming
Diffstat (limited to 'zenstore/compactcas.cpp')
| -rw-r--r-- | zenstore/compactcas.cpp | 111 |
1 files changed, 55 insertions, 56 deletions
diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp index 6c6fd2436..51fe7a901 100644 --- a/zenstore/compactcas.cpp +++ b/zenstore/compactcas.cpp @@ -9,7 +9,6 @@ #include <zencore/fmtutils.h> #include <zencore/logging.h> #include <zencore/scopeguard.h> -#include <zencore/workthreadpool.h> #include <gsl/gsl-lite.hpp> #include <xxhash.h> @@ -18,6 +17,7 @@ # include <zencore/compactbinarybuilder.h> # include <zencore/testing.h> # include <zencore/testutils.h> +# include <zencore/workthreadpool.h> # include <zenstore/cidstore.h> # include <algorithm> # include <random> @@ -114,12 +114,12 @@ namespace { return RootPath / (ContainerBaseName + LogExtension); } - std::filesystem::path GetLegacyUcasPath(const std::filesystem::path& RootPath, const std::string& ContainerBaseName) + std::filesystem::path GetLegacyDataPath(const std::filesystem::path& RootPath, const std::string& ContainerBaseName) { return RootPath / (ContainerBaseName + DataExtension); } - std::filesystem::path GetLegacyUidxPath(const std::filesystem::path& RootPath, const std::string& ContainerBaseName) + std::filesystem::path GetLegacyIndexPath(const std::filesystem::path& RootPath, const std::string& ContainerBaseName) { return RootPath / (ContainerBaseName + IndexExtension); } @@ -913,17 +913,17 @@ CasContainerStrategy::MakeIndexSnapshot() namespace fs = std::filesystem; - fs::path SidxPath = GetIndexPath(m_Config.RootDirectory, m_ContainerBaseName); - fs::path STmpSidxPath = GetTempIndexPath(m_Config.RootDirectory, m_ContainerBaseName); + fs::path IndexPath = GetIndexPath(m_Config.RootDirectory, m_ContainerBaseName); + fs::path TempIndexPath = GetTempIndexPath(m_Config.RootDirectory, m_ContainerBaseName); // Move index away, we keep it if something goes wrong - if (fs::is_regular_file(STmpSidxPath)) + if (fs::is_regular_file(TempIndexPath)) { - fs::remove(STmpSidxPath); + fs::remove(TempIndexPath); } - if (fs::is_regular_file(SidxPath)) + if (fs::is_regular_file(IndexPath)) { - fs::rename(SidxPath, STmpSidxPath); + fs::rename(IndexPath, TempIndexPath); } try @@ -951,7 +951,7 @@ CasContainerStrategy::MakeIndexSnapshot() } BasicFile ObjectIndexFile; - ObjectIndexFile.Open(SidxPath, BasicFile::Mode::kTruncate); + ObjectIndexFile.Open(IndexPath, BasicFile::Mode::kTruncate); CasDiskIndexHeader Header = {.EntryCount = Entries.size(), .LogPosition = LogCount, .PayloadAlignment = gsl::narrow<uint32_t>(m_PayloadAlignment)}; @@ -970,15 +970,15 @@ CasContainerStrategy::MakeIndexSnapshot() // Restore any previous snapshot - if (fs::is_regular_file(STmpSidxPath)) + if (fs::is_regular_file(TempIndexPath)) { - fs::remove(SidxPath); - fs::rename(STmpSidxPath, SidxPath); + fs::remove(IndexPath); + fs::rename(TempIndexPath, IndexPath); } } - if (fs::is_regular_file(STmpSidxPath)) + if (fs::is_regular_file(TempIndexPath)) { - fs::remove(STmpSidxPath); + fs::remove(TempIndexPath); } } @@ -986,8 +986,8 @@ uint64_t CasContainerStrategy::ReadIndexFile() { std::vector<CasDiskIndexEntry> Entries; - std::filesystem::path SidxPath = GetIndexPath(m_Config.RootDirectory, m_ContainerBaseName); - if (std::filesystem::is_regular_file(SidxPath)) + std::filesystem::path IndexPath = GetIndexPath(m_Config.RootDirectory, m_ContainerBaseName); + if (std::filesystem::is_regular_file(IndexPath)) { Stopwatch Timer; const auto _ = MakeGuard([this, &Entries, &Timer] { @@ -998,7 +998,7 @@ CasContainerStrategy::ReadIndexFile() }); BasicFile ObjectIndexFile; - ObjectIndexFile.Open(SidxPath, BasicFile::Mode::kRead); + ObjectIndexFile.Open(IndexPath, BasicFile::Mode::kRead); uint64_t Size = ObjectIndexFile.FileSize(); if (Size >= sizeof(CasDiskIndexHeader)) { @@ -1018,7 +1018,7 @@ CasContainerStrategy::ReadIndexFile() { if (!ValidateEntry(Entry, InvalidEntryReason)) { - ZEN_WARN("skipping invalid entry in '{}', reason: '{}'", SidxPath, InvalidEntryReason); + ZEN_WARN("skipping invalid entry in '{}', reason: '{}'", IndexPath, InvalidEntryReason); continue; } m_LocationMap[Entry.Key] = Entry.Location; @@ -1028,7 +1028,7 @@ CasContainerStrategy::ReadIndexFile() } else { - ZEN_WARN("skipping invalid index file '{}'", SidxPath); + ZEN_WARN("skipping invalid index file '{}'", IndexPath); } } } @@ -1039,8 +1039,8 @@ uint64_t CasContainerStrategy::ReadLog(uint64_t SkipEntryCount) { std::vector<CasDiskIndexEntry> Entries; - std::filesystem::path SlogPath = GetLogPath(m_Config.RootDirectory, m_ContainerBaseName); - if (std::filesystem::is_regular_file(SlogPath)) + std::filesystem::path LogPath = GetLogPath(m_Config.RootDirectory, m_ContainerBaseName); + if (std::filesystem::is_regular_file(LogPath)) { Stopwatch Timer; const auto _ = MakeGuard([this, &Entries, &Timer] { @@ -1051,13 +1051,13 @@ CasContainerStrategy::ReadLog(uint64_t SkipEntryCount) }); TCasLogFile<CasDiskIndexEntry> CasLog; - CasLog.Open(SlogPath, CasLogFile::Mode::kRead); + CasLog.Open(LogPath, CasLogFile::Mode::kRead); if (CasLog.Initialize()) { uint64_t EntryCount = CasLog.GetLogCount(); if (EntryCount < SkipEntryCount) { - ZEN_WARN("reading full log at '{}', reason: Log position from index snapshot is out of range", SlogPath); + ZEN_WARN("reading full log at '{}', reason: Log position from index snapshot is out of range", LogPath); SkipEntryCount = 0; } uint64_t ReadCount = EntryCount - SkipEntryCount; @@ -1072,7 +1072,7 @@ CasContainerStrategy::ReadLog(uint64_t SkipEntryCount) } if (!ValidateEntry(Record, InvalidEntryReason)) { - ZEN_WARN("skipping invalid entry in '{}', reason: '{}'", SlogPath, InvalidEntryReason); + ZEN_WARN("skipping invalid entry in '{}', reason: '{}'", LogPath, InvalidEntryReason); return; } m_LocationMap[Record.Key] = Record.Location; @@ -1096,9 +1096,8 @@ CasContainerStrategy::MigrateLegacyData(bool CleanSource) ZEN_INFO("migrating store '{}'", m_Config.RootDirectory / m_ContainerBaseName); - std::filesystem::path BlocksBasePath = GetBlocksBasePath(m_Config.RootDirectory, m_ContainerBaseName); - std::filesystem::path LegacySobsPath = GetLegacyUcasPath(m_Config.RootDirectory, m_ContainerBaseName); - std::filesystem::path LegacySidxPath = GetLegacyUidxPath(m_Config.RootDirectory, m_ContainerBaseName); + std::filesystem::path LegacyDataPath = GetLegacyDataPath(m_Config.RootDirectory, m_ContainerBaseName); + std::filesystem::path LegacyIndexPath = GetLegacyIndexPath(m_Config.RootDirectory, m_ContainerBaseName); uint64_t MigratedChunkCount = 0; uint32_t MigratedBlockCount = 0; @@ -1114,7 +1113,7 @@ CasContainerStrategy::MigrateLegacyData(bool CleanSource) }); uint32_t WriteBlockIndex = 0; - while (std::filesystem::exists(GetBlockPath(BlocksBasePath, WriteBlockIndex))) + while (std::filesystem::exists(GetBlockPath(m_BlocksBasePath, WriteBlockIndex))) { ++WriteBlockIndex; } @@ -1137,7 +1136,7 @@ CasContainerStrategy::MigrateLegacyData(bool CleanSource) } BasicFile BlockFile; - BlockFile.Open(LegacySobsPath, CleanSource ? BasicFile::Mode::kWrite : BasicFile::Mode::kRead); + BlockFile.Open(LegacyDataPath, CleanSource ? BasicFile::Mode::kWrite : BasicFile::Mode::kRead); std::unordered_map<IoHash, LegacyCasDiskIndexEntry, IoHash::Hasher> LegacyDiskIndex; uint64_t InvalidEntryCount = 0; @@ -1212,9 +1211,9 @@ CasContainerStrategy::MigrateLegacyData(bool CleanSource) BasicFile LegacyLog; LegacyLog.Open(LegacyLogPath, BasicFile::Mode::kTruncate); BasicFile LegacySobs; - LegacySobs.Open(LegacySobsPath, BasicFile::Mode::kTruncate); + LegacySobs.Open(LegacyDataPath, BasicFile::Mode::kTruncate); BasicFile LegacySidx; - LegacySidx.Open(LegacySidxPath, BasicFile::Mode::kTruncate); + LegacySidx.Open(LegacyIndexPath, BasicFile::Mode::kTruncate); } return 0; } @@ -1261,10 +1260,10 @@ CasContainerStrategy::MigrateLegacyData(bool CleanSource) } } - std::filesystem::path SlogPath = GetLogPath(m_Config.RootDirectory, m_ContainerBaseName); - CreateDirectories(SlogPath.parent_path()); + std::filesystem::path LogPath = GetLogPath(m_Config.RootDirectory, m_ContainerBaseName); + CreateDirectories(LogPath.parent_path()); TCasLogFile<CasDiskIndexEntry> CasLog; - CasLog.Open(SlogPath, CasLogFile::Mode::kWrite); + CasLog.Open(LogPath, CasLogFile::Mode::kWrite); if (CleanSource && (MaxRequiredBlockCount < 2)) { @@ -1281,10 +1280,10 @@ CasContainerStrategy::MigrateLegacyData(bool CleanSource) LogEntries.push_back( {.Key = Entry.second.Key, .Location = NewLocation, .ContentType = Record.ContentType, .Flags = Record.Flags}); } - std::filesystem::path BlockPath = GetBlockPath(BlocksBasePath, WriteBlockIndex); + std::filesystem::path BlockPath = GetBlockPath(m_BlocksBasePath, WriteBlockIndex); CreateDirectories(BlockPath.parent_path()); BlockFile.Close(); - std::filesystem::rename(LegacySobsPath, BlockPath); + std::filesystem::rename(LegacyDataPath, BlockPath); CasLog.Append(LogEntries); for (const CasDiskIndexEntry& Entry : LogEntries) { @@ -1343,7 +1342,7 @@ CasContainerStrategy::MigrateLegacyData(bool CleanSource) BlockRanges.push_back(BlockRange); WriteBlockIndex++; - while (std::filesystem::exists(GetBlockPath(BlocksBasePath, WriteBlockIndex))) + while (std::filesystem::exists(GetBlockPath(m_BlocksBasePath, WriteBlockIndex))) { ++WriteBlockIndex; } @@ -1382,7 +1381,7 @@ CasContainerStrategy::MigrateLegacyData(bool CleanSource) NiceTimeSpanMs(ETA)); } - std::filesystem::path BlockPath = GetBlockPath(BlocksBasePath, BlockRange.BlockIndex); + std::filesystem::path BlockPath = GetBlockPath(m_BlocksBasePath, BlockRange.BlockIndex); BlockStoreFile ChunkBlock(BlockPath); ChunkBlock.Create(BlockRange.BlockSize); uint64_t Offset = 0; @@ -1445,9 +1444,9 @@ CasContainerStrategy::MigrateLegacyData(bool CleanSource) BasicFile LegacyLog; LegacyLog.Open(LegacyLogPath, BasicFile::Mode::kTruncate); BasicFile LegacySobs; - LegacySobs.Open(LegacySobsPath, BasicFile::Mode::kTruncate); + LegacySobs.Open(LegacyDataPath, BasicFile::Mode::kTruncate); BasicFile LegacySidx; - LegacySidx.Open(LegacySidxPath, BasicFile::Mode::kTruncate); + LegacySidx.Open(LegacyIndexPath, BasicFile::Mode::kTruncate); } return MigratedChunkCount; } @@ -1464,11 +1463,11 @@ CasContainerStrategy::OpenContainer(bool IsNewStore) if (IsNewStore) { - std::filesystem::path LegacySobsPath = GetLegacyUcasPath(m_Config.RootDirectory, m_ContainerBaseName); + std::filesystem::path LegacyDataPath = GetLegacyDataPath(m_Config.RootDirectory, m_ContainerBaseName); std::filesystem::path LegacyLogPath = GetLegacyLogPath(m_Config.RootDirectory, m_ContainerBaseName); std::filesystem::remove(LegacyLogPath); - std::filesystem::remove(LegacySobsPath); + std::filesystem::remove(LegacyDataPath); std::filesystem::remove_all(BasePath); } @@ -1478,8 +1477,8 @@ CasContainerStrategy::OpenContainer(bool IsNewStore) CreateDirectories(BasePath); - std::filesystem::path SlogPath = GetLogPath(m_Config.RootDirectory, m_ContainerBaseName); - m_CasLog.Open(SlogPath, CasLogFile::Mode::kWrite); + std::filesystem::path LogPath = GetLogPath(m_Config.RootDirectory, m_ContainerBaseName); + m_CasLog.Open(LogPath, CasLogFile::Mode::kWrite); std::unordered_set<uint32_t> KnownBlocks; for (const auto& Entry : m_LocationMap) @@ -2196,16 +2195,16 @@ TEST_CASE("compactcas.legacyconversion") Gc.CollectGarbage(GcCtx); } - std::filesystem::path CasPath = GetBlockPath(GetBlocksBasePath(CasConfig.RootDirectory, "test"), 1); - std::filesystem::path LegacyCasPath = GetLegacyUcasPath(CasConfig.RootDirectory, "test"); - std::filesystem::rename(CasPath, LegacyCasPath); + std::filesystem::path BlockPath = GetBlockPath(GetBlocksBasePath(CasConfig.RootDirectory, "test"), 1); + std::filesystem::path LegacyDataPath = GetLegacyDataPath(CasConfig.RootDirectory, "test"); + std::filesystem::rename(BlockPath, LegacyDataPath); std::vector<CasDiskIndexEntry> LogEntries; - std::filesystem::path SidxPath = GetIndexPath(CasConfig.RootDirectory, "test"); - if (std::filesystem::is_regular_file(SidxPath)) + std::filesystem::path IndexPath = GetIndexPath(CasConfig.RootDirectory, "test"); + if (std::filesystem::is_regular_file(IndexPath)) { BasicFile ObjectIndexFile; - ObjectIndexFile.Open(SidxPath, BasicFile::Mode::kRead); + ObjectIndexFile.Open(IndexPath, BasicFile::Mode::kRead); uint64_t Size = ObjectIndexFile.FileSize(); if (Size >= sizeof(CasDiskIndexHeader)) { @@ -2220,19 +2219,19 @@ TEST_CASE("compactcas.legacyconversion") } } ObjectIndexFile.Close(); - std::filesystem::remove(SidxPath); + std::filesystem::remove(IndexPath); } - std::filesystem::path SlogPath = GetLogPath(CasConfig.RootDirectory, "test"); + std::filesystem::path LogPath = GetLogPath(CasConfig.RootDirectory, "test"); { TCasLogFile<CasDiskIndexEntry> CasLog; - CasLog.Open(SlogPath, CasLogFile::Mode::kRead); + CasLog.Open(LogPath, CasLogFile::Mode::kRead); LogEntries.reserve(CasLog.GetLogCount()); CasLog.Replay([&](const CasDiskIndexEntry& Record) { LogEntries.push_back(Record); }, 0); } TCasLogFile<LegacyCasDiskIndexEntry> LegacyCasLog; - std::filesystem::path SLegacylogPath = GetLegacyLogPath(CasConfig.RootDirectory, "test"); - LegacyCasLog.Open(SLegacylogPath, CasLogFile::Mode::kTruncate); + std::filesystem::path LegacylogPath = GetLegacyLogPath(CasConfig.RootDirectory, "test"); + LegacyCasLog.Open(LegacylogPath, CasLogFile::Mode::kTruncate); for (const CasDiskIndexEntry& Entry : LogEntries) { |