Commit 0b16bccc authored by Terri Chu's avatar Terri Chu Committed by Kamil Trzciński

ES Reindex should restore current refresh_interval setting

parent 269809cf
......@@ -35,9 +35,9 @@ module Elastic
[elastic_helper.target_name] + elastic_helper.standalone_indices_proxies.map(&:index_name)
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,
translog: { durability: 'request' }
}
......@@ -142,7 +142,7 @@ module Elastic
def apply_default_index_options
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
......
---
title: Restore refresh_interval from settings after reindex
merge_request: 51147
author:
type: changed
......@@ -69,9 +69,10 @@ RSpec.describe Elastic::ClusterReindexingService, :elastic do
context 'state: reindexing' do
let(:task) { create(:elastic_reindexing_task, state: :reindexing) }
let(:subtask) { create(:elastic_reindexing_subtask, elastic_reindexing_task: task, documents_count: 10)}
let(:refresh_interval) { nil }
let(:expected_default_settings) do
{
refresh_interval: nil,
refresh_interval: refresh_interval,
number_of_replicas: Gitlab::CurrentSettings.elasticsearch_replicas,
translog: { durability: 'request' }
}
......@@ -108,17 +109,27 @@ RSpec.describe Elastic::ClusterReindexingService, :elastic do
end
context 'task finishes correctly' do
before do
allow(helper).to receive(:documents_count).with(index_name: subtask.index_name_to).and_return(subtask.reload.documents_count)
using RSpec::Parameterized::TableSyntax
where(:refresh_interval, :current_settings) do
nil | {}
'60s' | { refresh_interval: '60s' }
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)
with_them do
before do
allow(helper).to receive(:documents_count).with(index_name: subtask.index_name_to).and_return(subtask.reload.documents_count)
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(task.reload.delete_original_index_at).to be_within(1.minute).of(described_class::DELETE_ORIGINAL_INDEX_AFTER.from_now)
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)
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