diff options
| author | Stefan Boberg <[email protected]> | 2021-09-15 19:49:20 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-15 19:49:20 +0200 |
| commit | 83ccd52321a23c8f1c8a3228cbbf34b8f199a22b (patch) | |
| tree | 9cf1fb68651f616aef2fa28000e4f328ef9204d8 /zenstore/cidstore.cpp | |
| parent | Added GetSize/GetData functions to reduce cognitive load and bridge the gap b... (diff) | |
| parent | Tweaked logging to streamline access, and simplified setup code for new loggers (diff) | |
| download | zen-83ccd52321a23c8f1c8a3228cbbf34b8f199a22b.tar.xz zen-83ccd52321a23c8f1c8a3228cbbf34b8f199a22b.zip | |
Merge branch 'main' into cbpackage-update
Diffstat (limited to 'zenstore/cidstore.cpp')
| -rw-r--r-- | zenstore/cidstore.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/zenstore/cidstore.cpp b/zenstore/cidstore.cpp index 4e5188f1c..e6c7f98ee 100644 --- a/zenstore/cidstore.cpp +++ b/zenstore/cidstore.cpp @@ -2,11 +2,12 @@ #include "zenstore/cidstore.h" +#include <zencore/compress.h> #include <zencore/filesystem.h> +#include <zencore/logging.h> #include <zenstore/CAS.h> #include <zenstore/caslog.h> -#include <spdlog/spdlog.h> #include <filesystem> namespace zen { @@ -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}); } @@ -70,7 +86,7 @@ struct CidStore::CidState m_LogFile.Replay([&](const IndexEntry& Ie) { m_CidMap.insert_or_assign(Ie.Uncompressed, Ie.Compressed); }); - spdlog::debug("CID index initialized: {} entries found", m_CidMap.size()); + ZEN_DEBUG("CID index initialized: {} entries found", m_CidMap.size()); } void Flush() { m_LogFile.Flush(); } @@ -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) { |