Commit efb5a230 authored by Dylan Griffith's avatar Dylan Griffith

Remove dead code ElasticBatchProjectIndexerWorker

This worker was first added in
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/1144 in %"8.17" but
all usages were removed in
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/13437 in %"12.0" .
Given that the usages of this worker have been removed for at least 1
major release now we should be safe to remove this worker itself. In
fact we could have removed it already in %"13.0" .
parent 7318445e
---
title: Remove dead Elasticsearch indexing code
merge_request: 35936
author:
type: other
......@@ -78,8 +78,6 @@
- 1
- - detect_repository_languages
- 1
- - elastic_batch_project_indexer
- 1
- - elastic_commit_indexer
- 1
- - elastic_delete_project
......
# frozen_string_literal: true
class RemoveElasticBatchProjectIndexerWorkerQueue < ActiveRecord::Migration[6.0]
DOWNTIME = false
def up
Sidekiq.redis do |conn|
conn.del "queue:elastic_batch_project_indexer"
end
end
end
......@@ -23541,5 +23541,6 @@ COPY "schema_migrations" (version) FROM STDIN;
20200626130220
20200702123805
20200703154822
20200706005325
\.
......@@ -571,14 +571,6 @@
:weight: 2
:idempotent:
:tags: []
- :name: elastic_batch_project_indexer
:feature_category: :global_search
:has_external_dependencies:
:urgency: :low
:resource_boundary: :unknown
:weight: 1
:idempotent:
:tags: []
- :name: elastic_commit_indexer
:feature_category: :global_search
:has_external_dependencies:
......
# frozen_string_literal: true
class ElasticBatchProjectIndexerWorker # rubocop:disable Scalability/IdempotentWorker
include ApplicationWorker
feature_category :global_search
# Batch indexing is a generally a onetime option, so give finer control over
# queuing and concurrency
# This worker is long-running, but idempotent, so retry many times if
# necessary
sidekiq_options retry: 10
def perform(start, finish)
projects = build_relation(start, finish)
projects.find_each { |project| run_indexer(project) }
end
private
def run_indexer(project)
return unless project.use_elasticsearch?
# Ensure we remove the hold on the project, no matter what, so ElasticCommitIndexerWorker can do its thing
# We do this before the indexer starts to avoid the possibility of pushes coming in during this time not
# being indexed.
Gitlab::Redis::SharedState.with { |redis| redis.srem(:elastic_projects_indexing, project.id) }
logger.info "Indexing #{project.full_name} (ID=#{project.id})..."
Gitlab::Elastic::Indexer.new(project).run
logger.info "Indexing #{project.full_name} (ID=#{project.id}) is done!"
rescue => err
logger.warn("#{err.message} indexing #{project.full_name} (ID=#{project.id}), trace - #{err.backtrace}")
end
# rubocop: disable CodeReuse/ActiveRecord
def build_relation(start, finish)
relation = Project.includes(:index_status)
table = Project.arel_table
relation = relation.where(table[:id].gteq(start)) if start
relation = relation.where(table[:id].lteq(finish)) if finish
relation
end
# rubocop: enable CodeReuse/ActiveRecord
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ElasticBatchProjectIndexerWorker do
subject(:worker) { described_class.new }
let(:projects) { create_list(:project, 2) }
describe '#perform' do
before do
stub_ee_application_setting(elasticsearch_indexing: true)
end
context 'with elasticsearch only enabled for a particular project' do
before do
stub_ee_application_setting(elasticsearch_limit_indexing: true)
create :elasticsearch_indexed_project, project: projects.first
end
it 'only indexes the enabled project' do
projects.each { |project| expect_index(project).and_call_original }
expect(Gitlab::Elastic::Indexer).to receive(:new).with(projects.first).and_return(double(run: true))
expect(Gitlab::Elastic::Indexer).not_to receive(:new).with(projects.last)
worker.perform(projects.first.id, projects.last.id)
end
end
it 'runs the indexer for projects in the batch range' do
projects.each { |project| expect_index(project) }
worker.perform(projects.first.id, projects.last.id)
end
it 'skips projects not in the batch range' do
expect_index(projects.first).never
expect_index(projects.last)
worker.perform(projects.last.id, projects.last.id)
end
it 'clears the "locked" state from redis when the project finishes indexing' do
Gitlab::Redis::SharedState.with { |redis| redis.sadd(:elastic_projects_indexing, projects.first.id) }
expect_index(projects.first).and_call_original
expect_next_instance_of(Gitlab::Elastic::Indexer) do |indexer|
expect(indexer).to receive(:run)
end
expect { worker.perform(projects.first.id, projects.first.id) }
.to change { project_locked?(projects.first) }.from(true).to(false)
end
it 'reindexes projects that were already indexed' do
expect_index(projects.first)
expect_index(projects.last)
worker.perform(projects.first.id, projects.last.id)
end
it 'indexes all projects it receives even if already indexed', :sidekiq_might_not_need_inline do
expect_index(projects.first).and_call_original
expect_next_instance_of(Gitlab::Elastic::Indexer) do |indexer|
expect(indexer).to receive(:run)
end
worker.perform(projects.first.id, projects.first.id)
end
end
def expect_index(project)
expect(worker).to receive(:run_indexer).with(project)
end
def project_locked?(project)
Gitlab::Redis::SharedState.with { |redis| redis.sismember(:elastic_projects_indexing, project.id) }
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