Commit a866b43e authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch...

Merge branch '197310-geo-improve-performance-of-registry-backfill-service-with-bulk-insert' into 'master'

Geo - Improve performance of RegistryBackfillService with bulk insert

Closes #197310

See merge request gitlab-org/gitlab!27720
parents e872ea0c 59a4ebff
# frozen_string_literal: true # frozen_string_literal: true
class Geo::BaseRegistry < Geo::TrackingBase class Geo::BaseRegistry < Geo::TrackingBase
include BulkInsertSafe
self.abstract_class = true self.abstract_class = true
def self.pluck_model_ids_in_range(range) def self.pluck_model_ids_in_range(range)
...@@ -15,12 +17,11 @@ class Geo::BaseRegistry < Geo::TrackingBase ...@@ -15,12 +17,11 @@ class Geo::BaseRegistry < Geo::TrackingBase
where.not(self::MODEL_FOREIGN_KEY => ids) where.not(self::MODEL_FOREIGN_KEY => ids)
end end
# TODO: Investigate replacing this with bulk insert (there was an obstacle).
# https://gitlab.com/gitlab-org/gitlab/issues/197310
def self.insert_for_model_ids(ids) def self.insert_for_model_ids(ids)
ids.map do |id| records = ids.map do |id|
registry = create(self::MODEL_FOREIGN_KEY => id) new(self::MODEL_FOREIGN_KEY => id, created_at: Time.zone.now)
registry.id end
end.compact
bulk_insert!(records, returns: :ids)
end end
end end
...@@ -28,13 +28,12 @@ class Geo::UploadRegistry < Geo::BaseRegistry ...@@ -28,13 +28,12 @@ class Geo::UploadRegistry < Geo::BaseRegistry
false false
end end
# TODO: Investigate replacing this with bulk insert (there was an obstacle).
# https://gitlab.com/gitlab-org/gitlab/issues/197310
def self.insert_for_model_ids(attrs) def self.insert_for_model_ids(attrs)
attrs.map do |file_id, file_type| records = attrs.map do |file_id, file_type|
registry = create(file_id: file_id, file_type: file_type) new(file_id: file_id, file_type: file_type, created_at: Time.zone.now)
registry.id end
end.compact
bulk_insert!(records, returns: :ids)
end end
def self.with_search(query) def self.with_search(query)
......
...@@ -99,8 +99,8 @@ module Geo ...@@ -99,8 +99,8 @@ module Geo
registry_class: registry_class.name, registry_class: registry_class.name,
start: range.first, start: range.first,
finish: range.last, finish: range.last,
created: created.size, created: created.length,
failed_to_create: untracked.size - created.size failed_to_create: untracked.length - created.length
} }
) )
end end
......
---
title: Geo - Use bulk insert to improve performance of RegistryBackfillService
merge_request: 27720
author:
type: performance
...@@ -3,6 +3,11 @@ ...@@ -3,6 +3,11 @@
require 'spec_helper' require 'spec_helper'
describe Geo::ContainerRepositoryRegistry, :geo do describe Geo::ContainerRepositoryRegistry, :geo do
it_behaves_like 'a BulkInsertSafe model', Geo::ContainerRepositoryRegistry do
let(:valid_items_for_bulk_insertion) { build_list(:container_repository_registry, 10, created_at: Time.zone.now) }
let(:invalid_items_for_bulk_insertion) { [] } # class does not have any validations defined
end
let_it_be(:registry) { create(:container_repository_registry) } let_it_be(:registry) { create(:container_repository_registry) }
describe 'relationships' do describe 'relationships' do
......
...@@ -3,6 +3,11 @@ ...@@ -3,6 +3,11 @@
require 'spec_helper' require 'spec_helper'
describe Geo::DesignRegistry, :geo do describe Geo::DesignRegistry, :geo do
it_behaves_like 'a BulkInsertSafe model', Geo::DesignRegistry do
let(:valid_items_for_bulk_insertion) { build_list(:geo_design_registry, 10, created_at: Time.zone.now) }
let(:invalid_items_for_bulk_insertion) { [] } # class does not have any validations defined
end
let!(:design_registry) { create(:geo_design_registry) } let!(:design_registry) { create(:geo_design_registry) }
describe 'relationships' do describe 'relationships' do
......
# frozen_string_literal: true
require 'spec_helper'
describe Geo::JobArtifactRegistry, :geo do
it_behaves_like 'a BulkInsertSafe model', Geo::JobArtifactRegistry do
let(:valid_items_for_bulk_insertion) { build_list(:geo_job_artifact_registry, 10) }
let(:invalid_items_for_bulk_insertion) { [] } # class does not have any validations defined
end
end
...@@ -6,4 +6,9 @@ describe Geo::LfsObjectRegistry, :geo do ...@@ -6,4 +6,9 @@ describe Geo::LfsObjectRegistry, :geo do
describe 'relationships' do describe 'relationships' do
it { is_expected.to belong_to(:lfs_object).class_name('LfsObject') } it { is_expected.to belong_to(:lfs_object).class_name('LfsObject') }
end end
it_behaves_like 'a BulkInsertSafe model', Geo::LfsObjectRegistry do
let(:valid_items_for_bulk_insertion) { build_list(:geo_lfs_object_registry, 10) }
let(:invalid_items_for_bulk_insertion) { [] } # class does not have any validations defined
end
end end
...@@ -3,9 +3,8 @@ ...@@ -3,9 +3,8 @@
require 'spec_helper' require 'spec_helper'
describe Geo::PackageFileRegistry, :geo, type: :model do describe Geo::PackageFileRegistry, :geo, type: :model do
let_it_be(:registry) { create(:package_file_registry) } it_behaves_like 'a BulkInsertSafe model', Geo::PackageFileRegistry do
let(:valid_items_for_bulk_insertion) { build_list(:package_file_registry, 10, created_at: Time.zone.now) }
specify 'factory is valid' do let(:invalid_items_for_bulk_insertion) { [] } # class does not have any validations defined
expect(registry).to be_valid
end end
end end
...@@ -11,6 +11,11 @@ describe Geo::ProjectRegistry do ...@@ -11,6 +11,11 @@ describe Geo::ProjectRegistry do
subject { registry } subject { registry }
it_behaves_like 'a BulkInsertSafe model', Geo::ProjectRegistry do
let(:valid_items_for_bulk_insertion) { build_list(:geo_project_registry, 10, created_at: Time.zone.now) }
let(:invalid_items_for_bulk_insertion) { [] } # class does not have any validations defined
end
describe 'relationships' do describe 'relationships' do
it { is_expected.to belong_to(:project) } it { is_expected.to belong_to(:project) }
end end
......
...@@ -6,6 +6,11 @@ describe Geo::UploadRegistry, :geo, :geo_fdw do ...@@ -6,6 +6,11 @@ describe Geo::UploadRegistry, :geo, :geo_fdw do
let!(:failed) { create(:geo_upload_registry, :failed) } let!(:failed) { create(:geo_upload_registry, :failed) }
let!(:synced) { create(:geo_upload_registry) } let!(:synced) { create(:geo_upload_registry) }
it_behaves_like 'a BulkInsertSafe model', Geo::UploadRegistry do
let(:valid_items_for_bulk_insertion) { build_list(:geo_upload_registry, 10, created_at: Time.zone.now) }
let(:invalid_items_for_bulk_insertion) { [] } # class does not have any validations defined
end
it 'finds associated Upload record' do it 'finds associated Upload record' do
registry = create(:geo_upload_registry, :attachment, :with_file) registry = create(:geo_upload_registry, :attachment, :with_file)
......
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