diff options
| author | Stefan Boberg <[email protected]> | 2023-05-02 10:01:47 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-05-02 10:01:47 +0200 |
| commit | 075d17f8ada47e990fe94606c3d21df409223465 (patch) | |
| tree | e50549b766a2f3c354798a54ff73404217b4c9af /src/zenstore/compactcas.h | |
| parent | fix: bundle shouldn't append content zip to zen (diff) | |
| download | zen-075d17f8ada47e990fe94606c3d21df409223465.tar.xz zen-075d17f8ada47e990fe94606c3d21df409223465.zip | |
moved source directories into `/src` (#264)
* moved source directories into `/src`
* updated bundle.lua for new `src` path
* moved some docs, icon
* removed old test trees
Diffstat (limited to 'src/zenstore/compactcas.h')
| -rw-r--r-- | src/zenstore/compactcas.h | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/zenstore/compactcas.h b/src/zenstore/compactcas.h new file mode 100644 index 000000000..b0c6699eb --- /dev/null +++ b/src/zenstore/compactcas.h @@ -0,0 +1,95 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#pragma once + +#include <zencore/zencore.h> +#include <zenstore/blockstore.h> +#include <zenstore/caslog.h> +#include <zenstore/gc.h> + +#include "cas.h" + +#include <atomic> +#include <limits> +#include <unordered_map> + +namespace spdlog { +class logger; +} + +namespace zen { + +////////////////////////////////////////////////////////////////////////// + +#pragma pack(push) +#pragma pack(1) + +struct CasDiskIndexEntry +{ + static const uint8_t kTombstone = 0x01; + + IoHash Key; + BlockStoreDiskLocation Location; + ZenContentType ContentType = ZenContentType::kUnknownContentType; + uint8_t Flags = 0; +}; + +#pragma pack(pop) + +static_assert(sizeof(CasDiskIndexEntry) == 32); + +/** This implements a storage strategy for small CAS values + * + * New chunks are simply appended to a small object file, and an index is + * maintained to allow chunks to be looked up within the active small object + * files + * + */ + +struct CasContainerStrategy final : public GcStorage +{ + CasContainerStrategy(GcManager& Gc); + ~CasContainerStrategy(); + + CasStore::InsertResult InsertChunk(IoBuffer Chunk, const IoHash& ChunkHash); + IoBuffer FindChunk(const IoHash& ChunkHash); + bool HaveChunk(const IoHash& ChunkHash); + void FilterChunks(HashKeySet& InOutChunks); + void Initialize(const std::filesystem::path& RootDirectory, + 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; + virtual GcStorageSize StorageSize() const override { return {.DiskSize = m_BlockStore.TotalSize()}; } + +private: + CasStore::InsertResult InsertChunk(const void* ChunkData, size_t ChunkSize, const IoHash& ChunkHash); + void MakeIndexSnapshot(); + uint64_t ReadIndexFile(); + uint64_t ReadLog(uint64_t SkipEntryCount); + void OpenContainer(bool IsNewStore); + + spdlog::logger& Log() { return m_Log; } + + std::filesystem::path m_RootDirectory; + spdlog::logger& m_Log; + uint64_t m_PayloadAlignment = 1u << 4; + uint64_t m_MaxBlockSize = 1u << 28; + bool m_IsInitialized = false; + TCasLogFile<CasDiskIndexEntry> m_CasLog; + uint64_t m_LogFlushPosition = 0; + std::string m_ContainerBaseName; + std::filesystem::path m_BlocksBasePath; + BlockStore m_BlockStore; + + RwLock m_LocationMapLock; + typedef std::unordered_map<IoHash, BlockStoreDiskLocation, IoHash::Hasher> LocationMap_t; + LocationMap_t m_LocationMap; +}; + +void compactcas_forcelink(); + +} // namespace zen |