aboutsummaryrefslogtreecommitdiff
path: root/zenstore
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-11-18 12:02:41 +0100
committerDan Engelbrecht <[email protected]>2022-11-25 10:17:34 +0100
commit5041f3521c2b3074032c06ed04a391ed90a06c7e (patch)
treefbe6c18c79de5abff79394b69d65e38004d9e39e /zenstore
parent0.1.9 (diff)
downloadzen-5041f3521c2b3074032c06ed04a391ed90a06c7e.tar.xz
zen-5041f3521c2b3074032c06ed04a391ed90a06c7e.zip
reduce parsing of compressed headers
Diffstat (limited to 'zenstore')
-rw-r--r--zenstore/cidstore.cpp12
-rw-r--r--zenstore/compactcas.cpp13
-rw-r--r--zenstore/filecas.cpp6
-rw-r--r--zenstore/gc.cpp5
-rw-r--r--zenstore/include/zenstore/cidstore.h2
5 files changed, 22 insertions, 16 deletions
diff --git a/zenstore/cidstore.cpp b/zenstore/cidstore.cpp
index 8b2797ce9..6319c2d2e 100644
--- a/zenstore/cidstore.cpp
+++ b/zenstore/cidstore.cpp
@@ -23,14 +23,12 @@ struct CidStore::Impl
void Initialize(const CidStoreConfiguration& Config) { m_CasStore.Initialize(Config); }
- CidStore::InsertResult AddChunk(const CompressedBuffer& ChunkData, CidStore::InsertMode Mode)
+ CidStore::InsertResult AddChunk(const IoBuffer& ChunkData, const IoHash& RawHash, CidStore::InsertMode Mode)
{
- const IoHash DecompressedId = IoHash::FromBLAKE3(ChunkData.GetRawHash());
- IoBuffer Payload = ChunkData.GetCompressed().Flatten().AsIoBuffer();
-
+ IoBuffer Payload(ChunkData);
Payload.SetContentType(ZenContentType::kCompressedBinary);
- CasStore::InsertResult Result = m_CasStore.InsertChunk(Payload, DecompressedId, static_cast<CasStore::InsertMode>(Mode));
+ CasStore::InsertResult Result = m_CasStore.InsertChunk(Payload, RawHash, static_cast<CasStore::InsertMode>(Mode));
return {.New = Result.New};
}
@@ -78,9 +76,9 @@ CidStore::Initialize(const CidStoreConfiguration& Config)
}
CidStore::InsertResult
-CidStore::AddChunk(const CompressedBuffer& ChunkData, InsertMode Mode)
+CidStore::AddChunk(const IoBuffer& ChunkData, const IoHash& RawHash, InsertMode Mode)
{
- return m_Impl->AddChunk(ChunkData, Mode);
+ return m_Impl->AddChunk(ChunkData, RawHash, Mode);
}
IoBuffer
diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp
index d0c2f59ac..9e181eb87 100644
--- a/zenstore/compactcas.cpp
+++ b/zenstore/compactcas.cpp
@@ -269,9 +269,11 @@ CasContainerStrategy::Scrub(ScrubContext& Ctx)
}
IoBuffer Buffer(IoBuffer::Wrap, Data, Size);
- if (CompressedBuffer Compressed = CompressedBuffer::FromCompressed(SharedBuffer(Buffer)); Compressed)
+ IoHash RawHash;
+ uint64_t RawSize;
+ if (CompressedBuffer Compressed = CompressedBuffer::FromCompressed(SharedBuffer(Buffer), RawHash, RawSize); Compressed)
{
- if (IoHash::FromBLAKE3(Compressed.GetRawHash()) != Hash)
+ if (RawHash != Hash)
{
// Hash mismatch
BadKeys.push_back(Hash);
@@ -295,10 +297,13 @@ CasContainerStrategy::Scrub(ScrubContext& Ctx)
const IoHash& Hash = ChunkIndexToChunkHash[ChunkIndex];
IoBuffer Buffer(IoBuffer::BorrowedFile, File.GetBasicFile().Handle(), Offset, Size);
+
+ IoHash RawHash;
+ uint64_t RawSize;
// TODO: Add API to verify compressed buffer without having to memorymap the whole file
- if (CompressedBuffer Compressed = CompressedBuffer::FromCompressed(SharedBuffer(Buffer)); Compressed)
+ if (CompressedBuffer Compressed = CompressedBuffer::FromCompressed(SharedBuffer(Buffer), RawHash, RawSize); Compressed)
{
- if (IoHash::FromBLAKE3(Compressed.GetRawHash()) != Hash)
+ if (RawHash != Hash)
{
// Hash mismatch
BadKeys.push_back(Hash);
diff --git a/zenstore/filecas.cpp b/zenstore/filecas.cpp
index 1b53c405b..70ee67d93 100644
--- a/zenstore/filecas.cpp
+++ b/zenstore/filecas.cpp
@@ -789,9 +789,11 @@ FileCasStrategy::Scrub(ScrubContext& Ctx)
ChunkBytes += Payload.FileSize();
IoBuffer Buffer(IoBuffer::BorrowedFile, Payload.Handle(), 0, Payload.FileSize());
- if (CompressedBuffer Compressed = CompressedBuffer::FromCompressed(SharedBuffer(Buffer)); Compressed)
+ IoHash RawHash;
+ uint64_t RawSize;
+ if (CompressedBuffer Compressed = CompressedBuffer::FromCompressed(SharedBuffer(Buffer), RawHash, RawSize); Compressed)
{
- if (IoHash::FromBLAKE3(Compressed.GetRawHash()) != Hash)
+ if (RawHash != Hash)
{
// Hash mismatch
BadHashes.push_back(Hash);
diff --git a/zenstore/gc.cpp b/zenstore/gc.cpp
index 8aac65bb4..e0cddb291 100644
--- a/zenstore/gc.cpp
+++ b/zenstore/gc.cpp
@@ -701,7 +701,8 @@ TEST_CASE("gc.basic")
IoBuffer Chunk = CreateChunk(128);
auto CompressedChunk = Compress(Chunk);
- const auto InsertResult = CidStore.AddChunk(CompressedChunk);
+ const auto InsertResult =
+ CidStore.AddChunk(CompressedChunk.GetCompressed().Flatten().AsIoBuffer(), IoHash::FromBLAKE3(CompressedChunk.DecodeRawHash()));
CHECK(InsertResult.New);
GcContext GcCtx;
@@ -710,7 +711,7 @@ TEST_CASE("gc.basic")
CidStore.Flush();
Gc.CollectGarbage(GcCtx);
- CHECK(!CidStore.ContainsChunk(IoHash::FromBLAKE3(CompressedChunk.GetRawHash())));
+ CHECK(!CidStore.ContainsChunk(IoHash::FromBLAKE3(CompressedChunk.DecodeRawHash())));
}
TEST_CASE("gc.full")
diff --git a/zenstore/include/zenstore/cidstore.h b/zenstore/include/zenstore/cidstore.h
index e8984a83d..16ca78225 100644
--- a/zenstore/include/zenstore/cidstore.h
+++ b/zenstore/include/zenstore/cidstore.h
@@ -70,7 +70,7 @@ public:
};
void Initialize(const CidStoreConfiguration& Config);
- InsertResult AddChunk(const CompressedBuffer& ChunkData, InsertMode Mode = InsertMode::kMayBeMovedInPlace);
+ InsertResult AddChunk(const IoBuffer& ChunkData, const IoHash& RawHash, InsertMode Mode = InsertMode::kMayBeMovedInPlace);
IoBuffer FindChunkByCid(const IoHash& DecompressedId);
bool ContainsChunk(const IoHash& DecompressedId);
void FilterChunks(HashKeySet& InOutChunks);