Files
seaweedfs/weed/storage/blockvol/v2bridge/reader.go
T
pingqiuandClaude Opus 4.6 d5b2a3a345 fix: WALTailLSN is now an LSN boundary, ScanWALEntries uses durable checkpoint
Finding 1: WALTailLSN semantic fix
- StatusSnapshot().WALTailLSN now reads super.WALCheckpointLSN (an LSN)
- Was: wal.Tail() which returns a physical byte offset
- Entries with LSN > WALTailLSN are guaranteed in the WAL

Finding 2: ScanWALEntries replay-source fix
- ScanWALEntries passes super.WALCheckpointLSN as the recycled boundary
- Was: flusher.CheckpointLSN() which in V1 equals CommittedLSN
- The flusher's live checkpoint may advance in memory, but entries above
  the durable superblock checkpoint are still physically in the WAL
- Normal catch-up (replica at 70, committed at 100) now works because
  fromLSN=71 > super.WALCheckpointLSN (which is the last persisted
  checkpoint, not the live flusher state)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 20:26:27 -07:00

60 lines
2.1 KiB
Go

// Package v2bridge implements the V2 engine bridge contract interfaces
// using real blockvol internals. This package lives in the weed/ module
// so it can import blockvol directly.
//
// Import direction:
// v2bridge → blockvol (real state)
// v2bridge exports types matching sw-block/bridge/blockvol/ contracts
// v2bridge does NOT import sw-block/ (to avoid cross-module dependency)
//
// The sw-block/bridge/blockvol/ package consumes these implementations
// through its contract interfaces (BlockVolReader, BlockVolPinner, etc.).
package v2bridge
import (
"github.com/seaweedfs/seaweedfs/weed/storage/blockvol"
)
// BlockVolState mirrors the contract type from sw-block/bridge/blockvol/.
// Fields are populated from real blockvol internals.
type BlockVolState struct {
WALHeadLSN uint64
WALTailLSN uint64
CommittedLSN uint64
CheckpointLSN uint64
CheckpointTrusted bool
}
// Reader implements BlockVolReader by reading real blockvol fields.
type Reader struct {
vol *blockvol.BlockVol
}
// NewReader creates a reader for a real blockvol instance.
func NewReader(vol *blockvol.BlockVol) *Reader {
return &Reader{vol: vol}
}
// ReadState reads current blockvol state from real fields.
// Each field maps to a specific blockvol source:
//
// WALHeadLSN ← vol.nextLSN - 1 (last written LSN)
// WALTailLSN ← vol.super.WALCheckpointLSN (LSN boundary, not byte offset)
// CommittedLSN ← vol.flusher.CheckpointLSN() (V1 interim: committed = checkpointed)
// CheckpointLSN ← vol.super.WALCheckpointLSN
// CheckpointTrusted ← vol.super.Validate() == nil (superblock integrity)
//
// Note: CommittedLSN maps to CheckpointLSN in the current V1 model where
// barrier-confirmed = flusher-checkpointed. In V2, these may diverge when
// distributed commit is separated from local flush.
func (r *Reader) ReadState() BlockVolState {
snap := r.vol.StatusSnapshot()
return BlockVolState{
WALHeadLSN: snap.WALHeadLSN,
WALTailLSN: snap.WALTailLSN,
CommittedLSN: snap.CommittedLSN,
CheckpointLSN: snap.CheckpointLSN,
CheckpointTrusted: snap.CheckpointTrusted,
}
}