aboutsummaryrefslogtreecommitdiff
path: root/zenserver/cache/structuredcachestore.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-05-02 16:41:32 +0200
committerDan Engelbrecht <[email protected]>2022-05-02 16:41:32 +0200
commitbb7593c9ea3412a48b3d29f3e7f7b23d7a785b2f (patch)
tree133f4ada4cce17ca808ec65249aab7f2d2a83ae1 /zenserver/cache/structuredcachestore.cpp
parentMerge branch 'de/block-store-refactor' of github.com:EpicGames/zen into de/bl... (diff)
downloadzen-bb7593c9ea3412a48b3d29f3e7f7b23d7a785b2f.tar.xz
zen-bb7593c9ea3412a48b3d29f3e7f7b23d7a785b2f.zip
Refactor WriteChunk to not need callback
Diffstat (limited to 'zenserver/cache/structuredcachestore.cpp')
-rw-r--r--zenserver/cache/structuredcachestore.cpp46
1 files changed, 20 insertions, 26 deletions
diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp
index 015912ce9..6f6f182b9 100644
--- a/zenserver/cache/structuredcachestore.cpp
+++ b/zenserver/cache/structuredcachestore.cpp
@@ -860,7 +860,7 @@ ZenCacheDiskLayer::CacheBucket::MigrateLegacyData(bool CleanSource)
{
BasicFile BlockFile;
BlockFile.Open(LegacyDataPath, CleanSource ? BasicFile::Mode::kWrite : BasicFile::Mode::kRead);
- BlockFileSize = BlockFile.FileSize();strcut
+ BlockFileSize = BlockFile.FileSize();
}
std::unordered_map<IoHash, LegacyDiskIndexEntry, IoHash::Hasher> LegacyDiskIndex;
@@ -1845,31 +1845,25 @@ ZenCacheDiskLayer::CacheBucket::PutInlineCacheValue(const IoHash& HashKey, const
EntryFlags |= DiskLocation::kCompressed;
}
- uint64_t ChunkSize = Value.Value.Size();
-
- m_BlockStore.WriteChunk(Value.Value.Data(),
- ChunkSize,
- m_PayloadAlignment,
- [this, &HashKey, EntryFlags](const BlockStoreLocation& BlockStoreLocation) {
- DiskLocation Location(BlockStoreLocation, m_PayloadAlignment, EntryFlags);
- const DiskIndexEntry DiskIndexEntry{.Key = HashKey, .Location = Location};
- m_SlogFile.Append(DiskIndexEntry);
- m_TotalSize.fetch_add(BlockStoreLocation.Size, std::memory_order_seq_cst);
- RwLock::ExclusiveLockScope __(m_IndexLock);
- if (auto It = m_Index.find(HashKey); It != m_Index.end())
- {
- // TODO: should check if write is idempotent and bail out if it is?
- // this would requiring comparing contents on disk unless we add a
- // content hash to the index entry
- IndexEntry& Entry = It.value();
- Entry.Location = Location;
- Entry.LastAccess.store(GcClock::TickCount(), std::memory_order_relaxed);
- }
- else
- {
- m_Index.insert({HashKey, {Location, GcClock::TickCount()}});
- }
- });
+ BlockStoreLocation BlockStoreLocation = m_BlockStore.WriteChunk(Value.Value.Data(), Value.Value.Size(), m_PayloadAlignment);
+ DiskLocation Location(BlockStoreLocation, m_PayloadAlignment, EntryFlags);
+ const DiskIndexEntry DiskIndexEntry{.Key = HashKey, .Location = Location};
+ m_SlogFile.Append(DiskIndexEntry);
+ m_TotalSize.fetch_add(BlockStoreLocation.Size, std::memory_order_seq_cst);
+ RwLock::ExclusiveLockScope __(m_IndexLock);
+ if (auto It = m_Index.find(HashKey); It != m_Index.end())
+ {
+ // TODO: should check if write is idempotent and bail out if it is?
+ // this would requiring comparing contents on disk unless we add a
+ // content hash to the index entry
+ IndexEntry& Entry = It.value();
+ Entry.Location = Location;
+ Entry.LastAccess.store(GcClock::TickCount(), std::memory_order_relaxed);
+ }
+ else
+ {
+ m_Index.insert({HashKey, {Location, GcClock::TickCount()}});
+ }
}
//////////////////////////////////////////////////////////////////////////