mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-07-29 19:43:19 +00:00
Local fencing primitives for block volumes. Every write path validates role + epoch + lease before accepting data. RoleNone (default) skips all checks for Phase 3 backward compatibility. New files: epoch.go, lease.go, role.go, write_gate.go Modified: superblock.go (Epoch field), blockvol.go (fencing fields, writeGate in WriteLBA/Trim), group_commit.go (PostSyncCheck/Gotcha A), dirty_map.go (P3-BUG-9 power-of-2 panic) Bug fixes: BUG-4A-1 (atomic epoch), BUG-4A-2 (CAS SetRole), BUG-4A-3 (mutex SetEpoch), BUG-4A-4 (single role.Load), BUG-4A-6 (safeCallback recover) 837 tests (557 engine + 280 iSCSI), all passing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
29 lines
662 B
Go
29 lines
662 B
Go
package blockvol
|
|
|
|
import "errors"
|
|
|
|
var (
|
|
ErrNotPrimary = errors.New("blockvol: not primary")
|
|
ErrEpochStale = errors.New("blockvol: epoch stale")
|
|
ErrLeaseExpired = errors.New("blockvol: lease expired")
|
|
)
|
|
|
|
// writeGate checks role, epoch, and lease before allowing a write.
|
|
// RoleNone skips all checks for Phase 3 backward compatibility.
|
|
func (v *BlockVol) writeGate() error {
|
|
r := Role(v.role.Load())
|
|
if r == RoleNone {
|
|
return nil // Phase 3 compat: no fencing
|
|
}
|
|
if r != RolePrimary {
|
|
return ErrNotPrimary
|
|
}
|
|
if v.epoch.Load() != v.masterEpoch.Load() {
|
|
return ErrEpochStale
|
|
}
|
|
if !v.lease.IsValid() {
|
|
return ErrLeaseExpired
|
|
}
|
|
return nil
|
|
}
|