Skip to content

Setup shared connection for BG migration methods

What does this MR do and why?

Setup the SharedModel connection in the BG migration coordinator for methods that running background migration jobs. We already do this in BackgroundMigrationWorker, but if we call #steal or #perform directly on the coordinator, we also want to ensure we use the correct connection.

For reference, this is enabled by !73789 (merged), which lets us nest calls to SharedModel.using_connection as long as we use the same connection object.

Related to #343047 (closed)

How to set up and validate locally

  1. Setup a test migration job:
    module Gitlab
      module BackgroundMigration
        class MyTestMigration
          def perform(*args)
            puts Gitlab::Database::SharedModel.connection
          end
        end
      end
    end
  2. Create a coordinator to run jobs and override its connection:
    coordinator = Gitlab::BackgroundMigration::JobCoordinator.for_database(:main)
    coordinator.instance_variable_set(:@connection, 'my connection')
  3. Run the job inline and verify the connection:
    coordinator.perform('MyTestMigration', []) # outputs "my connection"
  4. Steal the job and verify the connection:
    BackgroundMigrationWorker.perform_in(1.month, 'MyTestMigration')
    coordinator.steal('MyTestMigration') # outputs "my connection"

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