diff options
Diffstat (limited to 'src/zenserver/cache/structuredcachestore.cpp')
| -rw-r--r-- | src/zenserver/cache/structuredcachestore.cpp | 65 |
1 files changed, 42 insertions, 23 deletions
diff --git a/src/zenserver/cache/structuredcachestore.cpp b/src/zenserver/cache/structuredcachestore.cpp index 1847c724d..f80670a17 100644 --- a/src/zenserver/cache/structuredcachestore.cpp +++ b/src/zenserver/cache/structuredcachestore.cpp @@ -15,6 +15,7 @@ #include <zencore/thread.h> #include <zencore/timer.h> #include <zencore/trace.h> +#include <zencore/workthreadpool.h> #include <zenstore/scrubcontext.h> #include <zenutil/cache/cache.h> @@ -223,7 +224,12 @@ ZenCacheStore::ZenCacheStore(GcManager& Gc, const Configuration& Configuration) : m_Log(logging::Get("z$")) , m_Gc(Gc) , m_Configuration(Configuration) +, m_PendingAsyncLogging(1) { + if (m_Configuration.EnableAccessLog || m_Configuration.EnableWriteLog) + { + m_AsyncLogging = std::make_unique<WorkerThreadPool>(1, "cache_async_log"); + } CreateDirectories(m_Configuration.BasePath); ZEN_INFO("Initializing at '{}'", m_Configuration.BasePath); @@ -263,6 +269,9 @@ ZenCacheStore::ZenCacheStore(GcManager& Gc, const Configuration& Configuration) ZenCacheStore::~ZenCacheStore() { + m_PendingAsyncLogging.CountDown(); + m_PendingAsyncLogging.Wait(); + m_AsyncLogging.reset(); m_Namespaces.clear(); } @@ -283,18 +292,23 @@ ZenCacheStore::Get(const CacheRequestContext& Context, { if (OutValue.Value.GetContentType() == ZenContentType::kCbObject) { - const IoHash ObjectHash = IoHash::HashBuffer(OutValue.Value.GetView()); - const size_t ObjectSize = OutValue.Value.GetSize(); - - ZEN_LOG_INFO(LogCacheActivity, - "GET HIT [{}] {}/{}/{} -> {} {} {}", - Context, - Namespace, - Bucket, - HashKey, - ObjectHash, - ObjectSize, - ToString(OutValue.Value.GetContentType())) + m_PendingAsyncLogging.AddCount(1); + m_AsyncLogging->ScheduleWork( + [this, OutValue, Context, Namespace = std::string(Namespace), Bucket = std::string(Bucket), HashKey]() { + auto _ = MakeGuard([this]() { m_PendingAsyncLogging.CountDown(); }); + const IoHash ObjectHash = IoHash::HashBuffer(OutValue.Value.GetView()); + const size_t ObjectSize = OutValue.Value.GetSize(); + + ZEN_LOG_INFO(LogCacheActivity, + "GET HIT [{}] {}/{}/{} -> {} {} {}", + Context, + Namespace, + Bucket, + HashKey, + ObjectHash, + ObjectSize, + ToString(OutValue.Value.GetContentType())) + }); } else { @@ -337,18 +351,23 @@ ZenCacheStore::Put(const CacheRequestContext& Context, { if (Value.Value.GetContentType() == ZenContentType::kCbObject) { - const IoHash ObjectHash = IoHash::HashBuffer(Value.Value.GetView()); - const size_t ObjectSize = Value.Value.GetSize(); + m_PendingAsyncLogging.AddCount(1); + m_AsyncLogging->ScheduleWork( + [this, Value, Context, Namespace = std::string(Namespace), Bucket = std::string(Bucket), HashKey]() { + auto _ = MakeGuard([this]() { m_PendingAsyncLogging.CountDown(); }); + const IoHash ObjectHash = IoHash::HashBuffer(Value.Value.GetView()); + const size_t ObjectSize = Value.Value.GetSize(); - ZEN_LOG_INFO(LogCacheActivity, - "PUT [{}] {}/{}/{} -> {} {} {}", - Context, - Namespace, - Bucket, - HashKey, - ObjectHash, - ObjectSize, - ToString(Value.Value.GetContentType())); + ZEN_LOG_INFO(LogCacheActivity, + "PUT [{}] {}/{}/{} -> {} {} {}", + Context, + Namespace, + Bucket, + HashKey, + ObjectHash, + ObjectSize, + ToString(Value.Value.GetContentType())); + }); } else { |