aboutsummaryrefslogtreecommitdiff
path: root/zenstore/compactcas.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-04-01 10:41:21 +0200
committerDan Engelbrecht <[email protected]>2022-04-01 10:41:21 +0200
commit4585da99f7b763468a3eb6b8393a696670086d48 (patch)
treec0f89c5e0ae657e169f77d2c5147cb9a2919c232 /zenstore/compactcas.cpp
parentmove chunk location validation to ValidateLegacyEntry (diff)
downloadzen-4585da99f7b763468a3eb6b8393a696670086d48.tar.xz
zen-4585da99f7b763468a3eb6b8393a696670086d48.zip
cleanup
Diffstat (limited to 'zenstore/compactcas.cpp')
-rw-r--r--zenstore/compactcas.cpp77
1 files changed, 44 insertions, 33 deletions
diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp
index 51060ca94..3569b034b 100644
--- a/zenstore/compactcas.cpp
+++ b/zenstore/compactcas.cpp
@@ -108,7 +108,7 @@ namespace {
Path.AppendAsciiRange(BlockHexString, BlockHexString + 4);
Path.AppendSeparator();
Path.Append(BlockHexString);
- Path.Append(".ucas");
+ Path.Append(DataExtension);
return Path.ToPath();
}
@@ -395,13 +395,21 @@ namespace {
if (LegacyDiskIndex.empty())
{
+ BlockFile.Close();
LegacyCasLog.Close();
if (CleanSource)
{
- std::filesystem::remove(LegacyLogPath);
- BlockFile.Close();
- std::filesystem::remove(LegacySobsPath);
- std::filesystem::remove(LegacySidxPath);
+ // Older versions of CasContainerStrategy expects the legacy files to exist if it can find
+ // a CAS manifest and crashes on startup if they don't.
+ // In order to not break startup when switching back an older version, lets just reset
+ // the legacy data files to zero length.
+
+ BasicFile LegacyLog;
+ LegacyLog.Open(LegacyLogPath, BasicFile::EMode::kTruncate);
+ BasicFile LegacySobs;
+ LegacySobs.Open(LegacySobsPath, BasicFile::EMode::kTruncate);
+ BasicFile LegacySidx;
+ LegacySidx.Open(LegacySidxPath, BasicFile::EMode::kTruncate);
}
return Result;
}
@@ -423,26 +431,28 @@ namespace {
return Result;
}
+ constexpr const uint64_t DiskReserve = 1ul << 28;
+
if (CleanSource)
{
- if (Space.Free < (MaxBlockSize + (1 << 28)))
+ if (Space.Free < (MaxBlockSize + DiskReserve))
{
ZEN_INFO("legacy store migration from '{}' aborted, not enough disk space available {} ({})",
RootPath / ContainerBaseName,
NewBlockIndex + 1,
- NiceBytes(MaxBlockSize + (1 << 28)),
+ NiceBytes(MaxBlockSize + DiskReserve),
NiceBytes(Space.Free));
return Result;
}
}
else
{
- if (Space.Free < (RequiredDiskSpace + (1 << 28)))
+ if (Space.Free < (RequiredDiskSpace + DiskReserve))
{
ZEN_INFO("legacy store migration from '{}' aborted, not enough disk space available {} ({})",
RootPath / ContainerBaseName,
NewBlockIndex + 1,
- NiceBytes(RequiredDiskSpace + (1 << 28)),
+ NiceBytes(RequiredDiskSpace + DiskReserve),
NiceBytes(Space.Free));
return Result;
}
@@ -619,6 +629,7 @@ namespace {
// a CAS manifest and crashes on startup if they don't.
// In order to not break startup when switching back an older version, lets just reset
// the legacy data files to zero length.
+
BasicFile LegacyLog;
LegacyLog.Open(LegacyLogPath, BasicFile::EMode::kTruncate);
BasicFile LegacySobs;
@@ -692,7 +703,7 @@ CasContainerStrategy::InsertChunk(const void* ChunkData, size_t ChunkSize, const
RwLock::ExclusiveLockScope __(m_LocationMapLock);
if (m_ChunkBlocks.size() == BlockStoreDiskLocation::MaxBlockIndex)
{
- throw std::runtime_error(fmt::format("unable to allocate a new block in {}", m_ContainerBaseName));
+ throw std::runtime_error(fmt::format("unable to allocate a new block in '{}'", m_ContainerBaseName));
}
WriteBlockIndex += IsWriting ? 1 : 0;
while (m_ChunkBlocks.contains(WriteBlockIndex))
@@ -913,23 +924,6 @@ CasContainerStrategy::Scrub(ScrubContext& Ctx)
}
void
-CasContainerStrategy::UpdateLocations(const std::span<CasDiskIndexEntry>& Entries)
-{
- for (const CasDiskIndexEntry& Entry : Entries)
- {
- if (Entry.Flags & CasDiskIndexEntry::kTombstone)
- {
- auto KeyIt = m_LocationMap.find(Entry.Key);
- uint64_t ChunkSize = KeyIt->second.GetSize();
- m_TotalSize.fetch_sub(ChunkSize);
- m_LocationMap.erase(KeyIt);
- continue;
- }
- m_LocationMap[Entry.Key] = Entry.Location;
- }
-}
-
-void
CasContainerStrategy::CollectGarbage(GcContext& GcCtx)
{
// It collects all the blocks that we want to delete chunks from. For each such
@@ -1120,6 +1114,21 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx)
uint32_t NewBlockIndex = 0;
DeletedChunks.reserve(DeleteCount);
+ auto UpdateLocations = [this](const std::span<CasDiskIndexEntry>& Entries) {
+ for (const CasDiskIndexEntry& Entry : Entries)
+ {
+ if (Entry.Flags & CasDiskIndexEntry::kTombstone)
+ {
+ auto KeyIt = m_LocationMap.find(Entry.Key);
+ uint64_t ChunkSize = KeyIt->second.GetSize();
+ m_TotalSize.fetch_sub(ChunkSize);
+ m_LocationMap.erase(KeyIt);
+ continue;
+ }
+ m_LocationMap[Entry.Key] = Entry.Location;
+ }
+ };
+
std::unordered_map<IoHash, BlockStoreDiskLocation> MovedBlockChunks;
for (uint32_t BlockIndex : BlocksToReWrite)
{
@@ -1261,7 +1270,7 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx)
{
NewBlockFile->Truncate(WriteOffset);
NewBlockFile->Flush();
- NewBlockFile = Ref<BlockStoreFile>();
+ NewBlockFile = {};
}
const std::vector<IoHash>& DeleteMap = DeleteChunks[ChunkMapIndex];
@@ -1527,7 +1536,6 @@ CasContainerStrategy::OpenContainer(bool IsNewStore)
}
std::vector<CasDiskIndexEntry> LegacyEntries =
MigrateLegacyData(m_Config.RootDirectory, m_ContainerBaseName, m_MaxBlockSize, m_PayloadAlignment, true, ExistingChunks);
- std::string InvalidEntryReason;
for (const CasDiskIndexEntry& Entry : LegacyEntries)
{
m_LocationMap[Entry.Key] = Entry.Location;
@@ -1580,7 +1588,7 @@ CasContainerStrategy::OpenContainer(bool IsNewStore)
{
// Log removing unreferenced block
// Clear out unused blocks
- ZEN_INFO("removing unused block for '{}' at '{}'", m_Config.RootDirectory / m_ContainerBaseName, Path);
+ ZEN_INFO("removing unused block for '{}' at '{}'", BasePath, Path);
std::error_code Ec;
std::filesystem::remove(Path, Ec);
if (Ec)
@@ -1589,8 +1597,7 @@ CasContainerStrategy::OpenContainer(bool IsNewStore)
}
continue;
}
- std::filesystem::path BlockPath = GetBlockPath(m_BlocksBasePath, BlockIndex);
- Ref<BlockStoreFile> BlockFile = new BlockStoreFile(BlockPath);
+ Ref<BlockStoreFile> BlockFile = new BlockStoreFile(Path);
BlockFile->Open();
m_ChunkBlocks[BlockIndex] = BlockFile;
}
@@ -1598,6 +1605,10 @@ CasContainerStrategy::OpenContainer(bool IsNewStore)
++FolderOffset;
}
}
+ else
+ {
+ CreateDirectories(m_BlocksBasePath);
+ }
// Create GC reserve file if possible
std::filesystem::path GCReservePath = GetGCReservePath(m_Config.RootDirectory, m_ContainerBaseName);
@@ -1606,7 +1617,7 @@ CasContainerStrategy::OpenContainer(bool IsNewStore)
DiskSpace Space = DiskSpaceInfo(m_Config.RootDirectory, Error);
if (Error)
{
- ZEN_ERROR("get disk space in {} FAILED, reason '{}'", m_ContainerBaseName, Error.message());
+ ZEN_ERROR("get disk space in {} FAILED, reason '{}'", m_Config.RootDirectory, Error.message());
return;
}