aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2023-09-15 16:50:46 -0400
committerGitHub <[email protected]>2023-09-15 22:50:46 +0200
commite98c2965db684c83e65ac2f4b319bb79dd895044 (patch)
tree815c48ec5a33d0ebd554c15b73b793dbb5e1e399 /src
parentv0.2.22 (diff)
downloadzen-e98c2965db684c83e65ac2f4b319bb79dd895044.tar.xz
zen-e98c2965db684c83e65ac2f4b319bb79dd895044.zip
add DiskWriteBlocker to structured cache store log writer (#408)
* add DiskWriteBlocker to structured cache store log writer * changelog
Diffstat (limited to 'src')
-rw-r--r--src/zenserver/cache/structuredcachestore.cpp70
-rw-r--r--src/zenserver/cache/structuredcachestore.h4
-rw-r--r--src/zenserver/zenserver.cpp3
3 files changed, 45 insertions, 32 deletions
diff --git a/src/zenserver/cache/structuredcachestore.cpp b/src/zenserver/cache/structuredcachestore.cpp
index 2ba1f61bd..c8384d330 100644
--- a/src/zenserver/cache/structuredcachestore.cpp
+++ b/src/zenserver/cache/structuredcachestore.cpp
@@ -224,8 +224,9 @@ ZEN_DEFINE_LOG_CATEGORY_STATIC(LogCacheActivity, "z$");
static constinit std::string_view UE4DDCNamespaceName = "ue4.ddc";
-ZenCacheStore::ZenCacheStore(GcManager& Gc, const Configuration& Configuration)
+ZenCacheStore::ZenCacheStore(GcManager& Gc, const Configuration& Configuration, const DiskWriteBlocker* InDiskWriteBlocker)
: m_Log(logging::Get("z$"))
+, m_DiskWriteBlocker(InDiskWriteBlocker)
, m_Gc(Gc)
, m_Configuration(Configuration)
, m_ExitLogging(false)
@@ -293,44 +294,53 @@ ZenCacheStore::LogWorker()
try
{
m_LogQueueLock.WithExclusiveLock([this, &Items]() { Items.swap(m_LogQueue); });
- for (const auto& Item : Items)
+ if (m_DiskWriteBlocker == nullptr || m_DiskWriteBlocker->AreDiskWritesAllowed())
{
- if (Item.Value.Value)
+ for (const auto& Item : Items)
{
- const bool IsCbObject = Item.Value.Value.GetContentType() == ZenContentType::kCbObject;
-
- try
+ if (Item.Value.Value)
{
- const IoHash ObjectHash = IsCbObject ? IoHash::HashBuffer(Item.Value.Value.GetView()) : Item.Value.RawHash;
- const size_t ObjectSize = IsCbObject ? Item.Value.Value.GetSize() : Item.Value.RawSize;
+ const bool IsCbObject = Item.Value.Value.GetContentType() == ZenContentType::kCbObject;
- ZEN_LOG_INFO(LogCacheActivity,
- "{} [{}] {}/{}/{} -> {} {} {}",
- Item.Op,
- Item.Context,
- Item.Namespace,
- Item.Bucket,
- Item.HashKey,
- ObjectHash,
- ObjectSize,
- ToString(Item.Value.Value.GetContentType()))
+ try
+ {
+ const IoHash ObjectHash = IsCbObject ? IoHash::HashBuffer(Item.Value.Value.GetView()) : Item.Value.RawHash;
+ const size_t ObjectSize = IsCbObject ? Item.Value.Value.GetSize() : Item.Value.RawSize;
+
+ ZEN_LOG_INFO(LogCacheActivity,
+ "{} [{}] {}/{}/{} -> {} {} {}",
+ Item.Op,
+ Item.Context,
+ Item.Namespace,
+ Item.Bucket,
+ Item.HashKey,
+ ObjectHash,
+ ObjectSize,
+ ToString(Item.Value.Value.GetContentType()))
+ }
+ catch (std::exception& Ex)
+ {
+ ZEN_LOG_INFO(LogCacheActivity,
+ "{} [{}] {}/{}/{} failed: Reason: '{}'",
+ Item.Op,
+ Item.Context,
+ Item.Namespace,
+ Item.Bucket,
+ Item.HashKey,
+ Ex.what())
+ }
}
- catch (std::exception& Ex)
+ else
{
ZEN_LOG_INFO(LogCacheActivity,
- "{} [{}] {}/{}/{} failed: Reason: '{}'",
+ "{} [{}] {}/{}/{}",
Item.Op,
Item.Context,
Item.Namespace,
Item.Bucket,
- Item.HashKey,
- Ex.what())
+ Item.HashKey);
}
}
- else
- {
- ZEN_LOG_INFO(LogCacheActivity, "{} [{}] {}/{}/{}", Item.Op, Item.Context, Item.Namespace, Item.Bucket, Item.HashKey);
- }
}
if (!Items.empty())
{
@@ -1227,7 +1237,7 @@ TEST_CASE("z$.namespaces")
IoHash Key2;
{
GcManager Gc;
- ZenCacheStore Zcs(Gc, {.BasePath = TempDir.Path() / "cache", .AllowAutomaticCreationOfNamespaces = false});
+ ZenCacheStore Zcs(Gc, {.BasePath = TempDir.Path() / "cache", .AllowAutomaticCreationOfNamespaces = false}, nullptr);
const auto Bucket = "teardrinker"sv;
const auto CustomNamespace = "mynamespace"sv;
@@ -1252,7 +1262,7 @@ TEST_CASE("z$.namespaces")
{
GcManager Gc;
- ZenCacheStore Zcs(Gc, {.BasePath = TempDir.Path() / "cache", .AllowAutomaticCreationOfNamespaces = true});
+ ZenCacheStore Zcs(Gc, {.BasePath = TempDir.Path() / "cache", .AllowAutomaticCreationOfNamespaces = true}, nullptr);
const auto Bucket = "teardrinker"sv;
const auto CustomNamespace = "mynamespace"sv;
@@ -1313,7 +1323,7 @@ TEST_CASE("z$.drop.bucket")
WorkerThreadPool Workers(1);
{
GcManager Gc;
- ZenCacheStore Zcs(Gc, {.BasePath = TempDir.Path() / "cache", .AllowAutomaticCreationOfNamespaces = true});
+ ZenCacheStore Zcs(Gc, {.BasePath = TempDir.Path() / "cache", .AllowAutomaticCreationOfNamespaces = true}, nullptr);
const auto Bucket = "teardrinker"sv;
const auto Namespace = "mynamespace"sv;
@@ -1384,7 +1394,7 @@ TEST_CASE("z$.drop.namespace")
WorkerThreadPool Workers(1);
{
GcManager Gc;
- ZenCacheStore Zcs(Gc, {.BasePath = TempDir.Path() / "cache", .AllowAutomaticCreationOfNamespaces = true});
+ ZenCacheStore Zcs(Gc, {.BasePath = TempDir.Path() / "cache", .AllowAutomaticCreationOfNamespaces = true}, nullptr);
const auto Bucket1 = "teardrinker1"sv;
const auto Bucket2 = "teardrinker2"sv;
const auto Namespace1 = "mynamespace1"sv;
diff --git a/src/zenserver/cache/structuredcachestore.h b/src/zenserver/cache/structuredcachestore.h
index 05b60da34..8c1f995a4 100644
--- a/src/zenserver/cache/structuredcachestore.h
+++ b/src/zenserver/cache/structuredcachestore.h
@@ -37,6 +37,7 @@ namespace zen {
******************************************************************************/
class WorkerThreadPool;
+class DiskWriteBlocker;
/* Z$ namespace
@@ -130,7 +131,7 @@ public:
GcStorageSize StorageSize;
};
- ZenCacheStore(GcManager& Gc, const Configuration& Configuration);
+ ZenCacheStore(GcManager& Gc, const Configuration& Configuration, const DiskWriteBlocker* InDiskWriteBlocker);
~ZenCacheStore();
bool Get(const CacheRequestContext& Context,
@@ -168,6 +169,7 @@ private:
spdlog::logger& m_Log;
spdlog::logger& Log() { return m_Log; }
+ const DiskWriteBlocker* m_DiskWriteBlocker = nullptr;
mutable RwLock m_NamespacesLock;
NamespaceMap m_Namespaces;
std::vector<std::unique_ptr<ZenCacheNamespace>> m_DroppedNamespaces;
diff --git a/src/zenserver/zenserver.cpp b/src/zenserver/zenserver.cpp
index 1baedd6eb..988f72273 100644
--- a/src/zenserver/zenserver.cpp
+++ b/src/zenserver/zenserver.cpp
@@ -886,7 +886,8 @@ ZenServer::InitializeStructuredCache(const ZenServerOptions& ServerOptions)
ZenCacheStore::Configuration{.BasePath = m_DataRoot / "cache",
.AllowAutomaticCreationOfNamespaces = true,
.EnableWriteLog = ServerOptions.StructuredCacheWriteLogEnabled,
- .EnableAccessLog = ServerOptions.StructuredCacheAccessLogEnabled});
+ .EnableAccessLog = ServerOptions.StructuredCacheAccessLogEnabled},
+ m_GcManager.GetDiskWriteBlocker());
const ZenUpstreamCacheConfig& UpstreamConfig = ServerOptions.UpstreamCacheConfig;