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, 12 insertions, 44 deletions
diff --git a/zenstore/compactcas.h b/zenstore/compactcas.h
index 204482534..35f118f34 100644
--- a/zenstore/compactcas.h
+++ b/zenstore/compactcas.h
@@ -3,21 +3,10 @@
#pragma once
#include <zencore/zencore.h>
-
-#include <zencore/iobuffer.h>
-#include <zencore/iohash.h>
-#include <zencore/string.h>
-#include <zencore/thread.h>
-#include <zencore/uid.h>
#include <zenstore/basicfile.h>
-#include <zenstore/cas.h>
#include <zenstore/caslog.h>
#include <zenstore/gc.h>
-#if ZEN_PLATFORM_WINDOWS
-# include <zencore/windows.h>
-#endif
-
#include <atomic>
#include <unordered_map>
@@ -34,34 +23,9 @@ namespace zen {
struct CasDiskLocation
{
- CasDiskLocation(uint64_t InOffset, uint64_t InSize)
- {
- ZEN_ASSERT(InOffset <= 0xff'ffff'ffff);
- ZEN_ASSERT(InSize <= 0xff'ffff'ffff);
-
- memcpy(&m_Offset[0], &InOffset, sizeof m_Offset);
- memcpy(&m_Size[0], &InSize, sizeof m_Size);
- }
-
- CasDiskLocation() = default;
-
- inline uint64_t GetOffset() const
- {
- uint64_t Offset = 0;
- memcpy(&Offset, &m_Offset, sizeof m_Offset);
- return Offset;
- }
-
- inline uint64_t GetSize() const
- {
- uint64_t Size = 0;
- memcpy(&Size, &m_Size, sizeof m_Size);
- return Size;
- }
-
-private:
- uint8_t m_Offset[5];
- uint8_t m_Size[5];
+ uint16_t BlockIndex;
+ uint32_t Offset;
+ uint32_t Size;
};
struct CasDiskIndexEntry
@@ -96,7 +60,7 @@ struct CasContainerStrategy final : public GcStorage
IoBuffer FindChunk(const IoHash& ChunkHash);
bool HaveChunk(const IoHash& ChunkHash);
void FilterChunks(CasChunkSet& InOutChunks);
- void Initialize(const std::string_view ContainerBaseName, uint64_t Alignment, bool IsNewStore);
+ void Initialize(const std::string_view ContainerBaseName, uint32_t MaxBlockSize, uint64_t Alignment, bool IsNewStore);
void Flush();
void Scrub(ScrubContext& Ctx);
virtual void CollectGarbage(GcContext& GcCtx) override;
@@ -109,16 +73,20 @@ private:
const CasStoreConfiguration& m_Config;
spdlog::logger& m_Log;
uint64_t m_PayloadAlignment = 1 << 4;
+ uint64_t m_MaxBlockSize = 1L << 30; // 1 Gb
bool m_IsInitialized = false;
- BasicFile m_SmallObjectFile;
TCasLogFile<CasDiskIndexEntry> m_CasLog;
std::string m_ContainerBaseName;
RwLock m_LocationMapLock;
std::unordered_map<IoHash, CasDiskLocation, IoHash::Hasher> m_LocationMap;
- RwLock m_InsertLock; // used to serialize inserts
- std::atomic_uint64_t m_CurrentInsertOffset{};
- std::atomic_uint64_t m_TotalSize{};
+
+ RwLock m_InsertLock; // used to serialize inserts
+ std::unordered_map<uint16_t, std::shared_ptr<BasicFile>> m_OpenBlocks;
+ std::weak_ptr<BasicFile> m_CurrentBlock;
+ uint16_t m_CurrentBlockIndex = 0;
+ std::atomic_uint32_t m_CurrentInsertOffset{};
+ std::atomic_uint64_t m_TotalSize{};
void MakeIndexSnapshot();
};