Commit 11cd07a4 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'ab/reindexing-limits' into 'master'

Remove upper index size limit for reindexing

See merge request gitlab-org/gitlab!73951
parents 2e85e952 c6591acd
...@@ -9,8 +9,8 @@ module Gitlab ...@@ -9,8 +9,8 @@ module Gitlab
# Only reindex indexes with a relative bloat level (bloat estimate / size) higher than this # Only reindex indexes with a relative bloat level (bloat estimate / size) higher than this
MINIMUM_RELATIVE_BLOAT = 0.2 MINIMUM_RELATIVE_BLOAT = 0.2
# Only consider indexes with a total ondisk size in this range (before reindexing) # Only consider indexes beyond this size (before reindexing)
INDEX_SIZE_RANGE = (1.gigabyte..100.gigabyte).freeze INDEX_SIZE_MINIMUM = 1.gigabyte
delegate :each, to: :indexes delegate :each, to: :indexes
...@@ -32,7 +32,7 @@ module Gitlab ...@@ -32,7 +32,7 @@ module Gitlab
@indexes ||= candidates @indexes ||= candidates
.not_recently_reindexed .not_recently_reindexed
.where(ondisk_size_bytes: INDEX_SIZE_RANGE) .where('ondisk_size_bytes >= ?', INDEX_SIZE_MINIMUM)
.sort_by(&:relative_bloat_level) # forced N+1 .sort_by(&:relative_bloat_level) # forced N+1
.reverse .reverse
.select { |candidate| candidate.relative_bloat_level >= MINIMUM_RELATIVE_BLOAT } .select { |candidate| candidate.relative_bloat_level >= MINIMUM_RELATIVE_BLOAT }
......
...@@ -8,7 +8,7 @@ module Gitlab ...@@ -8,7 +8,7 @@ module Gitlab
ReindexError = Class.new(StandardError) ReindexError = Class.new(StandardError)
TEMPORARY_INDEX_PATTERN = '\_ccnew[0-9]*' TEMPORARY_INDEX_PATTERN = '\_ccnew[0-9]*'
STATEMENT_TIMEOUT = 9.hours STATEMENT_TIMEOUT = 24.hours
PG_MAX_INDEX_NAME_LENGTH = 63 PG_MAX_INDEX_NAME_LENGTH = 63
attr_reader :index, :logger attr_reader :index, :logger
......
...@@ -46,14 +46,14 @@ RSpec.describe Gitlab::Database::Reindexing::IndexSelection do ...@@ -46,14 +46,14 @@ RSpec.describe Gitlab::Database::Reindexing::IndexSelection do
expect(subject).not_to include(excluded.index) expect(subject).not_to include(excluded.index)
end end
it 'excludes indexes larger than 100 GB ondisk size' do it 'includes indexes larger than 100 GB ondisk size' do
excluded = create( included = create(
:postgres_index_bloat_estimate, :postgres_index_bloat_estimate,
index: create(:postgres_index, ondisk_size_bytes: 101.gigabytes), index: create(:postgres_index, ondisk_size_bytes: 101.gigabytes),
bloat_size_bytes: 25.gigabyte bloat_size_bytes: 25.gigabyte
) )
expect(subject).not_to include(excluded.index) expect(subject).to include(included.index)
end end
context 'with time frozen' do context 'with time frozen' do
......
...@@ -62,7 +62,7 @@ RSpec.describe Gitlab::Database::Reindexing::ReindexConcurrently, '#perform' do ...@@ -62,7 +62,7 @@ RSpec.describe Gitlab::Database::Reindexing::ReindexConcurrently, '#perform' do
it 'recreates the index using REINDEX with a long statement timeout' do it 'recreates the index using REINDEX with a long statement timeout' do
expect_to_execute_in_order( expect_to_execute_in_order(
"SET statement_timeout TO '32400s'", "SET statement_timeout TO '86400s'",
"REINDEX INDEX CONCURRENTLY \"public\".\"#{index.name}\"", "REINDEX INDEX CONCURRENTLY \"public\".\"#{index.name}\"",
"RESET statement_timeout" "RESET statement_timeout"
) )
...@@ -84,7 +84,7 @@ RSpec.describe Gitlab::Database::Reindexing::ReindexConcurrently, '#perform' do ...@@ -84,7 +84,7 @@ RSpec.describe Gitlab::Database::Reindexing::ReindexConcurrently, '#perform' do
it 'drops the dangling indexes while controlling lock_timeout' do it 'drops the dangling indexes while controlling lock_timeout' do
expect_to_execute_in_order( expect_to_execute_in_order(
# Regular index rebuild # Regular index rebuild
"SET statement_timeout TO '32400s'", "SET statement_timeout TO '86400s'",
"REINDEX INDEX CONCURRENTLY \"public\".\"#{index_name}\"", "REINDEX INDEX CONCURRENTLY \"public\".\"#{index_name}\"",
"RESET statement_timeout", "RESET statement_timeout",
# Drop _ccnew index # Drop _ccnew index
......
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