diff options
author | Alex Hanselka <alex@gitlab.com> | 2018-12-11 00:42:50 +0300 |
---|---|---|
committer | Alex Hanselka <alex@gitlab.com> | 2018-12-11 00:42:50 +0300 |
commit | f77888fe0857c9f4a47133f434c741a510946767 (patch) | |
tree | b227b60894474ba2c9a8864b66e4df65763b35b8 /app/models/pool_repository.rb | |
parent | d2120ff1e705799752e7d9704cae3f1896d8e186 (diff) | |
parent | 2d7dc668506a0576e231fbe290c89e47cf088300 (diff) |
Merge branch '11-6-stable-prepare-rc5' into '11-6-stable'
Prepare 11.6 RC5 release
See merge request gitlab-org/gitlab-ce!23704
Diffstat (limited to 'app/models/pool_repository.rb')
-rw-r--r-- | app/models/pool_repository.rb | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/app/models/pool_repository.rb b/app/models/pool_repository.rb index bad0e30ceb5..dbde00b5584 100644 --- a/app/models/pool_repository.rb +++ b/app/models/pool_repository.rb @@ -1,12 +1,89 @@ # frozen_string_literal: true +# The PoolRepository model is the database equivalent of an ObjectPool for Gitaly +# That is; PoolRepository is the record in the database, ObjectPool is the +# repository on disk class PoolRepository < ActiveRecord::Base include Shardable + include AfterCommitQueue + + has_one :source_project, class_name: 'Project' + validates :source_project, presence: true has_many :member_projects, class_name: 'Project' after_create :correct_disk_path + state_machine :state, initial: :none do + state :scheduled + state :ready + state :failed + + event :schedule do + transition none: :scheduled + end + + event :mark_ready do + transition [:scheduled, :failed] => :ready + end + + event :mark_failed do + transition all => :failed + end + + state all - [:ready] do + def joinable? + false + end + end + + state :ready do + def joinable? + true + end + end + + after_transition none: :scheduled do |pool, _| + pool.run_after_commit do + ::ObjectPool::CreateWorker.perform_async(pool.id) + end + end + + after_transition scheduled: :ready do |pool, _| + pool.run_after_commit do + ::ObjectPool::ScheduleJoinWorker.perform_async(pool.id) + end + end + end + + def create_object_pool + object_pool.create + end + + # The members of the pool should have fetched the missing objects to their own + # objects directory. If the caller fails to do so, data loss might occur + def delete_object_pool + object_pool.delete + end + + def link_repository(repository) + object_pool.link(repository.raw) + end + + # This RPC can cause data loss, as not all objects are present the local repository + # No execution path yet, will be added through: + # https://gitlab.com/gitlab-org/gitaly/issues/1415 + def delete_repository_alternate(repository) + object_pool.unlink_repository(repository.raw) + end + + def object_pool + @object_pool ||= Gitlab::Git::ObjectPool.new( + shard.name, + disk_path + '.git', + source_project.repository.raw) + end + private def correct_disk_path |