diff options
author | Jan Provaznik <jprovaznik@gitlab.com> | 2018-06-08 23:06:08 +0300 |
---|---|---|
committer | Jan Provaznik <jprovaznik@gitlab.com> | 2018-06-12 10:34:07 +0300 |
commit | c3f499e7c8656fa09b333b88950c70f7377f95f9 (patch) | |
tree | 2d0a4175febeb24f5f613b72a4374b5a18131fef /app/uploaders/object_storage.rb | |
parent | fa1a75ae28b421c5d3bd926c2795a053e4c6af15 (diff) |
Use upload ID instead of model ID in lease key
For FileUploaders it's possible that a model has many uploads
and if lease key is created only from model id, it causes that
the model's uploads can not be migrated in parallel because the
exclusive lease key would be same for all uploads of the model.
Diffstat (limited to 'app/uploaders/object_storage.rb')
-rw-r--r-- | app/uploaders/object_storage.rb | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/app/uploaders/object_storage.rb b/app/uploaders/object_storage.rb index 23b3dcf84c0..d8ec5a81968 100644 --- a/app/uploaders/object_storage.rb +++ b/app/uploaders/object_storage.rb @@ -298,6 +298,15 @@ module ObjectStorage super end + def exclusive_lease_key + # For FileUploaders, model may have many uploaders. In that case + # we want to use exclusive key per upload, not per model to allow + # parallel migration + key_object = self.is_a?(RecordsUploads::Concern) && upload ? upload : model + + "object_storage_migrate:#{key_object.class}:#{key_object.id}" + end + private def schedule_background_upload? @@ -364,10 +373,6 @@ module ObjectStorage end end - def exclusive_lease_key - "object_storage_migrate:#{model.class}:#{model.id}" - end - def with_exclusive_lease uuid = Gitlab::ExclusiveLease.new(exclusive_lease_key, timeout: 1.hour.to_i).try_obtain raise 'exclusive lease already taken' unless uuid |