mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-09-26 09:54:47 +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>
32 lines
701 B
Go
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
|
|
}
|