Class: Agent::Lock::Manager::Enforcement
- Inherits:
-
Object
- Object
- Agent::Lock::Manager::Enforcement
- Defined in:
- lib/agent/lock/manager/enforcement.rb
Overview
acquire --enforce: freezing the files of a lock already won, and
writing down which ones.
Freezing happens after the claim is won, never before. Flagging files first and then losing the race would leave a tree full of unwritable files that no lock admits to having frozen, which is the one failure this whole feature is supposed to prevent.
The walk and chflags run outside the store's mutex, since every
other session would be waiting on them. That leaves a window in which
the lock can be noted, broken, or broken and taken by somebody else,
and a record's id is only its tree and scope, so the newcomer's lock
has the id of the one this call won. Writing the record captured
before the walk back over it lost the note, brought a broken lock
back, or replaced another agent's lock with this one; deleting it by
id on a refused freeze deleted the other agent's. So both writes go
back under the mutex and act only on the claim this call won, read
again: #standing.
Instance Method Summary collapse
-
#apply(record, scope, wide:) ⇒ Array(Record, String)
Not for use inside the store's mutex, which it takes itself.
-
#initialize(tree, store) ⇒ Enforcement
constructor
A new instance of Enforcement.
Constructor Details
#initialize(tree, store) ⇒ Enforcement
Returns a new instance of Enforcement.
29 30 31 32 |
# File 'lib/agent/lock/manager/enforcement.rb', line 29 def initialize(tree, store) @tree = tree @store = store end |
Instance Method Details
#apply(record, scope, wide:) ⇒ Array(Record, String)
Not for use inside the store's mutex, which it takes itself.
46 47 48 49 50 51 52 53 |
# File 'lib/agent/lock/manager/enforcement.rb', line 46 def apply(record, scope, wide:) wanted = Freeze.matches(scope, @tree) frozen = Freeze.apply(wanted, tree: @tree, wide: wide) [@store.synchronize { settle(record, scope, frozen) }, shortfall(wanted, frozen)] rescue Freeze::TooBroad @store.synchronize { standing(record, @store.find(scope))&.then { |current| @store.delete(current) } } raise end |