Skip to content
Snippets Groups Projects
Verified Commit 06db6416 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre
Browse files

Remove legacy hashed storage migration code

This code is not being used since the hashed storage
migration has already been enforced, and the Geo legacy
replication code has been removed.

Changelog: removed
EE: true
parent a168b763
No related branches found
No related tags found
2 merge requests!144312Change service start (cut-off) date for code suggestions to March 15th,!143443Geo - Remove legacy hashed storage code
Showing
with 9 additions and 389 deletions
......@@ -985,7 +985,6 @@ Layout/LineLength:
- 'ee/app/services/geo/event_service.rb'
- 'ee/app/services/geo/file_registry_removal_service.rb'
- 'ee/app/services/geo/framework_repository_sync_service.rb'
- 'ee/app/services/geo/hashed_storage_attachments_migration_service.rb'
- 'ee/app/services/geo/request_service.rb'
- 'ee/app/services/geo/verification_state_backfill_service.rb'
- 'ee/app/services/gitlab_subscriptions/plan_upgrade_service.rb'
......@@ -2061,7 +2060,6 @@ Layout/LineLength:
- 'ee/spec/services/geo/blob_download_service_spec.rb'
- 'ee/spec/services/geo/container_repository_sync_spec.rb'
- 'ee/spec/services/geo/framework_repository_sync_service_spec.rb'
- 'ee/spec/services/geo/hashed_storage_attachments_event_store_spec.rb'
- 'ee/spec/services/gitlab_subscriptions/check_future_renewal_service_spec.rb'
- 'ee/spec/services/gitlab_subscriptions/create_service_spec.rb'
- 'ee/spec/services/groups/memberships/export_service_spec.rb'
......
......@@ -11,7 +11,6 @@ Rails/TimeZone:
- 'ee/spec/lib/gitlab/geo/base_request_spec.rb'
- 'ee/spec/lib/gitlab/geo/log_cursor/events/cache_invalidation_event_spec.rb'
- 'ee/spec/lib/gitlab/geo/log_cursor/events/event_spec.rb'
- 'ee/spec/lib/gitlab/geo/log_cursor/events/hashed_storage_attachments_event_spec.rb'
- 'ee/spec/lib/gitlab/geo/log_cursor/logger_spec.rb'
- 'lib/api/helpers.rb'
- 'lib/api/sidekiq_metrics.rb'
......
......@@ -22,7 +22,6 @@ RSpec/ExpectChange:
- 'ee/spec/lib/gitlab/compliance_management/violations/approved_by_committer_spec.rb'
- 'ee/spec/lib/gitlab/compliance_management/violations/approved_by_insufficient_users_spec.rb'
- 'ee/spec/lib/gitlab/compliance_management/violations/approved_by_merge_request_author_spec.rb'
- 'ee/spec/lib/gitlab/geo/log_cursor/events/hashed_storage_attachments_event_spec.rb'
- 'ee/spec/lib/gitlab/instrumentation/elasticsearch_transport_spec.rb'
- 'ee/spec/lib/gitlab/legacy_github_import/project_creator_spec.rb'
- 'ee/spec/lib/quality/seeders/vulnerabilities_spec.rb'
......@@ -134,7 +133,6 @@ RSpec/ExpectChange:
- 'ee/spec/services/iterations/roll_over_issues_service_spec.rb'
- 'ee/spec/services/projects/alerting/notify_service_spec.rb'
- 'ee/spec/services/projects/destroy_service_spec.rb'
- 'ee/spec/services/projects/hashed_storage/migrate_attachments_service_spec.rb'
- 'ee/spec/services/projects/transfer_service_spec.rb'
- 'ee/spec/services/protected_environments/create_service_spec.rb'
- 'ee/spec/services/quality_management/test_cases/create_service_spec.rb'
......
......@@ -1378,7 +1378,6 @@ RSpec/FeatureCategory:
- 'ee/spec/services/projects/gitlab_projects_import_service_spec.rb'
- 'ee/spec/services/projects/group_links/destroy_service_spec.rb'
- 'ee/spec/services/projects/group_links/update_service_spec.rb'
- 'ee/spec/services/projects/hashed_storage/migrate_attachments_service_spec.rb'
- 'ee/spec/services/projects/import_export/export_service_spec.rb'
- 'ee/spec/services/projects/import_service_spec.rb'
- 'ee/spec/services/projects/mark_for_deletion_service_spec.rb'
......
......@@ -429,7 +429,6 @@ RSpec/NamedSubject:
- 'ee/spec/lib/gitlab/geo/log_cursor/event_logs_spec.rb'
- 'ee/spec/lib/gitlab/geo/log_cursor/events/cache_invalidation_event_spec.rb'
- 'ee/spec/lib/gitlab/geo/log_cursor/events/event_spec.rb'
- 'ee/spec/lib/gitlab/geo/log_cursor/events/hashed_storage_attachments_event_spec.rb'
- 'ee/spec/lib/gitlab/geo/oauth/session_spec.rb'
- 'ee/spec/lib/gitlab/geo/registry_batcher_spec.rb'
- 'ee/spec/lib/gitlab/geo/replication/blob_retriever_spec.rb'
......@@ -1040,7 +1039,6 @@ RSpec/NamedSubject:
- 'ee/spec/services/geo/file_registry_removal_service_spec.rb'
- 'ee/spec/services/geo/framework_repository_sync_service_spec.rb'
- 'ee/spec/services/geo/graphql_request_service_spec.rb'
- 'ee/spec/services/geo/hashed_storage_attachments_event_store_spec.rb'
- 'ee/spec/services/geo/metrics_update_service_spec.rb'
- 'ee/spec/services/geo/replication_toggle_request_service_spec.rb'
- 'ee/spec/services/gitlab_subscriptions/activate_service_spec.rb'
......@@ -1098,7 +1096,6 @@ RSpec/NamedSubject:
- 'ee/spec/services/projects/gitlab_projects_import_service_spec.rb'
- 'ee/spec/services/projects/group_links/create_service_spec.rb'
- 'ee/spec/services/projects/group_links/destroy_service_spec.rb'
- 'ee/spec/services/projects/hashed_storage/migrate_attachments_service_spec.rb'
- 'ee/spec/services/projects/import_export/export_service_spec.rb'
- 'ee/spec/services/projects/import_service_spec.rb'
- 'ee/spec/services/projects/mark_for_deletion_service_spec.rb'
......
......@@ -63,5 +63,3 @@ def find_old_attachments_path(project)
end
end
end
Projects::HashedStorage::MigrateAttachmentsService.prepend_mod_with('Projects::HashedStorage::MigrateAttachmentsService')
......@@ -3,8 +3,14 @@
module Geo
class EventLog < ApplicationRecord
include IgnorableColumns
ignore_column :geo_event_id_convert_to_bigint, remove_with: '16.11', remove_after: '2024-03-21'
ignore_columns %i[
hashed_storage_migrated_event_id
hashed_storage_attachments_event_id
], remove_with: '17.0', remove_after: '2024-05-16'
include Geo::Model
include ::EachBatch
......@@ -15,8 +21,6 @@ class EventLog < ApplicationRecord
Geo::RepositoryRenamedEvent
Geo::RepositoriesChangedEvent
Geo::ResetChecksumEvent
Geo::HashedStorageMigratedEvent
Geo::HashedStorageAttachmentsEvent
Geo::Event].freeze
belongs_to :cache_invalidation_event,
......@@ -43,14 +47,6 @@ class EventLog < ApplicationRecord
class_name: 'Geo::RepositoriesChangedEvent',
foreign_key: :repositories_changed_event_id
belongs_to :hashed_storage_migrated_event,
class_name: 'Geo::HashedStorageMigratedEvent',
foreign_key: :hashed_storage_migrated_event_id
belongs_to :hashed_storage_attachments_event,
class_name: 'Geo::HashedStorageAttachmentsEvent',
foreign_key: :hashed_storage_attachments_event_id
belongs_to :reset_checksum_event,
class_name: 'Geo::ResetChecksumEvent',
foreign_key: :reset_checksum_event_id
......@@ -86,8 +82,6 @@ def event
repository_deleted_event ||
repository_renamed_event ||
repositories_changed_event ||
hashed_storage_migrated_event ||
hashed_storage_attachments_event ||
reset_checksum_event ||
cache_invalidation_event ||
geo_event
......
# frozen_string_literal: true
module Geo
class HashedStorageAttachmentsEvent < ApplicationRecord
include Geo::Model
include Geo::Eventable
belongs_to :project
validates :project, :old_attachments_path, :new_attachments_path, presence: true
end
end
# frozen_string_literal: true
module Geo
class HashedStorageMigratedEvent < ApplicationRecord
include Geo::Model
include Geo::Eventable
belongs_to :project
validates :project, :repository_storage_name,
:old_disk_path, :new_disk_path, :old_wiki_disk_path,
:new_wiki_disk_path, :new_storage_version, presence: true
end
end
# frozen_string_literal: true
module EE
module Projects
module HashedStorage
module MigrateAttachmentsService
extend ::Gitlab::Utils::Override
override :execute
def execute
super do
break true if skipped?
::Geo::HashedStorageAttachmentsEventStore.new(
project,
old_attachments_path: old_disk_path,
new_attachments_path: new_disk_path
).create!
end
end
end
end
end
end
# frozen_string_literal: true
module Geo
class HashedStorageAttachmentsEventStore < EventStore
self.event_type = :hashed_storage_attachments_event
private
def build_event
Geo::HashedStorageAttachmentsEvent.new(
project: project,
old_attachments_path: old_attachments_path,
new_attachments_path: new_attachments_path
)
end
def old_attachments_path
params.fetch(:old_attachments_path)
end
def new_attachments_path
params.fetch(:new_attachments_path)
end
end
end
# frozen_string_literal: true
module Geo
AttachmentMigrationError = Class.new(StandardError)
class HashedStorageAttachmentsMigrationService
include ::Gitlab::Geo::LogHelpers
attr_reader :project_id, :old_attachments_path, :new_attachments_path
def initialize(project_id, old_attachments_path:, new_attachments_path:)
@project_id = project_id
@old_attachments_path = old_attachments_path
@new_attachments_path = new_attachments_path
end
def async_execute
Geo::HashedStorageAttachmentsMigrationWorker.perform_async(
project_id,
old_attachments_path,
new_attachments_path
)
end
def execute
origin = File.join(FileUploader.root, old_attachments_path)
target = File.join(FileUploader.root, new_attachments_path)
move_folder!(origin, target)
end
private
def project
@project ||= Project.find(project_id)
end
def move_folder!(old_path, new_path)
unless File.directory?(old_path)
log_info("Skipped attachments migration to Hashed Storage, source path doesn't exist or is not a directory", project_id: project.id, source: old_path, target: new_path)
return
end
if File.exist?(new_path)
log_error("Cannot migrate attachments to Hashed Storage, target path already exist", project_id: project.id, source: old_path, target: new_path)
raise AttachmentMigrationError, "Target path '#{new_path}' already exist"
end
# Create hashed storage base path folder
FileUtils.mkdir_p(File.dirname(new_path))
FileUtils.mv(old_path, new_path)
log_info("Migrated project attachments to Hashed Storage", project_id: project.id, source: old_path, target: new_path)
true
end
end
end
......@@ -10,12 +10,8 @@ class HashedStorageAttachmentsMigrationWorker # rubocop:disable Scalability/Idem
loggable_arguments 1, 2
def perform(project_id, old_attachments_path, new_attachments_path)
Geo::HashedStorageAttachmentsMigrationService.new(
project_id,
old_attachments_path: old_attachments_path,
new_attachments_path: new_attachments_path
).execute
def perform(_project_id, _old_attachments_path, _new_attachments_path)
# no-op
end
end
end
......@@ -8,28 +8,7 @@ class HashedStorageAttachmentsEvent
include BaseEvent
def process
job_id = hashed_storage_attachments_migrate
log_event(job_id)
end
private
def hashed_storage_attachments_migrate
# Must always schedule, regardless of shard health
::Geo::HashedStorageAttachmentsMigrationService.new(
event.project_id,
old_attachments_path: event.old_attachments_path,
new_attachments_path: event.new_attachments_path
).async_execute
end
def log_event(job_id)
super(
'Migrating attachments to hashed storage',
project_id: event.project_id,
old_attachments_path: event.old_attachments_path,
new_attachments_path: event.new_attachments_path,
job_id: job_id)
# no-op
end
end
end
......
......@@ -18,14 +18,6 @@
repository_renamed_event factory: :geo_repository_renamed_event
end
trait :hashed_storage_migration_event do
hashed_storage_migrated_event factory: :geo_hashed_storage_migrated_event
end
trait :hashed_storage_attachments_event do
hashed_storage_attachments_event factory: :geo_hashed_storage_attachments_event
end
trait :reset_checksum_event do
reset_checksum_event factory: :geo_reset_checksum_event
end
......@@ -80,24 +72,6 @@
new_path { "#{project.path}_new" }
end
factory :geo_hashed_storage_migrated_event, class: 'Geo::HashedStorageMigratedEvent' do
project { association(:project, :repository) }
repository_storage_name { project.repository_storage }
old_disk_path { project.path_with_namespace }
new_disk_path { "#{project.path_with_namespace}_new" }
old_wiki_disk_path { project.wiki.path_with_namespace }
new_wiki_disk_path { "#{project.wiki.path_with_namespace}_new" }
new_storage_version { Project::HASHED_STORAGE_FEATURES[:repository] }
end
factory :geo_hashed_storage_attachments_event, class: 'Geo::HashedStorageAttachmentsEvent' do
project { association(:project, :repository) }
old_attachments_path { Storage::LegacyProject.new(project).disk_path }
new_attachments_path { Storage::Hashed.new(project).disk_path }
end
factory :geo_reset_checksum_event, class: 'Geo::ResetChecksumEvent' do
project
end
......
......@@ -142,80 +142,6 @@
daemon.find_and_handle_events!
end
end
context 'when node has namespace restrictions' do
let(:group_1) { create(:group) }
let(:group_2) { create(:group) }
let(:project) { create(:project, group: group_1) }
let(:hashed_storage_attachments_event) { create(:geo_hashed_storage_attachments_event, project: project) }
let(:event_log) { create(:geo_event_log, hashed_storage_attachments_event: hashed_storage_attachments_event) }
let!(:event_log_state) { create(:geo_event_log_state, event_id: event_log.id - 1) }
let!(:registry) { create(:geo_project_repository_registry, :synced, project: project) }
before do
allow(Gitlab::ShardHealthCache).to receive(:healthy_shard?).with('default').and_return(true)
allow(Gitlab::Geo::Logger).to receive(:info).and_call_original
end
it 'detects when an event was skipped' do
updated_event = create(:geo_hashed_storage_attachments_event, project: project)
new_event = create(:geo_event_log, id: event_log.id + 2, hashed_storage_attachments_event: updated_event)
daemon.find_and_handle_events!
create(:geo_event_log, id: event_log.id + 1)
expect(read_gaps).to eq([event_log.id + 1])
expect(::Geo::EventLogState.last_processed.id).to eq(new_event.id)
end
it 'detects when an event was skipped between batches' do
updated_event = create(:geo_hashed_storage_attachments_event, project: project)
new_event = create(:geo_event_log, hashed_storage_attachments_event: updated_event)
daemon.find_and_handle_events!
create(:geo_event_log, id: new_event.id + 3, hashed_storage_attachments_event: updated_event)
daemon.find_and_handle_events!
create(:geo_event_log, id: new_event.id + 1, hashed_storage_attachments_event: updated_event)
create(:geo_event_log, id: new_event.id + 2, hashed_storage_attachments_event: updated_event)
expect(read_gaps).to eq([new_event.id + 1, new_event.id + 2])
end
it "logs a message if an associated event can't be found" do
new_event = create(:geo_event_log)
expect(Gitlab::Geo::Logger).to receive(:warn)
.with(hash_including(
class: 'Gitlab::Geo::LogCursor::Daemon',
message: '#handle_single_event: unknown event',
event_log_id: new_event.id))
daemon.find_and_handle_events!
expect(::Geo::EventLogState.last_processed.id).to eq(new_event.id)
end
it 'logs a message for skipped events' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [group_2])
expect(Gitlab::Geo::Logger).to receive(:info).with(hash_including(
:pid,
:cursor_delay_s,
message: 'Skipped event',
class: 'Gitlab::Geo::LogCursor::Daemon',
event_log_id: event_log.id,
event_id: hashed_storage_attachments_event.id,
event_type: 'Geo::HashedStorageAttachmentsEvent',
project_id: project.id))
daemon.find_and_handle_events!
end
end
end
describe '#handle_events' do
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Geo::LogCursor::Events::HashedStorageAttachmentsEvent,
:clean_gitlab_redis_shared_state,
feature_category: :geo_replication do
let(:logger) { Gitlab::Geo::LogCursor::Logger.new(described_class, Logger::INFO) }
let(:event_log) { create(:geo_event_log, :hashed_storage_attachments_event) }
let!(:event_log_state) { create(:geo_event_log_state, event_id: event_log.id - 1) }
let(:hashed_storage_attachments_event) { event_log.hashed_storage_attachments_event }
let(:project) { hashed_storage_attachments_event.project }
let(:old_attachments_path) { hashed_storage_attachments_event.old_attachments_path }
let(:new_attachments_path) { hashed_storage_attachments_event.new_attachments_path }
subject { described_class.new(hashed_storage_attachments_event, Time.now, logger) }
around do |example|
Sidekiq::Testing.fake! { example.run }
end
describe '#process' do
it 'schedules a Geo::HashedStorageAttachmentsMigrationWorker' do
expect(::Geo::HashedStorageAttachmentsMigrationWorker).to receive(:perform_async)
.with(project.id, old_attachments_path, new_attachments_path)
subject.process
end
it_behaves_like 'logs event source info'
end
end
......@@ -11,8 +11,6 @@
it { is_expected.to belong_to(:repository_renamed_event).class_name('Geo::RepositoryRenamedEvent').with_foreign_key('repository_renamed_event_id') }
it { is_expected.to belong_to(:repository_updated_event).class_name('Geo::RepositoryUpdatedEvent').with_foreign_key('repository_updated_event_id') }
it { is_expected.to belong_to(:reset_checksum_event).class_name('Geo::ResetChecksumEvent').with_foreign_key('reset_checksum_event_id') }
it { is_expected.to belong_to(:hashed_storage_migrated_event).class_name('Geo::HashedStorageMigratedEvent').with_foreign_key('hashed_storage_migrated_event_id') }
it { is_expected.to belong_to(:hashed_storage_attachments_event).class_name('Geo::HashedStorageAttachmentsEvent').with_foreign_key('hashed_storage_attachments_event_id') }
end
describe '.next_unprocessed_event' do
......@@ -84,20 +82,6 @@
expect(subject.event).to eq repositories_changed_event
end
it 'returns hashed_storage_migrated_event when set' do
hashed_storage_migrated_event = build(:geo_hashed_storage_migrated_event)
subject.hashed_storage_migrated_event = hashed_storage_migrated_event
expect(subject.event).to eq hashed_storage_migrated_event
end
it 'returns hashed_storage_attachments_event when set' do
hashed_storage_attachments_event = build(:geo_hashed_storage_attachments_event)
subject.hashed_storage_attachments_event = hashed_storage_attachments_event
expect(subject.event).to eq hashed_storage_attachments_event
end
it 'returns reset_checksum_event when set' do
reset_checksum_event = build(:geo_reset_checksum_event)
subject.reset_checksum_event = reset_checksum_event
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Geo::HashedStorageMigratedEvent, type: :model, feature_category: :geo_replication do
describe 'relationships' do
it { is_expected.to belong_to(:project) }
end
describe 'validations' do
it { is_expected.to validate_presence_of(:project) }
it { is_expected.to validate_presence_of(:repository_storage_name) }
it { is_expected.to validate_presence_of(:old_disk_path) }
it { is_expected.to validate_presence_of(:new_disk_path) }
it { is_expected.to validate_presence_of(:old_wiki_disk_path) }
it { is_expected.to validate_presence_of(:new_wiki_disk_path) }
it { is_expected.to validate_presence_of(:new_storage_version) }
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Geo::HashedStorageAttachmentsEventStore, feature_category: :geo_replication do
include EE::GeoHelpers
let_it_be(:secondary_node) { create(:geo_node) }
let(:project) { create(:project, path: 'bar') }
let(:attachments_event) { build(:geo_hashed_storage_attachments_event, project: project) }
let(:old_attachments_path) { attachments_event.old_attachments_path }
let(:new_attachments_path) { attachments_event.new_attachments_path }
subject { described_class.new(project, old_storage_version: 1, new_storage_version: 2, old_attachments_path: old_attachments_path, new_attachments_path: new_attachments_path) }
before do
TestEnv.clean_test_path
end
describe '#create!' do
it_behaves_like 'a Geo event store', Geo::HashedStorageAttachmentsEvent
context 'when running on a primary node' do
before do
stub_primary_node
end
it 'tracks project attributes' do
subject.create!
expect(Geo::HashedStorageAttachmentsEvent.last).to have_attributes(
old_attachments_path: old_attachments_path,
new_attachments_path: new_attachments_path
)
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment