Commit da54d644 authored by Marc Shaw's avatar Marc Shaw

Add default lease_key to git garbage collect worker and project cleanup

Issue: gitlab.com/gitlab-org/gitlab/-/issues/29536
Merge Request: gitlab.com/gitlab-org/gitlab/-/merge_requests/38686
parent fbcd3261
...@@ -22,7 +22,7 @@ module Projects ...@@ -22,7 +22,7 @@ module Projects
apply_bfg_object_map! apply_bfg_object_map!
# Remove older objects that are no longer referenced # Remove older objects that are no longer referenced
GitGarbageCollectWorker.new.perform(project.id, :gc) GitGarbageCollectWorker.new.perform(project.id, :gc, "project_cleanup:gc:#{project.id}")
# The cache may now be inaccurate, and holding onto it could prevent # The cache may now be inaccurate, and holding onto it could prevent
# bugs assuming the presence of some object from manifesting for some # bugs assuming the presence of some object from manifesting for some
......
...@@ -11,6 +11,7 @@ class GitGarbageCollectWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -11,6 +11,7 @@ class GitGarbageCollectWorker # rubocop:disable Scalability/IdempotentWorker
LEASE_TIMEOUT = 86400 LEASE_TIMEOUT = 86400
def perform(project_id, task = :gc, lease_key = nil, lease_uuid = nil) def perform(project_id, task = :gc, lease_key = nil, lease_uuid = nil)
lease_key ||= "git_gc:#{task}:#{project_id}"
project = Project.find(project_id) project = Project.find(project_id)
active_uuid = get_lease_uuid(lease_key) active_uuid = get_lease_uuid(lease_key)
......
...@@ -19,7 +19,7 @@ RSpec.describe Projects::CleanupService do ...@@ -19,7 +19,7 @@ RSpec.describe Projects::CleanupService do
it 'runs garbage collection on the repository' do it 'runs garbage collection on the repository' do
expect_next_instance_of(GitGarbageCollectWorker) do |worker| expect_next_instance_of(GitGarbageCollectWorker) do |worker|
expect(worker).to receive(:perform) expect(worker).to receive(:perform).with(project.id, :gc, "project_cleanup:gc:#{project.id}")
end end
service.execute service.execute
......
...@@ -95,6 +95,7 @@ RSpec.describe GitGarbageCollectWorker do ...@@ -95,6 +95,7 @@ RSpec.describe GitGarbageCollectWorker do
it_behaves_like 'it updates the project statistics' it_behaves_like 'it updates the project statistics'
it "flushes ref caches when the task if 'gc'" do it "flushes ref caches when the task if 'gc'" do
expect(subject).to receive(:get_lease_uuid).with("git_gc:#{task}:#{project.id}").and_return(false)
expect_any_instance_of(Repository).to receive(:after_create_branch).and_call_original expect_any_instance_of(Repository).to receive(:after_create_branch).and_call_original
expect_any_instance_of(Repository).to receive(:branch_names).and_call_original expect_any_instance_of(Repository).to receive(:branch_names).and_call_original
expect_any_instance_of(Repository).to receive(:has_visible_content?).and_call_original expect_any_instance_of(Repository).to receive(:has_visible_content?).and_call_original
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment