aboutsummaryrefslogtreecommitdiff
path: root/zenserver/cache/structuredcachestore.cpp
diff options
context:
space:
mode:
authorPer Larsson <[email protected]>2022-01-03 13:18:12 +0100
committerPer Larsson <[email protected]>2022-01-03 13:18:12 +0100
commit44dcfa3326d5fa143299f90171c3cd51b440b741 (patch)
tree510405a86e23291db53ba0f9dc57477a350a16f1 /zenserver/cache/structuredcachestore.cpp
parentRun tests via xmake instead of executing target. (diff)
downloadzen-44dcfa3326d5fa143299f90171c3cd51b440b741.tar.xz
zen-44dcfa3326d5fa143299f90171c3cd51b440b741.zip
Changed timestamp to atomic int64.
Diffstat (limited to 'zenserver/cache/structuredcachestore.cpp')
-rw-r--r--zenserver/cache/structuredcachestore.cpp41
1 files changed, 19 insertions, 22 deletions
diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp
index a1a30e4af..e74becb3a 100644
--- a/zenserver/cache/structuredcachestore.cpp
+++ b/zenserver/cache/structuredcachestore.cpp
@@ -333,11 +333,11 @@ ZenCacheMemoryLayer::TotalSize() const
void
ZenCacheMemoryLayer::CacheBucket::Scrub(ScrubContext& Ctx)
{
- RwLock::SharedLockScope _(m_bucketLock);
+ RwLock::SharedLockScope _(m_BucketLock);
std::vector<IoHash> BadHashes;
- for (auto& Kv : m_cacheMap)
+ for (auto& Kv : m_CacheMap)
{
if (Kv.first != IoHash::HashBuffer(Kv.second.Payload))
{
@@ -354,8 +354,8 @@ ZenCacheMemoryLayer::CacheBucket::Scrub(ScrubContext& Ctx)
void
ZenCacheMemoryLayer::CacheBucket::GatherAccessTimes(std::vector<zen::access_tracking::KeyAccessTime>& AccessTimes)
{
- RwLock::SharedLockScope _(m_bucketLock);
- std::transform(m_cacheMap.begin(), m_cacheMap.end(), std::back_inserter(AccessTimes), [](const auto& Kv) {
+ RwLock::SharedLockScope _(m_BucketLock);
+ std::transform(m_CacheMap.begin(), m_CacheMap.end(), std::back_inserter(AccessTimes), [](const auto& Kv) {
return access_tracking::KeyAccessTime{.Key = Kv.first, .LastAccess = Kv.second.LastAccess};
});
}
@@ -363,28 +363,27 @@ ZenCacheMemoryLayer::CacheBucket::GatherAccessTimes(std::vector<zen::access_trac
bool
ZenCacheMemoryLayer::CacheBucket::Get(const IoHash& HashKey, ZenCacheValue& OutValue)
{
- RwLock::SharedLockScope _(m_bucketLock);
+ RwLock::SharedLockScope _(m_BucketLock);
- if (auto bucketIt = m_cacheMap.find(HashKey); bucketIt == m_cacheMap.end())
+ if (auto It = m_CacheMap.find(HashKey); It != m_CacheMap.end())
{
- return false;
- }
- else
- {
- BucketValue& Value = bucketIt.value();
+ BucketValue& Value = It.value();
OutValue.Value = Value.Payload;
- Value.LastAccess = GcClock::TickCount();
+
+ Value.LastAccess.store(GcClock::TickCount(), std::memory_order_relaxed);
return true;
}
+
+ return false;
}
void
ZenCacheMemoryLayer::CacheBucket::Put(const IoHash& HashKey, const ZenCacheValue& Value)
{
{
- RwLock::ExclusiveLockScope _(m_bucketLock);
- m_cacheMap.insert_or_assign(HashKey, BucketValue{.LastAccess = GcClock::TickCount(), .Payload = Value.Value});
+ RwLock::ExclusiveLockScope _(m_BucketLock);
+ m_CacheMap.insert_or_assign(HashKey, BucketValue(Value.Value, GcClock::TickCount()));
}
m_TotalSize.fetch_add(Value.Value.GetSize(), std::memory_order::relaxed);
@@ -455,7 +454,7 @@ ZenCacheDiskLayer::CacheBucket::OpenOrCreate(std::filesystem::path BucketDir, bo
if (auto It = m_Index.find(Key); It != m_Index.end())
{
- It.value().LastAccess = Obj["LastAccess"sv].AsInt64();
+ It.value().LastAccess.store(Obj["LastAccess"sv].AsInt64(), std::memory_order_relaxed);
}
}
@@ -491,7 +490,7 @@ ZenCacheDiskLayer::CacheBucket::OpenLog(const fs::path& BucketDir, const bool Is
}
else
{
- m_Index[Entry.Key] = {.Location = Entry.Location, .LastAccess = GcClock::TickCount()};
+ m_Index.insert_or_assign(Entry.Key, IndexEntry(Entry.Location, GcClock::TickCount()));
m_TotalSize.fetch_add(Entry.Location.Size(), std::memory_order::relaxed);
}
MaxFileOffset = std::max<uint64_t>(MaxFileOffset, Entry.Location.Offset() + Entry.Location.Size());
@@ -583,9 +582,7 @@ ZenCacheDiskLayer::CacheBucket::Get(const IoHash& HashKey, ZenCacheValue& OutVal
if (auto It = m_Index.find(HashKey); It != m_Index.end())
{
IndexEntry& Entry = It.value();
- Entry.LastAccess = GcClock::TickCount();
- {
- }
+ Entry.LastAccess.store(GcClock::TickCount(), std::memory_order_relaxed);
if (GetInlineCacheValue(Entry.Location, OutValue))
{
@@ -641,7 +638,7 @@ ZenCacheDiskLayer::CacheBucket::Put(const IoHash& HashKey, const ZenCacheValue&
// content hash to the index entry
IndexEntry& Entry = It.value();
Entry.Location = Loc;
- Entry.LastAccess = GcClock::TickCount();
+ Entry.LastAccess.store(GcClock::TickCount(), std::memory_order_relaxed);
}
m_SlogFile.Append({.Key = HashKey, .Location = Loc});
@@ -1023,7 +1020,7 @@ ZenCacheDiskLayer::CacheBucket::UpdateAccessTimes(const std::vector<zen::access_
if (auto It = m_Index.find(KeyTime.Key); It != m_Index.end())
{
IndexEntry& Entry = It.value();
- Entry.LastAccess = KeyTime.LastAccess;
+ Entry.LastAccess.store(KeyTime.LastAccess, std::memory_order_relaxed);
}
}
}
@@ -1132,7 +1129,7 @@ ZenCacheDiskLayer::CacheBucket::PutStandaloneCacheValue(const IoHash& HashKey, c
RwLock::ExclusiveLockScope _(m_IndexLock);
DiskLocation Loc(/* Offset */ 0, Value.Value.Size(), 0, EntryFlags);
- IndexEntry Entry = IndexEntry{.Location = Loc, .LastAccess = GcClock::TickCount()};
+ IndexEntry Entry = IndexEntry(Loc, GcClock::TickCount());
if (auto It = m_Index.find(HashKey); It == m_Index.end())
{