diff options
Diffstat (limited to 'src/zenstore/blockstore.cpp')
| -rw-r--r-- | src/zenstore/blockstore.cpp | 24 |
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; } |