Skip to content

Commit

Permalink
check ErrPendingSizeTooLarge first (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
akiozihao committed Sep 21, 2023
1 parent 8a11180 commit 581142a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 581142a

Please sign in to comment.