aboutsummaryrefslogtreecommitdiff
path: root/zenstore/include
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-04-30 01:29:24 +0200
committerDan Engelbrecht <[email protected]>2022-04-30 09:41:24 +0200
commitde6057de814a4dc16654bdda84f697476b2ebef5 (patch)
tree7f5fac98b79a68e98b3effc91162379438682c8d /zenstore/include
parentMerge remote-tracking branch 'origin/main' into de/cache-with-block-store (diff)
downloadzen-de6057de814a4dc16654bdda84f697476b2ebef5.tar.xz
zen-de6057de814a4dc16654bdda84f697476b2ebef5.zip
first pass at generic block store with gc
Diffstat (limited to 'zenstore/include')
-rw-r--r--zenstore/include/zenstore/blockstore.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/zenstore/include/zenstore/blockstore.h b/zenstore/include/zenstore/blockstore.h
index 424db461a..4dd6e5289 100644
--- a/zenstore/include/zenstore/blockstore.h
+++ b/zenstore/include/zenstore/blockstore.h
@@ -15,8 +15,14 @@ struct BlockStoreLocation
uint32_t BlockIndex;
uint64_t Offset;
uint64_t Size;
+
+ inline auto operator<=>(const BlockStoreLocation& Rhs) const = default;
};
+constexpr BlockStoreLocation InvalidBlockStoreLocation{.BlockIndex = 0xfffffffful,
+ .Offset = 0xffffffffffffffffull,
+ .Size = 0xffffffffffffffffull};
+
#pragma pack(push)
#pragma pack(1)
@@ -99,6 +105,41 @@ private:
BasicFile m_File;
};
+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);
+ 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>&) {});
+
+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{};
+
+ uint64_t m_MaxBlockSize = 1u << 28;
+ uint64_t m_MaxBlockCount = BlockStoreDiskLocation::MaxBlockIndex + 1;
+ std::filesystem::path m_BlocksBasePath;
+ std::atomic_uint64_t m_TotalSize{};
+};
+
void blockstore_forcelink();
} // namespace zen