diff options
| author | Stefan Boberg <[email protected]> | 2021-09-14 21:40:42 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-14 21:40:42 +0200 |
| commit | 434e8d0001169025cdbf0816d9f96187e37f24f7 (patch) | |
| tree | b717227f663d2b48ea7e0914d67ed36a2171f812 | |
| parent | Changed path for crashpad exe since vcpkg decided to put it somewhere else no... (diff) | |
| download | zen-434e8d0001169025cdbf0816d9f96187e37f24f7.tar.xz zen-434e8d0001169025cdbf0816d9f96187e37f24f7.zip | |
Extended CidStore implementation with some helper functions
| -rw-r--r-- | zenstore/cidstore.cpp | 22 | ||||
| -rw-r--r-- | zenstore/include/zenstore/cidstore.h | 13 |
2 files changed, 31 insertions, 4 deletions
diff --git a/zenstore/cidstore.cpp b/zenstore/cidstore.cpp index 4e5188f1c..391520599 100644 --- a/zenstore/cidstore.cpp +++ b/zenstore/cidstore.cpp @@ -2,6 +2,7 @@ #include "zenstore/cidstore.h" +#include <zencore/compress.h> #include <zencore/filesystem.h> #include <zenstore/CAS.h> #include <zenstore/caslog.h> @@ -27,10 +28,25 @@ struct CidStore::CidState RwLock m_Lock; tsl::robin_map<IoHash, IoHash> m_CidMap; + CasStore::InsertResult AddChunk(CompressedBuffer& ChunkData) + { + IoBuffer Payload = ChunkData.GetCompressed().Flatten().AsIoBuffer(); + IoHash CompressedHash = IoHash::HashBuffer(Payload.Data(), Payload.Size()); + + CasStore::InsertResult Result = m_CasStore.InsertChunk(Payload, CompressedHash); + AddCompressedCid(IoHash::FromBLAKE3(ChunkData.GetRawHash()), CompressedHash); + + return Result; + } + void AddCompressedCid(const IoHash& DecompressedId, const IoHash& Compressed) { RwLock::ExclusiveLockScope _(m_Lock); m_CidMap.insert_or_assign(DecompressedId, Compressed); + // TODO: it's pretty wasteful to log even idempotent updates + // however we can't simply use the boolean returned by insert_or_assign + // since there's not a 1:1 mapping between compressed and uncompressed + // so if we want a last-write-wins policy then we have to log each update m_LogFile.Append({.Uncompressed = DecompressedId, .Compressed = Compressed}); } @@ -87,6 +103,12 @@ CidStore::~CidStore() { } +CasStore::InsertResult +CidStore::AddChunk(CompressedBuffer& ChunkData) +{ + return m_Impl->AddChunk(ChunkData); +} + void CidStore::AddCompressedCid(const IoHash& DecompressedId, const IoHash& Compressed) { diff --git a/zenstore/include/zenstore/cidstore.h b/zenstore/include/zenstore/cidstore.h index 2c2b395a5..62d642ad1 100644 --- a/zenstore/include/zenstore/cidstore.h +++ b/zenstore/include/zenstore/cidstore.h @@ -4,6 +4,7 @@ #include <tsl/robin_map.h> #include <zencore/iohash.h> +#include <zenstore/CAS.h> namespace std::filesystem { class path; @@ -12,6 +13,7 @@ class path; namespace zen { class CasStore; +class CompressedBuffer; class IoBuffer; /** Content Store @@ -29,10 +31,13 @@ public: CidStore(CasStore& InCasStore, const std::filesystem::path& RootDir); ~CidStore(); - void AddCompressedCid(const IoHash& DecompressedId, const IoHash& Compressed); - IoBuffer FindChunkByCid(const IoHash& DecompressedId); - bool ContainsChunk(const IoHash& DecompressedId); - void Flush(); + CasStore::InsertResult AddChunk(CompressedBuffer& ChunkData); + void AddCompressedCid(const IoHash& DecompressedId, const IoHash& Compressed); + IoBuffer FindChunkByCid(const IoHash& DecompressedId); + bool ContainsChunk(const IoHash& DecompressedId); + void Flush(); + + // TODO: add batch filter support private: struct CidState; |