diff options
Diffstat (limited to 'zenstore')
| -rw-r--r-- | zenstore/compactcas.cpp | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp index eb99dd3ba..244277330 100644 --- a/zenstore/compactcas.cpp +++ b/zenstore/compactcas.cpp @@ -127,6 +127,11 @@ namespace { return RootPath / (ContainerBaseName + DataExtension); } + std::filesystem::path GetLegacyUidxPath(const std::filesystem::path& RootPath, const std::string& ContainerBaseName) + { + return RootPath / (ContainerBaseName + IndexExtension); + } + struct LegacyCasDiskLocation { LegacyCasDiskLocation(uint64_t InOffset, uint64_t InSize) @@ -230,19 +235,23 @@ namespace { std::filesystem::path BlocksBasePath = GetBlocksBasePath(RootPath, ContainerBaseName); std::filesystem::path LegacyLogPath = GetLegacyLogPath(RootPath, ContainerBaseName); std::filesystem::path LegacySobsPath = GetLegacyUcasPath(RootPath, ContainerBaseName); + std::filesystem::path LegacySidxPath = GetLegacyUidxPath(RootPath, ContainerBaseName); if (!std::filesystem::is_regular_file(LegacyLogPath) || !std::filesystem::is_regular_file(LegacySobsPath)) { ZEN_DEBUG("migrate of {} SKIPPED, no legacy data found", RootPath / ContainerBaseName); return 0; } - uint32_t NewBlockIndex = 0; + uint64_t MigratedChunkCount = 0; + uint32_t MigratedBlockCount = 0; + uint32_t NewBlockIndex = 0; Stopwatch MigrationTimer; uint64_t TotalSize = 0; - const auto Guard = MakeGuard([RootPath, ContainerBaseName, &MigrationTimer, &NewBlockIndex, &TotalSize] { - ZEN_INFO("migrated store {} to {} blocks in {} ({})", + const auto Guard = MakeGuard([RootPath, ContainerBaseName, &MigrationTimer, &MigratedChunkCount, &MigratedBlockCount, &TotalSize] { + ZEN_INFO("migrated store {} to {} chunks in {} blocks in {} ({})", RootPath / ContainerBaseName, - NewBlockIndex + 1, + MigratedChunkCount, + MigratedBlockCount, NiceTimeSpanMs(MigrationTimer.GetElapsedTimeMs()), NiceBytes(TotalSize)); }); @@ -298,6 +307,14 @@ namespace { if (LegacyDiskIndex.empty()) { + LegacyCasLog.Close(); + if (CleanSource) + { + std::filesystem::remove(LegacyLogPath); + BlockFile.Close(); + std::filesystem::remove(LegacySobsPath); + std::filesystem::remove(LegacySidxPath); + } return 0; } @@ -354,8 +371,6 @@ namespace { TCasLogFile<CasDiskIndexEntry> CasLog; CasLog.Open(SlogPath, CasLogFile::EMode::kWrite); - uint64_t MovedCount = 0; - if (CleanSource && (MaxRequiredBlockCount < 2)) { std::vector<CasDiskIndexEntry> LogEntries; @@ -377,7 +392,8 @@ namespace { BlockFile.Close(); std::filesystem::rename(LegacySobsPath, BlockPath); CasLog.Append(LogEntries); - MovedCount = LogEntries.size(); + MigratedChunkCount = LogEntries.size(); + MigratedBlockCount++; } else { @@ -486,7 +502,8 @@ namespace { InOutLocationMap[Entry.first] = Location; } CasLog.Append(LogEntries); - MovedCount += LogEntries.size(); + MigratedChunkCount += LogEntries.size(); + MigratedBlockCount++; if (CleanSource) { @@ -509,8 +526,9 @@ namespace { std::filesystem::remove(LegacyLogPath); BlockFile.Close(); std::filesystem::remove(LegacySobsPath); + std::filesystem::remove(LegacySidxPath); } - return MovedCount; + return MigratedChunkCount; } } // namespace @@ -1302,7 +1320,7 @@ CasContainerStrategy::OpenContainer(bool IsNewStore) bool AddedFromCasLog = ReadIndex(m_Config.RootDirectory, m_ContainerBaseName, m_PayloadAlignment, m_LocationMap); - MigrateLegacyData(m_Config.RootDirectory, m_ContainerBaseName, m_MaxBlockSize, m_PayloadAlignment, false, m_LocationMap); + MigrateLegacyData(m_Config.RootDirectory, m_ContainerBaseName, m_MaxBlockSize, m_PayloadAlignment, true, m_LocationMap); CreateDirectories(BasePath); |