Commit 0d8d12ee authored by Andreas Brandl's avatar Andreas Brandl

Exclude lingering indexes from reindexing

parent 2ddfd434
...@@ -10,6 +10,13 @@ module Gitlab ...@@ -10,6 +10,13 @@ module Gitlab
end end
end end
end end
def self.candidate_indexes
Gitlab::Database::PostgresIndex
.regular
.not_match("^#{ConcurrentReindex::TEMPORARY_INDEX_PREFIX}")
.not_match("^#{ConcurrentReindex::REPLACED_INDEX_PREFIX}")
end
end end
end end
end end
...@@ -177,7 +177,7 @@ namespace :gitlab do ...@@ -177,7 +177,7 @@ namespace :gitlab do
indexes = if args[:index_name] indexes = if args[:index_name]
Gitlab::Database::PostgresIndex.by_identifier(args[:index_name]) Gitlab::Database::PostgresIndex.by_identifier(args[:index_name])
else else
Gitlab::Database::PostgresIndex.regular.random_few(2) Gitlab::Database::Reindexing.candidate_indexes.random_few(2)
end end
Gitlab::Database::Reindexing.perform(indexes) Gitlab::Database::Reindexing.perform(indexes)
......
...@@ -52,4 +52,15 @@ RSpec.describe Gitlab::Database::Reindexing do ...@@ -52,4 +52,15 @@ RSpec.describe Gitlab::Database::Reindexing do
it_behaves_like 'reindexing' it_behaves_like 'reindexing'
end end
end end
describe '.candidate_indexes' do
subject { described_class.candidate_indexes }
it 'retrieves regular indexes that are no left-overs from previous runs' do
result = double
expect(Gitlab::Database::PostgresIndex).to receive_message_chain('regular.not_match.not_match').with(no_args).with('^tmp_reindex_').with('^old_reindex_').and_return(result)
expect(subject).to eq(result)
end
end
end end
...@@ -170,7 +170,7 @@ RSpec.describe 'gitlab:db namespace rake task' do ...@@ -170,7 +170,7 @@ RSpec.describe 'gitlab:db namespace rake task' do
context 'when no index_name is given' do context 'when no index_name is given' do
it 'rebuilds a random number of large indexes' do it 'rebuilds a random number of large indexes' do
expect(Gitlab::Database::PostgresIndex).to receive_message_chain('regular.random_few').and_return(indexes) expect(Gitlab::Database::Reindexing).to receive_message_chain('candidate_indexes.random_few').and_return(indexes)
expect(Gitlab::Database::Reindexing).to receive(:perform).with(indexes) expect(Gitlab::Database::Reindexing).to receive(:perform).with(indexes)
run_rake_task('gitlab:db:reindex') run_rake_task('gitlab:db:reindex')
......
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