From 79296a86e7ab707ad9336528266ca586d08cdc0a Mon Sep 17 00:00:00 2001 From: akiozihao Date: Thu, 21 Sep 2023 15:33:48 +0800 Subject: [PATCH] check ErrPendingSizeTooLarge first --- wal.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/wal.go b/wal.go index 7dcb63b..8a34de8 100644 --- a/wal.go +++ b/wal.go @@ -354,16 +354,17 @@ func (wal *WAL) WriteAll() ([]*ChunkPosition, error) { wal.mu.Unlock() }() + // if the pending size is still larger than segment size, return error + if wal.pendingSize > wal.options.SegmentSize { + return nil, ErrPendingSizeTooLarge + } + // if the active segment file is full, sync it and create a new one. if wal.activeSegment.Size()+wal.pendingSize > wal.options.SegmentSize { if err := wal.rotateActiveSegment(); err != nil { return nil, err } } - // if the pending size is still larger than segment size, return error - if wal.pendingSize > wal.options.SegmentSize { - return nil, ErrPendingSizeTooLarge - } // write all data to the active segment file. positions, err := wal.activeSegment.writeAll(wal.pendingWrites)