Swap redis chunks when build finished

This commit is contained in:
Shinya Maeda 2018-04-24 14:53:14 +09:00
parent fd8a63f71e
commit 94ce223391
5 changed files with 10 additions and 9 deletions

View File

@ -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_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

View File

@ -4,8 +4,6 @@ module Ci
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)

View File

@ -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)

View File

@ -100,7 +100,7 @@ module Gitlab
FileUtils.rm(trace_path, force: true)
end
job.chunks.destroy_all
job.chunks.delete_all
job.erase_old_trace!
end
@ -111,7 +111,7 @@ module Gitlab
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|

View File

@ -140,7 +140,7 @@ module Gitlab
@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 @@ module Gitlab
true
end
def destroy!
job_chunks.destroy_all
def delete!
job_chunks.delete_all
@tell = @size = 0
ensure
invalidate_chunk_cache