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
4814fe2c
Commit
4814fe2c
authored
Dec 05, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring Geo::ProjectRegistryFinder
parent
7017fb41
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
46 deletions
+98
-46
app/models/geo_node_status.rb
app/models/geo_node_status.rb
+2
-2
ee/app/finders/geo/project_registry_finder.rb
ee/app/finders/geo/project_registry_finder.rb
+21
-26
spec/ee/spec/finders/geo/project_registry_finder_spec.rb
spec/ee/spec/finders/geo/project_registry_finder_spec.rb
+74
-18
spec/factories/geo/project_registry.rb
spec/factories/geo/project_registry.rb
+1
-0
No files found.
app/models/geo_node_status.rb
View file @
4814fe2c
...
...
@@ -72,8 +72,8 @@ class GeoNodeStatus < ActiveRecord::Base
self
.
db_replication_lag_seconds
=
Gitlab
::
Geo
::
HealthCheck
.
db_replication_lag_seconds
self
.
cursor_last_event_id
=
Geo
::
EventLogState
.
last_processed
&
.
event_id
self
.
cursor_last_event_date
=
Geo
::
EventLog
.
find_by
(
id:
self
.
cursor_last_event_id
)
&
.
created_at
self
.
repositories_synced_count
=
projects_finder
.
count_synced_projects
self
.
repositories_failed_count
=
projects_finder
.
count_failed_projects
self
.
repositories_synced_count
=
projects_finder
.
count_synced_project
_registrie
s
self
.
repositories_failed_count
=
projects_finder
.
count_failed_project
_registrie
s
self
.
lfs_objects_synced_count
=
lfs_objects_finder
.
count_synced_lfs_objects
self
.
lfs_objects_failed_count
=
lfs_objects_finder
.
count_failed_lfs_objects
self
.
attachments_synced_count
=
attachments_finder
.
find_synced_attachments
.
count
...
...
ee/app/finders/geo/project_registry_finder.rb
View file @
4814fe2c
module
Geo
class
ProjectRegistryFinder
<
RegistryFinder
def
count_synced_projects
def
count_synced_project
_registrie
s
relation
=
if
selective_sync?
legacy_find_synced_projects
legacy_find_synced_project
_registrie
s
else
find_synced_project
s
_registries
find_synced_project_registries
end
relation
.
count
end
def
count_failed_projects
relation
=
if
selective_sync?
legacy_find_failed_projects
else
find_failed_projects_registries
end
relation
.
count
def
count_failed_project_registries
find_failed_project_registries
.
count
end
def
find_failed_project_registries
(
type
=
nil
)
relation
=
if
selective_sync?
legacy_find_failed_project_registries
(
type
)
legacy_find_f
iltered_f
ailed_project_registries
(
type
)
else
find_f
ailed_projects
_registries
(
type
)
find_f
iltered_failed_project
_registries
(
type
)
end
relation
...
...
@@ -57,11 +50,11 @@ module Geo
protected
def
find_synced_project
s
_registries
def
find_synced_project_registries
Geo
::
ProjectRegistry
.
synced
end
def
find_f
ailed_projects
_registries
(
type
=
nil
)
def
find_f
iltered_failed_project
_registries
(
type
=
nil
)
case
type
when
'repository'
Geo
::
ProjectRegistry
.
failed_repos
...
...
@@ -117,16 +110,18 @@ module Geo
legacy_find_projects
(
Geo
::
ProjectRegistry
.
dirty
.
retry_due
.
pluck
(
:project_id
))
end
# @return [ActiveRecord::Relation<
Project
>] list of synced projects
def
legacy_find_synced_projects
legacy_find_project
s
(
Geo
::
ProjectRegistry
.
synced
.
pluck
(
:project_id
)
)
# @return [ActiveRecord::Relation<
Geo::ProjectRegistry
>] list of synced projects
def
legacy_find_synced_project
_registrie
s
legacy_find_project
_registries
(
Geo
::
ProjectRegistry
.
synced
)
end
# @return [ActiveRecord::Relation<Project>] list of projects that sync has failed
def
legacy_find_failed_projects
legacy_find_projects
(
Geo
::
ProjectRegistry
.
failed
.
pluck
(
:project_id
))
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of projects that sync has failed
def
legacy_find_filtered_failed_project_registries
(
type
=
nil
)
project_registries
=
find_filtered_failed_project_registries
(
type
)
legacy_find_project_registries
(
project_registries
)
end
# @return [ActiveRecord::Relation<Project>]
def
legacy_find_projects
(
registry_project_ids
)
return
Project
.
none
if
registry_project_ids
.
empty?
...
...
@@ -140,15 +135,15 @@ module Geo
joined_relation
end
def
legacy_find_failed_project_registries
(
type
)
project_registries
=
find_failed_projects_registries
(
type
)
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>]
def
legacy_find_project_registries
(
project_registries
)
return
Geo
::
ProjectRegistry
.
none
if
project_registries
.
empty?
joined_relation
=
project_registries
.
joins
(
<<~
SQL
)
INNER JOIN
(VALUES
#{
current_node
.
projects
.
pluck
(
:id
).
map
{
|
id
|
"(
#{
id
}
)"
}
.join(',')})
projects(
project_
id)
ON
#{
Geo
::
ProjectRegistry
.
table_name
}
.
id = projects.project_
id
projects(id)
ON
#{
Geo
::
ProjectRegistry
.
table_name
}
.
project_id = projects.
id
SQL
joined_relation
...
...
spec/ee/spec/finders/geo/project_registry_finder_spec.rb
View file @
4814fe2c
...
...
@@ -18,11 +18,11 @@ describe Geo::ProjectRegistryFinder, :geo, :truncate do
stub_current_geo_node
(
secondary
)
end
describe
'#count_synced_projects'
do
it
'delegates to #find_synced_project
s
_registries'
do
expect
(
subject
).
to
receive
(
:find_synced_project
s
_registries
).
and_call_original
describe
'#count_synced_project
_registrie
s'
do
it
'delegates to #find_synced_project_registries'
do
expect
(
subject
).
to
receive
(
:find_synced_project_registries
).
and_call_original
subject
.
count_synced_projects
subject
.
count_synced_project
_registrie
s
end
it
'counts projects that has been synced'
do
...
...
@@ -31,7 +31,7 @@ describe Geo::ProjectRegistryFinder, :geo, :truncate do
create
(
:geo_project_registry
,
:synced
,
:repository_dirty
,
project:
project_repository_dirty
)
create
(
:geo_project_registry
,
:synced
,
:wiki_dirty
,
project:
project_wiki_dirty
)
expect
(
subject
.
count_synced_projects
).
to
eq
1
expect
(
subject
.
count_synced_project
_registrie
s
).
to
eq
1
end
context
'with selective sync'
do
...
...
@@ -39,10 +39,10 @@ describe Geo::ProjectRegistryFinder, :geo, :truncate do
secondary
.
update_attribute
(
:namespaces
,
[
synced_group
])
end
it
'delegates to #legacy_find_synced_projects'
do
expect
(
subject
).
to
receive
(
:legacy_find_synced_projects
).
and_call_original
it
'delegates to #legacy_find_synced_project
_registrie
s'
do
expect
(
subject
).
to
receive
(
:legacy_find_synced_project
_registrie
s
).
and_call_original
subject
.
count_synced_projects
subject
.
count_synced_project
_registrie
s
end
it
'counts projects that has been synced'
do
...
...
@@ -53,16 +53,16 @@ describe Geo::ProjectRegistryFinder, :geo, :truncate do
create
(
:geo_project_registry
,
:synced
,
project:
project_1_in_synced_group
)
create
(
:geo_project_registry
,
:sync_failed
,
project:
project_2_in_synced_group
)
expect
(
subject
.
count_synced_projects
).
to
eq
1
expect
(
subject
.
count_synced_project
_registrie
s
).
to
eq
1
end
end
end
describe
'#count_failed_projects'
do
it
'delegates to #find_failed_project
s
_registries'
do
expect
(
subject
).
to
receive
(
:find_failed_project
s
_registries
).
and_call_original
describe
'#count_failed_project
_registrie
s'
do
it
'delegates to #find_failed_project_registries'
do
expect
(
subject
).
to
receive
(
:find_failed_project_registries
).
and_call_original
subject
.
count_failed_projects
subject
.
count_failed_project
_registrie
s
end
it
'counts projects that sync has failed'
do
...
...
@@ -71,7 +71,7 @@ describe Geo::ProjectRegistryFinder, :geo, :truncate do
create
(
:geo_project_registry
,
:repository_sync_failed
,
project:
project_repository_dirty
)
create
(
:geo_project_registry
,
:wiki_sync_failed
,
project:
project_wiki_dirty
)
expect
(
subject
.
count_failed_projects
).
to
eq
3
expect
(
subject
.
count_failed_project
_registrie
s
).
to
eq
3
end
context
'with selective sync'
do
...
...
@@ -79,10 +79,10 @@ describe Geo::ProjectRegistryFinder, :geo, :truncate do
secondary
.
update_attribute
(
:namespaces
,
[
synced_group
])
end
it
'delegates to #
legacy_find_failed_project
s'
do
expect
(
subject
).
to
receive
(
:
legacy_find_failed_project
s
).
and_call_original
it
'delegates to #
find_failed_project_registrie
s'
do
expect
(
subject
).
to
receive
(
:
find_failed_project_registrie
s
).
and_call_original
subject
.
count_failed_projects
subject
.
count_failed_project
_registrie
s
end
it
'counts projects that sync has failed'
do
...
...
@@ -93,7 +93,63 @@ describe Geo::ProjectRegistryFinder, :geo, :truncate do
create
(
:geo_project_registry
,
:repository_sync_failed
,
project:
project_1_in_synced_group
)
create
(
:geo_project_registry
,
:synced
,
project:
project_2_in_synced_group
)
expect
(
subject
.
count_failed_projects
).
to
eq
1
expect
(
subject
.
count_failed_project_registries
).
to
eq
1
end
end
end
describe
'#find_failed_project_registries'
do
let
(
:project_1_in_synced_group
)
{
create
(
:project
,
group:
synced_group
)
}
let
(
:project_2_in_synced_group
)
{
create
(
:project
,
group:
synced_group
)
}
let!
(
:synced
)
{
create
(
:geo_project_registry
,
:synced
)
}
let!
(
:sync_failed
)
{
create
(
:geo_project_registry
,
:sync_failed
,
project:
project_synced
)
}
let!
(
:repository_sync_failed
)
{
create
(
:geo_project_registry
,
:repository_sync_failed
,
project:
project_1_in_synced_group
)
}
let!
(
:wiki_sync_failed
)
{
create
(
:geo_project_registry
,
:wiki_sync_failed
,
project:
project_2_in_synced_group
)
}
it
'delegates to #find_filtered_failed_project_registries'
do
expect
(
subject
).
to
receive
(
:find_filtered_failed_project_registries
).
and_call_original
subject
.
find_failed_project_registries
end
it
'returns project registries that sync has failed'
do
expect
(
subject
.
find_failed_project_registries
).
to
match_array
([
sync_failed
,
repository_sync_failed
,
wiki_sync_failed
])
end
it
'returns only project registries that repository sync has failed'
do
expect
(
subject
.
find_failed_project_registries
(
'repository'
)).
to
match_array
([
sync_failed
,
repository_sync_failed
])
end
it
'returns only project registries that wiki sync has failed'
do
expect
(
subject
.
find_failed_project_registries
(
'wiki'
)).
to
match_array
([
sync_failed
,
wiki_sync_failed
])
end
context
'with selective sync'
do
before
do
secondary
.
update_attribute
(
:namespaces
,
[
synced_group
])
end
it
'delegates to #legacy_find_filtered_failed_project_registries'
do
expect
(
subject
).
to
receive
(
:legacy_find_filtered_failed_project_registries
).
and_call_original
subject
.
find_failed_project_registries
end
it
'returns project registries that sync has failed'
do
expect
(
subject
.
find_failed_project_registries
).
to
match_array
([
repository_sync_failed
,
wiki_sync_failed
])
end
it
'returns only project registries that repository sync has failed'
do
create
(
:geo_project_registry
,
:repository_sync_failed
)
expect
(
subject
.
find_failed_project_registries
(
'repository'
)).
to
match_array
([
repository_sync_failed
])
end
it
'returns only project registries that wiki sync has failed'
do
create
(
:geo_project_registry
,
:wiki_sync_failed
)
expect
(
subject
.
find_failed_project_registries
(
'wiki'
)).
to
match_array
([
wiki_sync_failed
])
end
end
end
...
...
spec/factories/geo/project_registry.rb
View file @
4814fe2c
...
...
@@ -40,6 +40,7 @@ FactoryGirl.define do
resync_repository
true
resync_wiki
true
repository_retry_count
1
wiki_retry_count
1
end
trait
:repository_sync_failed
do
...
...
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