Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
6daa44cd
Commit
6daa44cd
authored
Aug 05, 2019
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove orphaned project registries
Some registries can be orphaned because of lost Sidekiq job for example
parent
75ff95ed
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
109 additions
and
0 deletions
+109
-0
doc/administration/raketasks/geo.md
doc/administration/raketasks/geo.md
+17
-0
ee/changelogs/unreleased/13158-orphaned-project-registries.yml
...angelogs/unreleased/13158-orphaned-project-registries.yml
+5
-0
ee/lib/tasks/geo.rake
ee/lib/tasks/geo.rake
+40
-0
ee/spec/tasks/geo_rake_spec.rb
ee/spec/tasks/geo_rake_spec.rb
+47
-0
No files found.
doc/administration/raketasks/geo.md
View file @
6daa44cd
...
...
@@ -55,3 +55,20 @@ sudo gitlab-rake geo:git:housekeeping:gc
```
bash
sudo
-u
git
-H
bundle
exec
rake geo:git:housekeeping:gc
RAILS_ENV
=
production
```
## Remove orphaned project registries
Under certain conditions your project registry can contain obsolete records, you
can remove them using the rake task
`geo:run_orphaned_project_registry_cleaner`
:
**Omnibus Installation**
```
sudo gitlab-rake geo:run_orphaned_project_registry_cleaner
```
**Source Installation**
```
bash
sudo
-u
git
-H
bundle
exec
rake geo:run_orphaned_project_registry_cleaner
RAILS_ENV
=
production
```
ee/changelogs/unreleased/13158-orphaned-project-registries.yml
0 → 100644
View file @
6daa44cd
---
title
:
'
Geo:
Add
orphaned
project
registry
cleaner'
merge_request
:
15021
author
:
type
:
changed
ee/lib/tasks/geo.rake
View file @
6daa44cd
...
...
@@ -166,6 +166,46 @@ namespace :geo do
end
end
desc
'Run orphaned project registry cleaner'
task
run_orphaned_project_registry_cleaner: :environment
do
abort
GEO_LICENSE_ERROR_TEXT
unless
Gitlab
::
Geo
.
license_allows?
unless
Gitlab
::
Geo
.
secondary?
abort
'This is not a secondary node'
end
from_project_id
=
ENV
[
'FROM_PROJECT_ID'
]
||
Geo
::
ProjectRegistry
.
minimum
(
:project_id
)
to_project_id
=
ENV
[
'TO_PROJECT_ID'
]
||
Geo
::
ProjectRegistry
.
maximum
(
:project_id
)
if
from_project_id
>
to_project_id
abort
'FROM_PROJECT_ID can not be greater than TO_PROJECT_ID'
end
batch_size
=
1000
total_count
=
0
current_max_id
=
0
until
current_max_id
>=
to_project_id
current_max_id
=
[
from_project_id
+
batch_size
,
to_project_id
+
1
].
min
project_ids
=
Project
.
where
(
'id >= ? AND id < ?'
,
from_project_id
,
current_max_id
)
.
pluck_primary_key
orphaned_registries
=
Geo
::
ProjectRegistry
.
where
(
'project_id NOT IN(?)'
,
project_ids
)
.
where
(
'project_id >= ? AND project_id < ?'
,
from_project_id
,
current_max_id
)
count
=
orphaned_registries
.
delete_all
total_count
+=
count
puts
"Checked project ids from
#{
from_project_id
}
to
#{
current_max_id
}
registries. Removed
#{
count
}
orphaned registries"
from_project_id
=
current_max_id
end
puts
"Orphaned registries removed(total):
#{
total_count
}
"
end
desc
'Make this node the Geo primary'
task
set_primary_node: :environment
do
abort
GEO_LICENSE_ERROR_TEXT
unless
Gitlab
::
Geo
.
license_allows?
...
...
ee/spec/tasks/geo_rake_spec.rb
View file @
6daa44cd
...
...
@@ -347,4 +347,51 @@ describe 'geo rake tasks', :geo do
end
end
end
describe
'geo:run_orphaned_project_registry_cleaner'
do
let!
(
:current_node
)
{
create
(
:geo_node
)
}
before
do
stub_current_geo_node
(
current_node
)
create
(
:geo_project_registry
)
create
(
:geo_project_registry
)
@orphaned
=
create
(
:geo_project_registry
)
@orphaned
.
project
.
delete
@orphaned1
=
create
(
:geo_project_registry
)
@orphaned1
.
project
.
delete
create
(
:geo_project_registry
)
end
it
'removes orphaned registries'
do
run_rake_task
(
'geo:run_orphaned_project_registry_cleaner'
)
expect
(
Geo
::
ProjectRegistry
.
count
).
to
be
3
expect
(
Geo
::
ProjectRegistry
.
find_by_id
(
@orphaned
.
id
)).
to
be
nil
end
it
'removes orphaned registries taking into account TO_PROJECT_ID'
do
allow
(
ENV
).
to
receive
(
:[]
).
with
(
'FROM_PROJECT_ID'
).
and_return
(
nil
)
allow
(
ENV
).
to
receive
(
:[]
).
with
(
'TO_PROJECT_ID'
).
and_return
(
@orphaned
.
project_id
)
run_rake_task
(
'geo:run_orphaned_project_registry_cleaner'
)
expect
(
Geo
::
ProjectRegistry
.
count
).
to
be
4
expect
(
Geo
::
ProjectRegistry
.
find_by_id
(
@orphaned
.
id
)).
to
be
nil
expect
(
Geo
::
ProjectRegistry
.
find_by_id
(
@orphaned1
.
id
)).
not_to
be
nil
end
it
'removes orphaned registries taking into account FROM_PROJECT_ID'
do
allow
(
ENV
).
to
receive
(
:[]
).
with
(
'FROM_PROJECT_ID'
).
and_return
(
@orphaned1
.
project_id
)
allow
(
ENV
).
to
receive
(
:[]
).
with
(
'TO_PROJECT_ID'
).
and_return
(
nil
)
run_rake_task
(
'geo:run_orphaned_project_registry_cleaner'
)
expect
(
Geo
::
ProjectRegistry
.
count
).
to
be
4
expect
(
Geo
::
ProjectRegistry
.
find_by_id
(
@orphaned
.
id
)).
not_to
be
nil
expect
(
Geo
::
ProjectRegistry
.
find_by_id
(
@orphaned1
.
id
)).
to
be
nil
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment