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
826eedf4
Commit
826eedf4
authored
Jul 29, 2020
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor repositories clean up worker
Does not rely on FDW queries to find projects to clean up.
parent
85aeffd2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
34 deletions
+39
-34
ee/app/workers/geo/repositories_clean_up_worker.rb
ee/app/workers/geo/repositories_clean_up_worker.rb
+15
-6
ee/spec/workers/geo/repositories_clean_up_worker_spec.rb
ee/spec/workers/geo/repositories_clean_up_worker_spec.rb
+24
-28
No files found.
ee/app/workers/geo/repositories_clean_up_worker.rb
View file @
826eedf4
...
@@ -14,13 +14,14 @@ module Geo
...
@@ -14,13 +14,14 @@ module Geo
# rubocop:disable CodeReuse/ActiveRecord
# rubocop:disable CodeReuse/ActiveRecord
def
perform
(
geo_node_id
)
def
perform
(
geo_node_id
)
try_obtain_lease
do
try_obtain_lease
do
node
=
Geo
::
Fdw
::
Geo
Node
.
find
(
geo_node_id
)
node
=
GeoNode
.
find
(
geo_node_id
)
break
unless
node
.
selective_sync?
break
unless
node
.
selective_sync?
node
.
projects_outside_selective_sync
.
find_in_batches
(
batch_size:
BATCH_SIZE
)
do
|
batch
|
Geo
::
ProjectRegistry
.
select
(
:id
,
:project_id
).
find_in_batches
(
batch_size:
BATCH_SIZE
)
do
|
registries
|
batch
.
each
do
|
project
|
tracked_project_ids
=
registries
.
map
(
&
:project_id
)
clean_up_repositories
(
project
)
replicable_project_ids
=
node
.
projects
.
id_in
(
tracked_project_ids
).
pluck_primary_key
end
unused_tracked_project_ids
=
tracked_project_ids
-
replicable_project_ids
clean_up_repositories
(
unused_tracked_project_ids
)
end
end
end
end
rescue
ActiveRecord
::
RecordNotFound
=>
error
rescue
ActiveRecord
::
RecordNotFound
=>
error
...
@@ -30,7 +31,15 @@ module Geo
...
@@ -30,7 +31,15 @@ module Geo
private
private
def
clean_up_repositories
(
project
)
def
clean_up_repositories
(
unused_tracked_project_ids
)
unused_projects
=
Project
.
id_in
(
unused_tracked_project_ids
)
unused_projects
.
each
do
|
project
|
clean_up_repository
(
project
)
end
end
def
clean_up_repository
(
project
)
job_id
=
::
Geo
::
RepositoryCleanupWorker
.
perform_async
(
project
.
id
,
project
.
name
,
project
.
disk_path
,
project
.
repository
.
storage
)
job_id
=
::
Geo
::
RepositoryCleanupWorker
.
perform_async
(
project
.
id
,
project
.
name
,
project
.
disk_path
,
project
.
repository
.
storage
)
if
job_id
if
job_id
...
...
ee/spec/workers/geo/repositories_clean_up_worker_spec.rb
View file @
826eedf4
...
@@ -2,30 +2,25 @@
...
@@ -2,30 +2,25 @@
require
'spec_helper'
require
'spec_helper'
RSpec
.
describe
Geo
::
RepositoriesCleanUpWorker
,
:geo
,
:geo_fdw
do
RSpec
.
describe
Geo
::
RepositoriesCleanUpWorker
,
:geo
do
include
::
EE
::
GeoHelpers
include
::
EE
::
GeoHelpers
include
ExclusiveLeaseHelpers
include
ExclusiveLeaseHelpers
describe
'#perform'
do
describe
'#perform'
do
let
(
:secondary
)
{
create
(
:geo_node
)
}
let_it_be
(
:secondary
)
{
create
(
:geo_node
)
}
let_it_be
(
:synced_group
)
{
create
(
:group
)
}
let
(
:synced_group
)
{
create
(
:group
)
}
let_it_be
(
:synced_subgroup
)
{
create
(
:group
,
parent:
synced_group
)
}
let
(
:synced_subgroup
)
{
create
(
:group
,
parent:
synced_group
)
}
let_it_be
(
:unsynced_group
)
{
create
(
:group
)
}
let
(
:unsynced_group
)
{
create
(
:group
)
}
let_it_be
(
:project_1
)
{
create
(
:project
,
group:
synced_group
)
}
let_it_be
(
:project_2
)
{
create
(
:project
,
group:
synced_group
)
}
let
(
:project_1
)
{
create
(
:project
,
group:
synced_group
)
}
let_it_be
(
:project_3
)
{
create
(
:project
,
:repository
,
group:
unsynced_group
)
}
let
(
:project_2
)
{
create
(
:project
,
group:
synced_group
)
}
let_it_be
(
:project_4
)
{
create
(
:project
,
:repository
,
group:
unsynced_group
)
}
let!
(
:project_3
)
{
create
(
:project
,
:repository
,
group:
unsynced_group
)
}
let_it_be
(
:project_5
)
{
create
(
:project
,
group:
synced_subgroup
)
}
let
(
:project_4
)
{
create
(
:project
,
:repository
,
group:
unsynced_group
)
}
let_it_be
(
:project_6
)
{
create
(
:project
,
group:
synced_subgroup
)
}
let
(
:project_5
)
{
create
(
:project
,
group:
synced_subgroup
)
}
let_it_be
(
:project_7
)
{
create
(
:project
)
}
let
(
:project_6
)
{
create
(
:project
,
group:
synced_subgroup
)
}
let_it_be
(
:project_8
)
{
create
(
:project
)
}
let
(
:project_7
)
{
create
(
:project
)
}
let
(
:project_8
)
{
create
(
:project
)
}
before_all
do
before
do
stub_current_geo_node
(
secondary
)
stub_exclusive_lease
create
(
:geo_project_registry
,
project:
project_1
)
create
(
:geo_project_registry
,
project:
project_1
)
create
(
:geo_project_registry
,
project:
project_2
)
create
(
:geo_project_registry
,
project:
project_2
)
create
(
:geo_project_registry
,
project:
project_4
)
create
(
:geo_project_registry
,
project:
project_4
)
...
@@ -35,6 +30,11 @@ RSpec.describe Geo::RepositoriesCleanUpWorker, :geo, :geo_fdw do
...
@@ -35,6 +30,11 @@ RSpec.describe Geo::RepositoriesCleanUpWorker, :geo, :geo_fdw do
create
(
:geo_project_registry
,
project:
project_8
)
create
(
:geo_project_registry
,
project:
project_8
)
end
end
before
do
stub_current_geo_node
(
secondary
)
stub_exclusive_lease
end
it
'does not perform Geo::RepositoryCleanupWorker when cannnot obtain a lease'
do
it
'does not perform Geo::RepositoryCleanupWorker when cannnot obtain a lease'
do
stub_exclusive_lease_taken
stub_exclusive_lease_taken
...
@@ -76,10 +76,8 @@ RSpec.describe Geo::RepositoriesCleanUpWorker, :geo, :geo_fdw do
...
@@ -76,10 +76,8 @@ RSpec.describe Geo::RepositoriesCleanUpWorker, :geo, :geo_fdw do
subject
.
perform
(
secondary
.
id
)
subject
.
perform
(
secondary
.
id
)
end
end
it
'does not leave orphaned entries in the project_registry table'
do
it
'does not leave orphaned entries in the project_registry table'
,
:sidekiq_inline
do
Sidekiq
::
Testing
.
inline!
do
subject
.
perform
(
secondary
.
id
)
subject
.
perform
(
secondary
.
id
)
end
expect
(
Geo
::
ProjectRegistry
.
where
(
project_id:
[
project_3
,
project_4
,
project_7
,
project_8
])).
to
be_empty
expect
(
Geo
::
ProjectRegistry
.
where
(
project_id:
[
project_3
,
project_4
,
project_7
,
project_8
])).
to
be_empty
end
end
...
@@ -109,10 +107,8 @@ RSpec.describe Geo::RepositoriesCleanUpWorker, :geo, :geo_fdw do
...
@@ -109,10 +107,8 @@ RSpec.describe Geo::RepositoriesCleanUpWorker, :geo, :geo_fdw do
subject
.
perform
(
secondary
.
id
)
subject
.
perform
(
secondary
.
id
)
end
end
it
'does not leave orphaned entries in the project_registry table'
do
it
'does not leave orphaned entries in the project_registry table'
,
:sidekiq_inline
do
Sidekiq
::
Testing
.
inline!
do
subject
.
perform
(
secondary
.
id
)
subject
.
perform
(
secondary
.
id
)
end
expect
(
Geo
::
ProjectRegistry
.
where
(
project_id:
[
project_1
,
project_2
,
project_3
,
project_4
,
project_5
,
project_6
])).
to
be_empty
expect
(
Geo
::
ProjectRegistry
.
where
(
project_id:
[
project_1
,
project_2
,
project_3
,
project_4
,
project_5
,
project_6
])).
to
be_empty
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