Commit 07f36f22 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Ensure that only persisted chunk can be flushed

parent 7d9f4319
......@@ -138,13 +138,15 @@ module Ci
#
def persist_data!
in_lock(*lock_params) do # exclusive Redis lock is acquired first
raise FailedToPersistDataError, 'Modifed build trace chunk detected' if has_changes_to_save?
self.reset.then do |chunk| # we ensure having latest lock_version
chunk.unsafe_persist_data! # we migrate the data and update data store
end
end
rescue ActiveRecord::StaleObjectError
raise FailedToPersistDataError, <<~MSG
data migration race condition detected
Data migration race condition detected
store: #{data_store}
build: #{build.id}
......
......@@ -597,6 +597,14 @@ RSpec.describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
expect { build_trace_chunk.persist_data! }
.to raise_error(described_class::FailedToPersistDataError)
end
it 'does not allow flushing unpersisted chunk' do
build_trace_chunk.checksum = '12345'
expect { build_trace_chunk.persist_data! }
.to raise_error(described_class::FailedToPersistDataError,
/Modifed build trace chunk detected/)
end
end
end
end
......
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