diff options
| author | Dan Engelbrecht <[email protected]> | 2022-05-27 08:38:36 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-05-27 08:38:36 +0200 |
| commit | 761930a8f0b877ebeaae3c4211d513ee3124c1f6 (patch) | |
| tree | d8e1fb1a3f6cfd08d9a2af89b68836626c043258 /zenstore/blockstore.cpp | |
| parent | Merge pull request #107 from EpicGames/de/single-worker-clang-verify (diff) | |
| parent | Make sure we can properly create the block file before assigning it for use (diff) | |
| download | zen-761930a8f0b877ebeaae3c4211d513ee3124c1f6.tar.xz zen-761930a8f0b877ebeaae3c4211d513ee3124c1f6.zip | |
Merge pull request #110 from EpicGames/de/out-of-disk-space-error-handling
Make sure we can properly create the block file before assigning it for use
Diffstat (limited to 'zenstore/blockstore.cpp')
| -rw-r--r-- | zenstore/blockstore.cpp | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/zenstore/blockstore.cpp b/zenstore/blockstore.cpp index 3e27b0d12..7d3d2f5bb 100644 --- a/zenstore/blockstore.cpp +++ b/zenstore/blockstore.cpp @@ -225,23 +225,27 @@ BlockStore::WriteChunk(const void* Data, uint64_t Size, uint64_t Alignment, Writ { m_WriteBlock = nullptr; } + + if (m_ChunkBlocks.size() == m_MaxBlockCount) { - if (m_ChunkBlocks.size() == m_MaxBlockCount) - { - throw std::runtime_error(fmt::format("unable to allocate a new block in '{}'", m_BlocksBasePath)); - } - WriteBlockIndex += IsWriting ? 1 : 0; - while (m_ChunkBlocks.contains(WriteBlockIndex)) - { - WriteBlockIndex = (WriteBlockIndex + 1) & (m_MaxBlockCount - 1); - } - std::filesystem::path BlockPath = GetBlockPath(m_BlocksBasePath, WriteBlockIndex); - m_WriteBlock = new BlockStoreFile(BlockPath); - m_ChunkBlocks[WriteBlockIndex] = m_WriteBlock; - m_WriteBlockIndex.store(WriteBlockIndex, std::memory_order_release); + throw std::runtime_error(fmt::format("unable to allocate a new block in '{}'", m_BlocksBasePath)); + } + + WriteBlockIndex += IsWriting ? 1 : 0; + while (m_ChunkBlocks.contains(WriteBlockIndex)) + { + WriteBlockIndex = (WriteBlockIndex + 1) & (m_MaxBlockCount - 1); } + + std::filesystem::path BlockPath = GetBlockPath(m_BlocksBasePath, WriteBlockIndex); + + Ref<BlockStoreFile> NewBlockFile = new BlockStoreFile(BlockPath); + NewBlockFile->Create(m_MaxBlockSize); + + m_ChunkBlocks[WriteBlockIndex] = NewBlockFile; + m_WriteBlock = NewBlockFile; + m_WriteBlockIndex.store(WriteBlockIndex, std::memory_order_release); m_CurrentInsertOffset = 0; - m_WriteBlock->Create(m_MaxBlockSize); } uint64_t InsertOffset = m_CurrentInsertOffset; m_CurrentInsertOffset = RoundUp(InsertOffset + Size, Alignment); |