aboutsummaryrefslogtreecommitdiff
path: root/zenstore/compactcas.h
diff options
context:
space:
mode:
Diffstat (limited to 'zenstore/compactcas.h')
-rw-r--r--zenstore/compactcas.h85
1 files changed, 11 insertions, 74 deletions
diff --git a/zenstore/compactcas.h b/zenstore/compactcas.h
index 398218cd0..42f4b3f8f 100644
--- a/zenstore/compactcas.h
+++ b/zenstore/compactcas.h
@@ -3,6 +3,7 @@
#pragma once
#include <zencore/zencore.h>
+#include <zenstore/blockstore.h>
#include <zenstore/cas.h>
#include <zenstore/caslog.h>
#include <zenstore/gc.h>
@@ -19,79 +20,17 @@ namespace zen {
//////////////////////////////////////////////////////////////////////////
-struct CasLocation
-{
- uint32_t BlockIndex;
- uint64_t Offset;
- uint64_t Size;
-};
-
#pragma pack(push)
#pragma pack(1)
-struct CasDiskLocation
-{
- constexpr static uint32_t MaxBlockIndexBits = 20;
- constexpr static uint32_t MaxOffsetBits = 28;
- constexpr static uint32_t MaxBlockIndex = (1ul << CasDiskLocation::MaxBlockIndexBits) - 1ul;
- constexpr static uint32_t MaxOffset = (1ul << CasDiskLocation::MaxOffsetBits) - 1ul;
-
- CasDiskLocation(const CasLocation& Location, uint64_t OffsetAlignement)
- {
- Init(Location.BlockIndex, Location.Offset / OffsetAlignement, Location.Size);
- }
-
- CasDiskLocation() = default;
-
- inline CasLocation Get(uint64_t OffsetAlignement) const
- {
- uint64_t PackedOffset = 0;
- memcpy(&PackedOffset, &m_Offset, sizeof m_Offset);
- return {.BlockIndex = static_cast<std::uint32_t>(PackedOffset >> MaxOffsetBits),
- .Offset = (PackedOffset & MaxOffset) * OffsetAlignement,
- .Size = GetSize()};
- }
-
- inline uint32_t GetBlockIndex() const
- {
- uint64_t PackedOffset = 0;
- memcpy(&PackedOffset, &m_Offset, sizeof m_Offset);
- return static_cast<std::uint32_t>(PackedOffset >> MaxOffsetBits);
- }
-
- inline uint64_t GetOffset() const
- {
- uint64_t PackedOffset = 0;
- memcpy(&PackedOffset, &m_Offset, sizeof m_Offset);
- return PackedOffset & MaxOffset;
- }
-
- inline uint64_t GetSize() const { return m_Size; }
-
-private:
- inline void Init(uint32_t BlockIndex, uint64_t Offset, uint64_t Size)
- {
- ZEN_ASSERT(BlockIndex <= MaxBlockIndex);
- ZEN_ASSERT(Offset <= MaxOffset);
- ZEN_ASSERT(Size <= std::numeric_limits<std::uint32_t>::max());
-
- m_Size = static_cast<uint32_t>(Size);
- uint64_t PackedOffset = (static_cast<uint64_t>(BlockIndex) << MaxOffsetBits) + Offset;
- memcpy(&m_Offset[0], &PackedOffset, sizeof m_Offset);
- }
-
- uint32_t m_Size;
- uint8_t m_Offset[6];
-};
-
struct CasDiskIndexEntry
{
static const uint8_t kTombstone = 0x01;
- IoHash Key;
- CasDiskLocation Location;
- ZenContentType ContentType = ZenContentType::kUnknownContentType;
- uint8_t Flags = 0;
+ IoHash Key;
+ BlockStoreDiskLocation Location;
+ ZenContentType ContentType = ZenContentType::kUnknownContentType;
+ uint8_t Flags = 0;
};
#pragma pack(pop)
@@ -123,8 +62,6 @@ struct CasContainerStrategy final : public GcStorage
virtual GcStorageSize StorageSize() const override { return {.DiskSize = m_TotalSize.load(std::memory_order::relaxed)}; }
private:
- struct ChunkBlock;
-
void OpenContainer(bool IsNewStore);
spdlog::logger& Log() { return m_Log; }
@@ -137,13 +74,13 @@ private:
std::string m_ContainerBaseName;
std::filesystem::path m_BlocksBasePath;
- RwLock m_LocationMapLock;
- std::unordered_map<IoHash, CasDiskLocation, IoHash::Hasher> m_LocationMap;
- std::unordered_map<uint32_t, std::shared_ptr<ChunkBlock>> m_ChunkBlocks;
+ RwLock m_LocationMapLock;
+ std::unordered_map<IoHash, BlockStoreDiskLocation, IoHash::Hasher> m_LocationMap;
+ std::unordered_map<uint32_t, std::shared_ptr<BlockStoreFile>> m_ChunkBlocks;
- RwLock m_InsertLock; // used to serialize inserts
- std::weak_ptr<ChunkBlock> m_WriteBlock;
- std::uint64_t m_CurrentInsertOffset{};
+ RwLock m_InsertLock; // used to serialize inserts
+ std::weak_ptr<BlockStoreFile> m_WriteBlock;
+ std::uint64_t m_CurrentInsertOffset{};
std::atomic_uint32_t m_WriteBlockIndex{};
std::atomic_uint64_t m_TotalSize{};