Commit 04ab732f authored by Shinya Maeda's avatar Shinya Maeda

Remove traces efficiently

parent 4c1a2a9b
...@@ -376,6 +376,10 @@ module Ci ...@@ -376,6 +376,10 @@ module Ci
trace.exist? trace.exist?
end end
def has_old_trace?
old_trace.present?
end
def trace=(data) def trace=(data)
raise NotImplementedError raise NotImplementedError
end end
...@@ -385,6 +389,8 @@ module Ci ...@@ -385,6 +389,8 @@ module Ci
end end
def erase_old_trace! def erase_old_trace!
raise Gitlab::Ci::Trace::EraseError, 'Old trace does not exist' unless has_old_trace?
update_column(:trace, nil) update_column(:trace, nil)
end end
......
...@@ -6,6 +6,7 @@ module Gitlab ...@@ -6,6 +6,7 @@ module Gitlab
LEASE_TIMEOUT = 1.hour LEASE_TIMEOUT = 1.hour
ArchiveError = Class.new(StandardError) ArchiveError = Class.new(StandardError)
EraseError = Class.new(StandardError)
attr_reader :job attr_reader :job
...@@ -98,14 +99,18 @@ module Gitlab ...@@ -98,14 +99,18 @@ module Gitlab
end end
def erase! def erase!
trace_artifact&.destroy ##
# Erase an archived traces
paths.each do |trace_path| # This removes both a database-row and a real file in either a file storage or a object storage
FileUtils.rm(trace_path, force: true) trace_artifact&.destroy!
end
##
job.trace_chunks.fast_destroy_all # Erase a live trace
job.erase_old_trace! # Basically, jobs have _one_ of the following live traces, but it might be able to happen by a race condition
# Therefore, we remove all type of live traces.
job.trace_chunks.fast_destroy_all # Destroy chunks of a live trace
FileUtils.rm_f(current_path) if current_path # Remove a trace file of a live trace
job.erase_old_trace! if job.has_old_trace? # Remove a trace in database of a live trace
end end
def archive! def archive!
......
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