Commit 91f6d0b0 authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch 'rake-task-check-pending-migrations' into 'master'

Add rake task to check pending Elasticsearch migrations

See merge request gitlab-org/gitlab!54656
parents bf35f604 75fbfd40
......@@ -422,6 +422,7 @@ The following are some available Rake tasks:
| [`sudo gitlab-rake gitlab:elastic:projects_not_indexed`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Displays which projects are not indexed. |
| [`sudo gitlab-rake gitlab:elastic:reindex_cluster`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Schedules a zero-downtime cluster reindexing task. This feature should be used with an index that was created after GitLab 13.0. |
| [`sudo gitlab-rake gitlab:elastic:mark_reindex_failed`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake)`] | Mark the most recent re-index job as failed. |
| [`sudo gitlab-rake gitlab:elastic:list_pending_migrations`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake)`] | List pending migrations. Pending migrations include those that have not yet started, have started but not finished, and those that are halted. |
### Environment variables
......
......@@ -138,6 +138,33 @@ pending_job_classes = scheduled_queue.select { |job| job["class"] == "Background
pending_job_classes.each { |job_class| Gitlab::BackgroundMigration.steal(job_class) }
```
## Checking for pending Elasticsearch migrations
This section is only applicable if you have enabled the [Elasticsearch
integration](../integration/elasticsearch.md).
Certain major releases might require [Elasticsearch
migrations](../integration/elasticsearch.md#background-migrations) to be
finished. You can find pending migrations by running the following command:
**For Omnibus installations**
```shell
sudo gitlab-rake gitlab:elastic:list_pending_migrations
```
**For installations from source**
```shell
cd /home/git/gitlab
sudo -u git -H bundle exec rake gitlab:elastic:list_pending_migrations
```
### What do I do if my Elasticsearch migrations are stuck?
See [how to retry a halted
migration](../integration/elasticsearch.md#retry-a-halted-migration).
## Upgrade paths
Although you can generally upgrade through multiple GitLab versions in one go,
......
......@@ -61,6 +61,12 @@ module Elastic
end
end
def pending_migrations
migrations.select do |migration|
!migration_has_finished?(migration.name_for_key)
end
end
def halted_migrations?
migrations.reverse.any? do |migration|
migration_halted?(migration)
......
---
title: Add rake task to check pending Elasticsearch migrations
merge_request: 54656
author:
type: added
......@@ -149,6 +149,20 @@ namespace :gitlab do
end
end
desc "GitLab | Elasticsearch | List pending migrations"
task list_pending_migrations: :environment do
pending_migrations = ::Elastic::DataMigrationService.pending_migrations
if pending_migrations.any?
puts 'Pending migrations:'
pending_migrations.each do |migration|
puts migration.name
end
else
puts 'There are no pending migrations.'
end
end
def project_id_batches(&blk)
relation = Project.all
......
......@@ -188,4 +188,38 @@ RSpec.describe Elastic::DataMigrationService, :elastic do
expect(subject.halted_migration).to eq(migration)
end
end
describe 'pending_migrations?' do
context 'when there is a pending migration' do
let(:migration) { subject.migrations.first }
before do
migration.save!(completed: false)
end
it 'returns true' do
expect(subject.pending_migrations?).to eq(true)
end
end
context 'when there is no pending migration' do
it 'returns false' do
expect(subject.pending_migrations?).to eq(false)
end
end
end
describe 'pending_migrations' do
let(:pending_migration1) { subject.migrations[1] }
let(:pending_migration2) { subject.migrations[2] }
before do
pending_migration1.save!(completed: false)
pending_migration2.save!(completed: false)
end
it 'returns only pending migrations' do
expect(subject.pending_migrations.map(&:name)).to eq([pending_migration1, pending_migration2].map(&:name))
end
end
end
......@@ -207,4 +207,28 @@ RSpec.describe 'gitlab:elastic namespace rake tasks', :elastic do
end
end
end
describe 'list_pending_migrations' do
subject { run_rake_task('gitlab:elastic:list_pending_migrations') }
context 'when there are pending migrations' do
let(:pending_migration1) { ::Elastic::DataMigrationService.migrations[1] }
let(:pending_migration2) { ::Elastic::DataMigrationService.migrations[2] }
before do
pending_migration1.save!(completed: false)
pending_migration2.save!(completed: false)
end
it 'outputs pending migrations' do
expect { subject }.to output(/#{pending_migration1.name}\n#{pending_migration2.name}/).to_stdout
end
end
context 'when there is no pending migrations' do
it 'outputs message there are no pending migrations' do
expect { subject }.to output(/There are no pending migrations./).to_stdout
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