aboutsummaryrefslogtreecommitdiff
path: root/zenserver/cache/structuredcachestore.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-11-03 22:05:29 +0100
committerStefan Boberg <[email protected]>2021-11-03 22:05:29 +0100
commit924169d85b2af36a95e1844140dd01573cfb113e (patch)
treedce6ab5e25ab41cbaf434553ebd0c4f2d6f920d6 /zenserver/cache/structuredcachestore.cpp
parentfixed tests for new msvc compiler warnings (diff)
downloadzen-924169d85b2af36a95e1844140dd01573cfb113e.tar.xz
zen-924169d85b2af36a95e1844140dd01573cfb113e.zip
z$: basic access tracking
Diffstat (limited to 'zenserver/cache/structuredcachestore.cpp')
-rw-r--r--zenserver/cache/structuredcachestore.cpp36
1 files changed, 23 insertions, 13 deletions
diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp
index 1b6c30cbd..ac9f628d3 100644
--- a/zenserver/cache/structuredcachestore.cpp
+++ b/zenserver/cache/structuredcachestore.cpp
@@ -2,22 +2,24 @@
#include "structuredcachestore.h"
-#include <zencore/except.h>
-#include <zencore/windows.h>
+#include "cachetracking.h"
#include <zencore/compactbinary.h>
#include <zencore/compactbinarybuilder.h>
#include <zencore/compactbinarypackage.h>
#include <zencore/compactbinaryvalidation.h>
#include <zencore/compress.h>
+#include <zencore/except.h>
#include <zencore/filesystem.h>
#include <zencore/fmtutils.h>
#include <zencore/iobuffer.h>
#include <zencore/logging.h>
+#include <zencore/scopeguard.h>
#include <zencore/string.h>
#include <zencore/testing.h>
#include <zencore/testutils.h>
#include <zencore/thread.h>
+#include <zencore/windows.h>
#include <zenstore/basicfile.h>
#include <zenstore/cas.h>
#include <zenstore/caslog.h>
@@ -41,12 +43,14 @@ namespace zen {
using namespace fmt::literals;
-ZenCacheStore::ZenCacheStore(CasGc& Gc, const std::filesystem::path& RootDir) : GcContributor(Gc), m_DiskLayer{RootDir}
+ZenCacheStore::ZenCacheStore(CasGc& Gc, const std::filesystem::path& RootDir) : GcContributor(Gc), m_DiskLayer(RootDir)
{
ZEN_INFO("initializing structured cache at '{}'", RootDir);
CreateDirectories(RootDir);
m_DiskLayer.DiscoverBuckets();
+
+ m_AccessTracker.reset(new ZenCacheTracker(RootDir));
}
ZenCacheStore::~ZenCacheStore()
@@ -58,21 +62,27 @@ ZenCacheStore::Get(std::string_view InBucket, const IoHash& HashKey, ZenCacheVal
{
bool Ok = m_MemLayer.Get(InBucket, HashKey, OutValue);
+ auto _ = MakeGuard([&] {
+ if (!Ok)
+ return;
+
+ m_AccessTracker->TrackAccess(InBucket, HashKey);
+ });
+
if (Ok)
{
ZEN_ASSERT(OutValue.Value.Size());
+
+ return true;
}
- if (!Ok)
- {
- Ok = m_DiskLayer.Get(InBucket, HashKey, OutValue);
+ Ok = m_DiskLayer.Get(InBucket, HashKey, OutValue);
- if (Ok)
- {
- ZEN_ASSERT(OutValue.Value.Size());
- }
+ if (Ok)
+ {
+ ZEN_ASSERT(OutValue.Value.Size());
- if (Ok && (OutValue.Value.Size() <= m_DiskLayerSizeThreshold))
+ if (OutValue.Value.Size() <= m_DiskLayerSizeThreshold)
{
m_MemLayer.Put(InBucket, HashKey, OutValue);
}
@@ -528,7 +538,7 @@ ZenCacheDiskLayer::CacheBucket::OpenOrCreate(std::filesystem::path BucketDir, bo
m_SlogFile.Open(SlogPath, IsNew);
- uint64_t MaxFileOffset = 0;
+ uint64_t MaxFileOffset = 0;
uint64_t InvalidEntryCount = 0;
if (RwLock::ExclusiveLockScope _(m_IndexLock); m_Index.empty())
@@ -1011,7 +1021,7 @@ ZenCacheDiskLayer::DiscoverBuckets()
{
// New bucket needs to be created
- const std::string BucketName8 = ToUtf8(BucketName);
+ const std::string BucketName8 = ToUtf8(BucketName);
if (auto It = m_Buckets.find(BucketName8); It != m_Buckets.end())
{