Skip to content

Fix batched bg migration for missing ci model

Patrick Bair requested to merge pb-fix-ci-batched-bg-worker into master

What does this MR do and why?

Related to #354073 (closed)

Fix a bug where the batched background migration worker ci raises an error because the base model for ci doesn't exist in single-database mode.

There may be a better way to optionally configure this rather than have the worker run as a no-op, but this fixes the immediate noise generated by this worker continuously throwing errors.

How to set up and validate locally

Single database mode

  1. You can recreate the error on master in the rails console, while the worker for main is fine:
    [1] pry(main)> Database::BatchedBackgroundMigrationWorker.new.perform
    Gitlab::Database::BackgroundMigration::BatchedMigration Load (6.4ms)  SELECT "batched_background_migrations".* FROM "batched_background_migrations" WHERE "batched_background_migrations"."status" = 1 ORDER BY "batched_background_migrations"."id" ASC LIMIT 1 /*application:console,db_config_name:main_replica,line:/lib/gitlab/database/background_migration/batched_migration.rb:45:in `active_migration'*/
    => nil
    [2] pry(main)> Database::BatchedBackgroundMigration::CiDatabaseWorker.new.perform
    NoMethodError: undefined method `connection' for nil:NilClass
    from /Users/pbair/Projects/gitlab-development-kit/gitlab/app/workers/database/batched_background_migration/single_database_worker.rb:34:in `perform'
  2. Trying again on this branch, the worker for main continues to run, but the ci worker does nothing:
    [7] pry(main)> Database::BatchedBackgroundMigrationWorker.new.perform
    Gitlab::Database::BackgroundMigration::BatchedMigration Load (0.4ms)  SELECT "batched_background_migrations".* FROM "batched_background_migrations" WHERE "batched_background_migrations"."status" = 1 ORDER BY "batched_background_migrations"."id" ASC LIMIT 1 /*application:console,db_config_name:main_replica,line:/lib/gitlab/database/background_migration/batched_migration.rb:45:in `active_migration'*/
    => nil
    [8] pry(main)> Database::BatchedBackgroundMigration::CiDatabaseWorker.new.perform
    => nil

Multi-database mode

  1. On master, both workers run as expected:
    [4] pry(main)> Database::BatchedBackgroundMigrationWorker.new.perform
    Gitlab::Database::BackgroundMigration::BatchedMigration Load (0.2ms)  SELECT "batched_background_migrations".* FROM "batched_background_migrations" WHERE "batched_background_migrations"."status" = 1 ORDER BY "batched_background_migrations"."id" ASC LIMIT 1 /*application:console,db_config_name:main_replica,line:/lib/gitlab/database/background_migration/batched_migration.rb:45:in `active_migration'*/
    => nil
    [5] pry(main)> Database::BatchedBackgroundMigration::CiDatabaseWorker.new.perform
    Gitlab::Database::BackgroundMigration::BatchedMigration Load (0.4ms)  SELECT "batched_background_migrations".* FROM "batched_background_migrations" WHERE "batched_background_migrations"."status" = 1 ORDER BY "batched_background_migrations"."id" ASC LIMIT 1 /*application:console,db_config_name:main_replica,line:/lib/gitlab/database/background_migration/batched_migration.rb:45:in `active_migration'*/
    => nil
  2. On this branch, they still run as expected:
    [1] pry(main)> Database::BatchedBackgroundMigrationWorker.new.perform
    Gitlab::Database::BackgroundMigration::BatchedMigration Load (6.2ms)  SELECT "batched_background_migrations".* FROM "batched_background_migrations" WHERE "batched_background_migrations"."status" = 1 ORDER BY "batched_background_migrations"."id" ASC LIMIT 1 /*application:console,db_config_name:main_replica,line:/lib/gitlab/database/background_migration/batched_migration.rb:45:in `active_migration'*/
    => nil
    [2] pry(main)> Database::BatchedBackgroundMigration::CiDatabaseWorker.new.perform
    Gitlab::Database::BackgroundMigration::BatchedMigration Load (11.1ms)  SELECT "batched_background_migrations".* FROM "batched_background_migrations" WHERE "batched_background_migrations"."status" = 1 ORDER BY "batched_background_migrations"."id" ASC LIMIT 1 /*application:console,db_config_name:ci_replica,line:/lib/gitlab/database/background_migration/batched_migration.rb:45:in `active_migration'*/
    => nil

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Patrick Bair

Merge request reports