aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPer Larsson <[email protected]>2021-12-10 07:35:28 +0100
committerPer Larsson <[email protected]>2021-12-10 07:35:28 +0100
commit680d0a3b3c8e76762a0e8b19a94fd854429b91a6 (patch)
tree483fa84d88086baeeec0bfb3782cfea7c3e1c3dd
parentIgnore clangd cache directory. (diff)
downloadzen-680d0a3b3c8e76762a0e8b19a94fd854429b91a6.tar.xz
zen-680d0a3b3c8e76762a0e8b19a94fd854429b91a6.zip
Set GC default enabled and interval set to zero (off).
-rw-r--r--zenserver/config.cpp6
-rw-r--r--zenserver/config.h4
-rw-r--r--zenstore/gc.cpp79
-rw-r--r--zenstore/include/zenstore/gc.h12
4 files changed, 57 insertions, 44 deletions
diff --git a/zenserver/config.cpp b/zenserver/config.cpp
index 3aef3f499..e57a97c8b 100644
--- a/zenserver/config.cpp
+++ b/zenserver/config.cpp
@@ -307,7 +307,7 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions)
"",
"gc-enabled",
"Whether garbage collection is enabled or not.",
- cxxopts::value<bool>(ServerOptions.GcConfig.Enabled)->default_value("false"),
+ cxxopts::value<bool>(ServerOptions.GcConfig.Enabled)->default_value("true"),
"");
options.add_option("gc",
@@ -320,8 +320,8 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions)
options.add_option("gc",
"",
"gc-interval-seconds",
- "Garbage collection interval. Default is 1h.",
- cxxopts::value<int32_t>(ServerOptions.GcConfig.IntervalSeconds)->default_value("3600"),
+ "Garbage collection interval in seconds. Default set to 0 (Off).",
+ cxxopts::value<int32_t>(ServerOptions.GcConfig.IntervalSeconds)->default_value("0"),
"");
options.add_option("gc",
diff --git a/zenserver/config.h b/zenserver/config.h
index 086f761fc..bc8768961 100644
--- a/zenserver/config.h
+++ b/zenserver/config.h
@@ -75,9 +75,9 @@ struct ZenGcConfig
{
ZenCasEvictionPolicy Cas;
ZenCacheEvictionPolicy Cache;
- int32_t IntervalSeconds = 60 * 60;
+ int32_t IntervalSeconds = 0;
bool CollectSmallObjects = false;
- bool Enabled = false;
+ bool Enabled = true;
};
struct ZenServerOptions
diff --git a/zenstore/gc.cpp b/zenstore/gc.cpp
index bf04543b5..86f215b97 100644
--- a/zenstore/gc.cpp
+++ b/zenstore/gc.cpp
@@ -289,20 +289,19 @@ GcScheduler::Initialize(const GcSchedulerConfig& Config)
std::filesystem::create_directories(Config.RootDirectory);
- Timepoint CurrentTime = Clock::now();
+ GcClock::TimePoint LastGcTime = GcClock::Now();
if (CbObject SchedulerState = LoadCompactBinaryObject(Config.RootDirectory / "gc_state"))
{
- const int64_t LastGcTime = SchedulerState["LastGcTime"sv].AsInt64();
- CurrentTime = Timepoint(Clock::duration(LastGcTime));
+ LastGcTime = GcClock::TimePoint(GcClock::Duration(SchedulerState["LastGcTime"sv].AsInt64()));
- if (CurrentTime + m_Config.Interval < Clock::now())
+ if (LastGcTime + m_Config.Interval < GcClock::Now())
{
- CurrentTime = Clock::now();
+ LastGcTime = GcClock::Now();
}
}
- m_NextGcTime = CurrentTime + m_Config.Interval;
+ m_NextGcTime = NextGcTime(LastGcTime);
m_GcThread = std::jthread(&GcScheduler::SchedulerThread, this);
}
@@ -336,41 +335,57 @@ GcScheduler::SchedulerThread()
}
}
- if (m_Config.Enabled)
+ if (!m_Config.Enabled)
{
- Stopwatch Timer;
-
- DiskSpace Space;
- DiskSpaceInfo(m_Config.RootDirectory, Space);
- ZEN_INFO("garbage collection STARTING, disk space {}/{} (free/total)", NiceBytes(Space.Free), NiceBytes(Space.Total));
+ ZEN_INFO("disabled");
+ continue;
+ }
- GcContext GcCtx;
- GcCtx.SetDeletionMode(true);
- GcCtx.CollectSmallObjects(m_Config.CollectSmallObjects);
- GcCtx.MaxCacheDuration(m_Config.MaxCacheDuration);
+ Stopwatch Timer;
- ZEN_DEBUG("collecting small objects {}, max cache duration {}s",
- m_Config.CollectSmallObjects ? "YES"sv : "NO"sv,
- m_Config.MaxCacheDuration.count());
+ DiskSpace Space;
+ DiskSpaceInfo(m_Config.RootDirectory, Space);
+ ZEN_INFO("garbage collection STARTING, disk space {}/{} (free/total)", NiceBytes(Space.Free), NiceBytes(Space.Total));
- m_CasGc.CollectGarbage(GcCtx);
+ GcContext GcCtx;
+ GcCtx.SetDeletionMode(true);
+ GcCtx.CollectSmallObjects(m_Config.CollectSmallObjects);
+ GcCtx.MaxCacheDuration(m_Config.MaxCacheDuration);
- m_Status = static_cast<uint32_t>(GcSchedulerStatus::kIdle);
- m_NextGcTime = Clock::now() + m_Config.Interval;
+ ZEN_DEBUG("collecting small objects {}, max cache duration {}s",
+ m_Config.CollectSmallObjects ? "YES"sv : "NO"sv,
+ m_Config.MaxCacheDuration.count());
- {
- CbObjectWriter SchedulderState;
- SchedulderState << "LastGcTime"sv << static_cast<int64_t>(Clock::now().time_since_epoch().count());
- SaveCompactBinaryObject(m_Config.RootDirectory / "gc_state", SchedulderState.Save());
- }
+ m_CasGc.CollectGarbage(GcCtx);
- DiskSpaceInfo(m_Config.RootDirectory, Space);
+ m_Status = static_cast<uint32_t>(GcSchedulerStatus::kIdle);
+ m_NextGcTime = NextGcTime(GcClock::Now());
- ZEN_INFO("garbage collection DONE after {}, disk space {}/{} (free/total)",
- NiceTimeSpanMs(Timer.GetElapsedTimeMs()),
- NiceBytes(Space.Free),
- NiceBytes(Space.Total));
+ {
+ CbObjectWriter SchedulderState;
+ SchedulderState << "LastGcTime"sv << static_cast<int64_t>(GcClock::Now().time_since_epoch().count());
+ SaveCompactBinaryObject(m_Config.RootDirectory / "gc_state", SchedulderState.Save());
}
+
+ DiskSpaceInfo(m_Config.RootDirectory, Space);
+
+ ZEN_INFO("garbage collection DONE after {}, disk space {}/{} (free/total)",
+ NiceTimeSpanMs(Timer.GetElapsedTimeMs()),
+ NiceBytes(Space.Free),
+ NiceBytes(Space.Total));
+ }
+}
+
+GcClock::TimePoint
+GcScheduler::NextGcTime(GcClock::TimePoint CurrentTime)
+{
+ if (m_Config.Interval.count())
+ {
+ return CurrentTime + m_Config.Interval;
+ }
+ else
+ {
+ return GcClock::TimePoint::max();
}
}
diff --git a/zenstore/include/zenstore/gc.h b/zenstore/include/zenstore/gc.h
index 3c03c7feb..5a6afc8da 100644
--- a/zenstore/include/zenstore/gc.h
+++ b/zenstore/include/zenstore/gc.h
@@ -150,7 +150,7 @@ enum class GcSchedulerStatus : uint32_t
struct GcSchedulerConfig
{
std::filesystem::path RootDirectory;
- std::chrono::seconds Interval{3600};
+ std::chrono::seconds Interval{};
std::chrono::seconds MaxCacheDuration{86400};
bool CollectSmallObjects = false;
bool Enabled = false;
@@ -158,9 +158,6 @@ struct GcSchedulerConfig
class GcScheduler
{
- using Clock = std::chrono::system_clock;
- using Timepoint = std::chrono::time_point<Clock>;
-
public:
GcScheduler(CasGc& CasGc);
~GcScheduler();
@@ -171,13 +168,14 @@ public:
void Shutdown();
private:
- void SchedulerThread();
- spdlog::logger& Log() { return m_Log; }
+ void SchedulerThread();
+ GcClock::TimePoint NextGcTime(GcClock::TimePoint CurrentTime);
+ spdlog::logger& Log() { return m_Log; }
spdlog::logger& m_Log;
CasGc& m_CasGc;
GcSchedulerConfig m_Config;
- Timepoint m_NextGcTime{};
+ GcClock::TimePoint m_NextGcTime{};
std::atomic_uint32_t m_Status{};
std::jthread m_GcThread;
std::mutex m_GcMutex;