aboutsummaryrefslogtreecommitdiff
path: root/src/zenstore/blockstore.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2026-03-10 18:44:45 +0100
committerGitHub Enterprise <[email protected]>2026-03-10 18:44:45 +0100
commitda0af02b6f4adf4592168667cd6a68c16030eb87 (patch)
tree61375bdeed179a353c9bf318701968fd2e740894 /src/zenstore/blockstore.cpp
parentHttpClient using libcurl, Unix Sockets for HTTP. HTTPS support (#770) (diff)
downloadzen-da0af02b6f4adf4592168667cd6a68c16030eb87.tar.xz
zen-da0af02b6f4adf4592168667cd6a68c16030eb87.zip
minor zenstore/blockstore fixes (#821)
- Fix clang-format error accidentally introduced by recent PR - Fix `FileSize()` CAS race that repeatedly invalidated the cache when concurrent callers both missed; remove `store(0)` on CAS failure - Fix `WriteChunks` not accounting for initial alignment padding in `m_TotalSize`, causing drift vs `WriteChunk`'s correct accounting - Fix Create retry sleep computing negative values (100 - N*100 instead of 100 + N*100), matching the Open retry pattern - Fix `~BlockStore` error log missing format placeholder for `Ex.what()` - Fix `GetFreeBlockIndex` infinite loop when all indexes have orphan files on disk but aren't in `m_ChunkBlocks`; bound probe to `m_MaxBlockCount` - Fix `IterateBlock` ignoring `SmallSizeCallback` return value for single out-of-bounds chunks, preventing early termination - Fix `BlockStoreCompactState::IterateBlocks` iterating map by value instead of const reference
Diffstat (limited to 'src/zenstore/blockstore.cpp')
-rw-r--r--src/zenstore/blockstore.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/zenstore/blockstore.cpp b/src/zenstore/blockstore.cpp
index 6197c7f24..6528fcb2f 100644
--- a/src/zenstore/blockstore.cpp
+++ b/src/zenstore/blockstore.cpp
@@ -98,7 +98,7 @@ BlockStoreFile::Create(uint64_t InitialSize)
return false;
}
ZEN_WARN("Failed to create cas block '{}', reason: '{}', retries left: {}.", m_Path, Ec.message(), RetriesLeft);
- Sleep(100 - (3 - RetriesLeft) * 100); // Total 600 ms
+ Sleep(100 + (3 - RetriesLeft) * 100); // Total 600 ms
RetriesLeft--;
return true;
});
@@ -125,11 +125,7 @@ BlockStoreFile::FileSize() const
return 0;
}
uint64_t Expected = 0;
- if (!m_CachedFileSize.compare_exchange_strong(Expected, Size))
- {
- // Force a new check next time file size is fetched
- m_CachedFileSize.store(0);
- }
+ m_CachedFileSize.compare_exchange_strong(Expected, Size);
return Size;
}
return CachedSize;
@@ -388,7 +384,7 @@ BlockStore::~BlockStore()
}
catch (const std::exception& Ex)
{
- ZEN_ERROR("~BlockStore() failed with: ", Ex.what());
+ ZEN_ERROR("~BlockStore() failed with: {}", Ex.what());
}
}
@@ -624,7 +620,7 @@ BlockStore::GetFreeBlockIndex(uint32_t ProbeIndex, RwLock::ExclusiveLockScope&,
return (uint32_t)m_MaxBlockCount;
}
- while (true)
+ for (uint64_t ProbeCount = 0; ProbeCount < m_MaxBlockCount; ++ProbeCount)
{
if (!m_ChunkBlocks.contains(ProbeIndex))
{
@@ -645,7 +641,7 @@ BlockStore::GetFreeBlockIndex(uint32_t ProbeIndex, RwLock::ExclusiveLockScope&,
}
ProbeIndex = (ProbeIndex + 1) & (m_MaxBlockCount - 1);
}
- return ProbeIndex;
+ return (uint32_t)m_MaxBlockCount;
}
void
@@ -808,6 +804,7 @@ BlockStore::WriteChunks(std::span<const IoBuffer> Datas, uint32_t Alignment, con
Count++;
RangeSize = NextRangeSize;
}
+ uint32_t AlignmentPadding = AlignedInsertOffset - m_CurrentInsertOffset;
m_CurrentInsertOffset = AlignedInsertOffset + RangeSize;
Ref<BlockStoreFile> WriteBlock = m_WriteBlock;
AddActiveWriteBlock(InsertLock, WriteBlockIndex);
@@ -829,13 +826,13 @@ BlockStore::WriteChunks(std::span<const IoBuffer> Datas, uint32_t Alignment, con
WriteBuffer.MidInline(RoundUp(SourceBuffer.GetSize(), Alignment));
}
WriteBlock->Write(Buffer.data(), RangeSize, AlignedInsertOffset);
- m_TotalSize.fetch_add(RangeSize, std::memory_order::relaxed);
+ m_TotalSize.fetch_add(AlignmentPadding + RangeSize, std::memory_order::relaxed);
}
else
{
MemoryView SourceBuffer = Datas[Offset];
WriteBlock->Write(SourceBuffer.GetData(), SourceBuffer.GetSize(), AlignedInsertOffset);
- m_TotalSize.fetch_add(SourceBuffer.GetSize(), std::memory_order::relaxed);
+ m_TotalSize.fetch_add(AlignmentPadding + SourceBuffer.GetSize(), std::memory_order::relaxed);
}
uint32_t ChunkOffset = AlignedInsertOffset;
@@ -1087,7 +1084,10 @@ BlockStore::IterateBlock(std::span<const BlockStoreLocation> ChunkLocations,
BlockIndex,
BlockSize);
- SmallSizeCallback(ChunkIndex, nullptr, 0);
+ if (!SmallSizeCallback(ChunkIndex, nullptr, 0))
+ {
+ return false;
+ }
LocationIndexOffset++;
continue;
}