aboutsummaryrefslogtreecommitdiff
path: root/zenstore/include
diff options
context:
space:
mode:
authorPer Larsson <[email protected]>2021-12-05 16:03:27 +0100
committerPer Larsson <[email protected]>2021-12-05 16:03:27 +0100
commit9eb0876ab1f35317eb04dd8a74f0394e853f4f56 (patch)
tree1dfd11024baea97b01c69b40153086511987f361 /zenstore/include
parentMerge branch 'gc' of https://github.com/EpicGames/zen into gc (diff)
downloadzen-9eb0876ab1f35317eb04dd8a74f0394e853f4f56.tar.xz
zen-9eb0876ab1f35317eb04dd8a74f0394e853f4f56.zip
Added simple GC interval scheduling.
Diffstat (limited to 'zenstore/include')
-rw-r--r--zenstore/include/zenstore/CAS.h2
-rw-r--r--zenstore/include/zenstore/gc.h50
2 files changed, 41 insertions, 11 deletions
diff --git a/zenstore/include/zenstore/CAS.h b/zenstore/include/zenstore/CAS.h
index bba1bb721..72b750d6c 100644
--- a/zenstore/include/zenstore/CAS.h
+++ b/zenstore/include/zenstore/CAS.h
@@ -129,7 +129,7 @@ protected:
uint64_t m_LastScrubTime = 0;
};
-ZENCORE_API CasStore* CreateCasStore(CasGc& Gc);
+ZENCORE_API std::unique_ptr<CasStore> CreateCasStore(CasGc& Gc);
void CAS_forcelink();
diff --git a/zenstore/include/zenstore/gc.h b/zenstore/include/zenstore/gc.h
index 6b00f1ffb..94f3c32ac 100644
--- a/zenstore/include/zenstore/gc.h
+++ b/zenstore/include/zenstore/gc.h
@@ -6,11 +6,18 @@
#include <zencore/thread.h>
#include <atomic>
+#include <chrono>
+#include <filesystem>
#include <functional>
#include <span>
+#include <thread>
#define ZEN_USE_REF_TRACKING 0 // This is not currently functional
+namespace spdlog {
+class logger;
+}
+
namespace zen {
class CasStore;
@@ -97,7 +104,7 @@ public:
void AddGcStorage(GcStorage* Contributor);
void RemoveGcStorage(GcStorage* Contributor);
- void CollectGarbage();
+ void CollectGarbage(GcContext& GcCtx);
void SetCidStore(CidStore* Cids);
void OnNewCidReferences(std::span<IoHash> Hashes);
@@ -111,23 +118,46 @@ private:
CidStore* m_CidStore;
};
-enum class GcStatus : uint32_t
+enum class GcSchedulerStatus : uint32_t
{
kIdle,
- kRunning
+ kRunning,
+ kStopped
+};
+
+struct GcSchedulerConfig
+{
+ std::filesystem::path RootDirectory;
+ std::chrono::seconds Interval{3600};
+ bool Enabled = true;
};
-class Gc
+class GcScheduler
{
+ using Clock = std::chrono::system_clock;
+ using Timepoint = std::chrono::time_point<Clock>;
+
public:
- bool Trigger();
- CasGc& Cas() { return m_CasGc; }
- GcStatus Status() const { return static_cast<GcStatus>(m_Status.load()); }
+ GcScheduler(CasGc& CasGc);
+ ~GcScheduler();
+
+ void Initialize(const GcSchedulerConfig& Config);
+ bool ScheduleNow();
+ GcSchedulerStatus Status() const { return static_cast<GcSchedulerStatus>(m_Status.load()); }
+ void Shutdown();
private:
- CasGc m_CasGc;
- std::jthread m_GcThread;
- std::atomic_uint32_t m_Status;
+ void SchedulerThread();
+ spdlog::logger& Log() { return m_Log; }
+
+ spdlog::logger& m_Log;
+ CasGc& m_CasGc;
+ GcSchedulerConfig m_Config;
+ Timepoint m_NextGcTime{};
+ std::atomic_uint32_t m_Status{};
+ std::jthread m_GcThread;
+ std::mutex m_GcMutex;
+ std::condition_variable m_GcSignal;
};
} // namespace zen