aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2024-10-03 16:42:57 +0200
committerGitHub Enterprise <[email protected]>2024-10-03 16:42:57 +0200
commitb13b5f48bb497aaf9f9f3d74aceb6e474cf12898 (patch)
tree24b1ed63ece11fb773a0ecf41ce6308969468198 /src/zenserver
parent5.5.9-pre0 (diff)
downloadzen-b13b5f48bb497aaf9f9f3d74aceb6e474cf12898.tar.xz
zen-b13b5f48bb497aaf9f9f3d74aceb6e474cf12898.zip
remove gc v1 (#121)
* kill gc v1 * block use of gc v1 from zen command line * warn and flip to gcv2 if --gc-v2=false is specified for zenserver
Diffstat (limited to 'src/zenserver')
-rw-r--r--src/zenserver/admin/admin.cpp4
-rw-r--r--src/zenserver/config.cpp5
-rw-r--r--src/zenserver/projectstore/projectstore.cpp286
-rw-r--r--src/zenserver/projectstore/projectstore.h6
-rw-r--r--src/zenserver/zenserver.cpp2
5 files changed, 9 insertions, 294 deletions
diff --git a/src/zenserver/admin/admin.cpp b/src/zenserver/admin/admin.cpp
index eb49bac51..f6311cf3e 100644
--- a/src/zenserver/admin/admin.cpp
+++ b/src/zenserver/admin/admin.cpp
@@ -287,7 +287,7 @@ HttpAdminService::HttpAdminService(GcScheduler& Scheduler,
Response << "DiskSizeSoftLimit" << NiceBytes(State.Config.DiskSizeSoftLimit);
Response << "MinimumFreeDiskSpaceToAllowWrites" << NiceBytes(State.Config.MinimumFreeDiskSpaceToAllowWrites);
Response << "LightweightInterval" << ToTimeSpan(State.Config.LightweightInterval);
- Response << "UseGCVersion" << ((State.Config.UseGCVersion == GcVersion::kV1) ? "1" : "2");
+ Response << "UseGCVersion" << ((State.Config.UseGCVersion == GcVersion::kV1_Deprecated) ? "1" : "2");
Response << "CompactBlockUsageThresholdPercent" << State.Config.CompactBlockUsageThresholdPercent;
Response << "Verbose" << State.Config.Verbose;
Response << "SingleThreaded" << State.Config.SingleThreaded;
@@ -396,7 +396,7 @@ HttpAdminService::HttpAdminService(GcScheduler& Scheduler,
if (auto Param = Params.GetValue("forceusegcv1"); Param.empty() == false)
{
- GcParams.ForceGCVersion = GcVersion::kV1;
+ GcParams.ForceGCVersion = GcVersion::kV1_Deprecated;
}
if (auto Param = Params.GetValue("forceusegcv2"); Param.empty() == false)
diff --git a/src/zenserver/config.cpp b/src/zenserver/config.cpp
index 7466255a9..cda5aca16 100644
--- a/src/zenserver/config.cpp
+++ b/src/zenserver/config.cpp
@@ -171,6 +171,11 @@ ValidateOptions(ZenServerOptions& ServerOptions)
throw zen::OptionParseException(
fmt::format("GC attachment pass count can not be larger than {}", ZenGcConfig::GcMaxAttachmentPassCount));
}
+ if (ServerOptions.GcConfig.UseGCV2 == false)
+ {
+ ZEN_WARN("--gc-v2=false is deprecated, reverting to --gc-v2=true");
+ ServerOptions.GcConfig.UseGCV2 = true;
+ }
}
UpstreamCachePolicy
diff --git a/src/zenserver/projectstore/projectstore.cpp b/src/zenserver/projectstore/projectstore.cpp
index 4a943a565..6dbdb7029 100644
--- a/src/zenserver/projectstore/projectstore.cpp
+++ b/src/zenserver/projectstore/projectstore.cpp
@@ -1082,30 +1082,6 @@ ProjectStore::Oplog::ScrubStorage(ScrubContext& Ctx)
}
}
-void
-ProjectStore::Oplog::GatherReferences(GcContext& GcCtx)
-{
- ZEN_TRACE_CPU("Store::Oplog::GatherReferences");
- if (GcCtx.SkipCid())
- {
- return;
- }
-
- std::vector<IoHash> Cids;
- Cids.reserve(1024);
- IterateOplog(
- [&](CbObjectView Op) {
- Op.IterateAttachments([&](CbFieldView Visitor) { Cids.emplace_back(Visitor.AsAttachment()); });
- if (Cids.size() >= 1024)
- {
- GcCtx.AddRetainedCids(Cids);
- Cids.clear();
- }
- },
- Paging{});
- GcCtx.AddRetainedCids(Cids);
-}
-
uint64_t
ProjectStore::Oplog::TotalSize(const std::filesystem::path& BasePath)
{
@@ -3132,43 +3108,6 @@ ProjectStore::Project::ScrubStorage(ScrubContext& Ctx)
});
}
-void
-ProjectStore::Project::GatherReferences(GcContext& GcCtx)
-{
- ZEN_TRACE_CPU("Project::GatherReferences");
-
- Stopwatch Timer;
- const auto Guard = MakeGuard([&] {
- ZEN_DEBUG("gathered references from project store project {} in {}", Identifier, NiceTimeSpanMs(Timer.GetElapsedTimeMs()));
- });
-
- // GatherReferences needs to check all existing oplogs
- std::vector<std::string> OpLogs = ScanForOplogs();
- for (const std::string& OpLogId : OpLogs)
- {
- OpenOplog(OpLogId, /*AllowCompact*/ false);
- }
-
- {
- // Make sure any oplog at least have a last access time so they eventually will be GC:d if not touched
- RwLock::ExclusiveLockScope _(m_LastAccessTimesLock);
- for (const std::string& OpId : OpLogs)
- {
- if (auto It = m_LastAccessTimes.find(OpId); It == m_LastAccessTimes.end())
- {
- m_LastAccessTimes[OpId] = GcClock::TickCount();
- }
- }
- }
-
- IterateOplogs([&](const RwLock::SharedLockScope&, Oplog& Ops) {
- if (!IsExpired(GcCtx.ProjectStoreExpireTime(), Ops))
- {
- Ops.GatherReferences(GcCtx);
- }
- });
-}
-
uint64_t
ProjectStore::Project::TotalSize(const std::filesystem::path& BasePath)
{
@@ -3407,7 +3346,6 @@ ProjectStore::ProjectStore(CidStore& Store, std::filesystem::path BasePath, GcMa
{
ZEN_INFO("initializing project store at '{}'", m_ProjectBasePath);
// m_Log.set_level(spdlog::level::debug);
- m_Gc.AddGcContributor(this);
m_Gc.AddGcStorage(this);
m_Gc.AddGcReferencer(*this);
m_Gc.AddGcReferenceLocker(*this);
@@ -3419,7 +3357,6 @@ ProjectStore::~ProjectStore()
m_Gc.RemoveGcReferenceLocker(*this);
m_Gc.RemoveGcReferencer(*this);
m_Gc.RemoveGcStorage(this);
- m_Gc.RemoveGcContributor(this);
}
std::filesystem::path
@@ -3521,145 +3458,6 @@ ProjectStore::ScrubStorage(ScrubContext& Ctx)
}
}
-void
-ProjectStore::GatherReferences(GcContext& GcCtx)
-{
- ZEN_TRACE_CPU("Store::GatherReferences");
-
- size_t ProjectCount = 0;
- size_t ExpiredProjectCount = 0;
- Stopwatch Timer;
- const auto Guard = MakeGuard([&] {
- ZEN_DEBUG("gathered references from '{}' in {}, found {} active projects and {} expired projects",
- m_ProjectBasePath.string(),
- NiceTimeSpanMs(Timer.GetElapsedTimeMs()),
- ProjectCount,
- ExpiredProjectCount);
- });
-
- DiscoverProjects();
-
- std::vector<Ref<Project>> Projects;
- {
- RwLock::SharedLockScope Lock(m_ProjectsLock);
- Projects.reserve(m_Projects.size());
-
- for (auto& Kv : m_Projects)
- {
- if (Kv.second->IsExpired(GcCtx.ProjectStoreExpireTime()))
- {
- ExpiredProjectCount++;
- continue;
- }
- Projects.push_back(Kv.second);
- }
- }
- ProjectCount = Projects.size();
- for (const Ref<Project>& Project : Projects)
- {
- Project->GatherReferences(GcCtx);
- }
-}
-
-void
-ProjectStore::CollectGarbage(GcContext& GcCtx)
-{
- ZEN_TRACE_CPU("Store::CollectGarbage");
-
- size_t ProjectCount = 0;
- size_t ExpiredProjectCount = 0;
-
- Stopwatch Timer;
- const auto Guard = MakeGuard([&] {
- ZEN_DEBUG("garbage collect from '{}' DONE after {}, found {} active projects and {} expired projects",
- m_ProjectBasePath.string(),
- NiceTimeSpanMs(Timer.GetElapsedTimeMs()),
- ProjectCount,
- ExpiredProjectCount);
- });
- std::vector<Ref<Project>> ExpiredProjects;
- std::vector<Ref<Project>> Projects;
-
- {
- RwLock::SharedLockScope Lock(m_ProjectsLock);
- for (auto& Kv : m_Projects)
- {
- if (Kv.second->IsExpired(GcCtx.ProjectStoreExpireTime()))
- {
- ExpiredProjects.push_back(Kv.second);
- ExpiredProjectCount++;
- continue;
- }
- Projects.push_back(Kv.second);
- ProjectCount++;
- }
- }
-
- if (!GcCtx.IsDeletionMode())
- {
- ZEN_DEBUG("garbage collect DISABLED, for '{}' ", m_ProjectBasePath.string());
- return;
- }
-
- for (const Ref<Project>& Project : Projects)
- {
- std::vector<std::string> ExpiredOplogs;
- {
- Project->IterateOplogs([&GcCtx, &Project, &ExpiredOplogs](const RwLock::SharedLockScope&, ProjectStore::Oplog& Oplog) {
- if (Project->IsExpired(GcCtx.ProjectStoreExpireTime(), Oplog))
- {
- ExpiredOplogs.push_back(Oplog.OplogId());
- }
- });
- }
- for (const std::string& OplogId : ExpiredOplogs)
- {
- ZEN_DEBUG("ProjectStore::CollectGarbage garbage collected oplog '{}' in project '{}'. Removing storage on disk",
- OplogId,
- Project->Identifier);
- (void)Project->DeleteOplog(OplogId);
- }
- Project->Flush();
- }
-
- if (ExpiredProjects.empty())
- {
- ZEN_DEBUG("garbage collect for '{}', no expired projects found", m_ProjectBasePath.string());
- return;
- }
-
- for (const Ref<Project>& Project : ExpiredProjects)
- {
- std::filesystem::path PathToRemove;
- std::string ProjectId;
- {
- if (!Project->IsExpired(GcCtx.ProjectStoreExpireTime()))
- {
- ZEN_DEBUG("ProjectStore::CollectGarbage skipped garbage collect of project '{}'. Project no longer expired.", ProjectId);
- continue;
- }
-
- RwLock::ExclusiveLockScope _(m_ProjectsLock);
- bool Success = Project->PrepareForDelete(PathToRemove);
- if (!Success)
- {
- ZEN_DEBUG("ProjectStore::CollectGarbage skipped garbage collect of project '{}'. Project folder is locked.", ProjectId);
- continue;
- }
- m_Projects.erase(Project->Identifier);
- ProjectId = Project->Identifier;
- }
-
- ZEN_DEBUG("ProjectStore::CollectGarbage garbage collected project '{}'. Removing storage on disk", ProjectId);
- if (PathToRemove.empty())
- {
- continue;
- }
-
- DeleteDirectories(PathToRemove);
- }
-}
-
GcStorageSize
ProjectStore::StorageSize() const
{
@@ -6079,90 +5877,6 @@ TEST_CASE("project.store.gc")
}
}
- SUBCASE("v1")
- {
- {
- GcContext GcCtx(GcClock::Now() - std::chrono::hours(24), GcClock::Now() - std::chrono::hours(24));
- ProjectStore.GatherReferences(GcCtx);
- size_t RefCount = 0;
- GcCtx.IterateCids([&RefCount](const IoHash&) { RefCount++; });
- CHECK(RefCount == 21);
- ProjectStore.CollectGarbage(GcCtx);
- CHECK(ProjectStore.OpenProject("proj1"sv));
- CHECK(ProjectStore.OpenProject("proj2"sv));
- }
-
- {
- GcContext GcCtx(GcClock::Now() + std::chrono::hours(24), GcClock::Now() + std::chrono::hours(24));
- ProjectStore.GatherReferences(GcCtx);
- size_t RefCount = 0;
- GcCtx.IterateCids([&RefCount](const IoHash&) { RefCount++; });
- CHECK(RefCount == 21);
- ProjectStore.CollectGarbage(GcCtx);
- CHECK(ProjectStore.OpenProject("proj1"sv));
- CHECK(ProjectStore.OpenProject("proj2"sv));
- }
-
- std::filesystem::remove(Project1FilePath);
-
- {
- GcContext GcCtx(GcClock::Now() - std::chrono::hours(24), GcClock::Now() - std::chrono::hours(24));
- ProjectStore.GatherReferences(GcCtx);
- size_t RefCount = 0;
- GcCtx.IterateCids([&RefCount](const IoHash&) { RefCount++; });
- CHECK(RefCount == 21);
- ProjectStore.CollectGarbage(GcCtx);
- CHECK(ProjectStore.OpenProject("proj1"sv));
- CHECK(ProjectStore.OpenProject("proj2"sv));
- }
-
- {
- GcContext GcCtx(GcClock::Now() + std::chrono::hours(24), GcClock::Now() + std::chrono::hours(24));
- ProjectStore.GatherReferences(GcCtx);
- size_t RefCount = 0;
- GcCtx.IterateCids([&RefCount](const IoHash&) { RefCount++; });
- CHECK(RefCount == 14);
- ProjectStore.CollectGarbage(GcCtx);
- CHECK(!ProjectStore.OpenProject("proj1"sv));
- CHECK(ProjectStore.OpenProject("proj2"sv));
- }
-
- std::filesystem::remove(Project2Oplog1Path);
- {
- GcContext GcCtx(GcClock::Now() - std::chrono::hours(24), GcClock::Now() - std::chrono::hours(24));
- ProjectStore.GatherReferences(GcCtx);
- size_t RefCount = 0;
- GcCtx.IterateCids([&RefCount](const IoHash&) { RefCount++; });
- CHECK(RefCount == 14);
- ProjectStore.CollectGarbage(GcCtx);
- CHECK(!ProjectStore.OpenProject("proj1"sv));
- CHECK(ProjectStore.OpenProject("proj2"sv));
- }
-
- {
- GcContext GcCtx(GcClock::Now() + std::chrono::hours(24), GcClock::Now() + std::chrono::hours(24));
- ProjectStore.GatherReferences(GcCtx);
- size_t RefCount = 0;
- GcCtx.IterateCids([&RefCount](const IoHash&) { RefCount++; });
- CHECK(RefCount == 7);
- ProjectStore.CollectGarbage(GcCtx);
- CHECK(!ProjectStore.OpenProject("proj1"sv));
- CHECK(ProjectStore.OpenProject("proj2"sv));
- }
-
- std::filesystem::remove(Project2FilePath);
- {
- GcContext GcCtx(GcClock::Now() + std::chrono::hours(24), GcClock::Now() + std::chrono::hours(24));
- ProjectStore.GatherReferences(GcCtx);
- size_t RefCount = 0;
- GcCtx.IterateCids([&RefCount](const IoHash&) { RefCount++; });
- CHECK(RefCount == 0);
- ProjectStore.CollectGarbage(GcCtx);
- CHECK(!ProjectStore.OpenProject("proj1"sv));
- CHECK(!ProjectStore.OpenProject("proj2"sv));
- }
- }
-
SUBCASE("v2")
{
{
diff --git a/src/zenserver/projectstore/projectstore.h b/src/zenserver/projectstore/projectstore.h
index 2552f657f..0a5e71da4 100644
--- a/src/zenserver/projectstore/projectstore.h
+++ b/src/zenserver/projectstore/projectstore.h
@@ -58,7 +58,7 @@ static_assert(IsPow2(sizeof(OplogEntry)));
package data split into separate chunks for bulk data, exports and header
information.
*/
-class ProjectStore : public RefCounted, public GcStorage, public GcContributor, public GcReferencer, public GcReferenceLocker
+class ProjectStore : public RefCounted, public GcStorage, public GcReferencer, public GcReferenceLocker
{
struct OplogStorage;
@@ -145,7 +145,6 @@ public:
LoggerRef Log() { return m_OuterProject->Log(); }
void Flush();
void ScrubStorage(ScrubContext& Ctx);
- void GatherReferences(GcContext& GcCtx);
static uint64_t TotalSize(const std::filesystem::path& BasePath);
uint64_t TotalSize() const;
@@ -298,7 +297,6 @@ public:
void Flush();
void ScrubStorage(ScrubContext& Ctx);
LoggerRef Log() const;
- void GatherReferences(GcContext& GcCtx);
static uint64_t TotalSize(const std::filesystem::path& BasePath);
uint64_t TotalSize() const;
bool PrepareForDelete(std::filesystem::path& OutDeletePath);
@@ -374,9 +372,7 @@ public:
LoggerRef Log() { return m_Log; }
const std::filesystem::path& BasePath() const { return m_ProjectBasePath; }
- virtual void GatherReferences(GcContext& GcCtx) override;
virtual void ScrubStorage(ScrubContext& Ctx) override;
- virtual void CollectGarbage(GcContext& GcCtx) override;
virtual GcStorageSize StorageSize() const override;
virtual std::string GetGcName(GcCtx& Ctx) override;
diff --git a/src/zenserver/zenserver.cpp b/src/zenserver/zenserver.cpp
index 8d8da29b5..124e9ff5f 100644
--- a/src/zenserver/zenserver.cpp
+++ b/src/zenserver/zenserver.cpp
@@ -313,7 +313,7 @@ ZenServer::Initialize(const ZenServerOptions& ServerOptions, ZenServerState::Zen
.DiskSizeSoftLimit = ServerOptions.GcConfig.DiskSizeSoftLimit,
.MinimumFreeDiskSpaceToAllowWrites = ServerOptions.GcConfig.MinimumFreeDiskSpaceToAllowWrites,
.LightweightInterval = std::chrono::seconds(ServerOptions.GcConfig.LightweightIntervalSeconds),
- .UseGCVersion = ServerOptions.GcConfig.UseGCV2 ? GcVersion::kV2 : GcVersion::kV1,
+ .UseGCVersion = ServerOptions.GcConfig.UseGCV2 ? GcVersion::kV2 : GcVersion::kV1_Deprecated,
.CompactBlockUsageThresholdPercent = ServerOptions.GcConfig.CompactBlockUsageThresholdPercent,
.Verbose = ServerOptions.GcConfig.Verbose,
.SingleThreaded = ServerOptions.GcConfig.SingleThreaded,