diff options
| author | Stefan Boberg <[email protected]> | 2023-11-06 20:36:30 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-11-06 20:36:30 +0100 |
| commit | 07f288d6e119fc6bb524fb634bc9094109a2ab05 (patch) | |
| tree | 8531bd38d0d8c3567ba3d0a5603f549faf99632b /src/zenstore | |
| parent | gc v2 tests (#512) (diff) | |
| download | zen-07f288d6e119fc6bb524fb634bc9094109a2ab05.tar.xz zen-07f288d6e119fc6bb524fb634bc9094109a2ab05.zip | |
spdlog implementation hiding (#498)
this change aims to hide logging internals from client code, in order to make it easier to extend and take more control over the logging process in the future.
As a bonus side effect, the generated code is much tighter (net delta around 2.5% on the resulting executable which includes lots of thirdparty code) and should take less time to compile and link.
Client usage via macros is pretty much unchanged. The main exposure client code had to spdlog internals before was the use of custom loggers per subsystem, where it would be common to have `spdlog::logger` references to keep a reference to a logger within a class. This is now replaced by `zen::LoggerRef` which currently simply encapsulates an actual `spdlog::logger` instance, but this is intended to be an implementation detail which will change in the future.
The way the change works is that we now handle any formatting of log messages in the zencore logging subsystem instead of relying on `spdlog` to manage this. We use the `fmt` library to do the formatting which means the client usage is identical to using `spdlog`. The formatted message is then forwarded onto any sinks etc which are still implememted via `spdlog`.
Diffstat (limited to 'src/zenstore')
| -rw-r--r-- | src/zenstore/compactcas.h | 9 | ||||
| -rw-r--r-- | src/zenstore/filecas.h | 14 | ||||
| -rw-r--r-- | src/zenstore/include/zenstore/gc.h | 35 |
3 files changed, 24 insertions, 34 deletions
diff --git a/src/zenstore/compactcas.h b/src/zenstore/compactcas.h index 9f3aa6b07..3ed883801 100644 --- a/src/zenstore/compactcas.h +++ b/src/zenstore/compactcas.h @@ -2,6 +2,7 @@ #pragma once +#include <zencore/logbase.h> #include <zencore/zencore.h> #include <zenstore/blockstore.h> #include <zenstore/caslog.h> @@ -16,10 +17,6 @@ ZEN_THIRD_PARTY_INCLUDES_START #include <tsl/robin_map.h> ZEN_THIRD_PARTY_INCLUDES_END -namespace spdlog { -class logger; -} - namespace zen { ////////////////////////////////////////////////////////////////////////// @@ -82,9 +79,9 @@ private: void OpenContainer(bool IsNewStore); void CompactIndex(RwLock::ExclusiveLockScope&); - spdlog::logger& Log() { return m_Log; } + LoggerRef Log() { return m_Log; } - spdlog::logger& m_Log; + LoggerRef m_Log; GcManager& m_Gc; std::filesystem::path m_RootDirectory; uint64_t m_PayloadAlignment = 1u << 4; diff --git a/src/zenstore/filecas.h b/src/zenstore/filecas.h index c39a39bb7..cb1347580 100644 --- a/src/zenstore/filecas.h +++ b/src/zenstore/filecas.h @@ -16,10 +16,6 @@ #include <atomic> #include <functional> -namespace spdlog { -class logger; -} - namespace zen { class BasicFile; @@ -48,10 +44,10 @@ struct FileCasStrategy final : public GcStorage, public GcReferenceStore virtual GcReferencePruner* CreateReferencePruner(GcCtx& Ctx, GcReferenceStoreStats& Stats) override; private: - void MakeIndexSnapshot(); - uint64_t ReadIndexFile(const std::filesystem::path& IndexPath, uint32_t& OutVersion); - uint64_t ReadLog(const std::filesystem::path& LogPath, uint64_t LogPosition); - spdlog::logger& Log() { return m_Log; } + void MakeIndexSnapshot(); + uint64_t ReadIndexFile(const std::filesystem::path& IndexPath, uint32_t& OutVersion); + uint64_t ReadLog(const std::filesystem::path& LogPath, uint64_t LogPosition); + LoggerRef Log() { return m_Log; } struct IndexEntry { @@ -61,7 +57,7 @@ private: CasStore::InsertResult InsertChunkData(const void* ChunkData, size_t ChunkSize, const IoHash& ChunkHash); - spdlog::logger& m_Log; + LoggerRef m_Log; GcManager& m_Gc; std::filesystem::path m_RootDirectory; RwLock m_Lock; diff --git a/src/zenstore/include/zenstore/gc.h b/src/zenstore/include/zenstore/gc.h index 1b9929216..409c9b4d6 100644 --- a/src/zenstore/include/zenstore/gc.h +++ b/src/zenstore/include/zenstore/gc.h @@ -3,6 +3,7 @@ #pragma once #include <zencore/iohash.h> +#include <zencore/logbase.h> #include <zencore/thread.h> #include <zenstore/caslog.h> #include <zenstore/scrubcontext.h> @@ -24,10 +25,6 @@ ZEN_THIRD_PARTY_INCLUDES_START #include <tsl/robin_set.h> ZEN_THIRD_PARTY_INCLUDES_END -namespace spdlog { -class logger; -} - namespace zen { class CidStore; @@ -360,8 +357,8 @@ public: void SetDiskWriteBlocker(const DiskWriteBlocker* Monitor) { m_DiskWriteBlocker = Monitor; } private: - spdlog::logger& Log() { return m_Log; } - spdlog::logger& m_Log; + LoggerRef Log() { return m_Log; } + LoggerRef m_Log; mutable RwLock m_Lock; std::vector<GcContributor*> m_GcContribs; std::vector<GcStorage*> m_GcStorage; @@ -483,19 +480,19 @@ public: bool TriggerScrub(const TriggerScrubParams& Params); private: - void SchedulerThread(); - void CollectGarbage(const GcClock::TimePoint& CacheExpireTime, - const GcClock::TimePoint& ProjectStoreExpireTime, - bool Delete, - bool CollectSmallObjects, - bool SkipCid, - GcVersion UseGCVersion); - void ScrubStorage(bool DoDelete, std::chrono::seconds TimeSlice); - spdlog::logger& Log() { return m_Log; } - virtual bool AreDiskWritesAllowed() const override { return !m_AreDiskWritesBlocked.load(); } - DiskSpace CheckDiskSpace(); - - spdlog::logger& m_Log; + void SchedulerThread(); + void CollectGarbage(const GcClock::TimePoint& CacheExpireTime, + const GcClock::TimePoint& ProjectStoreExpireTime, + bool Delete, + bool CollectSmallObjects, + bool SkipCid, + GcVersion UseGCVersion); + void ScrubStorage(bool DoDelete, std::chrono::seconds TimeSlice); + LoggerRef Log() { return m_Log; } + virtual bool AreDiskWritesAllowed() const override { return !m_AreDiskWritesBlocked.load(); } + DiskSpace CheckDiskSpace(); + + LoggerRef m_Log; GcManager& m_GcManager; GcSchedulerConfig m_Config; GcClock::TimePoint m_LastGcTime{}; |