Commit d6a13539 authored by James Fargher's avatar James Fargher

Merge branch 'fix-es-reindexing-documents-count' into 'master'

Fix zero-downtime reindexing docs count issue

See merge request gitlab-org/gitlab!36173
parents 7f13e0bc 4e49eb91
...@@ -62,7 +62,7 @@ module Elastic ...@@ -62,7 +62,7 @@ module Elastic
index_name = elastic_helper.create_empty_index(with_alias: false, options: { settings: INITIAL_INDEX_OPTIONS }) index_name = elastic_helper.create_empty_index(with_alias: false, options: { settings: INITIAL_INDEX_OPTIONS })
# Record documents count # Record documents count
documents_count = elastic_helper.index_size.dig('docs', 'count') documents_count = elastic_helper.documents_count
# Trigger reindex # Trigger reindex
task_id = elastic_helper.reindex(to: index_name) task_id = elastic_helper.reindex(to: index_name)
...@@ -81,7 +81,7 @@ module Elastic ...@@ -81,7 +81,7 @@ module Elastic
def save_documents_count!(refresh:) def save_documents_count!(refresh:)
elastic_helper.refresh_index(index_name: current_task.index_name_to) if refresh elastic_helper.refresh_index(index_name: current_task.index_name_to) if refresh
new_documents_count = elastic_helper.index_size(index_name: current_task.index_name_to).dig('docs', 'count') new_documents_count = elastic_helper.documents_count(index_name: current_task.index_name_to)
current_task.update!(documents_count_target: new_documents_count) current_task.update!(documents_count_target: new_documents_count)
end end
......
---
title: Fix zero-downtime reindexing docs count
merge_request: 36173
author:
type: fixed
...@@ -105,6 +105,12 @@ module Gitlab ...@@ -105,6 +105,12 @@ module Gitlab
client.indices.stats['indices'][index_name || target_index_name]['total'] client.indices.stats['indices'][index_name || target_index_name]['total']
end end
def documents_count(index_name: nil)
index = index_name || target_index_name
client.indices.stats.dig('indices', index, 'primaries', 'docs', 'count')
end
def index_size_bytes def index_size_bytes
index_size['store']['size_in_bytes'] index_size['store']['size_in_bytes']
end end
......
...@@ -57,7 +57,7 @@ RSpec.describe Elastic::ClusterReindexingService, :elastic do ...@@ -57,7 +57,7 @@ RSpec.describe Elastic::ClusterReindexingService, :elastic do
context 'errors are raised' do context 'errors are raised' do
before do before do
allow(Gitlab::Elastic::Helper.default).to receive(:index_size).and_return('docs' => { 'count' => task.reload.documents_count * 2 }) allow(Gitlab::Elastic::Helper.default).to receive(:documents_count).with(index_name: task.index_name_to).and_return(task.reload.documents_count * 2)
end end
it 'errors if documents count is different' do it 'errors if documents count is different' do
...@@ -75,7 +75,7 @@ RSpec.describe Elastic::ClusterReindexingService, :elastic do ...@@ -75,7 +75,7 @@ RSpec.describe Elastic::ClusterReindexingService, :elastic do
context 'task finishes correctly' do context 'task finishes correctly' do
before do before do
allow(Gitlab::Elastic::Helper.default).to receive(:index_size).and_return('docs' => { 'count' => task.reload.documents_count }) allow(Gitlab::Elastic::Helper.default).to receive(:documents_count).with(index_name: task.index_name_to).and_return(task.reload.documents_count)
end end
it 'launches all state steps' do it 'launches all state steps' do
......
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