Commit bdefdb44 authored by Nick Thomas's avatar Nick Thomas

Merge branch '5928-geo-rake-task-to-force-housekeeping-on-next-sync' into 'master'

Resolve "Geo: Rake task to force housekeeping on next sync"

Closes #5928

See merge request gitlab-org/gitlab-ee!5623
parents 3857ab25 ea23f998
......@@ -184,6 +184,9 @@ gem 'httparty', '~> 0.13.3'
# Colored output to console
gem 'rainbow', '~> 2.2'
# Progress bar
gem 'ruby-progressbar'
# GitLab settings
gem 'settingslogic', '~> 2.0.9'
......
......@@ -1187,6 +1187,7 @@ DEPENDENCIES
rubocop-rspec (~> 1.22.1)
ruby-fogbugz (~> 0.2.1)
ruby-prof (~> 0.17.0)
ruby-progressbar
ruby_parser (~> 3.8)
rufus-scheduler (~> 3.4)
rugged (~> 0.27)
......
# Geo Rake Tasks
## Git housekeeping
There are few tasks you can run to schedule a git housekeeping to start at the
next repository sync in a **Secondary node**:
### Incremental Repack
This is equivalent of running `git repack -d` on a _bare_ repository.
**Omnibus Installation**
```
sudo gitlab-rake geo:git:housekeeping:incremental_repack
```
**Source Installation**
```bash
sudo -u git -H bundle exec rake geo:git:housekeeping:incremental_repack RAILS_ENV=production
```
### Full Repack
This is equivalent of running `git repack -d -A --pack-kept-objects` on a
_bare_ repository which will optionally, write a reachability bitmap index
when this is enabled in GitLab.
**Omnibus Installation**
```
sudo gitlab-rake geo:git:housekeeping:full_repack
```
**Source Installation**
```bash
sudo -u git -H bundle exec rake geo:git:housekeeping:full_repack RAILS_ENV=production
```
### GC
This is equivalent of running `git gc` on a _bare_ repository, optionally writing
a reachability bitmap index when this is enabled in GitLab.
**Omnibus Installation**
```
sudo gitlab-rake geo:git:housekeeping:gc
```
**Source Installation**
```bash
sudo -u git -H bundle exec rake geo:git:housekeeping:gc RAILS_ENV=production
```
......@@ -72,10 +72,16 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
Gitlab::Redis::SharedState.with { |redis| redis.del(fetches_since_gc_redis_key) }
end
def set_syncs_since_gc!(value)
return false if !value.is_a?(Integer) || value < 0
Gitlab::Redis::SharedState.with { |redis| redis.set(fetches_since_gc_redis_key, value) }
end
private
def fetches_since_gc_redis_key
"projects/#{project.id}/fetches_since_gc"
"projects/#{project_id}/fetches_since_gc"
end
def never_synced_repository?
......
---
title: 'Geo: Rake task to force housekeeping on next sync'
merge_request: 5623
author:
type: added
namespace :geo do
namespace :git do
namespace :housekeeping do
using ProgressBar::Refinements::Enumerator
desc "GitLab | Git | Housekeeping | Garbage Collection"
task gc: :gitlab_environment do
flag_for_housekeeping(Gitlab::CurrentSettings.housekeeping_gc_period)
end
desc "GitLab | Git | Housekeeping | Full Repack"
task full_repack: :gitlab_environment do
flag_for_housekeeping(Gitlab::CurrentSettings.housekeeping_full_repack_period)
end
desc "GitLab | Git | Housekeeping | Incremental Repack"
task incremental_repack: :gitlab_environment do
flag_for_housekeeping(Gitlab::CurrentSettings.housekeeping_incremental_repack_period)
end
def flag_for_housekeeping(period)
Geo::ProjectRegistry.select(:id, :project_id).find_in_batches.with_progressbar(format: '%t: |%B| %p%% %e') do |batches|
batches.each do |registry|
registry.set_syncs_since_gc!(period - 1)
end
end
end
end
end
end
require 'rake_helper'
describe 'geo:git:housekeeping' do
set(:project) { create(:project, :repository) }
set(:registry) { ::Geo::ProjectRegistry.find_or_create_by!(project: project) }
shared_examples 'housekeeping task' do |task_name, period_name|
it "sets existing projects syncs_gc count to #{period_name}-1" do
period = Gitlab::CurrentSettings.send(period_name)
expect { run_rake_task(task_name) }.to change { registry.syncs_since_gc }.to(period - 1)
end
end
before do
Rake.application.rake_require 'tasks/geo/git'
silence_progress_bar
end
after do
registry.reset_syncs_since_gc!
end
describe 'geo:git:housekeeping:gc' do
it_behaves_like 'housekeeping task', 'geo:git:housekeeping:gc', :housekeeping_gc_period
end
describe 'geo:git:housekeeping:full_repack' do
it_behaves_like 'housekeeping task', 'geo:git:housekeeping:full_repack', :housekeeping_full_repack_period
end
describe 'geo:git:housekeeping:incremental_repack' do
it_behaves_like 'housekeeping task', 'geo:git:housekeeping:incremental_repack', :housekeeping_incremental_repack_period
end
end
......@@ -13,6 +13,10 @@ module RakeHelpers
allow(main_object).to receive(:print)
end
def silence_progress_bar
allow_any_instance_of(ProgressBar::Output).to receive(:stream).and_return(double().as_null_object)
end
def main_object
@main_object ||= TOPLEVEL_BINDING.eval('self')
end
......
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