Commit 3a87bfb2 authored by Shinya Maeda's avatar Shinya Maeda

Add lock for delete

parent 0971f301
......@@ -110,7 +110,7 @@ module Gitlab
raise ArchiveError, 'Job is not finished yet' unless job.complete?
if ChunkedFile::LiveTrace.exist?(job.id)
ChunkedFile::LiveTrace.open(job.id, "wb") do |stream|
ChunkedFile::LiveTrace.open(job.id, 'a+b') do |stream|
archive_stream!(stream)
stream.delete
end
......
......@@ -128,7 +128,11 @@ module Gitlab
end
def present?
true
chunk_store.chunks_count(job_id) > 0
end
def delete
chunk_store.delete_all
end
private
......
......@@ -21,6 +21,7 @@ module Gitlab
# write_lock
before_method :write, :check_lock!
before_method :truncate, :check_lock!
before_method :delete, :check_lock!
end
def initialize(job_id, size, mode = 'rb')
......@@ -43,7 +44,7 @@ module Gitlab
end
def check_lock!
raise PermissionError, 'Could not write without lock' unless write_lock_uuid
raise PermissionError, 'Could not modify the file without lock' unless write_lock_uuid
end
def can_read!
......
......@@ -29,7 +29,7 @@ module Gitlab
# Efficient process than iterating each
def truncate(offset)
if truncate == 0
self.delete_all(job_id)
delete
elsif offset == size
# no-op
else
......@@ -37,6 +37,10 @@ module Gitlab
end
end
def present?
self.exist?(job_id)
end
def delete
ChunkStores::Redis.delete_all(job_id)
ChunkStores::Database.delete_all(job_id)
......
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