diff options
| author | Dan Engelbrecht <[email protected]> | 2024-09-25 09:48:15 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2024-09-25 09:48:15 +0200 |
| commit | 1f587062485dc7c69e9783cdb8bb187842eafc8a (patch) | |
| tree | 116cec9c8d05aeaf482af9721da600bd9bd00244 /src/zenstore | |
| parent | 5.5.8-pre1 (diff) | |
| download | zen-1f587062485dc7c69e9783cdb8bb187842eafc8a.tar.xz zen-1f587062485dc7c69e9783cdb8bb187842eafc8a.zip | |
exception safety when writing block (#168)
* make sure we always clear writing block from m_ActiveWriteBlocks even if we have an exception
Diffstat (limited to 'src/zenstore')
| -rw-r--r-- | src/zenstore/blockstore.cpp | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/zenstore/blockstore.cpp b/src/zenstore/blockstore.cpp index 00a38c3b6..7c6677052 100644 --- a/src/zenstore/blockstore.cpp +++ b/src/zenstore/blockstore.cpp @@ -539,16 +539,15 @@ BlockStore::WriteChunk(const void* Data, uint64_t Size, uint32_t Alignment, cons Ref<BlockStoreFile> WriteBlock = m_WriteBlock; m_ActiveWriteBlocks.push_back(WriteBlockIndex); InsertLock.ReleaseNow(); + auto _ = MakeGuard([this, WriteBlockIndex]() { + RwLock::ExclusiveLockScope _(m_InsertLock); + m_ActiveWriteBlocks.erase(std::find(m_ActiveWriteBlocks.begin(), m_ActiveWriteBlocks.end(), WriteBlockIndex)); + }); WriteBlock->Write(Data, ChunkSize, AlignedInsertOffset); m_TotalSize.fetch_add(AlignedWriteSize, std::memory_order::relaxed); Callback({.BlockIndex = WriteBlockIndex, .Offset = AlignedInsertOffset, .Size = ChunkSize}); - - { - RwLock::ExclusiveLockScope _(m_InsertLock); - m_ActiveWriteBlocks.erase(std::find(m_ActiveWriteBlocks.begin(), m_ActiveWriteBlocks.end(), WriteBlockIndex)); - } } void @@ -615,6 +614,10 @@ BlockStore::WriteChunks(std::span<IoBuffer> Datas, uint32_t Alignment, const Wri Ref<BlockStoreFile> WriteBlock = m_WriteBlock; m_ActiveWriteBlocks.push_back(WriteBlockIndex); InsertLock.ReleaseNow(); + auto _ = MakeGuard([this, WriteBlockIndex]() { + RwLock::ExclusiveLockScope _(m_InsertLock); + m_ActiveWriteBlocks.erase(std::find(m_ActiveWriteBlocks.begin(), m_ActiveWriteBlocks.end(), WriteBlockIndex)); + }); { MutableMemoryView WriteBuffer(Buffer.data(), RangeSize); @@ -639,11 +642,6 @@ BlockStore::WriteChunks(std::span<IoBuffer> Datas, uint32_t Alignment, const Wri } Callback(Locations); - { - RwLock::ExclusiveLockScope _(m_InsertLock); - m_ActiveWriteBlocks.erase(std::find(m_ActiveWriteBlocks.begin(), m_ActiveWriteBlocks.end(), WriteBlockIndex)); - } - Offset += Count; } } |