Commit c588dd84 authored by Shinya Maeda's avatar Shinya Maeda

Rename ExclusiveLease for trace write locking

parent 9d6fe7bf
...@@ -12,9 +12,9 @@ module Ci ...@@ -12,9 +12,9 @@ module Ci
CHUNK_SIZE = 128.kilobytes CHUNK_SIZE = 128.kilobytes
CHUNK_REDIS_TTL = 1.week CHUNK_REDIS_TTL = 1.week
LOCK_RETRY = 100 WRITE_LOCK_RETRY = 100
LOCK_SLEEP = 1 WRITE_LOCK_SLEEP = 1
LOCK_TTL = 5.minutes WRITE_LOCK_TTL = 5.minutes
enum data_store: { enum data_store: {
redis: 1, redis: 1,
...@@ -122,18 +122,18 @@ module Ci ...@@ -122,18 +122,18 @@ module Ci
end end
def redis_lock_key def redis_lock_key
"gitlab:ci:trace:#{build_id}:chunks:#{chunk_index}:lock" "trace_write:#{build_id}:chunks:#{chunk_index}"
end end
def in_lock def in_lock
lease = Gitlab::ExclusiveLease.new(redis_lock_key, timeout: LOCK_TTL) lease = Gitlab::ExclusiveLease.new(redis_lock_key, timeout: WRITE_LOCK_TTL)
retry_count = 0 retry_count = 0
until uuid = lease.try_obtain until uuid = lease.try_obtain
# Keep trying until we obtain the lease. To prevent hammering Redis too # Keep trying until we obtain the lease. To prevent hammering Redis too
# much we'll wait for a bit between retries. # much we'll wait for a bit between retries.
sleep(LOCK_SLEEP) sleep(WRITE_LOCK_SLEEP)
break if LOCK_RETRY < (retry_count += 1) break if WRITE_LOCK_RETRY < (retry_count += 1)
end end
raise WriteError, 'Failed to obtain write lock' unless uuid raise WriteError, 'Failed to obtain write lock' unless uuid
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment