Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions internal/wal/wal_aof.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
wl.bufWriter = bufio.NewWriterSize(wl.currentSegmentFile, wl.bufferSize)

go wl.keepSyncingBuffer()
switch wl.rotationMode {

Check failure on line 126 in internal/wal/wal_aof.go

View workflow job for this annotation

GitHub Actions / lint

singleCaseSwitch: should rewrite switch statement to if statement (gocritic)
case RotationModeTime:
go wl.rotateSegmentPeriodically()
go wl.deleteSegmentPeriodically()
Expand Down Expand Up @@ -171,12 +171,16 @@
}

bb = bb[:8+len(b)]
// Calculate CRC32 only on the payload
chk := crc32.ChecksumIEEE(b)

// Write header and payload
binary.LittleEndian.PutUint32(bb[0:4], chk)
binary.LittleEndian.PutUint32(bb[4:8], entrySize)
binary.LittleEndian.PutUint32(bb[4:8], uint32(len(b)))
copy(bb[8:], b)

wl.bufWriter.Write(bb)

Check failure on line 182 in internal/wal/wal_aof.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `wl.bufWriter.Write` is not checked (errcheck)

wl.currentSegmentSize += entrySize

// if wal-mode unbuffered immediately sync to disk
Expand Down Expand Up @@ -373,15 +377,15 @@
return fmt.Errorf("error reading WAL data: %w", err)
}

// Calculate CRC32 only on the payload part
expectedCRC := crc32.ChecksumIEEE(bb1ElementBytes)
// Calculate CRC32 only on the payload
expectedCRC := crc32.ChecksumIEEE(bb1ElementBytes[:entrySize])
if crc != expectedCRC {
file.Close()
return fmt.Errorf("CRC32 mismatch: expected %d, got %d", crc, expectedCRC)
}

// Unmarshal the WAL entry to get the payload
if err := proto.Unmarshal(bb1ElementBytes, &el); err != nil {
if err := proto.Unmarshal(bb1ElementBytes[:entrySize], &el); err != nil {
file.Close()
return fmt.Errorf("error unmarshaling WAL entry: %w", err)
}
Expand Down
Loading