Commit 42eb2e7f authored by Dmitry Gruzd's avatar Dmitry Gruzd

Remove old Advanced Search migrations

Changelog: changed
EE: true
parent d6cc7c98
......@@ -308,7 +308,8 @@ We choose to use GitLab major version upgrades as a safe time to remove
backwards compatibility for indices that have not been fully migrated. We
[document this in our upgrade
documentation](../update/index.md#upgrading-to-a-new-major-version). We also
choose to remove the migration code and tests so that:
choose to remove the migration code by replacing it with the halted migration
and remove tests so that:
- We don't need to maintain any code that is called from our Advanced Search
migrations.
......@@ -334,18 +335,10 @@ For every migration that was created 2 minor versions before the major version
being upgraded to, we do the following:
1. Confirm the migration has actually completed successfully for GitLab.com.
1. Replace the content of `migrate` and `completed?` methods as follows:
1. Replace the content of the migration with:
```ruby
def migrate
log_raise "Migration has been deleted in the last major version upgrade." \
"Migrations are supposed to be finished before upgrading major version https://docs.gitlab.com/ee/update/#upgrading-to-a-new-major-version ." \
"To correct this issue, recreate your index from scratch: https://docs.gitlab.com/ee/integration/elasticsearch.html#last-resort-to-recreate-an-index."
end
def completed?
false
end
include Elastic::MigrationObsolete
```
1. Delete any spec files to support this migration.
......
......@@ -4,7 +4,9 @@ module Elastic
class MigrationRecord
attr_reader :version, :name, :filename
delegate :migrate, :skip_migration?, :completed?, :batched?, :throttle_delay, :pause_indexing?, :space_requirements?, :space_required_bytes, to: :migration
delegate :migrate, :skip_migration?, :completed?, :batched?, :throttle_delay, :pause_indexing?,
:space_requirements?, :space_required_bytes, :obsolete?,
to: :migration
ELASTICSEARCH_SIZE = 25
......
......@@ -29,6 +29,15 @@ module Elastic
migrations.find { |migration| migration.name_for_key == name.to_s.underscore }
end
def find_by_name!(name)
migration = find_by_name(name)
raise ArgumentError, "Couldn't find Elastic::Migration with name='#{name}'" unless migration
raise ArgumentError, "Elastic::Migration with name='#{name}' is marked as obsolete" if migration.obsolete?
migration
end
def drop_migration_has_finished_cache!(migration)
Rails.cache.delete cache_key(:migration_has_finished, migration.name_for_key)
end
......
# frozen_string_literal: true
module Elastic
module MigrationObsolete
def migrate
log "Migration has been deleted in the last major version upgrade." \
"Migrations are supposed to be finished before upgrading major version https://docs.gitlab.com/ee/update/#upgrading-to-a-new-major-version ." \
"To correct this issue, recreate your index from scratch: https://docs.gitlab.com/ee/integration/elasticsearch.html#last-resort-to-recreate-an-index."
fail_migration_halt_error!
end
def completed?
false
end
def obsolete?
true
end
end
end
# frozen_string_literal: true
class ApplyMaxAnalyzedOffset < Elastic::Migration
# Important: Any update to the Elastic index mappings should be replicated in Elastic::Latest::Config
def migrate
if max_analyzed_offset_setting == current_max_analyzed_offset
log "Skipping highlight.max_analyzed_offset migration since it is already applied"
return
end
log "Setting highlight.max_analyzed_offset to #{max_analyzed_offset_setting}kb"
helper.update_settings(settings: { index: { 'highlight.max_analyzed_offset': max_analyzed_offset_setting } })
log 'Update of highlight.max_analyzed_offset is completed'
end
# Check if the migration has completed
# Return true if completed, otherwise return false
def completed?
max_analyzed_offset_setting == current_max_analyzed_offset
end
private
def max_analyzed_offset_setting
Gitlab::CurrentSettings.elasticsearch_indexed_file_size_limit_kb.kilobytes
end
def current_max_analyzed_offset
Gitlab::Elastic::Helper.default.get_settings.dig('highlight', 'max_analyzed_offset').to_i
end
include Elastic::MigrationObsolete
end
......@@ -23,6 +23,10 @@ module Elastic
raise NotImplementedError, 'Please extend Elastic::Migration'
end
def obsolete?
false
end
private
def helper
......
......@@ -43,7 +43,7 @@ module ElasticsearchHelpers
version = if name_or_version.is_a?(Numeric)
name_or_version
else
Elastic::DataMigrationService.find_by_name(name_or_version).version
Elastic::DataMigrationService.find_by_name!(name_or_version).version
end
Elastic::DataMigrationService.migrations.each do |migration|
......
# frozen_string_literal: true
require 'fast_spec_helper'
RSpec.describe Elastic::MigrationObsolete do
let(:migration_class) do
Class.new do
include Elastic::MigrationObsolete
end
end
subject { migration_class.new }
describe '#migrate' do
it 'logs a message and halts the migration' do
expect(subject).to receive(:log).with(/has been deleted in the last major version upgrade/)
expect(subject).to receive(:fail_migration_halt_error!).and_return(true)
subject.migrate
end
end
describe '#completed?' do
it 'returns false' do
expect(subject.completed?).to be false
end
end
describe '#obsolete?' do
it 'returns true' do
expect(subject.obsolete?).to be true
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