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
4fd415ad
Commit
4fd415ad
authored
Jul 10, 2020
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add methods to retrieve design repositories to sync
parent
5799e2d9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
13 deletions
+92
-13
ee/app/finders/geo/design_registry_finder.rb
ee/app/finders/geo/design_registry_finder.rb
+35
-0
ee/app/models/geo/design_registry.rb
ee/app/models/geo/design_registry.rb
+1
-0
ee/spec/finders/geo/design_registry_finder_spec.rb
ee/spec/finders/geo/design_registry_finder_spec.rb
+56
-13
No files found.
ee/app/finders/geo/design_registry_finder.rb
View file @
4fd415ad
...
...
@@ -20,6 +20,41 @@ module Geo
registries
.
count
end
# Returns Geo::DesignRegistry records that have never been synced.
#
# Does not care about selective sync, because it considers the Registry
# table to be the single source of truth. The contract is that other
# processes need to ensure that the table only contains records that should
# be synced.
#
# Any registries that have ever been synced that currently need to be
# resynced will be handled by other find methods (like
# #find_retryable_dirty_registries)
#
# You can pass a list with `except_ids:` so you can exclude items you
# already scheduled but haven't finished and aren't persisted to the database yet
#
# @param [Integer] batch_size used to limit the results returned
# @param [Array<Integer>] except_ids ids that will be ignored from the query
# rubocop:disable CodeReuse/ActiveRecord
def
find_never_synced_registries
(
batch_size
:,
except_ids:
[])
Geo
::
DesignRegistry
.
never_synced
.
model_id_not_in
(
except_ids
)
.
limit
(
batch_size
)
end
# rubocop:enable CodeReuse/ActiveRecord
# rubocop:disable CodeReuse/ActiveRecord
def
find_retryable_dirty_registries
(
batch_size
:,
except_ids:
[])
Geo
::
DesignRegistry
.
updated_recently
.
model_id_not_in
(
except_ids
)
.
order
(
Gitlab
::
Database
.
nulls_first_order
(
:last_synced_at
))
.
limit
(
batch_size
)
end
# rubocop:enable CodeReuse/ActiveRecord
private
def
registries
...
...
ee/app/models/geo/design_registry.rb
View file @
4fd415ad
...
...
@@ -10,6 +10,7 @@ class Geo::DesignRegistry < Geo::BaseRegistry
belongs_to
:project
scope
:never_synced
,
->
{
with_state
(
:pending
).
where
(
last_synced_at:
nil
)
}
scope
:pending
,
->
{
with_state
(
:pending
)
}
scope
:failed
,
->
{
with_state
(
:failed
)
}
scope
:synced
,
->
{
with_state
(
:synced
)
}
...
...
ee/spec/finders/geo/design_registry_finder_spec.rb
View file @
4fd415ad
...
...
@@ -2,9 +2,17 @@
require
'spec_helper'
RSpec
.
describe
Geo
::
DesignRegistryFinder
,
:geo
,
:geo_fdw
do
include
::
EE
::
GeoHelpers
let!
(
:secondary
)
{
create
(
:geo_node
)
}
let!
(
:project_1
)
{
create
(
:project
)
}
let!
(
:project_2
)
{
create
(
:project
)
}
let!
(
:project_3
)
{
create
(
:project
)
}
let!
(
:project_4
)
{
create
(
:project
)
}
let!
(
:project_5
)
{
create
(
:project
)
}
let!
(
:project_6
)
{
create
(
:project
)
}
subject
{
described_class
.
new
(
current_node_id:
secondary
.
id
)
}
context
'count all the things'
do
let!
(
:failed_registry
)
{
create
(
:geo_design_registry
,
:sync_failed
)
}
let!
(
:synced_registry
)
{
create
(
:geo_design_registry
,
:synced
)
}
...
...
@@ -13,13 +21,6 @@ RSpec.describe Geo::DesignRegistryFinder, :geo, :geo_fdw do
let
(
:synced_project
)
{
create
(
:project
,
group:
synced_group
)
}
let
(
:unsynced_project
)
{
create
(
:project
,
:broken_storage
,
group:
unsynced_group
)
}
subject
{
described_class
.
new
(
current_node_id:
secondary
.
id
)
}
before
do
stub_current_geo_node
(
secondary
)
end
context
'count all the things'
do
describe
'#count_syncable'
do
it
'returns number of design repositories'
do
# One more design for the same project to assert absence of duplicates
...
...
@@ -103,4 +104,46 @@ RSpec.describe Geo::DesignRegistryFinder, :geo, :geo_fdw do
end
end
end
describe
'#find_never_synced_registries'
do
let!
(
:registry_project_1
)
{
create
(
:geo_design_registry
,
:synced
,
project_id:
project_1
.
id
)
}
let!
(
:registry_project_2
)
{
create
(
:geo_design_registry
,
:sync_failed
,
project_id:
project_2
.
id
)
}
let!
(
:registry_project_3
)
{
create
(
:geo_design_registry
,
project_id:
project_3
.
id
,
last_synced_at:
nil
)
}
let!
(
:registry_project_4
)
{
create
(
:geo_design_registry
,
project_id:
project_4
.
id
,
last_synced_at:
3
.
days
.
ago
,
retry_at:
2
.
days
.
ago
)
}
let!
(
:registry_project_5
)
{
create
(
:geo_design_registry
,
project_id:
project_5
.
id
,
last_synced_at:
6
.
days
.
ago
)
}
let!
(
:registry_project_6
)
{
create
(
:geo_design_registry
,
project_id:
project_6
.
id
,
last_synced_at:
nil
)
}
it
'returns registries for projects that have never been synced'
do
registries
=
subject
.
find_never_synced_registries
(
batch_size:
10
)
expect
(
registries
).
to
match_ids
(
registry_project_3
,
registry_project_6
)
end
it
'excludes except_ids'
do
registries
=
subject
.
find_never_synced_registries
(
batch_size:
10
,
except_ids:
[
project_3
.
id
])
expect
(
registries
).
to
match_ids
(
registry_project_6
)
end
end
describe
'#find_retryable_dirty_registries'
do
let!
(
:registry_project_1
)
{
create
(
:geo_design_registry
,
:synced
,
project_id:
project_1
.
id
)
}
let!
(
:registry_project_2
)
{
create
(
:geo_design_registry
,
:sync_failed
,
project_id:
project_2
.
id
)
}
let!
(
:registry_project_3
)
{
create
(
:geo_design_registry
,
project_id:
project_3
.
id
,
last_synced_at:
nil
)
}
let!
(
:registry_project_4
)
{
create
(
:geo_design_registry
,
project_id:
project_4
.
id
,
last_synced_at:
3
.
days
.
ago
,
retry_at:
2
.
days
.
ago
)
}
let!
(
:registry_project_5
)
{
create
(
:geo_design_registry
,
project_id:
project_5
.
id
,
last_synced_at:
6
.
days
.
ago
)
}
let!
(
:registry_project_6
)
{
create
(
:geo_design_registry
,
project_id:
project_6
.
id
,
last_synced_at:
nil
)
}
it
'returns registries for projects that have been recently updated'
do
registries
=
subject
.
find_retryable_dirty_registries
(
batch_size:
10
)
expect
(
registries
).
to
match_ids
(
registry_project_2
,
registry_project_3
,
registry_project_4
,
registry_project_5
,
registry_project_6
)
end
it
'excludes except_ids'
do
registries
=
subject
.
find_retryable_dirty_registries
(
batch_size:
10
,
except_ids:
[
project_4
.
id
,
project_5
.
id
,
project_6
.
id
])
expect
(
registries
).
to
match_ids
(
registry_project_2
,
registry_project_3
)
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