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 ...@@ -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,8 +109,17 @@ RSpec.describe Elastic::ClusterReindexingService, :elastic do ...@@ -108,8 +109,17 @@ RSpec.describe Elastic::ClusterReindexingService, :elastic do
end end
context 'task finishes correctly' do context 'task finishes correctly' do
using RSpec::Parameterized::TableSyntax
where(:refresh_interval, :current_settings) do
nil | {}
'60s' | { refresh_interval: '60s' }
end
with_them do
before 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(: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 end
it 'launches all state steps' do it 'launches all state steps' do
...@@ -122,4 +132,5 @@ RSpec.describe Elastic::ClusterReindexingService, :elastic do ...@@ -122,4 +132,5 @@ RSpec.describe Elastic::ClusterReindexingService, :elastic do
end end
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