diff options
Diffstat (limited to 'zenserver')
| -rw-r--r-- | zenserver/admin/admin.cpp | 8 | ||||
| -rw-r--r-- | zenserver/cache/structuredcachestore.cpp | 28 | ||||
| -rw-r--r-- | zenserver/config.cpp | 9 | ||||
| -rw-r--r-- | zenserver/config.h | 1 | ||||
| -rw-r--r-- | zenserver/projectstore.cpp | 6 | ||||
| -rw-r--r-- | zenserver/zenserver.cpp | 17 |
6 files changed, 39 insertions, 30 deletions
diff --git a/zenserver/admin/admin.cpp b/zenserver/admin/admin.cpp index 676e9a830..7aa1b48d1 100644 --- a/zenserver/admin/admin.cpp +++ b/zenserver/admin/admin.cpp @@ -54,6 +54,14 @@ HttpAdminService::HttpAdminService(GcScheduler& Scheduler) : m_GcScheduler(Sched } } + if (auto Param = Params.GetValue("disksizesoftlimit"); Param.empty() == false) + { + if (auto Value = ParseInt<uint64_t>(Param)) + { + GcParams.DiskSizeSoftLimit = Value.value(); + } + } + const bool Started = m_GcScheduler.Trigger(GcParams); CbObjectWriter Response; diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp index 91ae452a8..c20e40655 100644 --- a/zenserver/cache/structuredcachestore.cpp +++ b/zenserver/cache/structuredcachestore.cpp @@ -1213,8 +1213,7 @@ ZenCacheDiskLayer::CacheBucket::GatherReferences(GcContext& GcCtx) NiceLatencyNs(ReadBlockLongestTimeUs)); }); - const GcClock::TimePoint ExpireTime = - GcCtx.MaxCacheDuration() == GcClock::Duration::max() ? GcClock::TimePoint::min() : GcCtx.Time() - GcCtx.MaxCacheDuration(); + const GcClock::TimePoint ExpireTime = GcCtx.ExpireTime(); const GcClock::Tick ExpireTicks = ExpireTime.time_since_epoch().count(); @@ -1310,7 +1309,7 @@ ZenCacheDiskLayer::CacheBucket::CollectGarbage(GcContext& GcCtx) uint64_t MovedCount = 0; const auto _ = MakeGuard([&] { - ZEN_INFO( + ZEN_DEBUG( "garbage collect from '{}' DONE after {}, write lock: {} ({}), read lock: {} ({}), collected {} bytes, deleted #{} and moved " "#{} " "of #{} " @@ -2379,8 +2378,7 @@ TEST_CASE("z$.gc") GcClock::Duration MaxDuration, std::span<const IoHash> Cids, std::vector<IoHash>& OutKeep) { - GcContext GcCtx(Time); - GcCtx.MaxCacheDuration(MaxDuration); + GcContext GcCtx(Time - MaxDuration); Gc.CollectGarbage(GcCtx); OutKeep.clear(); GcCtx.FilterCids(Cids, [&OutKeep](const IoHash& Hash) { OutKeep.push_back(Hash); }); @@ -2459,8 +2457,7 @@ TEST_CASE("z$.gc") } { - GcContext GcCtx; - GcCtx.MaxCacheDuration(std::chrono::hours(46)); + GcContext GcCtx(CurrentTime - std::chrono::hours(46)); Gc.CollectGarbage(GcCtx); @@ -2474,9 +2471,7 @@ TEST_CASE("z$.gc") // Move forward in time and collect again { - GcContext GcCtx(CurrentTime + std::chrono::hours(46)); - GcCtx.MaxCacheDuration(std::chrono::minutes(2)); - + GcContext GcCtx(CurrentTime + std::chrono::minutes(2)); Gc.CollectGarbage(GcCtx); for (const auto& Key : Keys) @@ -2495,8 +2490,7 @@ TEST_CASE("z$.gc") ScopedTemporaryDirectory TempDir; GcManager Gc; ZenCacheNamespace Zcs(Gc, TempDir.Path() / "cache"); - const auto Bucket = "rightintwo"sv; - const GcClock::TimePoint CurrentTime = GcClock::Now(); + const auto Bucket = "rightintwo"sv; std::vector<IoHash> Keys{CreateKey(1), CreateKey(2), CreateKey(3)}; @@ -2507,8 +2501,7 @@ TEST_CASE("z$.gc") } { - GcContext GcCtx; - GcCtx.MaxCacheDuration(std::chrono::hours(2)); + GcContext GcCtx(GcClock::Now() - std::chrono::hours(2)); GcCtx.CollectSmallObjects(true); Gc.CollectGarbage(GcCtx); @@ -2523,8 +2516,7 @@ TEST_CASE("z$.gc") // Move forward in time and collect again { - GcContext GcCtx(CurrentTime + std::chrono::hours(2)); - GcCtx.MaxCacheDuration(std::chrono::minutes(2)); + GcContext GcCtx(GcClock::Now() + std::chrono::minutes(2)); GcCtx.CollectSmallObjects(true); Zcs.Flush(); @@ -2713,7 +2705,7 @@ TEST_CASE("z$.threadedinsert") // * doctest::skip(true)) C++; } - GcContext GcCtx; + GcContext GcCtx(GcClock::Now() - std::chrono::hours(24)); GcCtx.CollectSmallObjects(true); GcCtx.AddRetainedCids(KeepHashes); Zcs.CollectGarbage(GcCtx); @@ -2761,7 +2753,7 @@ TEST_CASE("z$.threadedinsert") // * doctest::skip(true)) C++; } - GcContext GcCtx; + GcContext GcCtx(GcClock::Now() - std::chrono::hours(24)); GcCtx.CollectSmallObjects(true); GcCtx.AddRetainedCids(KeepHashes); Zcs.CollectGarbage(GcCtx); diff --git a/zenserver/config.cpp b/zenserver/config.cpp index 9531a5251..057b26c5b 100644 --- a/zenserver/config.cpp +++ b/zenserver/config.cpp @@ -493,6 +493,14 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions) "Garbage collection monitoring interval in seconds.", cxxopts::value<int32_t>(ServerOptions.GcConfig.MonitorIntervalSeconds)->default_value("30"), ""); + + options.add_option("gc", + "", + "gc-disksize-softlimit", + "Garbage collection disk usage soft limit. Default set to 0 (Off).", + cxxopts::value<uint64_t>(ServerOptions.GcConfig.Cache.DiskSizeSoftLimit)->default_value("0"), + ""); + try { auto result = options.parse(argc, argv); @@ -825,6 +833,7 @@ ParseConfigFile(const std::filesystem::path& Path, ZenServerOptions& ServerOptio ServerOptions.GcConfig.Cache.MaxDurationSeconds = CacheGcConfig.value().get_or("maxdurationseconds", int32_t(0)); ServerOptions.GcConfig.Cache.DiskSizeLimit = CacheGcConfig.value().get_or("disksizelimit", ~uint64_t(0)); ServerOptions.GcConfig.Cache.MemorySizeLimit = CacheGcConfig.value().get_or("memorysizelimit", ~uint64_t(0)); + ServerOptions.GcConfig.Cache.DiskSizeSoftLimit = CacheGcConfig.value().get_or("disksizesoftlimit", 0); } if (sol::optional<sol::table> CasGcConfig = GcConfig.value()["cas"]) diff --git a/zenserver/config.h b/zenserver/config.h index 5dbca4c41..4cdef0318 100644 --- a/zenserver/config.h +++ b/zenserver/config.h @@ -76,6 +76,7 @@ struct ZenCacheEvictionPolicy uint64_t DiskSizeLimit = ~uint64_t(0); uint64_t MemorySizeLimit = 1024 * 1024 * 1024; int32_t MaxDurationSeconds = 24 * 60 * 60; + uint64_t DiskSizeSoftLimit = 0; bool Enabled = true; }; diff --git a/zenserver/projectstore.cpp b/zenserver/projectstore.cpp index c3f10c9cd..3a65feb0f 100644 --- a/zenserver/projectstore.cpp +++ b/zenserver/projectstore.cpp @@ -1156,7 +1156,7 @@ ProjectStore::CollectGarbage(GcContext& GcCtx) if (!GcCtx.IsDeletionMode()) { - ZEN_INFO("garbage collect DISABLED, for '{}' ", m_ProjectBasePath.string()); + ZEN_DEBUG("garbage collect DISABLED, for '{}' ", m_ProjectBasePath.string()); return; } @@ -2756,7 +2756,7 @@ TEST_CASE("project.store.gc") } { - GcContext GcCtx; + GcContext GcCtx(GcClock::Now() - std::chrono::hours(24)); ProjectStore.GatherReferences(GcCtx); size_t RefCount = 0; GcCtx.IterateCids([&RefCount](const IoHash&) { RefCount++; }); @@ -2769,7 +2769,7 @@ TEST_CASE("project.store.gc") std::filesystem::remove(Project1FilePath); { - GcContext GcCtx; + GcContext GcCtx(GcClock::Now() - std::chrono::hours(24)); ProjectStore.GatherReferences(GcCtx); size_t RefCount = 0; GcCtx.IterateCids([&RefCount](const IoHash&) { RefCount++; }); diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp index cabff7389..cf3d90324 100644 --- a/zenserver/zenserver.cpp +++ b/zenserver/zenserver.cpp @@ -357,15 +357,14 @@ public: } ZEN_INFO("initializing GC, enabled '{}', interval {}s", ServerOptions.GcConfig.Enabled, ServerOptions.GcConfig.IntervalSeconds); - zen::GcSchedulerConfig GcConfig{ - .RootDirectory = m_DataRoot / "gc", - .MonitorInterval = std::chrono::seconds(ServerOptions.GcConfig.MonitorIntervalSeconds), - .Interval = std::chrono::seconds(ServerOptions.GcConfig.IntervalSeconds), - .MaxCacheDuration = std::chrono::seconds(ServerOptions.GcConfig.Cache.MaxDurationSeconds), - .CollectSmallObjects = ServerOptions.GcConfig.CollectSmallObjects, - .Enabled = ServerOptions.GcConfig.Enabled, - .DiskReserveSize = ServerOptions.GcConfig.DiskReserveSize, - }; + zen::GcSchedulerConfig GcConfig{.RootDirectory = m_DataRoot / "gc", + .MonitorInterval = std::chrono::seconds(ServerOptions.GcConfig.MonitorIntervalSeconds), + .Interval = std::chrono::seconds(ServerOptions.GcConfig.IntervalSeconds), + .MaxCacheDuration = std::chrono::seconds(ServerOptions.GcConfig.Cache.MaxDurationSeconds), + .CollectSmallObjects = ServerOptions.GcConfig.CollectSmallObjects, + .Enabled = ServerOptions.GcConfig.Enabled, + .DiskReserveSize = ServerOptions.GcConfig.DiskReserveSize, + .DiskSizeSoftLimit = ServerOptions.GcConfig.Cache.DiskSizeSoftLimit}; m_GcScheduler.Initialize(GcConfig); return EffectiveBasePort; |