Files
seaweedfs/weed/storage/blockvol/lease.go
T
Ping QiuandClaude Opus 4.6 a107685f00 feat: Phase 4A CP1 — epoch, lease, role state machine, write gate
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>
2026-03-01 16:00:06 -08:00

32 lines
701 B
Go

package blockvol
import (
"sync/atomic"
"time"
)
// Lease tracks a runtime-only lease expiry for write fencing.
// Zero-value is an expired (invalid) lease. Not persisted.
type Lease struct {
expiry atomic.Value // stores time.Time
}
// Grant sets the lease to expire after ttl from now.
func (l *Lease) Grant(ttl time.Duration) {
l.expiry.Store(time.Now().Add(ttl))
}
// IsValid returns true if the lease has not expired.
func (l *Lease) IsValid() bool {
v := l.expiry.Load()
if v == nil {
return false
}
return time.Now().Before(v.(time.Time))
}
// Revoke immediately invalidates the lease.
func (l *Lease) Revoke() {
l.expiry.Store(time.Time{}) // zero time is always in the past
}