aboutsummaryrefslogtreecommitdiff
path: root/zenstore/compactcas.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-03-11 22:58:04 +0100
committerDan Engelbrecht <[email protected]>2022-03-31 11:28:31 +0200
commit78e109d290b5b40b508af5c514c9e6546ce261c1 (patch)
tree12f16cd0aaa55bd23177e7a637b5338e3cc536ef /zenstore/compactcas.cpp
parentWe don't use the uidx file for anything, disable for now (diff)
downloadzen-78e109d290b5b40b508af5c514c9e6546ce261c1.tar.xz
zen-78e109d290b5b40b508af5c514c9e6546ce261c1.zip
Rewrite cas log on gc
Diffstat (limited to 'zenstore/compactcas.cpp')
-rw-r--r--zenstore/compactcas.cpp91
1 files changed, 55 insertions, 36 deletions
diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp
index 133784cb6..3d7eb695b 100644
--- a/zenstore/compactcas.cpp
+++ b/zenstore/compactcas.cpp
@@ -78,10 +78,10 @@ CasContainerStrategy::InsertChunk(const void* ChunkData, size_t ChunkSize, const
m_CurrentInsertOffset = (m_CurrentInsertOffset + ChunkSize + m_PayloadAlignment - 1) & ~(m_PayloadAlignment - 1);
const CasDiskLocation Location{InsertOffset, ChunkSize};
- CasDiskIndexEntry IndexEntry{.Key = ChunkHash, .Location = Location};
+ CasDiskIndexEntry IndexEntry{.Key = ChunkHash, .Location = Location};
-// m_SmallObjectIndex.Write(&IndexEntry, sizeof(CasDiskIndexEntry), m_CurrentIndexOffset);
-// m_CurrentIndexOffset += sizeof(CasDiskIndexEntry);
+ // m_SmallObjectIndex.Write(&IndexEntry, sizeof(CasDiskIndexEntry), m_CurrentIndexOffset);
+ // m_CurrentIndexOffset += sizeof(CasDiskIndexEntry);
RwLock::ExclusiveLockScope __(m_LocationMapLock);
m_LocationMap[ChunkHash] = Location;
@@ -144,7 +144,7 @@ void
CasContainerStrategy::Flush()
{
m_CasLog.Flush();
-// m_SmallObjectIndex.Flush();
+ // m_SmallObjectIndex.Flush();
m_SmallObjectFile.Flush();
}
@@ -312,7 +312,7 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx)
});
uint64_t NewTotalSize = 0;
- std::vector<CasDiskLocation> ChunkLocations; // Sorted by position
+ std::vector<CasDiskLocation> ChunkLocations;
ChunkLocations.reserve(ChunkHashes.size());
for (auto Entry : ChunkHashes)
{
@@ -347,6 +347,8 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx)
m_TotalSize.fetch_sub(static_cast<uint64_t>(ChunkLocation.GetSize()));
}
+ // We can break here if we only want to remove items without compacting of space
+
std::vector<IoHash> MovedChunks;
uint64_t WriteOffset{};
@@ -430,6 +432,8 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx)
m_CurrentInsertOffset = WriteOffset;
}
+ // We can break here if we want to do incremental GC
+
ChunkIndex++;
}
@@ -438,33 +442,48 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx)
m_CurrentInsertOffset = 0;
}
-// if (!MovedChunks.empty() || DeletedChunks.empty())
-// {
-// // Rewrite object index
-// std::filesystem::path SidxPath = m_Config.RootDirectory / (m_ContainerBaseName + ".uidx");
-// std::filesystem::path TmpSidxPath = m_Config.RootDirectory / (m_ContainerBaseName + ".gc.uidx");
-// BasicFile TmpSmallObjectIndex;
-// TmpSmallObjectIndex.Open(TmpSidxPath, true);
-//
-// std::vector<CasDiskIndexEntry> Entries{m_LocationMap.size()};
-// uint64_t EntryIndex = 0;
-// for (auto& Entry : m_LocationMap)
-// {
-// CasDiskIndexEntry& IndexEntry = Entries[EntryIndex++];
-// IndexEntry.Key = Entry.first;
-// IndexEntry.Location = Entry.second;
-// }
-//
-// TmpSmallObjectIndex.Write(Entries.data(), Entries.size() * sizeof(CasDiskIndexEntry), 0);
-// TmpSmallObjectIndex.Close();
-//
-// m_SmallObjectIndex.Close();
-// fs::remove(SidxPath);
-// fs::rename(TmpSidxPath, SidxPath);
-// m_SmallObjectIndex.Open(SidxPath, false);
-// }
-
- // TODO: Should we flush the cas log? It will grow forever...
+ if (!MovedChunks.empty() || DeletedChunks.empty())
+ {
+ // // Rewrite object index
+ // std::filesystem::path SidxPath = m_Config.RootDirectory / (m_ContainerBaseName + ".uidx");
+ // std::filesystem::path TmpSidxPath = m_Config.RootDirectory / (m_ContainerBaseName + ".gc.uidx");
+ // BasicFile TmpSmallObjectIndex;
+ // TmpSmallObjectIndex.Open(TmpSidxPath, true);
+ //
+ // std::vector<CasDiskIndexEntry> Entries{m_LocationMap.size()};
+ // uint64_t EntryIndex = 0;
+ // for (auto& Entry : m_LocationMap)
+ // {
+ // CasDiskIndexEntry& IndexEntry = Entries[EntryIndex++];
+ // IndexEntry.Key = Entry.first;
+ // IndexEntry.Location = Entry.second;
+ // }
+ //
+ // TmpSmallObjectIndex.Write(Entries.data(), Entries.size() * sizeof(CasDiskIndexEntry), 0);
+ // TmpSmallObjectIndex.Close();
+ //
+ // m_SmallObjectIndex.Close();
+ // fs::remove(SidxPath);
+ // fs::rename(TmpSidxPath, SidxPath);
+ // m_SmallObjectIndex.Open(SidxPath, false);
+
+ // Rewrite cas log
+ std::filesystem::path SlogPath = m_Config.RootDirectory / (m_ContainerBaseName + ".ulog");
+ std::filesystem::path TmpSlogPath = m_Config.RootDirectory / (m_ContainerBaseName + ".gc.ulog");
+ TCasLogFile<CasDiskIndexEntry> TmpCasLog;
+ TmpCasLog.Open(TmpSlogPath, true);
+
+ for (auto& Entry : m_LocationMap)
+ {
+ CasDiskIndexEntry IndexEntry{.Key = Entry.first, .Location = Entry.second};
+ TmpCasLog.Append(IndexEntry);
+ }
+ TmpCasLog.Close();
+ m_CasLog.Close();
+ fs::remove(SlogPath);
+ fs::rename(TmpSlogPath, SlogPath);
+ m_CasLog.Open(SlogPath, false);
+ }
uint64_t CurrentSize = m_SmallObjectFile.FileSize();
ZEN_INFO("garbage collection complete '{}', space {} to {}, moved {} and delete {} chunks",
@@ -485,14 +504,14 @@ CasContainerStrategy::OpenContainer(bool IsNewStore)
std::filesystem::path SlogPath = m_Config.RootDirectory / (m_ContainerBaseName + ".ulog");
m_SmallObjectFile.Open(SobsPath, IsNewStore);
-// m_SmallObjectIndex.Open(SidxPath, IsNewStore);
+ // m_SmallObjectIndex.Open(SidxPath, IsNewStore);
m_CasLog.Open(SlogPath, IsNewStore);
// TODO: should validate integrity of container files here
m_CurrentInsertOffset = 0;
-// m_CurrentIndexOffset = 0;
- m_TotalSize = 0;
+ // m_CurrentIndexOffset = 0;
+ m_TotalSize = 0;
m_LocationMap.clear();
@@ -518,7 +537,7 @@ CasContainerStrategy::OpenContainer(bool IsNewStore)
}
m_CurrentInsertOffset = (MaxFileOffset + m_PayloadAlignment - 1) & ~(m_PayloadAlignment - 1);
-// m_CurrentIndexOffset = m_SmallObjectIndex.FileSize();
+ // m_CurrentIndexOffset = m_SmallObjectIndex.FileSize();
}
//////////////////////////////////////////////////////////////////////////