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:
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user