Commit 94ce2233 authored by Shinya Maeda's avatar Shinya Maeda

Swap redis chunks when build finished

parent fd8a63f7
...@@ -25,7 +25,7 @@ module Ci ...@@ -25,7 +25,7 @@ module Ci
has_one :job_artifacts_metadata, -> { where(file_type: Ci::JobArtifact.file_types[:metadata]) }, class_name: 'Ci::JobArtifact', inverse_of: :job, foreign_key: :job_id has_one :job_artifacts_metadata, -> { where(file_type: Ci::JobArtifact.file_types[:metadata]) }, class_name: 'Ci::JobArtifact', inverse_of: :job, foreign_key: :job_id
has_one :job_artifacts_trace, -> { where(file_type: Ci::JobArtifact.file_types[:trace]) }, class_name: 'Ci::JobArtifact', inverse_of: :job, foreign_key: :job_id has_one :job_artifacts_trace, -> { where(file_type: Ci::JobArtifact.file_types[:trace]) }, class_name: 'Ci::JobArtifact', inverse_of: :job, foreign_key: :job_id
has_many :chunks, class_name: 'Ci::JobTraceChunk', foreign_key: :job_id, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent has_many :chunks, class_name: 'Ci::JobTraceChunk', foreign_key: :job_id
has_one :metadata, class_name: 'Ci::BuildMetadata' has_one :metadata, class_name: 'Ci::BuildMetadata'
delegate :timeout, to: :metadata, prefix: true, allow_nil: true delegate :timeout, to: :metadata, prefix: true, allow_nil: true
......
...@@ -4,8 +4,6 @@ module Ci ...@@ -4,8 +4,6 @@ module Ci
belongs_to :job, class_name: "Ci::Build", foreign_key: :job_id belongs_to :job, class_name: "Ci::Build", foreign_key: :job_id
after_destroy :redis_delete_data, if: :redis?
default_value_for :data_store, :redis default_value_for :data_store, :redis
WriteError = Class.new(StandardError) WriteError = Class.new(StandardError)
......
...@@ -6,7 +6,10 @@ class BuildFinishedWorker ...@@ -6,7 +6,10 @@ class BuildFinishedWorker
def perform(build_id) def perform(build_id)
Ci::Build.find_by(id: build_id).try do |build| Ci::Build.find_by(id: build_id).try do |build|
# We execute that in sync as this access the files in order to access local file, and reduce IO # Swap all trace chunks to Database from Redis
build.chunks.redis.map(&:use_database!)
# We execute that in sync as this access the files in order to access local data, and reduce IO
BuildTraceSectionsWorker.new.perform(build.id) BuildTraceSectionsWorker.new.perform(build.id)
BuildCoverageWorker.new.perform(build.id) BuildCoverageWorker.new.perform(build.id)
......
...@@ -100,7 +100,7 @@ module Gitlab ...@@ -100,7 +100,7 @@ module Gitlab
FileUtils.rm(trace_path, force: true) FileUtils.rm(trace_path, force: true)
end end
job.chunks.destroy_all job.chunks.delete_all
job.erase_old_trace! job.erase_old_trace!
end end
...@@ -111,7 +111,7 @@ module Gitlab ...@@ -111,7 +111,7 @@ module Gitlab
if job.chunks.any? if job.chunks.any?
Gitlab::Ci::Trace::ChunkedIO.new(job) do |stream| Gitlab::Ci::Trace::ChunkedIO.new(job) do |stream|
archive_stream!(stream) archive_stream!(stream)
stream.destroy! stream.delete!
end end
elsif current_path elsif current_path
File.open(current_path) do |stream| File.open(current_path) do |stream|
......
...@@ -140,7 +140,7 @@ module Gitlab ...@@ -140,7 +140,7 @@ module Gitlab
@size = offset @size = offset
# remove all next chunks # remove all next chunks
job_chunks.where('chunk_index > ?', chunk_index).destroy_all job_chunks.where('chunk_index > ?', chunk_index).delete_all
# truncate current chunk # truncate current chunk
current_chunk.truncate(chunk_offset) if chunk_offset != 0 current_chunk.truncate(chunk_offset) if chunk_offset != 0
...@@ -156,8 +156,8 @@ module Gitlab ...@@ -156,8 +156,8 @@ module Gitlab
true true
end end
def destroy! def delete!
job_chunks.destroy_all job_chunks.delete_all
@tell = @size = 0 @tell = @size = 0
ensure ensure
invalidate_chunk_cache invalidate_chunk_cache
......
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