diff options
author | Gabriel Mazetto <brodock@gmail.com> | 2018-12-22 06:01:24 +0300 |
---|---|---|
committer | Gabriel Mazetto <brodock@gmail.com> | 2019-01-08 01:53:06 +0300 |
commit | ee4af0c64cdf00d2c34ce7feb773e057f9758cff (patch) | |
tree | e020ae1eda2b9c2eb24a1e24c862d502c4f8e748 /app/models | |
parent | 7380364240a26d184d67edb1fe7ae0fc07217e0f (diff) |
Only set as `read_only` when starting the per-project migration
In the previous code, we locked the project during the migration
scheduling step, which works fine for small setups, but can be
problematic in really big installations.
We now moved the logic to inside the worker, so we minimize the time a
project will be read-only. We also make sure we only do that if
reference counter is `0` (no current operation is in progress).
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/project.rb | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index e2f010a0432..0187f2eb43f 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1786,6 +1786,24 @@ class Project < ActiveRecord::Base handle_update_attribute_error(e, value) end + # Tries to set repository as read_only, checking for existing Git transfers in progress beforehand + # + # @return [Boolean] true when set to read_only or false when an existing git transfer is in progress + def set_repository_read_only! + with_lock do + break false if git_transfer_in_progress? + + update_column(:repository_read_only, true) + end + end + + # Set repository as writable again + def set_repository_writable! + with_lock do + update_column(repository_read_only, false) + end + end + def pushes_since_gc Gitlab::Redis::SharedState.with { |redis| redis.get(pushes_since_gc_redis_shared_state_key).to_i } end @@ -1900,15 +1918,17 @@ class Project < ActiveRecord::Base def migrate_to_hashed_storage! return unless storage_upgradable? - update!(repository_read_only: true) - - if repo_reference_count > 0 || wiki_reference_count > 0 + if git_transfer_in_progress? ProjectMigrateHashedStorageWorker.perform_in(Gitlab::ReferenceCounter::REFERENCE_EXPIRE_TIME, id) else ProjectMigrateHashedStorageWorker.perform_async(id) end end + def git_transfer_in_progress? + repo_reference_count > 0 || wiki_reference_count > 0 + end + def storage_version=(value) super |