aboutsummaryrefslogtreecommitdiff
path: root/src/zenstore/include
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2023-05-09 15:11:10 +0200
committerGitHub <[email protected]>2023-05-09 15:11:10 +0200
commit2542797c56b84473395a877376b68fcc77687ea9 (patch)
tree698ebb1e4e6fb33ba9b8be973f8a851b2ee46c83 /src/zenstore/include
parentValidate that entries points inside valid blocks at startup (#280) (diff)
downloadzen-2542797c56b84473395a877376b68fcc77687ea9.tar.xz
zen-2542797c56b84473395a877376b68fcc77687ea9.zip
Low disk space detector (#277)
* - Feature: Disk writes are now blocked early and return an insufficient storage error if free disk space falls below the `--low-diskspace-threshold` value * Never keep an entry in m_ChunkBlocks that points to a nullptr
Diffstat (limited to 'src/zenstore/include')
-rw-r--r--src/zenstore/include/zenstore/gc.h29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/zenstore/include/zenstore/gc.h b/src/zenstore/include/zenstore/gc.h
index e0354b331..fe9857e6a 100644
--- a/src/zenstore/include/zenstore/gc.h
+++ b/src/zenstore/include/zenstore/gc.h
@@ -27,6 +27,7 @@ class HashKeySet;
class GcManager;
class CidStore;
struct IoHash;
+struct DiskSpace;
/** GC clock
*/
@@ -121,6 +122,14 @@ private:
GcManager& m_Gc;
};
+/** Interface for querying if we are running low on disk space, used to deny put/writes to disk
+ */
+class DiskWriteBlocker
+{
+public:
+ virtual bool AreDiskWritesAllowed() const = 0;
+};
+
/** GC orchestrator
*/
class GcManager
@@ -139,6 +148,9 @@ public:
GcStorageSize TotalStorageSize() const;
+ const DiskWriteBlocker* GetDiskWriteBlocker() { return m_DiskWriteBlocker; }
+ void SetDiskWriteBlocker(const DiskWriteBlocker* Monitor) { m_DiskWriteBlocker = Monitor; }
+
#if ZEN_USE_REF_TRACKING
void OnNewCidReferences(std::span<IoHash> Hashes);
void OnCommittedCidReferences(std::span<IoHash> Hashes);
@@ -151,7 +163,8 @@ private:
mutable RwLock m_Lock;
std::vector<GcContributor*> m_GcContribs;
std::vector<GcStorage*> m_GcStorage;
- CidStore* m_CidStore = nullptr;
+ CidStore* m_CidStore = nullptr;
+ const DiskWriteBlocker* m_DiskWriteBlocker = nullptr;
};
enum class GcSchedulerStatus : uint32_t
@@ -167,10 +180,11 @@ struct GcSchedulerConfig
std::chrono::seconds MonitorInterval{30};
std::chrono::seconds Interval{};
std::chrono::seconds MaxCacheDuration{86400};
- bool CollectSmallObjects = true;
- bool Enabled = true;
- uint64_t DiskReserveSize = 1ul << 28;
- uint64_t DiskSizeSoftLimit = 0;
+ bool CollectSmallObjects = true;
+ bool Enabled = true;
+ uint64_t DiskReserveSize = 1ul << 28;
+ uint64_t DiskSizeSoftLimit = 0;
+ uint64_t MinimumFreeDiskSpaceToAllowWrites = 1ul << 28;
};
class DiskUsageWindow
@@ -196,7 +210,7 @@ public:
/**
* GC scheduler
*/
-class GcScheduler
+class GcScheduler : private DiskWriteBlocker
{
public:
GcScheduler(GcManager& GcManager);
@@ -220,6 +234,8 @@ private:
void CollectGarbage(const GcClock::TimePoint& ExpireTime, bool Delete, bool CollectSmallObjects);
GcClock::TimePoint NextGcTime(GcClock::TimePoint CurrentTime);
spdlog::logger& Log() { return m_Log; }
+ virtual bool AreDiskWritesAllowed() const override { return !m_AreDiskWritesBlocked.load(); }
+ void CheckDiskSpace(const DiskSpace& Space);
spdlog::logger& m_Log;
GcManager& m_GcManager;
@@ -232,6 +248,7 @@ private:
std::mutex m_GcMutex;
std::condition_variable m_GcSignal;
std::optional<TriggerParams> m_TriggerParams;
+ std::atomic_bool m_AreDiskWritesBlocked = false;
TCasLogFile<DiskUsageWindow::DiskUsageEntry> m_DiskUsageLog;
DiskUsageWindow m_DiskUsageWindow;