Similar issues and TL;DR
My issue is similar to Background migrations does not start when upgrading from version 13.12.11 to version 14.0.12 however I am running FOSS. There was no reply to this issue.
It might be possible that my issue is similar to Background Migrations stuck after upgrade from 14.0.10 to 14.2.3 but the circumstances are slightly different. I haven’t tried their migrate:redo trick, which I will do after completing this post.
As a note, I have discovered through writing this issue that I have a sidekiq_queue called " cronjob:database_batched_background_migration" but no corresponding Cron job in sidekiq… I wonder if that’s the problem. There is no button for me to add the cronjob.
How to execute stuck background migrations?
Howdy Gitlab Forum goers. I seek your eternal wisdom.
I have inherited the astonishing technical debt of an aged Gitlab platform, that was running Debian 8 (Jessie) and Gitlab 12.5.X. Following the wonderful upgrade pathways and tooling provided by the documentation archives, I’ve been able to bring it into this decade; now running Debian 11 Bullseye and Gitlab 14-0-stable.
Previously, I have tried to upgrade following the recommended pathway:
- Upgrade Path
- 13.12.15 → 14.0.12 → 14.3.6
however I run into problems running the db:migration steps of the upgrade when going to 14.3.6, as it complains that there are unfinished background migrations, and there is no facility for me to resolve these. I believe it’s because there are critical migrations that are queued up in 14.0, 14.1 and 14.2 which are not addressed by the critical path upgrade, recommended by the upgrade tool.
The problem I have run into is that the upgrade pathway describes the next step as 14-3-stable, however elsewhere there are critical database migrations that need to be run, as some bigint/var limits change in some of the tables. I have determined that these jobs exist as “Background Migrations” (Distinctly different from Batched Background Migrations, introduced circa version 15 or late 14, which are the newer, allegedly better, version of background migrations which predate them.)
When I upgrade to version 14-0-stable, I can see there are 9 jobs in the Background Migrations (Admin GUI > Monitoring > Background Migrations) that are active and sitting at 0%. I have left them over the weekend, ensuring that my sidekiq cron jobs are all enabled, but there’s been no change.
I do not have any facility that I have found after a few days of trawling forums and issues and stackoverflow and the rest of the internet that will allow me to run these database background migrations manually. Downtime is not a problem here, and I can do dangerous maneuvers if required because I have snapshots and backups to rely on if something goes south.
Gitlab Check is otherwise gravy, and the output of “database migrations outstanding” is 0, whilst queued jobs is at 9.
And here’s the output of the Background Migrations Remaining checks, showing the 9 queued jobs:
root@git:/home/git/gitlab# sudo -u git -H bundle exec rails runner -e production 'puts Gitlab::BackgroundMigration.remaining'
0
root@git:/home/git/gitlab# sudo -u git -H bundle exec rails runner -e production 'puts Gitlab::Database::BackgroundMigration::BatchedMigration.queued.count'
9
There are no error messages in the logs that are obviously related to this issue, in fact the logs are very quiet, with few warnings or errors; I have pasted a few items that might be related below:
Summary
From application_json.log, this appears more-or-less on the hour
{"severity":"INFO","time":"2024-04-14T20:00:29.470Z","correlation_id":"3a11f55645c5e611ef2e30b17412513f","message":"StuckCiJobsWorker: Cleaning stuck builds"}
Steps to reproduce
- I have already tried to forge ahead and upgrade to 14-3-stable but run into errors with the db:migrate. I am not comfortable pushing past these as I have determined that the schema change will likely be breaking, and I will end up locked at 14-3
- I have tried a littany of rails console/rake commands to try and force the background jobs to complete; such as
sudo -u git -H bundle exec rake "gitlab:background_migrations:finalize" RAILS_ENV=production
Output of the finalize:
Summary
root@git:/home/git/gitlab# sudo -u git -H bundle exec rake “gitlab:background_migrations:finalize” RAILS_ENV=production
rake aborted!
Don’t know how to build task ‘gitlab:background_migrations:finalize’ (See the list of available tasks with rake --tasks
)
Did you mean? gitlab:packages:migrate
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/rake-13.0.3/exe/rake:27:in <top (required)>' /usr/local/bin/bundle:23:in
load’
/usr/local/bin/bundle:23:in `’
(See full trace by running task with --trace)
When running “rake --tasks” to check for other likely candidates, I get:
root@git:/home/git/gitlab# sudo -u git -H bundle exec rake --tasks RAILS_ENV=production
rake aborted!
NameError: uninitialized constant RSpec
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/active_support.rb:80:in block in load_missing_constant' /home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/active_support.rb:9:in
without_bootsnap_cache’
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/active_support.rb:80:in rescue in load_missing_constant' /home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/active_support.rb:59:in
load_missing_constant’
/home/git/gitlab/lib/tasks/benchmark.rake:7:in block in <main>' /home/git/gitlab/lib/tasks/benchmark.rake:5:in
’
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:55:in load' /home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:55:in
load’
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/railties-6.1.3.2/lib/rails/engine.rb:675:in block in run_tasks_blocks' /home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/railties-6.1.3.2/lib/rails/engine.rb:675:in
each’
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/railties-6.1.3.2/lib/rails/engine.rb:675:in run_tasks_blocks' /home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/railties-6.1.3.2/lib/rails/application.rb:521:in
run_tasks_blocks’
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/railties-6.1.3.2/lib/rails/engine.rb:464:in load_tasks' /home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/railties-6.1.3.2/lib/rails/railtie.rb:207:in
public_send’
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/railties-6.1.3.2/lib/rails/railtie.rb:207:in method_missing' /home/git/gitlab/Rakefile:14:in
<top (required)>’
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/rake-13.0.3/exe/rake:27:in <top (required)>' /usr/local/bin/bundle:23:in
load’
/usr/local/bin/bundle:23:in `’
Caused by:
NameError: uninitialized constant RSpec
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/active_support.rb:61:in block in load_missing_constant' /home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/active_support.rb:17:in
allow_bootsnap_retry’
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/active_support.rb:60:in load_missing_constant' /home/git/gitlab/lib/tasks/benchmark.rake:7:in
block in ’
/home/git/gitlab/lib/tasks/benchmark.rake:5:in <main>' /home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:55:in
load’
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:55:in load' /home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/railties-6.1.3.2/lib/rails/engine.rb:675:in
block in run_tasks_blocks’
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/railties-6.1.3.2/lib/rails/engine.rb:675:in each' /home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/railties-6.1.3.2/lib/rails/engine.rb:675:in
run_tasks_blocks’
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/railties-6.1.3.2/lib/rails/application.rb:521:in run_tasks_blocks' /home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/railties-6.1.3.2/lib/rails/engine.rb:464:in
load_tasks’
/home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/railties-6.1.3.2/lib/rails/railtie.rb:207:in public_send' /home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/railties-6.1.3.2/lib/rails/railtie.rb:207:in
method_missing’
/home/git/gitlab/Rakefile:14:in <top (required)>' /home/git/gitlab/vendor/bundle/ruby/2.7.0/gems/rake-13.0.3/exe/rake:27:in
<top (required)>’
/usr/local/bin/bundle:23:in load' /usr/local/bin/bundle:23:in
’
(See full trace by running task with --trace)
- I have tried waiting out the migrations as some posts indicate that it can take “up to a day”. I have left them all weekend.
I believe that this can be replicating by building a FOSS Gitlab at ~12.5 and doing the FOSS manual upgrade steps by documentation to 14-0-stable, however I only have my environment to boot. The operating system or configuration could be a contributing factor.
Configuration
Here’s Gitlab Check:
Summary
root@git:/home/git/gitlab# sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
Checking GitLab subtasks …
Checking GitLab Shell …
GitLab Shell: … GitLab Shell version >= 13.19.1 ? … OK (13.19.1)
Running /home/git/gitlab-shell/bin/check
Internal API available: OK
Redis available via internal API: OK
gitlab-shell self-check successful
Checking GitLab Shell … Finished
Checking Gitaly …
Gitaly: … default … OK
Checking Gitaly … Finished
Checking Sidekiq …
Sidekiq: … Running? … yes
Number of Sidekiq processes (cluster/worker) … 1/1
Checking Sidekiq … Finished
Checking Incoming Email …
Incoming Email: … Reply by email is disabled in config/gitlab.yml
Checking Incoming Email … Finished
Checking LDAP …
LDAP: … LDAP is disabled in config/gitlab.yml
Checking LDAP … Finished
Checking GitLab App …
Git configured correctly? … yes
Database config exists? … yes
All migrations up? … yes
Database contains orphaned GroupMembers? … no
GitLab config exists? … yes
GitLab config up to date? … yes
Log directory writable? … yes
Tmp directory writable? … yes
Uploads directory exists? … yes
Uploads directory has correct permissions? … yes
Uploads directory tmp has correct permissions? … yes
Init script exists? … yes
Init script up-to-date? … yes
Projects have namespace: …
Redacted Namespaces … yes
…
Redacted Namespaces … yes
Redis version >= 5.0.0? … yes
Ruby version >= 2.7.2 ? … yes (2.7.2)
Git version >= 2.31.0 ? … yes (2.32.0)
Git user has default SSH configuration? … yes
Active users: … 20
Is authorized keys file accessible? … yes
GitLab configured to store new projects in hashed storage? … yes
All projects are in hashed storage? … yes
Checking GitLab App … Finished
Checking GitLab subtasks … Finished
I am running the default gitlab init script, and the gitlab.yml based on the 14-0-stable examlpe, with my own instances’ configuration.
The main thing I can see that is “out of order” is that my environment is running Postgres13, and whilst the upgrade docs say “at least Postgres12” they were probably written at the time before 13 was released; I can see in another doc that 13 may not be supported, presumably because it hadn’t been tested at the time.
Versions
- Self-managed Gitlab, from Source - 14.0.12 (git:14-0-stable)
Here’s Gitlab Env Info:
Summary
root@git:/home/git/gitlab# sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
System information
System: Debian 11
Current User: git
Using RVM: no
Ruby Version: 2.7.2p137
Gem Version: 3.1.4
Bundler Version:2.1.4
Rake Version: 13.0.3
Redis Version: 6.0.16
Git Version: 2.32.0
Sidekiq Version:5.2.9
Go Version: go1.13.5 linux/amd64
GitLab information
Version: 14.0.12
Revision: def69dde9f1
Directory: /home/git/gitlab
DB Adapter: PostgreSQL
DB Version: 13.14
URL: https://git.micron21.com
HTTP Clone URL: https://git.micron21.com/some-group/some-project.git
SSH Clone URL: git@git.micron21.com:some-group/some-project.git
Using LDAP: no
Using Omniauth: no
GitLab Shell
Version: 13.19.1
Repository storage paths:
- default: /home/git/repositories
GitLab Shell path: /home/git/gitlab-shell
Git: /usr/local/bin/git
Versions
- GitLab (Web:
/help
or self-managed system information):
Conclusion
I still have a few leads to follow up on:
- bundle exec rake db:migrate:status might have leads for me, based on another issue
- The fact that I don’t seem to have a cron that corresponds to the sidekiq queue doesn’t make sense to me; see if I can find out more about the relatoinship there.
but please, if there’s anything you can do to point me in the right direction, I will be grateful.