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
b07e5036
Commit
b07e5036
authored
Apr 16, 2019
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement selective sync support for the FDW queries
parent
b560bf15
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
32 deletions
+28
-32
ee/app/finders/geo/attachment_registry_finder.rb
ee/app/finders/geo/attachment_registry_finder.rb
+28
-32
No files found.
ee/app/finders/geo/attachment_registry_finder.rb
View file @
b07e5036
...
...
@@ -10,7 +10,7 @@ module Geo
if
use_legacy_queries_for_selective_sync?
legacy_finder
.
syncable
elsif
selective_sync?
legacy_finder
.
syncable
fdw_all
.
geo_
syncable
else
Upload
.
geo_syncable
end
...
...
@@ -106,13 +106,27 @@ module Geo
end
# rubocop:enable CodeReuse/Finder
def
fdw_geo_node
@fdw_geo_node
||=
Geo
::
Fdw
::
GeoNode
.
find
(
current_node
.
id
)
end
# rubocop: disable CodeReuse/ActiveRecord
def
fdw_all
if
selective_sync?
Geo
::
Fdw
::
Upload
.
where
(
fdw_group_uploads
.
or
(
fdw_project_uploads
).
or
(
fdw_other_uploads
))
else
Geo
::
Fdw
::
Upload
.
all
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
group_uploads
def
fdw_
group_uploads
namespace_ids
=
if
current_node
.
selective_sync_by_namespaces?
Gitlab
::
ObjectHierarchy
.
new
(
current
_node
.
namespaces
).
base_and_descendants
.
select
(
:id
)
Gitlab
::
ObjectHierarchy
.
new
(
fdw_geo
_node
.
namespaces
).
base_and_descendants
.
select
(
:id
)
elsif
current_node
.
selective_sync_by_shards?
leaf_groups
=
Namespace
.
where
(
id:
current
_node
.
projects
.
select
(
:namespace_id
))
leaf_groups
=
Geo
::
Fdw
::
Namespace
.
where
(
id:
fdw_geo
_node
.
projects
.
select
(
:namespace_id
))
Gitlab
::
ObjectHierarchy
.
new
(
leaf_groups
).
base_and_ancestors
.
select
(
:id
)
else
Namespace
.
none
...
...
@@ -121,29 +135,29 @@ module Geo
# This query was intentionally converted to a raw one to get it work in Rails 5.0.
# In Rails 5.0 and 5.1 there's a bug: https://github.com/rails/arel/issues/531
# Please convert it back when on rails 5.2 as it works again as expected since 5.2.
namespace_ids_in_sql
=
Arel
::
Nodes
::
SqlLiteral
.
new
(
"
uploads.model_id
IN (
#{
namespace_ids
.
to_sql
}
)"
)
namespace_ids_in_sql
=
Arel
::
Nodes
::
SqlLiteral
.
new
(
"
#{
fdw_upload_table
.
name
}
.
#{
fdw_upload_table
[
:model_id
].
name
}
IN (
#{
namespace_ids
.
to_sql
}
)"
)
upload_table
[
:model_type
].
eq
(
'Namespace'
).
and
(
namespace_ids_in_sql
)
fdw_
upload_table
[
:model_type
].
eq
(
'Namespace'
).
and
(
namespace_ids_in_sql
)
end
# rubocop: enable CodeReuse/ActiveRecord
def
project_uploads
project_ids
=
current
_node
.
projects
.
select
(
:id
)
def
fdw_
project_uploads
project_ids
=
fdw_geo
_node
.
projects
.
select
(
:id
)
# This query was intentionally converted to a raw one to get it work in Rails 5.0.
# In Rails 5.0 and 5.1 there's a bug: https://github.com/rails/arel/issues/531
# Please convert it back when on rails 5.2 as it works again as expected since 5.2.
project_ids_in_sql
=
Arel
::
Nodes
::
SqlLiteral
.
new
(
"
uploads.model_id
IN (
#{
project_ids
.
to_sql
}
)"
)
project_ids_in_sql
=
Arel
::
Nodes
::
SqlLiteral
.
new
(
"
#{
fdw_upload_table
.
name
}
.
#{
fdw_upload_table
[
:model_id
].
name
}
IN (
#{
project_ids
.
to_sql
}
)"
)
upload_table
[
:model_type
].
eq
(
'Project'
).
and
(
project_ids_in_sql
)
fdw_
upload_table
[
:model_type
].
eq
(
'Project'
).
and
(
project_ids_in_sql
)
end
def
other_uploads
upload_table
[
:model_type
].
not_in
(
%w[Namespace Project]
)
def
fdw_
other_uploads
fdw_
upload_table
[
:model_type
].
not_in
(
%w[Namespace Project]
)
end
def
upload_table
Upload
.
arel_table
def
fdw_
upload_table
Geo
::
Fdw
::
Upload
.
arel_table
end
def
find_synced
...
...
@@ -174,10 +188,6 @@ module Geo
find_synced_registries
.
missing_on_primary
end
#
# FDW accessors
#
def
fdw_find_synced
fdw_find_syncable
.
merge
(
Geo
::
FileRegistry
.
synced
)
end
...
...
@@ -211,16 +221,6 @@ module Geo
fdw_find_synced
.
merge
(
Geo
::
FileRegistry
.
missing_on_primary
)
end
# rubocop: disable CodeReuse/ActiveRecord
def
fdw_all
if
selective_sync?
Geo
::
Fdw
::
Upload
.
where
(
group_uploads
.
or
(
project_uploads
).
or
(
other_uploads
))
else
Geo
::
Fdw
::
Upload
.
all
end
end
# rubocop: enable CodeReuse/ActiveRecord
def
fdw_table
Geo
::
Fdw
::
Upload
.
table_name
end
...
...
@@ -234,10 +234,6 @@ module Geo
end
# rubocop: enable CodeReuse/ActiveRecord
#
# Legacy accessors (non FDW)
#
# rubocop: disable CodeReuse/ActiveRecord
def
legacy_find_synced
legacy_inner_join_registry_ids
(
...
...
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