aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-06-14 15:34:06 +0200
committerDan Engelbrecht <[email protected]>2022-06-14 15:34:06 +0200
commit304bb51b305e10cf2dc1fdda0bba0dec2bd19b2b (patch)
tree1fa261770f0d4014775858f246f473f13ce79206
parentsmall cleanup (diff)
downloadzen-304bb51b305e10cf2dc1fdda0bba0dec2bd19b2b.tar.xz
zen-304bb51b305e10cf2dc1fdda0bba0dec2bd19b2b.zip
review feedback
-rw-r--r--zenserver/cache/structuredcachestore.cpp85
-rw-r--r--zenstore/blockstore.cpp6
-rw-r--r--zenstore/compactcas.cpp60
-rw-r--r--zenstore/include/zenstore/blockstore.h6
4 files changed, 79 insertions, 78 deletions
diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp
index 7bcd7b06a..4be33170c 100644
--- a/zenserver/cache/structuredcachestore.cpp
+++ b/zenserver/cache/structuredcachestore.cpp
@@ -1315,10 +1315,8 @@ ZenCacheDiskLayer::CacheBucket::Scrub(ScrubContext& Ctx)
auto ValidateEntry = [](ZenContentType ContentType, IoBuffer Buffer) {
if (ContentType == ZenContentType::kCbObject)
{
- if (CbValidateError Error = ValidateCompactBinary(Buffer, CbValidateMode::All); Error != CbValidateError::None)
- {
- return false;
- }
+ CbValidateError Error = ValidateCompactBinary(Buffer, CbValidateMode::All);
+ return Error == CbValidateError::None;
}
if (ContentType == ZenContentType::kCompressedBinary)
{
@@ -1332,7 +1330,7 @@ ZenCacheDiskLayer::CacheBucket::Scrub(ScrubContext& Ctx)
RwLock::SharedLockScope _(m_IndexLock);
- size_t BlockChunkInitialCount = m_Index.size() / 4;
+ const size_t BlockChunkInitialCount = m_Index.size() / 4;
ChunkLocations.reserve(BlockChunkInitialCount);
ChunkIndexToChunkHash.reserve(BlockChunkInitialCount);
@@ -1382,44 +1380,45 @@ ZenCacheDiskLayer::CacheBucket::Scrub(ScrubContext& Ctx)
}
}
- m_BlockStore.IterateChunks(
- ChunkLocations,
- [&](size_t ChunkIndex, const void* Data, uint64_t Size) {
- const IoHash& Hash = ChunkIndexToChunkHash[ChunkIndex];
- if (!Data)
- {
- // ChunkLocation out of range of stored blocks
- BadKeys.push_back(Hash);
- return;
- }
- IoBuffer Buffer(IoBuffer::Wrap, Data, Size);
- if (!Buffer)
- {
- BadKeys.push_back(Hash);
- return;
- }
- ZenContentType ContentType = m_Index.at(Hash).Location.GetContentType();
- if (!ValidateEntry(ContentType, Buffer))
- {
- BadKeys.push_back(Hash);
- return;
- }
- },
- [&](size_t ChunkIndex, BlockStoreFile& File, uint64_t Offset, uint64_t Size) {
- const IoHash& Hash = ChunkIndexToChunkHash[ChunkIndex];
- IoBuffer Buffer(IoBuffer::BorrowedFile, File.GetBasicFile().Handle(), Offset, Size);
- if (!Buffer)
- {
- BadKeys.push_back(Hash);
- return;
- }
- ZenContentType ContentType = m_Index.at(Hash).Location.GetContentType();
- if (!ValidateEntry(ContentType, Buffer))
- {
- BadKeys.push_back(Hash);
- return;
- }
- });
+ const auto ValidateSmallChunk = [&](size_t ChunkIndex, const void* Data, uint64_t Size) {
+ const IoHash& Hash = ChunkIndexToChunkHash[ChunkIndex];
+ if (!Data)
+ {
+ // ChunkLocation out of range of stored blocks
+ BadKeys.push_back(Hash);
+ return;
+ }
+ IoBuffer Buffer(IoBuffer::Wrap, Data, Size);
+ if (!Buffer)
+ {
+ BadKeys.push_back(Hash);
+ return;
+ }
+ ZenContentType ContentType = m_Index.at(Hash).Location.GetContentType();
+ if (!ValidateEntry(ContentType, Buffer))
+ {
+ BadKeys.push_back(Hash);
+ return;
+ }
+ };
+
+ const auto ValidateLargeChunk = [&](size_t ChunkIndex, BlockStoreFile& File, uint64_t Offset, uint64_t Size) {
+ const IoHash& Hash = ChunkIndexToChunkHash[ChunkIndex];
+ IoBuffer Buffer(IoBuffer::BorrowedFile, File.GetBasicFile().Handle(), Offset, Size);
+ if (!Buffer)
+ {
+ BadKeys.push_back(Hash);
+ return;
+ }
+ ZenContentType ContentType = m_Index.at(Hash).Location.GetContentType();
+ if (!ValidateEntry(ContentType, Buffer))
+ {
+ BadKeys.push_back(Hash);
+ return;
+ }
+ };
+
+ m_BlockStore.IterateChunks(ChunkLocations, ValidateSmallChunk, ValidateLargeChunk);
_.ReleaseNow();
diff --git a/zenstore/blockstore.cpp b/zenstore/blockstore.cpp
index 1ea704669..88592d785 100644
--- a/zenstore/blockstore.cpp
+++ b/zenstore/blockstore.cpp
@@ -209,7 +209,7 @@ BlockStore::Close()
}
void
-BlockStore::WriteChunk(const void* Data, uint64_t Size, uint64_t Alignment, WriteChunkCallback Callback)
+BlockStore::WriteChunk(const void* Data, uint64_t Size, uint64_t Alignment, const WriteChunkCallback& Callback)
{
ZEN_ASSERT(Data != nullptr);
ZEN_ASSERT(Size > 0u);
@@ -613,8 +613,8 @@ BlockStore::ReclaimSpace(const ReclaimSnapshotState& Snapshot,
void
BlockStore::IterateChunks(const std::vector<BlockStoreLocation>& ChunkLocations,
- IterateChunksSmallSizeCallback SmallSizeCallback,
- IterateChunksLargeSizeCallback LargeSizeCallback)
+ const IterateChunksSmallSizeCallback& SmallSizeCallback,
+ const IterateChunksLargeSizeCallback& LargeSizeCallback)
{
std::vector<size_t> LocationIndexes;
LocationIndexes.reserve(ChunkLocations.size());
diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp
index 3b22f5b20..5aed02e7f 100644
--- a/zenstore/compactcas.cpp
+++ b/zenstore/compactcas.cpp
@@ -336,35 +336,37 @@ CasContainerStrategy::Scrub(ScrubContext& Ctx)
}
}
- m_BlockStore.IterateChunks(
- ChunkLocations,
- [&](size_t ChunkIndex, const void* Data, uint64_t Size) {
- const IoHash& Hash = ChunkIndexToChunkHash[ChunkIndex];
- if (!Data)
- {
- // ChunkLocation out of range of stored blocks
- BadKeys.push_back(Hash);
- return;
- }
- const IoHash ComputedHash = IoHash::HashBuffer(Data, Size);
- if (ComputedHash != Hash)
- {
- // Hash mismatch
- BadKeys.push_back(Hash);
- return;
- }
- },
- [&](size_t ChunkIndex, BlockStoreFile& File, uint64_t Offset, uint64_t Size) {
- IoHashStream Hasher;
- File.StreamByteRange(Offset, Size, [&](const void* Data, uint64_t Size) { Hasher.Append(Data, Size); });
- IoHash ComputedHash = Hasher.GetHash();
- const IoHash& Hash = ChunkIndexToChunkHash[ChunkIndex];
- if (ComputedHash != Hash)
- {
- // Hash mismatch
- BadKeys.push_back(Hash);
- }
- });
+ const auto ValidateSmallChunk = [&](size_t ChunkIndex, const void* Data, uint64_t Size) {
+ const IoHash& Hash = ChunkIndexToChunkHash[ChunkIndex];
+ if (!Data)
+ {
+ // ChunkLocation out of range of stored blocks
+ BadKeys.push_back(Hash);
+ return;
+ }
+ const IoHash ComputedHash = IoHash::HashBuffer(Data, Size);
+ if (ComputedHash != Hash)
+ {
+ // Hash mismatch
+ BadKeys.push_back(Hash);
+ return;
+ }
+ };
+
+ const auto ValidateLargeChunk = [&](size_t ChunkIndex, BlockStoreFile& File, uint64_t Offset, uint64_t Size) {
+ IoHashStream Hasher;
+ File.StreamByteRange(Offset, Size, [&](const void* Data, uint64_t Size) { Hasher.Append(Data, Size); });
+ IoHash ComputedHash = Hasher.GetHash();
+ const IoHash& Hash = ChunkIndexToChunkHash[ChunkIndex];
+ if (ComputedHash != Hash)
+ {
+ // Hash mismatch
+ BadKeys.push_back(Hash);
+ return;
+ }
+ };
+
+ m_BlockStore.IterateChunks(ChunkLocations, ValidateSmallChunk, ValidateLargeChunk);
_.ReleaseNow();
diff --git a/zenstore/include/zenstore/blockstore.h b/zenstore/include/zenstore/blockstore.h
index 4ad7a805f..fe435cdff 100644
--- a/zenstore/include/zenstore/blockstore.h
+++ b/zenstore/include/zenstore/blockstore.h
@@ -132,7 +132,7 @@ public:
const std::vector<BlockStoreLocation>& KnownLocations);
void Close();
- void WriteChunk(const void* Data, uint64_t Size, uint64_t Alignment, WriteChunkCallback Callback);
+ void WriteChunk(const void* Data, uint64_t Size, uint64_t Alignment, const WriteChunkCallback& Callback);
IoBuffer TryGetChunk(const BlockStoreLocation& Location);
void Flush();
@@ -148,8 +148,8 @@ public:
const ClaimDiskReserveCallback& DiskReserveCallback = []() { return 0; });
void IterateChunks(const std::vector<BlockStoreLocation>& ChunkLocations,
- IterateChunksSmallSizeCallback SmallSizeCallback,
- IterateChunksLargeSizeCallback LargeSizeCallback);
+ const IterateChunksSmallSizeCallback& SmallSizeCallback,
+ const IterateChunksLargeSizeCallback& LargeSizeCallback);
static bool Split(const std::vector<BlockStoreLocation>& ChunkLocations,
const std::filesystem::path& SourceBlockFilePath,