Skip to content
代码片段 群组 项目
提交 ab5a04b0 编辑于 作者: Michael Kozono's avatar Michael Kozono
浏览文件

Merge branch...

Merge branch '371397-geo-invalid-deletion-on-secondary-when-managed-object-replication-is-disabled' into 'master'

Geo - Skip file removal for files on object storage when GitLab managed replication is disabled

See merge request gitlab-org/gitlab!95937
No related branches found
No related tags found
无相关合并请求
...@@ -65,11 +65,15 @@ def destroy_file ...@@ -65,11 +65,15 @@ def destroy_file
end end
def destroy_object_storage_file def destroy_object_storage_file
if object_file.nil? if sync_object_storage_enabled?
log_error("Can't find #{object_file_path} in object storage path #{object_storage_config[:remote_directory]}") if object_file.nil?
log_error("Can't find #{object_file_path} in object storage path #{object_storage_config[:remote_directory]}")
else
log_info("Removing #{object_file_path} from #{object_storage_config[:remote_directory]}")
object_file.destroy
end
else else
log_info("Removing #{object_file_path} from #{object_storage_config[:remote_directory]}") log_info('Skipping file deletion as this secondary node is not allowed to replicate content on Object Storage')
object_file.destroy
end end
end end
...@@ -125,6 +129,10 @@ def lease_key ...@@ -125,6 +129,10 @@ def lease_key
"file_registry_removal_service:#{object_type}:#{object_db_id}" "file_registry_removal_service:#{object_type}:#{object_db_id}"
end end
def sync_object_storage_enabled?
Gitlab::Geo.current_node.sync_object_storage
end
def object_storage_config def object_storage_config
return if file_uploader.nil? return if file_uploader.nil?
......
...@@ -98,6 +98,10 @@ ...@@ -98,6 +98,10 @@
end end
describe 'created event consumption' do describe 'created event consumption' do
before do
stub_current_geo_node(secondary)
end
context "when the blob's project is in replicables for this geo node" do context "when the blob's project is in replicables for this geo node" do
it 'invokes Geo::BlobDownloadService' do it 'invokes Geo::BlobDownloadService' do
expect(replicator).to receive(:in_replicables_for_current_secondary?).and_return(true) expect(replicator).to receive(:in_replicables_for_current_secondary?).and_return(true)
...@@ -124,6 +128,7 @@ ...@@ -124,6 +128,7 @@
describe 'deleted event consumption' do describe 'deleted event consumption' do
before do before do
model_record.save! model_record.save!
stub_current_geo_node(secondary)
end end
let!(:model_record_id) { replicator.model_record_id } let!(:model_record_id) { replicator.model_record_id }
...@@ -180,11 +185,26 @@ ...@@ -180,11 +185,26 @@
directory.files.create(key: blob_path) # rubocop:disable Rails/SaveBang directory.files.create(key: blob_path) # rubocop:disable Rails/SaveBang
end end
it 'deletes the file from object storage' do context 'when GitLab managed replication is enabled' do
service = ::Geo::FileRegistryRemovalService.new(secondary_side_replicator.replicable_name, model_record_id, secondary_blob_path, uploader_class) it 'deletes the file from object storage' do
expect(directory.files.head(blob_path)).not_to be_nil service = ::Geo::FileRegistryRemovalService.new(secondary_side_replicator.replicable_name, model_record_id, secondary_blob_path, uploader_class)
service.execute expect(directory.files.head(blob_path)).not_to be_nil
expect(directory.files.head(blob_path)).to be_nil service.execute
expect(directory.files.head(blob_path)).to be_nil
end
end
context 'when GitLab managed replication is disabled' do
before do
allow(secondary).to receive(:sync_object_storage).and_return(false)
end
it 'does not delete the file from object storage' do
service = ::Geo::FileRegistryRemovalService.new(secondary_side_replicator.replicable_name, model_record_id, secondary_blob_path, uploader_class)
expect(directory.files.head(blob_path)).not_to be_nil
service.execute
expect(directory.files.head(blob_path)).not_to be_nil
end
end end
end end
end end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册