avoid name collision for locks method

This commit is contained in:
Nick Elser
2015-04-13 20:29:03 -07:00
parent 1dee338e16
commit 7591c08a28

View File

@@ -39,9 +39,9 @@ module Suo
def locks(key) def locks(key)
val, _ = get(key) val, _ = get(key)
locks = deserialize_locks(val) cleared_locks = deserialize_and_clear_locks(val)
locks cleared_locks
end end
def refresh(key, acquisition_token) def refresh(key, acquisition_token)
@@ -53,11 +53,11 @@ module Suo
next next
end end
locks = deserialize_and_clear_locks(val) cleared_locks = deserialize_and_clear_locks(val)
refresh_lock(locks, acquisition_token) refresh_lock(cleared_locks, acquisition_token)
break if set(key, serialize_locks(locks), cas) break if set(key, serialize_locks(cleared_locks), cas)
end end
end end
@@ -69,12 +69,12 @@ module Suo
break if val.nil? break if val.nil?
locks = deserialize_and_clear_locks(val) cleared_locks = deserialize_and_clear_locks(val)
acquisition_lock = remove_lock(locks, acquisition_token) acquisition_lock = remove_lock(cleared_locks, acquisition_token)
break unless acquisition_lock break unless acquisition_lock
break if set(key, serialize_locks(locks), cas) break if set(key, serialize_locks(cleared_locks), cas)
end end
rescue LockClientError => _ # rubocop:disable Lint/HandleExceptions rescue LockClientError => _ # rubocop:disable Lint/HandleExceptions
# ignore - assume success due to optimistic locking # ignore - assume success due to optimistic locking
@@ -98,12 +98,12 @@ module Suo
next next
end end
locks = deserialize_and_clear_locks(val) cleared_locks = deserialize_and_clear_locks(val)
if locks.size < resources if cleared_locks.size < resources
add_lock(locks, token) add_lock(cleared_locks, token)
newval = serialize_locks(locks) newval = serialize_locks(cleared_locks)
if set(key, newval, cas) if set(key, newval, cas)
acquisition_token = token acquisition_token = token
@@ -171,8 +171,8 @@ module Suo
locks.reject { |time, _| time < expired } locks.reject { |time, _| time < expired }
end end
def add_lock(locks, token) def add_lock(locks, token, time = Time.now.to_f)
locks << [Time.now.to_f, token] locks << [time, token]
end end
def remove_lock(locks, acquisition_token) def remove_lock(locks, acquisition_token)