diff options
| author | Dan Engelbrecht <[email protected]> | 2023-11-24 13:26:51 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-11-24 13:26:51 +0100 |
| commit | 254d2f89c110fc5f14e658505559a7e7534a984d (patch) | |
| tree | 511e8dcbae633ae4ccaea20f29b9b04bc41ea875 /src/zenstore/include | |
| parent | fix truncation of sentry hostname (diff) | |
| download | zen-254d2f89c110fc5f14e658505559a7e7534a984d.tar.xz zen-254d2f89c110fc5f14e658505559a7e7534a984d.zip | |
Add GC Cancel/Stop (#568)
- GcScheduler will now cancel any running GC when it shuts down.
- Old GC is rather limited in *when* it reacts to cancel of GC. GCv2 is more responsive.
Diffstat (limited to 'src/zenstore/include')
| -rw-r--r-- | src/zenstore/include/zenstore/blockstore.h | 12 | ||||
| -rw-r--r-- | src/zenstore/include/zenstore/gc.h | 9 |
2 files changed, 16 insertions, 5 deletions
diff --git a/src/zenstore/include/zenstore/blockstore.h b/src/zenstore/include/zenstore/blockstore.h index 1429a6b02..b748fc8f6 100644 --- a/src/zenstore/include/zenstore/blockstore.h +++ b/src/zenstore/include/zenstore/blockstore.h @@ -126,7 +126,7 @@ public: typedef std::vector<size_t> ChunkIndexArray; typedef std::function<void(const MovedChunksArray& MovedChunks, const ChunkIndexArray& RemovedChunks)> ReclaimCallback; - typedef std::function<void(const MovedChunksArray& MovedChunks, uint64_t FreedDiskSpace)> CompactCallback; + typedef std::function<bool(const MovedChunksArray& MovedChunks, uint64_t FreedDiskSpace)> CompactCallback; typedef std::function<uint64_t()> ClaimDiskReserveCallback; typedef std::function<void(size_t ChunkIndex, const void* Data, uint64_t Size)> IterateChunksSmallSizeCallback; typedef std::function<void(size_t ChunkIndex, BlockStoreFile& File, uint64_t Offset, uint64_t Size)> IterateChunksLargeSizeCallback; @@ -163,7 +163,7 @@ public: void CompactBlocks( const BlockStoreCompactState& CompactState, uint64_t PayloadAlignment, - const CompactCallback& ChangeCallback = [](const MovedChunksArray&, uint64_t) {}, + const CompactCallback& ChangeCallback = [](const MovedChunksArray&, uint64_t) { return true; }, const ClaimDiskReserveCallback& DiskReserveCallback = []() { return 0; }); static const char* GetBlockFileExtension(); @@ -230,14 +230,18 @@ public: const BlockStoreLocation& GetLocation(size_t Index) const { return m_ChunkLocations[Index]; } - void IterateBlocks(std::function<void(uint32_t BlockIndex, + void IterateBlocks(std::function<bool(uint32_t BlockIndex, const std::vector<size_t>& KeepChunkIndexes, const std::vector<BlockStoreLocation>& ChunkLocations)> Callback) const { for (auto It : m_BlockIndexToChunkMapIndex) { size_t ChunkMapIndex = It.second; - Callback(It.first, m_KeepChunks[ChunkMapIndex], m_ChunkLocations); + bool Continue = Callback(It.first, m_KeepChunks[ChunkMapIndex], m_ChunkLocations); + if (!Continue) + { + break; + } } } diff --git a/src/zenstore/include/zenstore/gc.h b/src/zenstore/include/zenstore/gc.h index f50af8006..486dca3c6 100644 --- a/src/zenstore/include/zenstore/gc.h +++ b/src/zenstore/include/zenstore/gc.h @@ -121,6 +121,8 @@ struct GcResult std::chrono::milliseconds WriteBlockMS = {}; std::chrono::milliseconds ElapsedMS = {}; + + bool WasCancelled = false; }; class CbObjectWriter; @@ -129,7 +131,8 @@ void WriteGCResult(CbObjectWriter& Writer, const GcResult& Result, bool HumanRea struct GcCtx { - const GcSettings Settings; + const GcSettings Settings; + std::atomic_bool& IsCancelledFlag; }; typedef tsl::robin_set<IoHash> HashSet; @@ -341,6 +344,7 @@ public: void RemoveGcReferenceStore(GcReferenceStore& ReferenceStore); GcResult CollectGarbage(const GcSettings& Settings); + void SetCancelGC(bool CancelFlag); //////// End GC V2 @@ -359,6 +363,7 @@ public: void SetDiskWriteBlocker(const DiskWriteBlocker* Monitor) { m_DiskWriteBlocker = Monitor; } private: + bool CheckGCCancel() { return m_CancelGC.load(); } LoggerRef Log() { return m_Log; } LoggerRef m_Log; mutable RwLock m_Lock; @@ -369,6 +374,8 @@ private: std::vector<GcReferencer*> m_GcReferencers; std::vector<GcReferenceStore*> m_GcReferenceStores; + + std::atomic_bool m_CancelGC{false}; }; enum class GcSchedulerStatus : uint32_t |