aboutsummaryrefslogtreecommitdiff
path: root/zenstore/compactcas.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-03-25 12:35:47 +0100
committerDan Engelbrecht <[email protected]>2022-03-31 11:29:28 +0200
commit2c8e66c5119a37216c968a3e3d2165b9062f1283 (patch)
tree1345930b5d904e0f6ace82863d9131abc6ce1647 /zenstore/compactcas.cpp
parentcaslog represents what's on disk, not memory state (diff)
downloadzen-2c8e66c5119a37216c968a3e3d2165b9062f1283.tar.xz
zen-2c8e66c5119a37216c968a3e3d2165b9062f1283.zip
clean up old zen cache by default
Diffstat (limited to 'zenstore/compactcas.cpp')
-rw-r--r--zenstore/compactcas.cpp38
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);