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

Add lock for delete

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