aboutsummaryrefslogtreecommitdiff
path: root/src/zenstore/blockstore.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zenstore/blockstore.cpp')
-rw-r--r--src/zenstore/blockstore.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/zenstore/blockstore.cpp b/src/zenstore/blockstore.cpp
index f99b0bc4a..968e919d6 100644
--- a/src/zenstore/blockstore.cpp
+++ b/src/zenstore/blockstore.cpp
@@ -171,6 +171,7 @@ BlockStore::Initialize(const std::filesystem::path& BlocksBasePath, uint64_t Max
if (std::filesystem::is_directory(m_BlocksBasePath))
{
+ uint32_t NextBlockIndex = 0;
std::vector<std::filesystem::path> FoldersToScan;
FoldersToScan.push_back(m_BlocksBasePath);
size_t FolderOffset = 0;
@@ -202,10 +203,15 @@ BlockStore::Initialize(const std::filesystem::path& BlocksBasePath, uint64_t Max
m_TotalSize.fetch_add(BlockFile->FileSize(), std::memory_order::relaxed);
m_ChunkBlocks[BlockIndex] = BlockFile;
FoundBlocks[BlockIndex] = BlockFile->FileSize();
+ if (BlockIndex >= NextBlockIndex)
+ {
+ NextBlockIndex = (BlockIndex + 1) & (m_MaxBlockCount - 1);
+ }
}
}
++FolderOffset;
}
+ m_WriteBlockIndex.store(NextBlockIndex, std::memory_order_release);
}
else
{
@@ -363,14 +369,11 @@ BlockStore::Flush(bool ForceNewBlock)
RwLock::ExclusiveLockScope _(m_InsertLock);
if (m_CurrentInsertOffset > 0)
{
- uint32_t WriteBlockIndex = m_WriteBlockIndex.load(std::memory_order_acquire);
- WriteBlockIndex = (WriteBlockIndex + 1) & (m_MaxBlockCount - 1);
if (m_WriteBlock)
{
m_WriteBlock->Flush();
}
- m_WriteBlock = nullptr;
- m_WriteBlockIndex.store(WriteBlockIndex, std::memory_order_release);
+ m_WriteBlock = nullptr;
m_CurrentInsertOffset = 0;
}
return;