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 /zenstore/cidstore.cpp | |
| 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
Diffstat (limited to 'zenstore/cidstore.cpp')
| -rw-r--r-- | zenstore/cidstore.cpp | 22 |
1 files changed, 22 insertions, 0 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) { |