Class: Higgs::LockManager::CollisionCheckLockHandler
- Inherits:
-
CriticalRegionLockHandler
- Object
- CriticalRegionLockHandler
- Higgs::LockManager::CollisionCheckLockHandler
- Defined in:
- lib/higgs/lock.rb
Instance Method Summary collapse
- #check_collision ⇒ Object
-
#initialize(*args) ⇒ CollisionCheckLockHandler
constructor
A new instance of CollisionCheckLockHandler.
- #lock(key, type, cnum) ⇒ Object
Methods inherited from CriticalRegionLockHandler
Constructor Details
#initialize(*args) ⇒ CollisionCheckLockHandler
Returns a new instance of CollisionCheckLockHandler.
65 66 67 68 |
# File 'lib/higgs/lock.rb', line 65 def initialize(*args) super @cnum_map = {} end |
Instance Method Details
#check_collision ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/higgs/lock.rb', line 79 def check_collision for (key, type), cnum in @cnum_map last_cnum = yield(key, type) if (cnum != last_cnum) then raise CollisionError, "`#{key}(#{type})' is changed (cnum: #{cnum.inspect} -> #{last_cnum.inspect}) by other transaction and this transaction may be retried." end end self end |
#lock(key, type, cnum) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/higgs/lock.rb', line 70 def lock(key, type, cnum) key_pair = [ key, type ] if (@cnum_map[key_pair] && @cnum_map[key_pair] != cnum) then raise "unexpected changed cnum at`#{key}(#{type})': #{@cnum_map[key].inspect} -> #{cnum.inspect}" end @cnum_map[key_pair] = cnum self end |