Skip to content

Make sure the shards table has its index created before populating it

What does this MR do?

This fixes a race-condition discovered in #212436 (closed).

Shards are populated in an initializer, which would run in any container that runs GitLab and tries to start it up: https://gitlab.com/gitlab-org/gitlab/-/blob/dc17873201097e7d4838f6be9211f5945c96ec1e/config/initializers/fill_shards.rb#L3

So as soon as Active Record is connected and the shards table exists and the database isn't read-only, shards are being populated, which could occur after the shards is created by db:structure:load but before the index_shards_on_name is created (since indexes are located at the end of structure.sql)!

This MR ensure the shards population can only happen after the unique index on name is created.

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Closes #212436 (closed).

Edited by Rémy Coutable

Merge request reports