Files
seaweedfs/weed/storage/blockvol/v2bridge/reader.go
T
pingqiuandClaude Opus 4.6 680b530314 refactor: Task E — reader returns bridge.BlockVolState directly
Reader backend-binding extraction:
- v2bridge/reader.go: Reader.ReadState() now returns bridge.BlockVolState
  directly instead of a local v2bridge.BlockVolState mirror type.
  Removed the local BlockVolState type entirely.
- block_recovery.go: removed readerShimForRecovery (12 lines of 1:1
  field copying). Reader is now passed directly as bridge.BlockVolReader.

Before: v2bridge.Reader → v2bridge.BlockVolState → readerShim → bridge.BlockVolState
After:  v2bridge.Reader → bridge.BlockVolState (direct)

v2bridge now imports sw-block/bridge/blockvol for the contract type
(control.go already did this, reader.go now follows the same pattern).

Validation:
- go test ./sw-block/bridge/blockvol/... → PASS
- go test ./weed/storage/blockvol/v2bridge/ -run "TestReader_" → PASS
- go test ./weed/server/ -run "TestP4_|TestP16B_" → PASS (8 tests)

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

47 lines
1.7 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 → sw-block/bridge/blockvol (contract types)
// v2bridge → sw-block/engine/replication (engine types)
package v2bridge
import (
bridge "github.com/seaweedfs/seaweedfs/sw-block/bridge/blockvol"
"github.com/seaweedfs/seaweedfs/weed/storage/blockvol"
)
// Reader implements bridge.BlockVolReader by reading real blockvol fields.
// This is a thin backend binding — it fetches a snapshot from real BlockVol
// and returns the contract type directly. No state-shaping logic here.
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.
// Returns bridge.BlockVolState directly (no intermediate local type).
//
// Field mapping:
// WALHeadLSN ← StatusSnapshot().WALHeadLSN
// WALTailLSN ← StatusSnapshot().WALTailLSN
// CommittedLSN ← StatusSnapshot().CommittedLSN
// CheckpointLSN ← StatusSnapshot().CheckpointLSN
// CheckpointTrusted ← StatusSnapshot().CheckpointTrusted
func (r *Reader) ReadState() bridge.BlockVolState {
snap := r.vol.StatusSnapshot()
return bridge.BlockVolState{
WALHeadLSN: snap.WALHeadLSN,
WALTailLSN: snap.WALTailLSN,
CommittedLSN: snap.CommittedLSN,
CheckpointLSN: snap.CheckpointLSN,
CheckpointTrusted: snap.CheckpointTrusted,
}
}