Fix a race condition intermittently breaking GitLab startup
This commit is contained in:
parent
132e6c9f95
commit
3d1690c776
2 changed files with 10 additions and 6 deletions
|
@ -9,14 +9,13 @@ class Shard < ActiveRecord::Base
|
||||||
|
|
||||||
# The GitLab config does not change for the lifecycle of the process
|
# The GitLab config does not change for the lifecycle of the process
|
||||||
in_config = Gitlab.config.repositories.storages.keys.map(&:to_s)
|
in_config = Gitlab.config.repositories.storages.keys.map(&:to_s)
|
||||||
|
|
||||||
transaction do
|
|
||||||
in_db = all.pluck(:name)
|
in_db = all.pluck(:name)
|
||||||
missing = in_config - in_db
|
|
||||||
|
|
||||||
|
# This may race with other processes creating shards at the same time, but
|
||||||
|
# `by_name` will handle that correctly
|
||||||
|
missing = in_config - in_db
|
||||||
missing.map { |name| by_name(name) }
|
missing.map { |name| by_name(name) }
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def self.by_name(name)
|
def self.by_name(name)
|
||||||
find_or_create_by(name: name)
|
find_or_create_by(name: name)
|
||||||
|
|
5
changelogs/unreleased/53972-fix-fill-shards.yml
Normal file
5
changelogs/unreleased/53972-fix-fill-shards.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Fix a race condition intermittently breaking GitLab startup
|
||||||
|
merge_request: 23028
|
||||||
|
author:
|
||||||
|
type: fixed
|
Loading…
Reference in a new issue