aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-05-25 12:54:06 +0200
committerStefan Boberg <[email protected]>2021-05-25 12:54:06 +0200
commite9a1089cfb918a7790503309726d9b6cd5004c39 (patch)
tree93b4b20b2c19b2c0bb80a7862f3ea7d73c80bffc
parentStructured cache now verifies attachment payloads (diff)
downloadzen-e9a1089cfb918a7790503309726d9b6cd5004c39.tar.xz
zen-e9a1089cfb918a7790503309726d9b6cd5004c39.zip
Removed pointer-based InsertChunk from CAS store interface.
All code must now use the IoBuffer path
-rw-r--r--zen/chunk/chunk.cpp15
-rw-r--r--zenserver/casstore.cpp4
-rw-r--r--zenstore/CAS.cpp28
-rw-r--r--zenstore/filecas.cpp4
-rw-r--r--zenstore/include/zenstore/CAS.h1
5 files changed, 16 insertions, 36 deletions
diff --git a/zen/chunk/chunk.cpp b/zen/chunk/chunk.cpp
index 0a7efd56a..3c54f7bac 100644
--- a/zen/chunk/chunk.cpp
+++ b/zen/chunk/chunk.cpp
@@ -626,6 +626,9 @@ public:
if (true)
{
// Compress using ZSTD
+
+ // TODO: use CompressedBuffer format
+
const size_t CompressBufferSize = ZSTD_compressBound(DataSize);
zen::IoBuffer CompressedBuffer = m_CompressionBufferManager->AllocBuffer();
@@ -643,9 +646,9 @@ public:
if (m_CasStore)
{
- const zen::IoHash CompressedHash = zen::IoHash::HashMemory(CompressBuffer, CompressedSize);
- zen::CasStore::InsertResult Result =
- m_CasStore->InsertChunk(CompressBuffer, CompressedSize, CompressedHash);
+ const zen::IoHash CompressedHash = zen::IoHash::HashMemory(CompressBuffer, CompressedSize);
+ zen::IoBuffer CompressedData = zen::IoBuffer(zen::IoBuffer::Wrap, CompressBuffer, CompressedSize);
+ zen::CasStore::InsertResult Result = m_CasStore->InsertChunk(CompressedData, CompressedHash);
if (Result.New)
{
@@ -675,9 +678,9 @@ public:
if (m_CasStore)
{
- const zen::IoHash CompressedHash = zen::IoHash::HashMemory(CompressBuffer, CompressedSize);
- zen::CasStore::InsertResult Result =
- m_CasStore->InsertChunk(CompressBuffer, CompressedSize, CompressedHash);
+ const zen::IoHash CompressedHash = zen::IoHash::HashMemory(CompressBuffer, CompressedSize);
+ zen::IoBuffer CompressedData = zen::IoBuffer(zen::IoBuffer::Wrap, CompressBuffer, CompressedSize);
+ zen::CasStore::InsertResult Result = m_CasStore->InsertChunk(CompressedData, CompressedHash);
if (Result.New)
{
diff --git a/zenserver/casstore.cpp b/zenserver/casstore.cpp
index 4afcf21a6..2560659ec 100644
--- a/zenserver/casstore.cpp
+++ b/zenserver/casstore.cpp
@@ -92,7 +92,7 @@ HttpCasService::HttpCasService(CasStore& Store) : m_CasStore(Store)
return ServerRequest.WriteResponse(HttpResponse::BadRequest);
}
- m_CasStore.InsertChunk(Payload.Data(), Payload.Size(), PayloadHash);
+ m_CasStore.InsertChunk(Payload, PayloadHash);
return ServerRequest.WriteResponse(HttpResponse::OK);
}
@@ -125,7 +125,7 @@ HttpCasService::HandleRequest(zen::HttpServerRequest& Request)
spdlog::debug("CAS POST request for {} ({} bytes)", PayloadHash, Payload.Size());
- auto InsertResult = m_CasStore.InsertChunk(Payload.Data(), Payload.Size(), PayloadHash);
+ auto InsertResult = m_CasStore.InsertChunk(Payload, PayloadHash);
if (InsertResult.New)
{
diff --git a/zenstore/CAS.cpp b/zenstore/CAS.cpp
index 8d81fc5cb..1f477cb17 100644
--- a/zenstore/CAS.cpp
+++ b/zenstore/CAS.cpp
@@ -38,7 +38,6 @@ public:
virtual ~CasImpl();
virtual void Initialize(const CasStoreConfiguration& InConfig) override;
- virtual CasStore::InsertResult InsertChunk(const void* ChunkData, size_t ChunkSize, const IoHash& ChunkHash) override;
virtual CasStore::InsertResult InsertChunk(IoBuffer Chunk, const IoHash& ChunkHash) override;
virtual IoBuffer FindChunk(const IoHash& ChunkHash) override;
@@ -104,39 +103,22 @@ CasImpl::Initialize(const CasStoreConfiguration& InConfig)
}
CasStore::InsertResult
-CasImpl::InsertChunk(const void* ChunkData, size_t ChunkSize, const IoHash& ChunkHash)
-{
- if (ChunkSize < m_Config.TinyValueThreshold)
- {
- return m_TinyStrategy.InsertChunk(ChunkData, ChunkSize, ChunkHash);
- }
- else if (ChunkSize >= m_Config.HugeValueThreshold)
- {
- return m_LargeStrategy.InsertChunk(ChunkData, ChunkSize, ChunkHash);
- }
- else
- {
- return m_SmallStrategy.InsertChunk(ChunkData, ChunkSize, ChunkHash);
- }
-}
-
-CasStore::InsertResult
CasImpl::InsertChunk(IoBuffer Chunk, const IoHash& ChunkHash)
{
const uint64_t ChunkSize = Chunk.Size();
if (ChunkSize < m_Config.TinyValueThreshold)
{
+ ZEN_ASSERT(ChunkSize);
+
return m_TinyStrategy.InsertChunk(Chunk, ChunkHash);
}
- else if (Chunk.Size() >= m_Config.HugeValueThreshold)
- {
- return m_LargeStrategy.InsertChunk(Chunk, ChunkHash);
- }
- else
+ else if (ChunkSize < m_Config.HugeValueThreshold)
{
return m_SmallStrategy.InsertChunk(Chunk, ChunkHash);
}
+
+ return m_LargeStrategy.InsertChunk(Chunk, ChunkHash);
}
IoBuffer
diff --git a/zenstore/filecas.cpp b/zenstore/filecas.cpp
index 1e9b50e63..4f5cf370e 100644
--- a/zenstore/filecas.cpp
+++ b/zenstore/filecas.cpp
@@ -331,10 +331,6 @@ public:
}
}
- virtual CasStore::InsertResult InsertChunk(const void* chunkData, size_t chunkSize, const IoHash& chunkHash) override
- {
- return m_Strategy.InsertChunk(chunkData, chunkSize, chunkHash);
- }
virtual CasStore::InsertResult InsertChunk(IoBuffer Chunk, const IoHash& chunkHash) override
{
return m_Strategy.InsertChunk(Chunk, chunkHash);
diff --git a/zenstore/include/zenstore/CAS.h b/zenstore/include/zenstore/CAS.h
index 9c569f2aa..3f3f3007d 100644
--- a/zenstore/include/zenstore/CAS.h
+++ b/zenstore/include/zenstore/CAS.h
@@ -50,7 +50,6 @@ public:
};
virtual void Initialize(const CasStoreConfiguration& Config) = 0;
- virtual InsertResult InsertChunk(const void* ChunkData, size_t ChunkSize, const IoHash& ChunkHash) = 0;
virtual InsertResult InsertChunk(IoBuffer Data, const IoHash& ChunkHash) = 0;
virtual IoBuffer FindChunk(const IoHash& ChunkHash) = 0;