summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-11-13 23:05:08 +0000
committerStan Hu <stanhu@gmail.com>2018-11-13 23:05:08 +0000
commit078fab665bee3cf283053fe03193b6a73ff7d427 (patch)
tree2615495046c5fa1985be223b305017d6a1977411
parentc718c6ee2ac035582a656efe82ccda5cb502375f (diff)
parent3d1690c77625fbbfa5c0ec28aeabc9702c5dfb05 (diff)
downloadgitlab-ce-078fab665bee3cf283053fe03193b6a73ff7d427.tar.gz
Merge branch '53972-fix-fill-shards' into 'master'
Fix a race condition in the shard population logic Closes #53972 See merge request gitlab-org/gitlab-ce!23028
-rw-r--r--app/models/shard.rb11
-rw-r--r--changelogs/unreleased/53972-fix-fill-shards.yml5
2 files changed, 10 insertions, 6 deletions
diff --git a/app/models/shard.rb b/app/models/shard.rb
index 2fa22bd040c..2e75bc91df0 100644
--- a/app/models/shard.rb
+++ b/app/models/shard.rb
@@ -9,13 +9,12 @@ class Shard < ActiveRecord::Base
# The GitLab config does not change for the lifecycle of the process
in_config = Gitlab.config.repositories.storages.keys.map(&:to_s)
+ in_db = all.pluck(:name)
- transaction do
- in_db = all.pluck(:name)
- missing = in_config - in_db
-
- missing.map { |name| by_name(name) }
- end
+ # 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) }
end
def self.by_name(name)
diff --git a/changelogs/unreleased/53972-fix-fill-shards.yml b/changelogs/unreleased/53972-fix-fill-shards.yml
new file mode 100644
index 00000000000..ca94d6cc589
--- /dev/null
+++ b/changelogs/unreleased/53972-fix-fill-shards.yml
@@ -0,0 +1,5 @@
+---
+title: Fix a race condition intermittently breaking GitLab startup
+merge_request: 23028
+author:
+type: fixed