fix: address Final Verification Wave findings

- Sync() now flushes BlockWriter before fd.Sync() for durability
- Pre-validate encoding before sequence allocation (design doc compliance)
- Remove dead _ = rec assignment in recover.go
- Remove unused maxPayload field from SegmentWriter
- Handle Put error in MemTable.Publish with panic on invariant violation
This commit is contained in:
dailz
2026-06-12 14:29:53 +08:00
parent 5905dbc06f
commit b833a21848
5 changed files with 100 additions and 10 deletions
+3 -4
View File
@@ -19,7 +19,6 @@ type SegmentWriter struct {
startSequence uint64
blockWriter *BlockWriter
currentOffset uint64 // total bytes written (starts at WalFileHeaderSize)
maxPayload uint64 // cfg.MaxSegmentSize - WalFileHeaderSize
}
// NewSegmentWriter creates a new WAL segment file and writes the file header.
@@ -89,8 +88,6 @@ func NewSegmentWriter(
dirFD.Close()
}
maxPayload := cfg.MaxSegmentSize - WalFileHeaderSize
return &SegmentWriter{
fd: fd,
dir: dir,
@@ -99,7 +96,6 @@ func NewSegmentWriter(
startSequence: startSequence,
blockWriter: NewBlockWriter(),
currentOffset: WalFileHeaderSize,
maxPayload: maxPayload,
}, nil
}
@@ -133,6 +129,9 @@ func (sw *SegmentWriter) AppendBatch(encodedBatch []byte) error {
// Sync flushes the segment file to durable storage.
func (sw *SegmentWriter) Sync() error {
if err := sw.blockWriter.Flush(sw.fd); err != nil {
return fmt.Errorf("wal: flushing partial block before sync: %w", err)
}
return sw.fd.Sync()
}