diff options
| author | Dan Engelbrecht <[email protected]> | 2025-05-07 10:23:42 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2025-05-07 10:23:42 +0200 |
| commit | 68938614c95635045a394ff0a52786b82f01ffc4 (patch) | |
| tree | 6193f85d4fe3ec154e78bb494b979a91733f9ae6 /src/zencore/basicfile.cpp | |
| parent | added logic to handle empty directories correctly (#383) (diff) | |
| download | zen-68938614c95635045a394ff0a52786b82f01ffc4.tar.xz zen-68938614c95635045a394ff0a52786b82f01ffc4.zip | |
optimize block store CompactBlocks (#384)
- Improvement: Optimize block compact reducing memcpy operations
- Improvement: Handle padding of block store blocks when compacting to avoid excessive flusing of write buffer
- Improvement: Handle padding when writing oplog index snapshot to avoid unnecessary flushing of write buffer
Diffstat (limited to 'src/zencore/basicfile.cpp')
| -rw-r--r-- | src/zencore/basicfile.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/zencore/basicfile.cpp b/src/zencore/basicfile.cpp index ea526399c..12ee26155 100644 --- a/src/zencore/basicfile.cpp +++ b/src/zencore/basicfile.cpp @@ -792,6 +792,35 @@ BasicFileWriter::~BasicFileWriter() } void +BasicFileWriter::AddPadding(uint64_t Padding) +{ + while (Padding) + { + const uint64_t BufferOffset = m_BufferEnd - m_BufferStart; + const uint64_t RemainingBufferCapacity = m_BufferSize - BufferOffset; + const uint64_t BlockPadBytes = Min(RemainingBufferCapacity, Padding); + + memset(m_Buffer + BufferOffset, 0, BlockPadBytes); + m_BufferEnd += BlockPadBytes; + Padding -= BlockPadBytes; + + if ((BufferOffset + BlockPadBytes) == m_BufferSize) + { + Flush(); + } + } +} + +uint64_t +BasicFileWriter::AlignTo(uint64_t Alignment) +{ + uint64_t AlignedPos = RoundUp(m_BufferEnd, Alignment); + uint64_t Padding = AlignedPos - m_BufferEnd; + AddPadding(Padding); + return AlignedPos; +} + +void BasicFileWriter::Write(const void* Data, uint64_t Size, uint64_t FileOffset) { if (m_Buffer == nullptr || (Size >= m_BufferSize)) |