diff options
-rw-r--r-- | app/models/ci/build_trace_chunk.rb | 18 | ||||
-rw-r--r-- | app/workers/ci/build_trace_chunk_flush_worker.rb | 2 | ||||
-rw-r--r-- | spec/models/ci/build_trace_chunk_spec.rb | 4 |
3 files changed, 10 insertions, 14 deletions
diff --git a/app/models/ci/build_trace_chunk.rb b/app/models/ci/build_trace_chunk.rb index 179c5830678..59096f54f0b 100644 --- a/app/models/ci/build_trace_chunk.rb +++ b/app/models/ci/build_trace_chunk.rb @@ -75,9 +75,7 @@ module Ci raise ArgumentError, 'Offset is out of range' if offset > size || offset < 0 raise ArgumentError, 'Chunk size overflow' if CHUNK_SIZE < (offset + new_data.bytesize) - in_lock(*lock_params) do - self.reload if self.persisted? - + in_lock(*lock_params) do # Write opetation is atomic unsafe_set_data!(data.byteslice(0, offset) + new_data) end @@ -100,21 +98,19 @@ module Ci (start_offset...end_offset) end - def persisted? + def data_persisted? !redis? end - def persist! - in_lock(*lock_params) do - self.reload if self.persisted? - - unsafe_move_to!(self.class.persist_store) + def persist_data! + in_lock(*lock_params) do # Write opetation is atomic + unsafe_migrate_to!(self.class.persist_store) end end private - def unsafe_move_to!(new_store) + def unsafe_migrate_to!(new_store) return if data_store == new_store.to_s return unless size > 0 @@ -143,7 +139,7 @@ module Ci end def schedule_to_persist - return if persisted? + return if data_persisted? Ci::BuildTraceChunkFlushWorker.perform_async(id) end diff --git a/app/workers/ci/build_trace_chunk_flush_worker.rb b/app/workers/ci/build_trace_chunk_flush_worker.rb index 8e08ccbc414..49ff0f4ab94 100644 --- a/app/workers/ci/build_trace_chunk_flush_worker.rb +++ b/app/workers/ci/build_trace_chunk_flush_worker.rb @@ -5,7 +5,7 @@ module Ci def perform(build_trace_chunk_id) ::Ci::BuildTraceChunk.find_by(id: build_trace_chunk_id).try do |build_trace_chunk| - build_trace_chunk.persist! + build_trace_chunk.persist_data! end end end diff --git a/spec/models/ci/build_trace_chunk_spec.rb b/spec/models/ci/build_trace_chunk_spec.rb index f0c36067c87..79e0f1f20bf 100644 --- a/spec/models/ci/build_trace_chunk_spec.rb +++ b/spec/models/ci/build_trace_chunk_spec.rb @@ -286,8 +286,8 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do end end - describe '#persist!' do - subject { build_trace_chunk.persist! } + describe '#persist_data!' do + subject { build_trace_chunk.persist_data! } context 'when data_store is redis' do let(:data_store) { :redis } |