diff options
| author | Dan Engelbrecht <[email protected]> | 2022-05-01 10:17:35 +0200 |
|---|---|---|
| committer | Dan Engelbrecht <[email protected]> | 2022-05-01 10:17:35 +0200 |
| commit | 7dc31ec99aa3fc2f40000258e45d5d6381403ff8 (patch) | |
| tree | 9c5a986c506128405fe63df3acfbdede4c2a2995 /zenstore/include | |
| parent | first pass at generic block store with gc (diff) | |
| download | zen-7dc31ec99aa3fc2f40000258e45d5d6381403ff8.tar.xz zen-7dc31ec99aa3fc2f40000258e45d5d6381403ff8.zip | |
threading issues resolved
Diffstat (limited to 'zenstore/include')
| -rw-r--r-- | zenstore/include/zenstore/blockstore.h | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/zenstore/include/zenstore/blockstore.h b/zenstore/include/zenstore/blockstore.h index 4dd6e5289..084142636 100644 --- a/zenstore/include/zenstore/blockstore.h +++ b/zenstore/include/zenstore/blockstore.h @@ -6,6 +6,8 @@ #include <zencore/zencore.h> #include <zenstore/basicfile.h> +#include <unordered_set> + namespace zen { ////////////////////////////////////////////////////////////////////////// @@ -108,31 +110,47 @@ private: class BlockStore { public: - void Initialize(const std::filesystem::path& BlocksBasePath, - uint64_t MaxBlockSize, - uint64_t MaxBlockCount, - const std::vector<BlockStoreLocation>& KnownLocations); - BlockStoreLocation WriteChunk(const void* Data, uint64_t Size, uint64_t Alignment); + struct ReclaimSnapshotState + { + std::unordered_set<uint32_t> ExcludeBlockIndexes; + size_t BlockCount; + }; + typedef std::function<void(uint32_t BlockIndex, + const std::unordered_map<size_t, BlockStoreLocation>& MovedChunks, + const std::vector<size_t>& RemovedChunks)> + ReclaimCallback; + typedef std::function<void(const BlockStoreLocation& Location)> WriteCompleteCallback; + + void Initialize(const std::filesystem::path& BlocksBasePath, + uint64_t MaxBlockSize, + uint64_t MaxBlockCount, + const std::vector<BlockStoreLocation>& KnownLocations); + void WriteChunk( + const void* Data, + uint64_t Size, + uint64_t Alignment, + WriteCompleteCallback Callback = [](const BlockStoreLocation&) {}); Ref<BlockStoreFile> GetChunkBlock(const BlockStoreLocation& Location); void Flush(); - typedef std::function<void(const std::unordered_map<size_t, BlockStoreLocation>& MovedChunks, const std::vector<size_t> RemovedChunks)> - ReclaimCallback; - - void ReclaimSpace( - const std::vector<BlockStoreLocation>& ChunkLocations, - const std::vector<size_t>& KeepChunkIndexes, - uint64_t PayloadAlignment, - bool DryRun, - const ReclaimCallback& Callback = [](const std::unordered_map<size_t, BlockStoreLocation>&, const std::vector<size_t>&) {}); + ReclaimSnapshotState GetReclaimSnapshotState(); + void ReclaimSpace( + const ReclaimSnapshotState& Snapshot, + const std::vector<BlockStoreLocation>& ChunkLocations, + const std::vector<size_t>& KeepChunkIndexes, + uint64_t PayloadAlignment, + bool DryRun, + const ReclaimCallback& Callback = [](uint32_t, const std::unordered_map<size_t, BlockStoreLocation>&, const std::vector<size_t>&) { + }); private: std::unordered_map<uint32_t, Ref<BlockStoreFile>> m_ChunkBlocks; - RwLock m_InsertLock; // used to serialize inserts - Ref<BlockStoreFile> m_WriteBlock; - std::uint64_t m_CurrentInsertOffset = 0; - std::atomic_uint32_t m_WriteBlockIndex{}; + RwLock m_InsertLock; // used to serialize inserts + Ref<BlockStoreFile> m_WriteBlock; + std::uint64_t m_CurrentInsertOffset = 0; + std::atomic_uint32_t m_WriteBlockIndex{}; + std::vector<uint32_t> m_ActiveWriteBlockIndexes; uint64_t m_MaxBlockSize = 1u << 28; uint64_t m_MaxBlockCount = BlockStoreDiskLocation::MaxBlockIndex + 1; |