mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 11:07:31 +01:00
* filer/posixlock: key lock owners and leases by principal A lock's owner becomes (Principal, Sid, Owner). The principal is server-side state, empty for unscoped callers, so owners with equal client-chosen sid and owner under different principals conflict and never match on unlock, release, reassertion or coalescing. The session index and leases key on (Principal, Sid). Scoped sessions are leased per key from their first acquisition: the lease ends at the earlier of TTL after the last acquisition or renewal on that key and Lease.NotAfter. Expired scoped locks are dropped before any operation on their key as well as by ReapExpired. Unscoped sessions keep their current whole-session lease, started by the first keepalive. The handler passes the unscoped session for now, so behaviour is unchanged. NewManagerWithClock lets tests drive lease boundaries. * filer: bind scoped POSIX locks to the verified token id PosixLock trusted the client-supplied sid. GET_LK reports a conflicting lock's sid and owner, so a scoped caller with a write grant on the same path could reuse them to unlock or release another holder's lock, keep it alive, or replace it through a KEEP_ALIVE reassertion. A tokenless request with the same identity could do the same. A request admitted for a scoped token now acts for that token's verified jti, derived in posixLockAuthority from the interceptor's authority. It controls only the locks it took, whatever sid or owner it names. Its lease on each key ends at the earlier of the 15s TTL after its last acquisition or renewal and the token's expiry plus the clock leeway. Each renewal passes admission for its key, so a narrower token cannot extend keys outside its grant. Tokenless and unscoped calls keep the unscoped namespace and behaviour, and can no longer match a scoped lock. Scoped TRY_LOCK and reassertion ranges must be well-formed read or write ranges, checked before any state changes. GET_LK, the protobuf and forwarding are unchanged; the principal is never returned or logged. A renewed token with a new jti is a new owner: the old locks expire and are reacquired. * filer/posixlock: release an expired session once, however many ranges it holds * posix locks: report a lock lost on re-assertion to the mount A mount whose lease lapsed, for example when its scoped token expired or was replaced by one with a new id, kept re-asserting locks that another session had since taken. The filer logged the loss but returned success, and the mount discarded the reply, so nothing on the mount side showed it. KEEP_ALIVE now returns the first conflicting lock in the existing has_conflict and conflict fields, which older mounts ignore. The mount warns once per key when it learns of a loss and forgets it once a re-assertion succeeds or the key is no longer held. Writes are not fenced. * filer/posixlock: drop every expired session's ranges in one pass * filer/posixlock: renew a scoped session's same-grant leases together Scoped leases expire per key and a keepalive renewed only the key it named. A mount renews its keys one keepalive at a time, so with many keys and slow keepalives a round could outlast the 15s lease and a healthy mount lost locks; unscoped sessions never had this problem because any keepalive renews the whole session. Each scoped lease now records a fingerprint of the verified grants it was acquired or re-asserted under: a SHA-256 over the sorted, deduplicated (access level, path) entries. A keepalive, bare or re-assertion, extends every live lease of the same session (principal and sid) held under the same fingerprint, each to the request's lease (the earlier of the TTL and the token's expiry plus leeway). Leases taken under other grants, such as a narrower token reusing the jti, are still renewed only by name, and a lease that already ended is not revived before the sweep drops it. No extra filer lookups; unscoped sessions are unchanged. * filer/posixlock: bound same-grant renewal and refuse ended-lease grants A scoped keepalive scanned every key of its session to renew those held under the same grant, so a mount renewing N keys one by one did N^2 lease visits per round under the manager's mutex. The scan now runs at most once per quarter lease TTL per grant; every key under the grant still ends no earlier than three quarters of a TTL after the latest renewal, and the named key is always renewed in full. TryLock now refuses a scoped grant whose lease has already ended, such as a request admitted just before its token expired that then waited on the manager, instead of granting a lock the next operation would drop. The filer returns Unauthenticated, which the mount reports as EIO. * filer/posixlock: skip same-grant scans by deadline floor, not by time The scan throttle remembered when a grant was last renewed, not how long that renewal made its keys last. A replacement token with the same id and grants but a later expiry could then renew one key while the others kept ending at the old token's expiry. Each session now keeps, per grant, the deadline the last scan gave every live key under it, lowered whenever a key is leased for less. A renewal skips the scan only while that floor already reaches the earlier of its own deadline and three quarters of a TTL from now, so a mount renewing keys one by one still costs linear work. A keepalive from a session holding no leases records nothing, and a session's floors go with its last lease, so lock-less keepalives with changing session ids no longer accumulate state the sweeper never sees. * filer/posixlock: never move a scoped lease's deadline earlier Renew, a re-assertion, a same-grant scan and a re-lock all set the key's deadline to the request's own bound. A request under the old token of a principal that already renews under a replacement (same id and grants, later expiry) can land after the replacement's renewal, for example one of the 32 concurrent keepalives in flight when the mount switched credentials. It then cut the key back to the old token's expiry, and the lock was dropped before the next round although the replacement had renewed it. Keep the later of the current and the requested deadline: every deadline still comes from an admitted request of the same principal, so a lease never outlives the latest of its tokens. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer/posixlock: keep each session's index and leases in one map bySession, lastSeen, leases and floors were four maps keyed by Session that had to be created and pruned together. They become one sessions map whose sessionState holds the session's keys (with each key's lease), its last keepalive and its grant floors, so a session's state is dropped in one place. The release loop shared by ReapExpired and ReleaseSession becomes releaseOn. ReleaseSession now also forgets an unscoped session's last keepalive, so a session it released is not reported again by the next sweep. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
502 lines
14 KiB
Go
502 lines
14 KiB
Go
package posixlock
|
|
|
|
import (
|
|
"errors"
|
|
"math"
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
// Manager is the owner filer's in-memory authority for POSIX advisory locks
|
|
// across inodes. Lock state lives here, not in replicated metadata: it is
|
|
// transient coordination, so keeping it out of the meta-log avoids churn and
|
|
// does not pollute what subscribers see (the distributed lock manager holds its
|
|
// locks the same way). A `Set` per inode key, plus a session index so a dead
|
|
// mount's locks are reaped in O(locks held) rather than by scanning every inode.
|
|
//
|
|
// key is an opaque inode identity supplied by the caller — the file's path, or
|
|
// "hl:"+hex(HardLinkId) for a hardlinked inode — so all names of one inode share
|
|
// a Set. The Manager is safe for concurrent use.
|
|
//
|
|
// Unscoped sessions (empty Principal) are leased as a whole once they renew.
|
|
// A scoped session is leased per key from its first acquisition: the lease ends
|
|
// at the earlier of Lease.TTL after its last acquisition or renewal on that key
|
|
// and Lease.NotAfter; no request moves it earlier, so a late request under an
|
|
// older token cannot cut short a replacement's renewal. A renewal also extends
|
|
// the session's other keys taken under the same Lease.Grant, skipping the scan
|
|
// while those keys already last long enough, so a mount renewing many keys one
|
|
// by one costs linear, not quadratic, work. Expired scoped locks are dropped
|
|
// before any operation on their key, so they never block a new holder until
|
|
// the next sweep.
|
|
type Manager struct {
|
|
mu sync.Mutex
|
|
now func() time.Time
|
|
byKey map[string]*Set // inode key -> held locks
|
|
sessions map[Session]*sessionState // session -> keys it holds locks on, and its leases
|
|
}
|
|
|
|
// sessionState is one session's index and lease state. keys maps each key the
|
|
// session holds locks on to its lease there, which only a scoped session has.
|
|
// lastSeen is an unscoped session's last keepalive, zero until it renews: only
|
|
// renewing sessions are leased. floors maps a scoped session's grant to the
|
|
// deadline every live key under it reaches.
|
|
type sessionState struct {
|
|
keys map[string]keyLease
|
|
lastSeen time.Time
|
|
floors map[string]time.Time
|
|
}
|
|
|
|
// ErrLeaseEnded refuses a scoped lock whose lease would end before it is
|
|
// granted, such as a request admitted just before its token expired.
|
|
var ErrLeaseEnded = errors.New("posix lock lease has already ended")
|
|
|
|
// Session is a mount session under the authority that holds it. Sid is chosen
|
|
// by the client; Principal, set by the server from the verified credential, is
|
|
// empty for unscoped callers.
|
|
type Session struct {
|
|
Principal string
|
|
Sid uint64
|
|
}
|
|
|
|
// Lease bounds a scoped session's hold on a key. It is ignored for unscoped
|
|
// sessions.
|
|
//
|
|
// Grant identifies the authority the caller holds, such as a digest of its
|
|
// verified grants. A key remembers the Grant it was acquired or re-asserted
|
|
// under, and a renewal under the same non-empty Grant extends every such key of
|
|
// the session: the caller could renew each of them on its own, and renewing
|
|
// them together keeps a mount that holds many keys from losing some while it
|
|
// renews them one by one. A key taken under another Grant, or under none, is
|
|
// renewed only by name.
|
|
type Lease struct {
|
|
TTL time.Duration
|
|
NotAfter time.Time
|
|
Grant string
|
|
}
|
|
|
|
// keyLease is a scoped session's lease on one key.
|
|
type keyLease struct {
|
|
deadline time.Time
|
|
grant string
|
|
}
|
|
|
|
func NewManager() *Manager {
|
|
return NewManagerWithClock(time.Now)
|
|
}
|
|
|
|
// NewManagerWithClock returns a Manager whose leases follow now.
|
|
func NewManagerWithClock(now func() time.Time) *Manager {
|
|
return &Manager{
|
|
now: now,
|
|
byKey: make(map[string]*Set),
|
|
sessions: make(map[Session]*sessionState),
|
|
}
|
|
}
|
|
|
|
// Renew records a keepalive from a session. An unscoped session is placed under
|
|
// lease management as a whole, regardless of key: only sessions that have
|
|
// renewed are subject to ReapExpired, so a session that never sends keepalives
|
|
// (e.g. before the mount keepalive exists) is never reaped. A scoped session
|
|
// renews its existing lease on key, keeping the Grant the key was taken under,
|
|
// and its other live leases taken under lease.Grant.
|
|
func (m *Manager) Renew(key string, ss Session, lease Lease) {
|
|
m.mu.Lock()
|
|
defer m.mu.Unlock()
|
|
if ss.Principal == "" {
|
|
m.session(ss).lastSeen = m.now()
|
|
return
|
|
}
|
|
m.live(key)
|
|
if st := m.sessions[ss]; st != nil {
|
|
if l, held := st.keys[key]; held {
|
|
l.deadline = laterOf(l.deadline, m.deadline(lease))
|
|
st.keys[key] = l
|
|
st.lowerFloor(l)
|
|
}
|
|
}
|
|
m.renewGrant(ss, lease)
|
|
}
|
|
|
|
// ReapExpired releases the locks of every leased unscoped session whose last
|
|
// keepalive is older than ttl — a dead or partitioned mount — and of every
|
|
// scoped lease past its deadline. Unscoped sessions that never renewed are left
|
|
// untouched. Returns the reaped session ids.
|
|
func (m *Manager) ReapExpired(ttl time.Duration) []uint64 {
|
|
m.mu.Lock()
|
|
defer m.mu.Unlock()
|
|
now := m.now()
|
|
cutoff := now.Add(-ttl)
|
|
var reaped []uint64
|
|
for ss, st := range m.sessions {
|
|
if ss.Principal == "" {
|
|
if st.lastSeen.IsZero() || st.lastSeen.After(cutoff) {
|
|
continue
|
|
}
|
|
for key := range st.keys {
|
|
m.releaseOn(key, ss)
|
|
}
|
|
delete(m.sessions, ss)
|
|
reaped = append(reaped, ss.Sid)
|
|
continue
|
|
}
|
|
expired := false
|
|
for key, l := range st.keys {
|
|
if now.Before(l.deadline) {
|
|
continue
|
|
}
|
|
m.releaseOn(key, ss)
|
|
m.deindex(ss, key)
|
|
expired = true
|
|
}
|
|
if expired {
|
|
reaped = append(reaped, ss.Sid)
|
|
}
|
|
}
|
|
return reaped
|
|
}
|
|
|
|
// TryLock grants lk on key, or returns the conflicting lock and false. The set
|
|
// is created on first use and dropped again when it empties. A grant to a
|
|
// scoped session starts or extends its lease on key; when that lease has
|
|
// already ended, nothing is granted and the error is ErrLeaseEnded.
|
|
func (m *Manager) TryLock(key string, lk Range, lease Lease) (Range, bool, error) {
|
|
m.mu.Lock()
|
|
defer m.mu.Unlock()
|
|
if lk.Principal != "" && !m.now().Before(m.deadline(lease)) {
|
|
return Range{}, false, ErrLeaseEnded
|
|
}
|
|
s := m.live(key)
|
|
created := s == nil
|
|
if created {
|
|
s = &Set{}
|
|
}
|
|
if c, granted := s.Acquire(lk); !granted {
|
|
return c, false, nil
|
|
}
|
|
if created {
|
|
m.byKey[key] = s
|
|
}
|
|
m.index(lk.Session(), key)
|
|
if lk.Principal != "" {
|
|
m.lease(lk.Session(), key, lease)
|
|
}
|
|
return Range{}, true, nil
|
|
}
|
|
|
|
// Track records a lock the server already granted, without arbitration. A mount
|
|
// uses it to mirror its own held locks so it can re-assert them to the inode's
|
|
// current owner filer after an ownership change or owner restart.
|
|
func (m *Manager) Track(key string, lk Range) {
|
|
m.mu.Lock()
|
|
defer m.mu.Unlock()
|
|
s, ok := m.byKey[key]
|
|
if !ok {
|
|
s = &Set{}
|
|
m.byKey[key] = s
|
|
}
|
|
s.Grant(lk)
|
|
m.index(lk.Session(), key)
|
|
}
|
|
|
|
// Snapshot returns a copy of the held locks per key. A mount calls it to drive
|
|
// re-assertion keepalives; the filer never does.
|
|
func (m *Manager) Snapshot() map[string][]Range {
|
|
m.mu.Lock()
|
|
defer m.mu.Unlock()
|
|
out := make(map[string][]Range, len(m.byKey))
|
|
for key, s := range m.byKey {
|
|
out[key] = append([]Range(nil), s.locks...)
|
|
}
|
|
return out
|
|
}
|
|
|
|
// Reassert rebuilds session ss's locks on key from the client's authoritative
|
|
// list, renewing the lease. It replaces ss's existing locks on the key, then
|
|
// re-acquires each asserted lock as ss — arbitrating against other sessions so
|
|
// it never double-grants. Locks that lost to another session in a migration
|
|
// window are returned as conflicts. A scoped re-assertion also renews ss's other
|
|
// live leases taken under lease.Grant, as Renew does. The owner filer calls this
|
|
// on a re-assertion keepalive.
|
|
func (m *Manager) Reassert(key string, ss Session, locks []Range, lease Lease) (conflicts []Range) {
|
|
m.mu.Lock()
|
|
defer m.mu.Unlock()
|
|
if ss.Principal == "" {
|
|
m.session(ss).lastSeen = m.now()
|
|
}
|
|
|
|
s := m.live(key)
|
|
if s == nil {
|
|
if len(locks) == 0 {
|
|
return nil
|
|
}
|
|
s = &Set{}
|
|
m.byKey[key] = s
|
|
}
|
|
s.ReleaseSession(ss)
|
|
for _, lk := range locks {
|
|
lk.Sid, lk.Principal = ss.Sid, ss.Principal
|
|
if c, granted := s.Acquire(lk); !granted {
|
|
conflicts = append(conflicts, c)
|
|
}
|
|
}
|
|
if setHasSession(s, ss) {
|
|
m.index(ss, key)
|
|
if ss.Principal != "" {
|
|
m.lease(ss, key, lease)
|
|
}
|
|
} else {
|
|
m.deindex(ss, key)
|
|
}
|
|
if s.Empty() {
|
|
delete(m.byKey, key)
|
|
}
|
|
if ss.Principal != "" {
|
|
m.renewGrant(ss, lease)
|
|
}
|
|
return conflicts
|
|
}
|
|
|
|
// Unlock releases lk's owner's locks within its namespace over lk's range.
|
|
func (m *Manager) Unlock(key string, lk Range) {
|
|
m.mu.Lock()
|
|
defer m.mu.Unlock()
|
|
s := m.live(key)
|
|
if s == nil {
|
|
return
|
|
}
|
|
s.Release(lk)
|
|
m.afterRelease(key, s, lk.Session())
|
|
}
|
|
|
|
// GetLk reports the lock that would block proposed on key, if any.
|
|
func (m *Manager) GetLk(key string, proposed Range) (Range, bool) {
|
|
m.mu.Lock()
|
|
defer m.mu.Unlock()
|
|
s := m.live(key)
|
|
if s == nil {
|
|
return Range{}, false
|
|
}
|
|
return s.Conflict(proposed)
|
|
}
|
|
|
|
// ReleasePosixOwner drops (ss, owner)'s fcntl locks on key — the flush-time path.
|
|
func (m *Manager) ReleasePosixOwner(key string, ss Session, owner uint64) {
|
|
m.mu.Lock()
|
|
defer m.mu.Unlock()
|
|
s := m.live(key)
|
|
if s == nil {
|
|
return
|
|
}
|
|
s.ReleasePosixOwner(ss, owner)
|
|
m.afterRelease(key, s, ss)
|
|
}
|
|
|
|
// ReleaseFlockOwner drops (ss, owner)'s flock locks on key — the release-time path.
|
|
func (m *Manager) ReleaseFlockOwner(key string, ss Session, owner uint64) {
|
|
m.mu.Lock()
|
|
defer m.mu.Unlock()
|
|
s := m.live(key)
|
|
if s == nil {
|
|
return
|
|
}
|
|
s.ReleaseFlockOwner(ss, owner)
|
|
m.afterRelease(key, s, ss)
|
|
}
|
|
|
|
// ReleaseSession drops every lock held by a session across all inodes it touched,
|
|
// reaping a mount whose lease expired. O(locks held by the session).
|
|
func (m *Manager) ReleaseSession(ss Session) {
|
|
m.mu.Lock()
|
|
defer m.mu.Unlock()
|
|
if st := m.sessions[ss]; st != nil {
|
|
for key := range st.keys {
|
|
m.releaseOn(key, ss)
|
|
}
|
|
}
|
|
delete(m.sessions, ss)
|
|
}
|
|
|
|
// releaseOn drops ss's locks on key, and the set when it empties.
|
|
func (m *Manager) releaseOn(key string, ss Session) {
|
|
s := m.byKey[key]
|
|
if s == nil {
|
|
return
|
|
}
|
|
s.ReleaseSession(ss)
|
|
if s.Empty() {
|
|
delete(m.byKey, key)
|
|
}
|
|
}
|
|
|
|
// live returns key's set after dropping the locks of scoped sessions whose
|
|
// lease on key has ended, or nil when nothing is held.
|
|
func (m *Manager) live(key string) *Set {
|
|
s := m.byKey[key]
|
|
if s == nil {
|
|
return nil
|
|
}
|
|
now := m.now()
|
|
// One pass finds the expired sessions and one more drops all their ranges,
|
|
// however many sessions expired and ranges they hold.
|
|
var expired map[Session]struct{}
|
|
for _, l := range s.locks {
|
|
ss := l.Session()
|
|
if ss.Principal == "" {
|
|
continue
|
|
}
|
|
if _, seen := expired[ss]; seen {
|
|
continue
|
|
}
|
|
if st := m.sessions[ss]; st != nil {
|
|
if l, ok := st.keys[key]; ok && now.Before(l.deadline) {
|
|
continue
|
|
}
|
|
}
|
|
if expired == nil {
|
|
expired = make(map[Session]struct{})
|
|
}
|
|
expired[ss] = struct{}{}
|
|
}
|
|
if expired != nil {
|
|
s.remove(func(h Range) bool {
|
|
_, gone := expired[h.Session()]
|
|
return gone
|
|
}, 0, math.MaxUint64)
|
|
for ss := range expired {
|
|
m.deindex(ss, key)
|
|
}
|
|
}
|
|
if s.Empty() {
|
|
delete(m.byKey, key)
|
|
return nil
|
|
}
|
|
return s
|
|
}
|
|
|
|
// lease sets ss's lease on key to lease's deadline, held under lease.Grant.
|
|
func (m *Manager) lease(ss Session, key string, lease Lease) {
|
|
st := m.session(ss)
|
|
l := keyLease{deadline: laterOf(st.keys[key].deadline, m.deadline(lease)), grant: lease.Grant}
|
|
st.keys[key] = l
|
|
st.lowerFloor(l)
|
|
}
|
|
|
|
// lowerFloor keeps the floor for l.grant at or below l's deadline, so a key
|
|
// leased for less than the last same-grant renewal gave its peers is never
|
|
// skipped by the next one.
|
|
func (st *sessionState) lowerFloor(l keyLease) {
|
|
if f, ok := st.floors[l.grant]; ok && l.deadline.Before(f) {
|
|
st.floors[l.grant] = l.deadline
|
|
}
|
|
}
|
|
|
|
// deadline is the earlier of lease.TTL from now and lease.NotAfter.
|
|
func (m *Manager) deadline(lease Lease) time.Time {
|
|
deadline := m.now().Add(lease.TTL)
|
|
if lease.NotAfter.Before(deadline) {
|
|
deadline = lease.NotAfter
|
|
}
|
|
return deadline
|
|
}
|
|
|
|
// renewGrant extends ss's leases taken under lease.Grant to lease's deadline.
|
|
// A lease that has already ended stays ended even before it is swept, so when
|
|
// a lease ends never depends on when the sweep runs.
|
|
//
|
|
// A mount renews its keys one by one, and a scan per renewal would cost N² for
|
|
// N keys. So the scan is skipped while every live key under the grant already
|
|
// lasts until the earlier of lease's deadline and three quarters of a TTL from
|
|
// now: the floor the last scan set, lowered by any key leased for less since.
|
|
// A renewal with a later deadline than the floor, such as one under a
|
|
// replacement token that expires later, scans as soon as the floor falls short.
|
|
func (m *Manager) renewGrant(ss Session, lease Lease) {
|
|
st := m.sessions[ss]
|
|
if lease.Grant == "" || st == nil {
|
|
return
|
|
}
|
|
now, deadline := m.now(), m.deadline(lease)
|
|
enough := now.Add(lease.TTL * 3 / 4)
|
|
if deadline.Before(enough) {
|
|
enough = deadline
|
|
}
|
|
if f, ok := st.floors[lease.Grant]; ok && !f.Before(enough) {
|
|
return
|
|
}
|
|
renewed := false
|
|
for key, l := range st.keys {
|
|
if l.grant == lease.Grant && now.Before(l.deadline) {
|
|
l.deadline = laterOf(l.deadline, deadline)
|
|
st.keys[key] = l
|
|
renewed = true
|
|
}
|
|
}
|
|
if !renewed {
|
|
return
|
|
}
|
|
if st.floors == nil {
|
|
st.floors = make(map[string]time.Time)
|
|
}
|
|
st.floors[lease.Grant] = deadline
|
|
}
|
|
|
|
func laterOf(a, b time.Time) time.Time {
|
|
if a.After(b) {
|
|
return a
|
|
}
|
|
return b
|
|
}
|
|
|
|
// afterRelease prunes the session index when ss no longer holds any lock on key,
|
|
// and drops the set when it empties. Only ss's presence can have changed, since
|
|
// a release only removes ss's locks.
|
|
func (m *Manager) afterRelease(key string, s *Set, ss Session) {
|
|
if s.Empty() {
|
|
delete(m.byKey, key)
|
|
m.deindex(ss, key)
|
|
return
|
|
}
|
|
if !setHasSession(s, ss) {
|
|
m.deindex(ss, key)
|
|
}
|
|
}
|
|
|
|
// session returns ss's state, creating it on first use.
|
|
func (m *Manager) session(ss Session) *sessionState {
|
|
st := m.sessions[ss]
|
|
if st == nil {
|
|
st = &sessionState{keys: make(map[string]keyLease)}
|
|
m.sessions[ss] = st
|
|
}
|
|
return st
|
|
}
|
|
|
|
func (m *Manager) index(ss Session, key string) {
|
|
st := m.session(ss)
|
|
if _, ok := st.keys[key]; !ok {
|
|
st.keys[key] = keyLease{}
|
|
}
|
|
}
|
|
|
|
// deindex forgets that ss holds locks on key, along with its lease there. A
|
|
// session holding no keys is forgotten, with its floors, unless it is an
|
|
// unscoped session that has renewed.
|
|
func (m *Manager) deindex(ss Session, key string) {
|
|
st := m.sessions[ss]
|
|
if st == nil {
|
|
return
|
|
}
|
|
delete(st.keys, key)
|
|
if len(st.keys) == 0 && st.lastSeen.IsZero() {
|
|
delete(m.sessions, ss)
|
|
}
|
|
}
|
|
|
|
func setHasSession(s *Set, ss Session) bool {
|
|
for _, l := range s.Locks() {
|
|
if l.Session() == ss {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|