Commit 4ec07eb4 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch...

Merge branch '249123-elasticsearch-reindexing-should-restore-the-original-refresh_interval' into 'master'

ES Reindex should restore current refresh_interval setting

See merge request gitlab-org/gitlab!51147
parents 71370d58 0b16bccc
...@@ -35,9 +35,9 @@ module Elastic ...@@ -35,9 +35,9 @@ module Elastic
[elastic_helper.target_name] + elastic_helper.standalone_indices_proxies.map(&:index_name) [elastic_helper.target_name] + elastic_helper.standalone_indices_proxies.map(&:index_name)
end end
def default_index_options def default_index_options(index_name)
{ {
refresh_interval: nil, # Change it back to the default refresh_interval: elastic_helper.get_settings(index_name: index_name).dig('refresh_interval'), # Use existing setting or nil for default
number_of_replicas: Gitlab::CurrentSettings.elasticsearch_replicas, number_of_replicas: Gitlab::CurrentSettings.elasticsearch_replicas,
translog: { durability: 'request' } translog: { durability: 'request' }
} }
...@@ -142,7 +142,7 @@ module Elastic ...@@ -142,7 +142,7 @@ module Elastic
def apply_default_index_options def apply_default_index_options
current_task.subtasks.each do |subtask| current_task.subtasks.each do |subtask|
elastic_helper.update_settings(index_name: subtask.index_name_to, settings: default_index_options) elastic_helper.update_settings(index_name: subtask.index_name_to, settings: default_index_options(subtask.index_name_from))
end end
end end
......
---
title: Restore refresh_interval from settings after reindex
merge_request: 51147
author:
type: changed
...@@ -69,9 +69,10 @@ RSpec.describe Elastic::ClusterReindexingService, :elastic do ...@@ -69,9 +69,10 @@ RSpec.describe Elastic::ClusterReindexingService, :elastic do
context 'state: reindexing' do context 'state: reindexing' do
let(:task) { create(:elastic_reindexing_task, state: :reindexing) } let(:task) { create(:elastic_reindexing_task, state: :reindexing) }
let(:subtask) { create(:elastic_reindexing_subtask, elastic_reindexing_task: task, documents_count: 10)} let(:subtask) { create(:elastic_reindexing_subtask, elastic_reindexing_task: task, documents_count: 10)}
let(:refresh_interval) { nil }
let(:expected_default_settings) do let(:expected_default_settings) do
{ {
refresh_interval: nil, refresh_interval: refresh_interval,
number_of_replicas: Gitlab::CurrentSettings.elasticsearch_replicas, number_of_replicas: Gitlab::CurrentSettings.elasticsearch_replicas,
translog: { durability: 'request' } translog: { durability: 'request' }
} }
...@@ -108,17 +109,27 @@ RSpec.describe Elastic::ClusterReindexingService, :elastic do ...@@ -108,17 +109,27 @@ RSpec.describe Elastic::ClusterReindexingService, :elastic do
end end
context 'task finishes correctly' do context 'task finishes correctly' do
before do using RSpec::Parameterized::TableSyntax
allow(helper).to receive(:documents_count).with(index_name: subtask.index_name_to).and_return(subtask.reload.documents_count)
where(:refresh_interval, :current_settings) do
nil | {}
'60s' | { refresh_interval: '60s' }
end end
it 'launches all state steps' do with_them do
expect(helper).to receive(:update_settings).with(index_name: subtask.index_name_to, settings: expected_default_settings) before do
expect(helper).to receive(:switch_alias).with(to: subtask.index_name_to, from: subtask.index_name_from, alias_name: subtask.alias_name) allow(helper).to receive(:documents_count).with(index_name: subtask.index_name_to).and_return(subtask.reload.documents_count)
expect(Gitlab::CurrentSettings).to receive(:update!).with(elasticsearch_pause_indexing: false) allow(helper).to receive(:get_settings).with(index_name: subtask.index_name_from).and_return(current_settings.with_indifferent_access)
end
it 'launches all state steps' do
expect(helper).to receive(:update_settings).with(index_name: subtask.index_name_to, settings: expected_default_settings)
expect(helper).to receive(:switch_alias).with(to: subtask.index_name_to, from: subtask.index_name_from, alias_name: subtask.alias_name)
expect(Gitlab::CurrentSettings).to receive(:update!).with(elasticsearch_pause_indexing: false)
expect { subject.execute }.to change { task.reload.state }.from('reindexing').to('success') expect { subject.execute }.to change { task.reload.state }.from('reindexing').to('success')
expect(task.reload.delete_original_index_at).to be_within(1.minute).of(described_class::DELETE_ORIGINAL_INDEX_AFTER.from_now) expect(task.reload.delete_original_index_at).to be_within(1.minute).of(described_class::DELETE_ORIGINAL_INDEX_AFTER.from_now)
end
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