aboutsummaryrefslogtreecommitdiff
path: root/zenstore/compactcas.h
diff options
context:
space:
mode:
Diffstat (limited to 'zenstore/compactcas.h')
-rw-r--r--zenstore/compactcas.h56
1 files changed, 52 insertions, 4 deletions
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;