aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/cache/structuredcachestore.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2023-09-11 11:21:35 -0400
committerGitHub <[email protected]>2023-09-11 17:21:35 +0200
commit0b869a4258ad748ee9157b2e163f2123eeb20734 (patch)
tree4c6d0fbc21aa25e70289d0b1eeb36cde87ba604a /src/zenserver/cache/structuredcachestore.cpp
parentadd `cache-write-log` and `cache-access-log“ configuration options (#394) (diff)
downloadzen-0b869a4258ad748ee9157b2e163f2123eeb20734.tar.xz
zen-0b869a4258ad748ee9157b2e163f2123eeb20734.zip
gracefully handle errors when writing cache log (#391)
* gracefully handle errors when writing cache log * changelog * fix log message
Diffstat (limited to 'src/zenserver/cache/structuredcachestore.cpp')
-rw-r--r--src/zenserver/cache/structuredcachestore.cpp79
1 files changed, 50 insertions, 29 deletions
diff --git a/src/zenserver/cache/structuredcachestore.cpp b/src/zenserver/cache/structuredcachestore.cpp
index a115839ce..1f284863d 100644
--- a/src/zenserver/cache/structuredcachestore.cpp
+++ b/src/zenserver/cache/structuredcachestore.cpp
@@ -286,43 +286,64 @@ ZenCacheStore::LogWorker()
std::vector<AccessLogItem> Items;
while (true)
{
- m_LogQueueLock.WithExclusiveLock([this, &Items]() { Items.swap(m_LogQueue); });
- for (const auto& Item : Items)
+ try
{
- if (Item.Value.Value)
+ m_LogQueueLock.WithExclusiveLock([this, &Items]() { Items.swap(m_LogQueue); });
+ for (const auto& Item : Items)
{
- const bool IsCbObject = Item.Value.Value.GetContentType() == ZenContentType::kCbObject;
-
- 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()))
+ if (Item.Value.Value)
+ {
+ const bool IsCbObject = Item.Value.Value.GetContentType() == ZenContentType::kCbObject;
+
+ 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())
+ }
+ }
+ else
+ {
+ ZEN_LOG_INFO(LogCacheActivity, "{} [{}] {}/{}/{}", Item.Op, Item.Context, Item.Namespace, Item.Bucket, Item.HashKey);
+ }
}
- else
+ if (!Items.empty())
{
- ZEN_LOG_INFO(LogCacheActivity, "{} [{}] {}/{}/{}", Item.Op, Item.Context, Item.Namespace, Item.Bucket, Item.HashKey);
+ Items.resize(0);
+ continue;
}
+ if (m_ExitLogging)
+ {
+ break;
+ }
+ m_LogEvent.Wait();
+ m_LogEvent.Reset();
}
- if (!Items.empty())
- {
- Items.resize(0);
- continue;
- }
- if (m_ExitLogging)
+ catch (std::exception& Ex)
{
- break;
+ ZEN_WARN("Log writer failed: '{}'", Ex.what());
}
- m_LogEvent.Wait();
- m_LogEvent.Reset();
}
}