diff options
| author | Dan Engelbrecht <[email protected]> | 2022-03-17 16:48:33 +0100 |
|---|---|---|
| committer | Dan Engelbrecht <[email protected]> | 2022-03-31 11:28:32 +0200 |
| commit | 4e5d5b70e517095c471908c378a49e753674c68b (patch) | |
| tree | 582a8adc2b5af9fe6269b041277103819d35e9b1 | |
| parent | Add header to cas index file (diff) | |
| download | zen-4e5d5b70e517095c471908c378a49e753674c68b.tar.xz zen-4e5d5b70e517095c471908c378a49e753674c68b.zip | |
WIP - bit assignement for CasDiskLocation
| -rw-r--r-- | zenstore/compactcas.cpp | 17 | ||||
| -rw-r--r-- | zenstore/compactcas.h | 56 |
2 files changed, 59 insertions, 14 deletions
diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp index 2dcc9aa7c..27f0d0e29 100644 --- a/zenstore/compactcas.cpp +++ b/zenstore/compactcas.cpp @@ -25,10 +25,10 @@ namespace zen { struct CasDiskIndexHeader { - static constexpr uint32_t ExpectedMagic = 0x75696478; // 'uidx'; - static constexpr uint32_t CurrentVersion = 1; - uint32_t Magic = ExpectedMagic; - uint32_t Version = CurrentVersion; + static constexpr uint32_t ExpectedMagic = 0x75696478; // 'uidx'; + static constexpr uint32_t CurrentVersion = 1; + uint32_t Magic = ExpectedMagic; + uint32_t Version = CurrentVersion; uint32_t PayloadAlignement; uint32_t Reserved0 = 0; uint64_t MaxBlockSize; @@ -1004,11 +1004,8 @@ CasContainerStrategy::OpenContainer(bool IsNewStore) uint64_t ExpectedEntryCount = (Size - sizeof(sizeof(CasDiskIndexHeader))) / sizeof(CasDiskIndexEntry); CasDiskIndexHeader Header; SmallObjectIndex.Read(&Header, sizeof(Header), 0); - if (Header.Magic == CasDiskIndexHeader::ExpectedMagic && - Header.Version == CasDiskIndexHeader::CurrentVersion && - Header.MaxBlockSize > 0 && - Header.PayloadAlignement > 0 && - Header.EntryCount == ExpectedEntryCount) + if (Header.Magic == CasDiskIndexHeader::ExpectedMagic && Header.Version == CasDiskIndexHeader::CurrentVersion && + Header.MaxBlockSize > 0 && Header.PayloadAlignement > 0 && Header.EntryCount == ExpectedEntryCount) { std::vector<CasDiskIndexEntry> Entries{Header.EntryCount}; SmallObjectIndex.Read(Entries.data(), Header.EntryCount * sizeof(CasDiskIndexEntry), sizeof(CasDiskIndexHeader)); @@ -1017,7 +1014,7 @@ CasContainerStrategy::OpenContainer(bool IsNewStore) { m_LocationMap[Entry.Key] = Entry.Location; } - m_MaxBlockSize = Header.MaxBlockSize; + m_MaxBlockSize = Header.MaxBlockSize; m_PayloadAlignment = Header.PayloadAlignement; } } diff --git a/zenstore/compactcas.h b/zenstore/compactcas.h index fcb6eec4c..5f58ccab1 100644 --- a/zenstore/compactcas.h +++ b/zenstore/compactcas.h @@ -8,6 +8,7 @@ #include <zenstore/gc.h> #include <atomic> +#include <limits> #include <unordered_map> namespace spdlog { @@ -23,9 +24,56 @@ namespace zen { struct CasDiskLocation { - uint16_t BlockIndex; - uint32_t Offset; + // 20 bits blockindex + // 28 bits offset + // 32 bits size + + CasDiskLocation(uint32_t BlockIndex, uint64_t Offset, uint64_t Size) + { + ZEN_ASSERT(BlockIndex < (1L << 20)); + ZEN_ASSERT(Offset < (1L << 28)); + ZEN_ASSERT(Size <= std::numeric_limits<std::uint32_t>::max()); + + m_Size = static_cast<uint32_t>(Size); + m_BlockIndexLowBits = static_cast<uint16_t>(BlockIndex & 0xffff); + m_OffsetLowBits = static_cast<uint16_t>(Offset & 0xffff); + m_BlockIndexAndOffsetHighBits = static_cast<uint16_t>(((BlockIndex >> 16) & 0xf) | (((Offset >> 16) & 0xfff) << 4)); + } + + CasDiskLocation() = default; + + inline uint32_t GetBlockIndex() const + { + return (static_cast<uint32_t>(m_BlockIndexAndOffsetHighBits & 0xf) << 16) | m_BlockIndexLowBits; + } + inline uint64_t Offset() const { return (static_cast<uint64_t>(m_BlockIndexAndOffsetHighBits & 0xfff0) << 8) | m_OffsetLowBits; } + inline uint64_t Size() const { return m_Size; } + +private: + uint32_t m_Size; + uint16_t m_BlockIndexLowBits; + uint16_t m_OffsetLowBits; + uint16_t m_BlockIndexAndOffsetHighBits; + +#if 0 + // 24 bits blockindex + // 24 bits offset + // 32 bits size + inline uint32_t GetBlockIndex() const + { + return (static_cast<uint32_t>(BlockIndexHighBits) << 16) | BlockIndexLowBits; + } + inline uint32_t Offset() const + { + return (static_cast<uint32_t>(OffsetHighBits) << 16) | OffsetLowBits; + } + uint32_t Size; + uint16_t BlockIndexLowBits; + uint16_t OffsetLowBits; + uint8_t BlockIndexHighBits; + uint8_t OffsetHighBits; +#endif }; struct CasDiskIndexEntry @@ -52,7 +100,7 @@ static_assert(sizeof(CasDiskIndexEntry) == 32); struct CasContainerStrategy final : public GcStorage { - static constexpr uint32_t DefaultMaxBlockSize = 1u << 30; // 1 Gb + static constexpr uint32_t DefaultMaxBlockSize = 1u << 30; // 1 Gb CasContainerStrategy(const CasStoreConfiguration& Config, CasGc& Gc); ~CasContainerStrategy(); @@ -78,7 +126,7 @@ private: spdlog::logger& m_Log; uint64_t m_PayloadAlignment; uint64_t m_MaxBlockSize; - bool m_IsInitialized = false; + bool m_IsInitialized = false; TCasLogFile<CasDiskIndexEntry> m_CasLog; std::string m_ContainerBaseName; |