aboutsummaryrefslogtreecommitdiff
path: root/zenstore/blockstore.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-05-02 16:41:32 +0200
committerDan Engelbrecht <[email protected]>2022-05-02 16:41:32 +0200
commitbb7593c9ea3412a48b3d29f3e7f7b23d7a785b2f (patch)
tree133f4ada4cce17ca808ec65249aab7f2d2a83ae1 /zenstore/blockstore.cpp
parentMerge branch 'de/block-store-refactor' of github.com:EpicGames/zen into de/bl... (diff)
downloadzen-bb7593c9ea3412a48b3d29f3e7f7b23d7a785b2f.tar.xz
zen-bb7593c9ea3412a48b3d29f3e7f7b23d7a785b2f.zip
Refactor WriteChunk to not need callback
Diffstat (limited to 'zenstore/blockstore.cpp')
-rw-r--r--zenstore/blockstore.cpp19
1 files changed, 6 insertions, 13 deletions
diff --git a/zenstore/blockstore.cpp b/zenstore/blockstore.cpp
index d293eb97d..178687b5f 100644
--- a/zenstore/blockstore.cpp
+++ b/zenstore/blockstore.cpp
@@ -193,8 +193,8 @@ BlockStore::Initialize(const std::filesystem::path& BlocksBasePath,
}
}
-void
-BlockStore::WriteChunk(const void* Data, uint64_t Size, uint64_t Alignment, WriteChunkCallback Callback)
+BlockStoreLocation
+BlockStore::WriteChunk(const void* Data, uint64_t Size, uint64_t Alignment)
{
RwLock::ExclusiveLockScope InsertLock(m_InsertLock);
@@ -227,15 +227,11 @@ BlockStore::WriteChunk(const void* Data, uint64_t Size, uint64_t Alignment, Writ
uint64_t InsertOffset = m_CurrentInsertOffset;
m_CurrentInsertOffset = RoundUp(InsertOffset + Size, Alignment);
Ref<BlockStoreFile> WriteBlock = m_WriteBlock;
- m_ActiveWriteBlockIndexes.push_back(WriteBlockIndex);
InsertLock.ReleaseNow();
WriteBlock->Write(Data, Size, InsertOffset);
- Callback({.BlockIndex = WriteBlockIndex, .Offset = InsertOffset, .Size = Size});
-
- RwLock::ExclusiveLockScope _(m_InsertLock);
- m_ActiveWriteBlockIndexes.erase(std::find(m_ActiveWriteBlockIndexes.begin(), m_ActiveWriteBlockIndexes.end(), WriteBlockIndex));
+ return {.BlockIndex = WriteBlockIndex, .Offset = InsertOffset, .Size = Size};
}
BlockStore::ReclaimSnapshotState
@@ -243,11 +239,8 @@ BlockStore::GetReclaimSnapshotState()
{
ReclaimSnapshotState State;
RwLock::ExclusiveLockScope _(m_InsertLock);
- for (uint32_t BlockIndex : m_ActiveWriteBlockIndexes)
- {
- State.ExcludeBlockIndexes.insert(BlockIndex);
- }
- State.BlockCount = m_ChunkBlocks.size();
+ State.ExcludeBlockIndex = m_WriteBlock ? m_WriteBlockIndex.load(std::memory_order_acquire) : 0xffffffffu;
+ State.BlockCount = m_ChunkBlocks.size();
_.ReleaseNow();
return State;
}
@@ -351,7 +344,7 @@ BlockStore::ReclaimSpace(const ReclaimSnapshotState& Snapshot,
{
const BlockStoreLocation& Location = ChunkLocations[Index];
OldTotalSize += Location.Size;
- if (Snapshot.ExcludeBlockIndexes.contains(Location.BlockIndex))
+ if (Location.BlockIndex == Snapshot.ExcludeBlockIndex)
{
continue;
}