aboutsummaryrefslogtreecommitdiff
path: root/src/zenstore/compactcas.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zenstore/compactcas.cpp')
-rw-r--r--src/zenstore/compactcas.cpp58
1 files changed, 30 insertions, 28 deletions
diff --git a/src/zenstore/compactcas.cpp b/src/zenstore/compactcas.cpp
index f85b19264..50af7246e 100644
--- a/src/zenstore/compactcas.cpp
+++ b/src/zenstore/compactcas.cpp
@@ -65,7 +65,7 @@ struct CasDiskIndexHeader
static_assert(sizeof(CasDiskIndexHeader) == 32);
-namespace {
+namespace cas::impl {
const char* IndexExtension = ".uidx";
const char* LogExtension = ".ulog";
@@ -124,17 +124,17 @@ namespace {
return true;
}
-} // namespace
+} // namespace cas::impl
//////////////////////////////////////////////////////////////////////////
-static const float IndexMinLoadFactor = 0.2f;
-static const float IndexMaxLoadFactor = 0.7f;
-
CasContainerStrategy::CasContainerStrategy(GcManager& Gc) : m_Log(logging::Get("containercas")), m_Gc(Gc)
{
ZEN_MEMSCOPE(GetCasContainerTag());
+ const float IndexMinLoadFactor = 0.2f;
+ const float IndexMaxLoadFactor = 0.7f;
+
m_LocationMap.min_load_factor(IndexMinLoadFactor);
m_LocationMap.max_load_factor(IndexMaxLoadFactor);
@@ -165,7 +165,7 @@ CasContainerStrategy::Initialize(const std::filesystem::path& RootDirectory,
m_ContainerBaseName = ContainerBaseName;
m_PayloadAlignment = Alignment;
m_MaxBlockSize = MaxBlockSize;
- m_BlocksBasePath = GetBlocksBasePath(m_RootDirectory, m_ContainerBaseName);
+ m_BlocksBasePath = cas::impl::GetBlocksBasePath(m_RootDirectory, m_ContainerBaseName);
OpenContainer(IsNewStore);
@@ -329,31 +329,33 @@ CasContainerStrategy::IterateChunks(std::span<IoHash> ChunkHashes,
{
ZEN_MEMSCOPE(GetCasContainerTag());
- const size_t ChunkCount = ChunkHashes.size();
- if (ChunkCount < 3)
+ const size_t ChunkCount = ChunkHashes.size();
+ std::vector<size_t> FoundChunkIndexes;
+ std::vector<BlockStoreLocation> FoundChunkLocations;
+ FoundChunkIndexes.reserve(ChunkCount);
+ FoundChunkLocations.reserve(ChunkCount);
{
+ RwLock::SharedLockScope _(m_LocationMapLock);
for (size_t ChunkIndex = 0; ChunkIndex < ChunkCount; ChunkIndex++)
{
- IoBuffer Chunk = FindChunk(ChunkHashes[ChunkIndex]);
- if (!AsyncCallback(ChunkIndex, Chunk))
+ if (auto KeyIt = m_LocationMap.find(ChunkHashes[ChunkIndex]); KeyIt != m_LocationMap.end())
{
- return false;
+ FoundChunkIndexes.push_back(ChunkIndex);
+ FoundChunkLocations.push_back(m_Locations[KeyIt->second].Get(m_PayloadAlignment));
}
}
- return true;
}
- std::vector<size_t> FoundChunkIndexes;
- std::vector<BlockStoreLocation> FoundChunkLocations;
- FoundChunkIndexes.reserve(ChunkCount);
- FoundChunkLocations.reserve(ChunkCount);
- RwLock::SharedLockScope _(m_LocationMapLock);
- for (size_t ChunkIndex = 0; ChunkIndex < ChunkCount; ChunkIndex++)
+ if (FoundChunkLocations.size() < 3)
{
- if (auto KeyIt = m_LocationMap.find(ChunkHashes[ChunkIndex]); KeyIt != m_LocationMap.end())
+ for (size_t ChunkIndex : FoundChunkIndexes)
{
- FoundChunkIndexes.push_back(ChunkIndex);
- FoundChunkLocations.push_back(m_Locations[KeyIt->second].Get(m_PayloadAlignment));
+ IoBuffer Chunk = m_BlockStore.TryGetChunk(FoundChunkLocations[ChunkIndex]);
+ if (!AsyncCallback(ChunkIndex, Chunk))
+ {
+ return false;
+ }
}
+ return true;
}
auto DoOneBlock = [&](std::span<const size_t> ChunkIndexes) {
@@ -919,8 +921,8 @@ CasContainerStrategy::MakeIndexSnapshot()
namespace fs = std::filesystem;
- fs::path IndexPath = GetIndexPath(m_RootDirectory, m_ContainerBaseName);
- fs::path TempIndexPath = GetTempIndexPath(m_RootDirectory, m_ContainerBaseName);
+ fs::path IndexPath = cas::impl::GetIndexPath(m_RootDirectory, m_ContainerBaseName);
+ fs::path TempIndexPath = cas::impl::GetTempIndexPath(m_RootDirectory, m_ContainerBaseName);
// Move index away, we keep it if something goes wrong
if (fs::is_regular_file(TempIndexPath))
@@ -1054,7 +1056,7 @@ CasContainerStrategy::ReadIndexFile(const std::filesystem::path& IndexPath, uint
std::string InvalidEntryReason;
for (const CasDiskIndexEntry& Entry : Entries)
{
- if (!ValidateEntry(Entry, InvalidEntryReason))
+ if (!cas::impl::ValidateEntry(Entry, InvalidEntryReason))
{
ZEN_WARN("skipping invalid entry in '{}', reason: '{}'", IndexPath, InvalidEntryReason);
continue;
@@ -1121,7 +1123,7 @@ CasContainerStrategy::ReadLog(const std::filesystem::path& LogPath, uint64_t Ski
m_LocationMap.erase(Record.Key);
return;
}
- if (!ValidateEntry(Record, InvalidEntryReason))
+ if (!cas::impl::ValidateEntry(Record, InvalidEntryReason))
{
ZEN_WARN("skipping invalid entry in '{}', reason: '{}'", LogPath, InvalidEntryReason);
return;
@@ -1147,7 +1149,7 @@ CasContainerStrategy::OpenContainer(bool IsNewStore)
m_LocationMap.clear();
m_Locations.clear();
- std::filesystem::path BasePath = GetBasePath(m_RootDirectory, m_ContainerBaseName);
+ std::filesystem::path BasePath = cas::impl::GetBasePath(m_RootDirectory, m_ContainerBaseName);
if (IsNewStore)
{
@@ -1158,8 +1160,8 @@ CasContainerStrategy::OpenContainer(bool IsNewStore)
m_BlockStore.Initialize(m_BlocksBasePath, m_MaxBlockSize, BlockStoreDiskLocation::MaxBlockIndex + 1);
- std::filesystem::path LogPath = GetLogPath(m_RootDirectory, m_ContainerBaseName);
- std::filesystem::path IndexPath = GetIndexPath(m_RootDirectory, m_ContainerBaseName);
+ std::filesystem::path LogPath = cas::impl::GetLogPath(m_RootDirectory, m_ContainerBaseName);
+ std::filesystem::path IndexPath = cas::impl::GetIndexPath(m_RootDirectory, m_ContainerBaseName);
if (std::filesystem::is_regular_file(IndexPath))
{