diff options
| author | Stefan Boberg <[email protected]> | 2021-05-22 12:02:02 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-05-22 12:02:02 +0200 |
| commit | aa6a5516c9e885546d7b64d10b23b063b39d555d (patch) | |
| tree | e69896794f26f1c16e5cdd2b2548ff139870ad76 /zenserver/cache/structuredcachestore.cpp | |
| parent | Split out structured cache store code into dedicated cpp/h pair (diff) | |
| download | zen-aa6a5516c9e885546d7b64d10b23b063b39d555d.tar.xz zen-aa6a5516c9e885546d7b64d10b23b063b39d555d.zip | |
Tidied up some code
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; |