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
2a9ab657
Commit
2a9ab657
authored
Apr 02, 2019
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use FDW to find unsynced projects when feature flag is enabled
parent
dc726031
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
80 deletions
+24
-80
ee/app/finders/geo/project_registry_finder.rb
ee/app/finders/geo/project_registry_finder.rb
+12
-38
ee/app/workers/geo/repository_shard_sync_worker.rb
ee/app/workers/geo/repository_shard_sync_worker.rb
+5
-5
ee/spec/finders/geo/project_registry_finder_spec.rb
ee/spec/finders/geo/project_registry_finder_spec.rb
+7
-37
No files found.
ee/app/finders/geo/project_registry_finder.rb
View file @
2a9ab657
...
...
@@ -72,18 +72,11 @@ module Geo
.
execute
end
# rubocop: disable CodeReuse/ActiveRecord
def
find_unsynced_projects
(
batch_size
:)
relation
=
if
use_legacy_queries?
legacy_find_unsynced_projects
else
fdw_find_unsynced_projects
end
relation
.
limit
(
batch_size
)
def
find_unsynced_projects
(
shard_name
:,
batch_size
:)
finder_klass_for_unsynced_projects
.
new
(
current_node:
current_node
,
shard_name:
shard_name
,
batch_size:
batch_size
)
.
execute
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
find_projects_updated_recently
(
batch_size
:)
...
...
@@ -100,18 +93,6 @@ module Geo
protected
#
# FDW accessors
#
# @return [ActiveRecord::Relation<Geo::Fdw::Project>]
# rubocop: disable CodeReuse/ActiveRecord
def
fdw_find_unsynced_projects
Geo
::
Fdw
::
Project
.
joins
(
"LEFT OUTER JOIN project_registry ON project_registry.project_id =
#{
fdw_project_table
.
name
}
.id"
)
.
where
(
project_registry:
{
project_id:
nil
})
end
# rubocop: enable CodeReuse/ActiveRecord
# @return [ActiveRecord::Relation<Geo::Fdw::Project>]
# rubocop: disable CodeReuse/ActiveRecord
def
fdw_find_projects_updated_recently
...
...
@@ -121,21 +102,6 @@ module Geo
end
# rubocop: enable CodeReuse/ActiveRecord
#
# Legacy accessors (non FDW)
#
# @return [ActiveRecord::Relation<Project>] list of unsynced projects
# rubocop: disable CodeReuse/ActiveRecord
def
legacy_find_unsynced_projects
legacy_left_outer_join_registry_ids
(
current_node
.
projects
,
Geo
::
ProjectRegistry
.
pluck
(
:project_id
),
Project
)
end
# rubocop: enable CodeReuse/ActiveRecord
# @return [ActiveRecord::Relation<Project>] list of projects updated recently
# rubocop: disable CodeReuse/ActiveRecord
def
legacy_find_projects_updated_recently
...
...
@@ -171,6 +137,14 @@ module Geo
fdw_disabled?
||
selective_sync?
&&
!
Gitlab
::
Geo
::
Fdw
.
enabled_for_selective_sync?
end
def
finder_klass_for_unsynced_projects
if
use_legacy_queries_for_selective_sync?
Geo
::
LegacyProjectUnsyncedFinder
else
Geo
::
ProjectUnsyncedFinder
end
end
def
finder_klass_for_synced_registries
if
use_legacy_queries_for_selective_sync?
Geo
::
LegacyProjectRegistrySyncedFinder
...
...
ee/app/workers/geo/repository_shard_sync_worker.rb
View file @
2a9ab657
...
...
@@ -77,19 +77,19 @@ module Geo
# rubocop: disable CodeReuse/ActiveRecord
def
find_project_ids_not_synced
(
batch_size
:)
shard_restriction
(
finder
.
find_unsynced_projects
(
batch_size:
batch_size
)
)
.
where
.
not
(
id:
scheduled_project_ids
)
finder
.
find_unsynced_projects
(
shard_name:
shard_name
,
batch_size:
batch_size
)
.
id_not_in
(
scheduled_project_ids
)
.
reorder
(
last_repository_updated_at: :desc
)
.
pluck
(
:id
)
.
pluck
_primary_key
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
find_project_ids_updated_recently
(
batch_size
:)
shard_restriction
(
finder
.
find_projects_updated_recently
(
batch_size:
batch_size
))
.
where
.
not
(
id:
scheduled_project_ids
)
.
id_not_in
(
scheduled_project_ids
)
.
order
(
'project_registry.last_repository_synced_at ASC NULLS FIRST, projects.last_repository_updated_at ASC'
)
.
pluck
(
:id
)
.
pluck
_primary_key
end
# rubocop: enable CodeReuse/ActiveRecord
...
...
ee/spec/finders/geo/project_registry_finder_spec.rb
View file @
2a9ab657
...
...
@@ -380,43 +380,6 @@ describe Geo::ProjectRegistryFinder, :geo do
end
shared_examples
'finds all the things'
do
|
method_prefix
|
describe
'#find_unsynced_projects'
do
it
'delegates to the correct method'
do
expect
(
subject
).
to
receive
(
"
#{
method_prefix
}
_find_unsynced_projects"
.
to_sym
).
and_call_original
subject
.
find_unsynced_projects
(
batch_size:
10
)
end
it
'returns projects without an entry on the tracking database'
do
project_not_synced
=
create
(
:project
)
create
(
:geo_project_registry
,
:synced
,
:repository_dirty
,
project:
project_1_in_synced_group
)
projects
=
subject
.
find_unsynced_projects
(
batch_size:
10
)
expect
(
projects
).
to
match_ids
(
project_not_synced
)
end
context
'with selective sync'
do
before
do
secondary
.
update!
(
selective_sync_type:
'namespaces'
,
namespaces:
[
synced_group
])
end
it
'delegates to #legacy_find_unsynced_projects'
do
expect
(
subject
).
to
receive
(
:legacy_find_unsynced_projects
).
and_call_original
subject
.
find_unsynced_projects
(
batch_size:
10
)
end
it
'returns untracked projects in the synced group'
do
create
(
:geo_project_registry
,
:sync_failed
,
project:
project_1_in_synced_group
)
projects
=
subject
.
find_unsynced_projects
(
batch_size:
10
)
expect
(
projects
).
to
match_ids
(
project_2_in_synced_group
)
end
end
end
describe
'#find_projects_updated_recently'
do
it
'delegates to the correct method'
do
expect
(
subject
).
to
receive
(
"
#{
method_prefix
}
_find_projects_updated_recently"
.
to_sym
).
and_call_original
...
...
@@ -522,6 +485,13 @@ describe Geo::ProjectRegistryFinder, :geo do
include_examples
'finds all the things'
,
'legacy'
end
describe
'#find_unsynced_projects'
,
:delete
do
include_examples
'delegates to the proper finder'
,
Geo
::
LegacyProjectUnsyncedFinder
,
Geo
::
ProjectUnsyncedFinder
,
:find_unsynced_projects
,
[
shard_name:
'default'
,
batch_size:
100
]
end
describe
'#find_failed_project_registries'
,
:delete
do
include_examples
'delegates to the proper finder'
,
Geo
::
LegacyProjectRegistrySyncFailedFinder
,
...
...
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