This instance will be upgraded to Heptapod 0.31.0 (final) on 2022-05-24 at 14:00 UTC+2 (a few minutes of down time)

Commit 8089dd58 authored by Shinya Maeda's avatar Shinya Maeda
Browse files

Swap redis chunks when build finished

parent b18d66c44ef0
......@@ -25,7 +25,7 @@ class Build < CommitStatus
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_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'
delegate :timeout, to: :metadata, prefix: true, allow_nil: true
......
......@@ -4,8 +4,6 @@ class JobTraceChunk < ActiveRecord::Base
belongs_to :job, class_name: "Ci::Build", foreign_key: :job_id
after_destroy :redis_delete_data, if: :redis?
default_value_for :data_store, :redis
WriteError = Class.new(StandardError)
......
......@@ -6,7 +6,10 @@ class BuildFinishedWorker
def perform(build_id)
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)
BuildCoverageWorker.new.perform(build.id)
......
......@@ -100,7 +100,7 @@ def erase!
FileUtils.rm(trace_path, force: true)
end
job.chunks.destroy_all
job.chunks.delete_all
job.erase_old_trace!
end
......@@ -111,7 +111,7 @@ def archive!
if job.chunks.any?
Gitlab::Ci::Trace::ChunkedIO.new(job) do |stream|
archive_stream!(stream)
stream.destroy!
stream.delete!
end
elsif current_path
File.open(current_path) do |stream|
......
......@@ -140,7 +140,7 @@ def truncate(offset)
@size = offset
# 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
current_chunk.truncate(chunk_offset) if chunk_offset != 0
......@@ -156,8 +156,8 @@ def present?
true
end
def destroy!
job_chunks.destroy_all
def delete!
job_chunks.delete_all
@tell = @size = 0
ensure
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