diff options
| author | Per Larsson <[email protected]> | 2021-12-05 19:04:39 +0100 |
|---|---|---|
| committer | Per Larsson <[email protected]> | 2021-12-05 19:04:39 +0100 |
| commit | 69c33063aaa85abf153bea036c58937067a80cd5 (patch) | |
| tree | 6c13f9c8095e727213cf754d274694af05afb3ce /zenstore/compactcas.cpp | |
| parent | Added simple GC interval scheduling. (diff) | |
| download | zen-69c33063aaa85abf153bea036c58937067a80cd5.tar.xz zen-69c33063aaa85abf153bea036c58937067a80cd5.zip | |
Check available disk space before GC.
Diffstat (limited to 'zenstore/compactcas.cpp')
| -rw-r--r-- | zenstore/compactcas.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp index fd4b9441e..eeaec6f36 100644 --- a/zenstore/compactcas.cpp +++ b/zenstore/compactcas.cpp @@ -257,6 +257,10 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx) { namespace fs = std::filesystem; + // A naive garbage collection implementation that just copies evicted chunks + // into a new container file. We probably need to partition the container file + // into several parts to prevent needing to keep the entire container file during GC. + ZEN_INFO("collecting garbage from '{}'", m_Config.RootDirectory / m_ContainerBaseName); RwLock::ExclusiveLockScope _(m_LocationMapLock); @@ -297,6 +301,23 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx) NewTotalSize += Loc.GetSize(); } + std::error_code Error; + DiskSpace Space = DiskSpaceInfo(m_Config.RootDirectory, Error); + if (Error) + { + ZEN_ERROR("get disk space FAILED, reason '{}'", Error.message()); + return; + } + + if (Space.Free < NewTotalSize + (64 << 20)) + { + ZEN_INFO("garbage collect from '{}' FAILED, required disk space {}, free {}", + m_Config.RootDirectory / m_ContainerBaseName, + NiceBytes(NewTotalSize), + NiceBytes(Space.Free)); + return; + } + const bool GcEnabled = GcCtx.IsDeletionMode() && GcCtx.IsContainerGcEnabled(); if (GcEnabled) |