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
c6ed91c4
Commit
c6ed91c4
authored
Apr 02, 2019
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add finder to find unsynced projects using FDW queries
parent
0cc97048
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
123 additions
and
0 deletions
+123
-0
ee/app/finders/geo/project_unsynced_finder.rb
ee/app/finders/geo/project_unsynced_finder.rb
+41
-0
ee/app/models/geo/fdw/project.rb
ee/app/models/geo/fdw/project.rb
+16
-0
ee/spec/finders/geo/project_unsynced_finder_spec.rb
ee/spec/finders/geo/project_unsynced_finder_spec.rb
+66
-0
No files found.
ee/app/finders/geo/project_unsynced_finder.rb
0 → 100644
View file @
c6ed91c4
# frozen_string_literal: true
# Finder for retrieving unsynced projects that belong to a specific
# shard using FDW queries.
#
# Basic usage:
#
# Geo::ProjectUnsyncedFinder
# .new(current_node: Gitlab::Geo.current_node, shard_name: 'default', batch_size: 1000)
# .execute.
module
Geo
class
ProjectUnsyncedFinder
def
initialize
(
current_node
:,
shard_name
:,
batch_size
:)
@current_node
=
Geo
::
Fdw
::
GeoNode
.
find
(
current_node
.
id
)
@shard_name
=
shard_name
@batch_size
=
batch_size
end
# rubocop:disable CodeReuse/ActiveRecord
def
execute
return
Geo
::
Fdw
::
Project
.
none
unless
valid_shard?
current_node
.
projects
.
missing_project_registry
.
within_shards
(
shard_name
)
.
limit
(
batch_size
)
end
# rubocop:enable CodeReuse/ActiveRecord
private
attr_reader
:current_node
,
:shard_name
,
:batch_size
def
valid_shard?
return
true
unless
current_node
.
selective_sync_by_shards?
current_node
.
selective_sync_shards
.
include?
(
shard_name
)
end
end
end
ee/app/models/geo/fdw/project.rb
View file @
c6ed91c4
...
...
@@ -8,6 +8,11 @@ module Geo
self
.
table_name
=
Gitlab
::
Geo
::
Fdw
.
foreign_table_name
(
'projects'
)
class
<<
self
def
missing_project_registry
left_outer_join_project_registry
.
where
(
Geo
::
ProjectRegistry
.
arel_table
[
:project_id
].
eq
(
nil
))
end
# Searches for a list of projects based on the query given in `query`.
#
# On PostgreSQL this method uses "ILIKE" to perform a case-insensitive
...
...
@@ -25,6 +30,17 @@ module Geo
def
within_shards
(
shard_names
)
where
(
repository_storage:
Array
(
shard_names
))
end
private
def
left_outer_join_project_registry
join_statement
=
arel_table
.
join
(
Geo
::
ProjectRegistry
.
arel_table
,
Arel
::
Nodes
::
OuterJoin
)
.
on
(
arel_table
[
:id
].
eq
(
Geo
::
ProjectRegistry
.
arel_table
[
:project_id
]))
joins
(
join_statement
.
join_sources
)
end
end
end
end
...
...
ee/spec/finders/geo/project_unsynced_finder_spec.rb
0 → 100644
View file @
c6ed91c4
# frozen_string_literal: true
require
'spec_helper'
describe
Geo
::
ProjectUnsyncedFinder
,
:geo
do
# Disable transactions via :delete method because a foreign table
# can't see changes inside a transaction of a different connection.
describe
'#execute'
,
:delete
do
let
(
:node
)
{
create
(
:geo_node
)
}
let
(
:group_1
)
{
create
(
:group
)
}
let
(
:group_2
)
{
create
(
:group
)
}
let
(
:nested_group_1
)
{
create
(
:group
,
parent:
group_1
)
}
let!
(
:project_1
)
{
create
(
:project
,
group:
group_1
)
}
let!
(
:project_2
)
{
create
(
:project
,
group:
nested_group_1
)
}
let!
(
:project_3
)
{
create
(
:project
,
group:
group_2
)
}
let!
(
:project_4
)
{
create
(
:project
,
group:
group_1
)
}
before
do
skip
(
'FDW is not configured'
)
unless
Gitlab
::
Geo
::
Fdw
.
enabled?
project_4
.
update_column
(
:repository_storage
,
'foo'
)
end
subject
{
described_class
.
new
(
current_node:
node
,
shard_name:
'default'
,
batch_size:
100
)
}
context
'without selective sync'
do
it
'returns projects without an entry on the tracking database'
do
create
(
:geo_project_registry
,
:synced
,
project:
project_2
)
expect
(
subject
.
execute
).
to
match_ids
(
project_1
,
project_3
)
end
end
context
'with selective sync by namespace'
do
it
'returns projects that belong to the namespaces without an entry on the tracking database'
do
create
(
:geo_project_registry
,
:synced
,
project:
project_4
)
node
.
update!
(
selective_sync_type:
'namespaces'
,
namespaces:
[
group_1
,
nested_group_1
])
expect
(
subject
.
execute
).
to
match_ids
(
project_1
,
project_2
)
end
end
context
'with selective sync by shard'
do
before
do
node
.
update!
(
selective_sync_type:
'shards'
,
selective_sync_shards:
[
'foo'
])
end
it
'does not return registries when selected shards to sync does not include the shard_name'
do
subject
=
described_class
.
new
(
current_node:
node
,
shard_name:
'default'
,
batch_size:
100
)
expect
(
subject
.
execute
).
to
be_empty
end
it
'returns projects that belong to the shards without an entry on the tracking database'
do
project_5
=
create
(
:project
,
group:
group_1
)
project_5
.
update_column
(
:repository_storage
,
'foo'
)
create
(
:geo_project_registry
,
:synced
,
project:
project_4
)
subject
=
described_class
.
new
(
current_node:
node
,
shard_name:
'foo'
,
batch_size:
100
)
expect
(
subject
.
execute
).
to
match_ids
(
project_5
)
end
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