Commit 5ed342ce authored by Gabriel Mazetto's avatar Gabriel Mazetto

Merge branch...

Merge branch '340316-self-service-framework-blob-types-can-be-orphaned-when-absolute-path-on-nodes-do-not-match' into 'master'

Geo: Use relative path for delete events in SSF

See merge request gitlab-org/gitlab!70619
parents 3fe9aeee ced802df
...@@ -66,10 +66,18 @@ module Geo ...@@ -66,10 +66,18 @@ module Geo
::Geo::FileRegistryRemovalService.new( ::Geo::FileRegistryRemovalService.new(
replicable_name, replicable_name,
model_record_id, model_record_id,
event_data[:blob_path] removed_blob_path(event_data[:uploader_class], event_data[:blob_path])
).execute ).execute
end end
def removed_blob_path(uploader_class, path)
return unless path.present?
# Backward compatibility check. Remove in 15.x
return path if uploader_class.nil?
File.join(uploader_class.constantize.root, path)
end
# Returns a checksum of the file # Returns a checksum of the file
# #
# @return [String] SHA256 hash of the carrierwave file # @return [String] SHA256 hash of the carrierwave file
...@@ -97,7 +105,7 @@ module Geo ...@@ -97,7 +105,7 @@ module Geo
end end
def deleted_params def deleted_params
{ model_record_id: model_record.id, blob_path: blob_path } { model_record_id: model_record.id, uploader_class: carrierwave_uploader.class.to_s, blob_path: carrierwave_uploader.relative_path }
end end
# Return whether it's capable of generating a checksum of itself # Return whether it's capable of generating a checksum of itself
......
...@@ -74,7 +74,14 @@ RSpec.shared_examples 'a blob replicator' do ...@@ -74,7 +74,14 @@ RSpec.shared_examples 'a blob replicator' do
end.to change { ::Geo::Event.count }.by(1) end.to change { ::Geo::Event.count }.by(1)
expect(::Geo::Event.last.attributes).to include( expect(::Geo::Event.last.attributes).to include(
"replicable_name" => replicator.replicable_name, "event_name" => "deleted", "payload" => { "model_record_id" => replicator.model_record.id, "blob_path" => replicator.blob_path }) "replicable_name" => replicator.replicable_name,
"event_name" => "deleted",
"payload" => {
"model_record_id" => replicator.model_record.id,
"uploader_class" => replicator.carrierwave_uploader.class.to_s,
"blob_path" => replicator.carrierwave_uploader.relative_path.to_s
}
)
end end
context 'when replication feature flag is disabled' do context 'when replication feature flag is disabled' do
...@@ -120,8 +127,9 @@ RSpec.shared_examples 'a blob replicator' do ...@@ -120,8 +127,9 @@ RSpec.shared_examples 'a blob replicator' do
end end
let!(:model_record_id) { replicator.model_record_id } let!(:model_record_id) { replicator.model_record_id }
let!(:blob_path) { replicator.blob_path } let!(:blob_path) { replicator.carrierwave_uploader.relative_path.to_s }
let!(:deleted_params) { { model_record_id: model_record_id, blob_path: blob_path } } let!(:uploader_class) { replicator.carrierwave_uploader.class.to_s }
let!(:deleted_params) { { model_record_id: model_record_id, uploader_class: uploader_class, blob_path: blob_path } }
context 'when model_record was deleted from the DB and the replicator only has its ID' do context 'when model_record was deleted from the DB and the replicator only has its ID' do
before do before do
...@@ -138,12 +146,28 @@ RSpec.shared_examples 'a blob replicator' do ...@@ -138,12 +146,28 @@ RSpec.shared_examples 'a blob replicator' do
it 'invokes Geo::FileRegistryRemovalService' do it 'invokes Geo::FileRegistryRemovalService' do
service = double(:service) service = double(:service)
secondary_blob_path = File.join(uploader_class.constantize.root, blob_path)
expect(service).to receive(:execute) expect(service).to receive(:execute)
expect(::Geo::FileRegistryRemovalService) expect(::Geo::FileRegistryRemovalService)
.to receive(:new).with(secondary_side_replicator.replicable_name, model_record_id, blob_path).and_return(service) .to receive(:new).with(secondary_side_replicator.replicable_name, model_record_id, secondary_blob_path).and_return(service)
secondary_side_replicator.consume(:deleted, **deleted_params) secondary_side_replicator.consume(:deleted, **deleted_params)
end end
context 'backward compatibility' do
let!(:deprecated_deleted_params) { { model_record_id: model_record_id, blob_path: blob_path } }
it 'invokes Geo::FileRegistryRemovalService when delete event is in deprecated format' do
service = double(:service)
expect(service).to receive(:execute)
expect(::Geo::FileRegistryRemovalService)
.to receive(:new).with(secondary_side_replicator.replicable_name, model_record_id, blob_path).and_return(service)
secondary_side_replicator.consume(:deleted, **deprecated_deleted_params)
end
end
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