diff options
| author | Dan Engelbrecht <[email protected]> | 2022-03-11 22:36:52 +0100 |
|---|---|---|
| committer | Dan Engelbrecht <[email protected]> | 2022-03-31 11:28:31 +0200 |
| commit | bec5873e4f5735b0767cf77e3d213d0e8fc25036 (patch) | |
| tree | e30e7117fd566da896d42387dbd3e3b36cd04ab3 /zenstore/compactcas.cpp | |
| parent | Simplified logic of last chunk move (diff) | |
| download | zen-bec5873e4f5735b0767cf77e3d213d0e8fc25036.tar.xz zen-bec5873e4f5735b0767cf77e3d213d0e8fc25036.zip | |
Rewrite smallobjectindex after gc
Diffstat (limited to 'zenstore/compactcas.cpp')
| -rw-r--r-- | zenstore/compactcas.cpp | 61 |
1 files changed, 37 insertions, 24 deletions
diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp index 806cea69f..7b68f0ebc 100644 --- a/zenstore/compactcas.cpp +++ b/zenstore/compactcas.cpp @@ -438,6 +438,35 @@ 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.Flush(); + 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... + uint64_t CurrentSize = m_SmallObjectFile.FileSize(); ZEN_INFO("garbage collection complete '{}', space {} to {}, moved {} and delete {} chunks", m_Config.RootDirectory / m_ContainerBaseName, @@ -450,24 +479,6 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx) } void -CasContainerStrategy::MakeSnapshot() -{ - RwLock::SharedLockScope _(m_LocationMapLock); - - 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; - } - - m_SmallObjectIndex.Write(Entries.data(), Entries.size() * sizeof(CasDiskIndexEntry), 0); -} - -void CasContainerStrategy::OpenContainer(bool IsNewStore) { std::filesystem::path SobsPath = m_Config.RootDirectory / (m_ContainerBaseName + ".ucas"); @@ -491,23 +502,25 @@ CasContainerStrategy::OpenContainer(bool IsNewStore) m_CasLog.Replay([&](const CasDiskIndexEntry& Record) { if (Record.Flags & CasDiskIndexEntry::kTombstone) { - m_TotalSize.fetch_sub(Record.Location.GetSize()); m_LocationMap.erase(Record.Key); } else { - m_TotalSize.fetch_add(Record.Location.GetSize()); m_LocationMap[Record.Key] = Record.Location; - MaxFileOffset = std::max<uint64_t>(MaxFileOffset, Record.Location.GetOffset() + Record.Location.GetSize()); } }); - // TODO: MaxFileOffset needs to be calculated when we have final m_LocationMap + std::vector<CasDiskIndexEntry> Entries{m_LocationMap.size()}; + for (const auto& Entry : m_LocationMap) + { + const auto& Location = Entry.second; + MaxFileOffset = std::max<uint64_t>(MaxFileOffset, Location.GetOffset() + Location.GetSize()); + m_TotalSize.fetch_add(Location.GetSize()); + } m_CurrentInsertOffset = (MaxFileOffset + m_PayloadAlignment - 1) & ~(m_PayloadAlignment - 1); - m_CurrentIndexOffset = m_SmallObjectIndex.FileSize(); - // TODO: Rewrite cal-log from m_LocationMap + m_CurrentIndexOffset = m_SmallObjectIndex.FileSize(); } void |