diff options
Diffstat (limited to 'zenserver/cache/structuredcachestore.cpp')
| -rw-r--r-- | zenserver/cache/structuredcachestore.cpp | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp index 3e0050fab..eb3b5d13d 100644 --- a/zenserver/cache/structuredcachestore.cpp +++ b/zenserver/cache/structuredcachestore.cpp @@ -217,7 +217,7 @@ ZenCacheDiskLayer::CacheBucket::~CacheBucket() void ZenCacheDiskLayer::CacheBucket::OpenOrCreate(std::filesystem::path BucketDir) { - std::filesystem::create_directories(BucketDir); + zen::CreateDirectories(BucketDir); m_BucketDir = BucketDir; @@ -250,7 +250,9 @@ ZenCacheDiskLayer::CacheBucket::OpenOrCreate(std::filesystem::path BucketDir) } if (!m_Ok) + { ManifestFile.Close(); + } } if (!m_Ok) @@ -313,7 +315,9 @@ bool ZenCacheDiskLayer::CacheBucket::Get(const zen::IoHash& HashKey, ZenCacheValue& OutValue) { if (!m_Ok) + { return false; + } { zen::RwLock::SharedLockScope _(m_IndexLock); @@ -360,27 +364,22 @@ ZenCacheDiskLayer::CacheBucket::Put(const zen::IoHash& HashKey, const ZenCacheVa zen::RwLock::ExclusiveLockScope _(m_IndexLock); - auto it = m_Index.find(HashKey); - DiskLocation Loc{.Offset = m_WriteCursor, .Size = gsl::narrow<uint32_t>(Value.Value.Size())}; - m_WriteCursor = (m_WriteCursor + Loc.Size + 15) & ~15; + m_WriteCursor = zen::RoundUp(m_WriteCursor + Loc.Size, 16); - if (it == m_Index.end()) + if (auto it = m_Index.find(HashKey); it == m_Index.end()) { + // Previously unknown object m_Index.insert({HashKey, Loc}); } else { // TODO: should check if write is idempotent and bail out if it is? - it->second = Loc; } - DiskIndexEntry IndexEntry{.Key = HashKey, .Location = Loc}; - - m_SlogFile.Append(IndexEntry); - + m_SlogFile.Append({.Key = HashKey, .Location = Loc}); m_SobsFile.Write(Value.Value.Data(), Loc.Size, Loc.Offset); return; |