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
07e336e4
Commit
07e336e4
authored
Jul 02, 2018
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split Geo::RepositoryVerificationFinder#find_failed_projects per type
parent
160344a4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
34 deletions
+68
-34
ee/app/finders/geo/repository_verification_finder.rb
ee/app/finders/geo/repository_verification_finder.rb
+16
-15
ee/app/workers/geo/repository_verification/primary/shard_worker.rb
...rkers/geo/repository_verification/primary/shard_worker.rb
+12
-1
ee/spec/finders/geo/repository_verification_finder_spec.rb
ee/spec/finders/geo/repository_verification_finder_spec.rb
+40
-18
No files found.
ee/app/finders/geo/repository_verification_finder.rb
View file @
07e336e4
...
...
@@ -4,13 +4,22 @@ module Geo
@shard_name
=
shard_name
end
def
find_failed_
project
s
(
batch_size
:)
query
=
build_query_to_find_failed_projects
(
batch_size:
batch_size
)
cte
=
Gitlab
::
SQL
::
CTE
.
new
(
:failed_
project
s
,
query
)
def
find_failed_
repositorie
s
(
batch_size
:)
query
=
build_query_to_find_failed_projects
(
type: :repository
,
batch_size:
batch_size
)
cte
=
Gitlab
::
SQL
::
CTE
.
new
(
:failed_
repositorie
s
,
query
)
Project
.
with
(
cte
.
to_arel
)
.
from
(
cte
.
alias_to
(
projects_table
))
.
order
(
last_repository_updated_at_asc
)
.
order
(
"projects.repository_retry_at ASC"
)
end
def
find_failed_wikis
(
batch_size
:)
query
=
build_query_to_find_failed_projects
(
type: :wiki
,
batch_size:
batch_size
)
cte
=
Gitlab
::
SQL
::
CTE
.
new
(
:failed_wikis
,
query
)
Project
.
with
(
cte
.
to_arel
)
.
from
(
cte
.
alias_to
(
projects_table
))
.
order
(
"projects.wiki_retry_at ASC"
)
end
def
find_outdated_projects
(
batch_size
:)
...
...
@@ -54,12 +63,12 @@ module Geo
attr_reader
:shard_name
def
build_query_to_find_failed_projects
(
batch_size
:)
def
build_query_to_find_failed_projects
(
type
:,
batch_size
:)
query
=
projects_table
.
join
(
repository_state_table
).
on
(
project_id_matcher
)
.
project
(
projects_table
[
:id
],
projects_table
[
:last_repository_updated_at
])
.
where
(
repository_
failed
.
or
(
wiki_failed
))
.
project
(
projects_table
[
:id
],
repository_state_table
[
"
#{
type
}
_retry_at"
])
.
where
(
repository_
state_table
[
"last_
#{
type
}
_verification_failure"
].
not_eq
(
nil
))
.
take
(
batch_size
)
query
=
apply_shard_restriction
(
query
)
if
shard_name
.
present?
...
...
@@ -97,19 +106,11 @@ module Geo
.
join_sources
end
def
repository_failed
repository_state_table
[
:last_repository_verification_failure
].
not_eq
(
nil
)
end
def
repository_outdated
repository_state_table
[
:repository_verification_checksum
].
eq
(
nil
)
.
and
(
repository_state_table
[
:last_repository_verification_failure
].
eq
(
nil
))
end
def
wiki_failed
repository_state_table
[
:last_wiki_verification_failure
].
not_eq
(
nil
)
end
def
wiki_outdated
repository_state_table
[
:wiki_verification_checksum
].
eq
(
nil
)
.
and
(
repository_state_table
[
:last_wiki_verification_failure
].
eq
(
nil
))
...
...
ee/app/workers/geo/repository_verification/primary/shard_worker.rb
View file @
07e336e4
...
...
@@ -60,7 +60,18 @@ module Geo
end
def
find_failed_project_ids
(
batch_size
:)
finder
.
find_failed_projects
(
batch_size:
batch_size
).
pluck
(
:id
)
repositories_ids
=
find_failed_repositories_ids
(
batch_size:
batch_size
)
wiki_ids
=
find_failed_wiki_ids
(
batch_size:
batch_size
)
take_batch
(
repositories_ids
,
wiki_ids
,
batch_size:
batch_size
)
end
def
find_failed_repositories_ids
(
batch_size
:)
finder
.
find_failed_repositories
(
batch_size:
batch_size
).
pluck
(
:id
)
end
def
find_failed_wiki_ids
(
batch_size
:)
finder
.
find_failed_wikis
(
batch_size:
batch_size
).
pluck
(
:id
)
end
end
end
...
...
ee/spec/finders/geo/repository_verification_finder_spec.rb
View file @
07e336e4
...
...
@@ -3,53 +3,75 @@ require 'spec_helper'
describe
Geo
::
RepositoryVerificationFinder
,
:postgresql
do
set
(
:project
)
{
create
(
:project
)
}
describe
'#find_failed_
project
s'
do
describe
'#find_failed_
repositorie
s'
do
it
'returns projects where repository verification failed'
do
create
(
:repository_state
,
:repository_failed
,
:wiki_verified
,
project:
project
)
expect
(
subject
.
find_failed_
project
s
(
batch_size:
10
))
expect
(
subject
.
find_failed_
repositorie
s
(
batch_size:
10
))
.
to
match_array
(
project
)
end
it
'does not return projects where repository verification is outdated'
do
create
(
:repository_state
,
:repository_outdated
,
project:
project
)
expect
(
subject
.
find_failed_
project
s
(
batch_size:
10
)).
to
be_empty
expect
(
subject
.
find_failed_
repositorie
s
(
batch_size:
10
)).
to
be_empty
end
it
'does not return projects where repository verification is pending'
do
create
(
:repository_state
,
:wiki_verified
,
project:
project
)
expect
(
subject
.
find_failed_
project
s
(
batch_size:
10
)).
to
be_empty
expect
(
subject
.
find_failed_
repositorie
s
(
batch_size:
10
)).
to
be_empty
end
it
'returns projects ordered by next retry time'
do
next_project
=
create
(
:project
)
create
(
:repository_state
,
:repository_failed
,
repository_retry_at:
1
.
hour
.
from_now
,
project:
project
)
create
(
:repository_state
,
:repository_failed
,
repository_retry_at:
30
.
minutes
.
from_now
,
project:
next_project
)
expect
(
subject
.
find_failed_repositories
(
batch_size:
10
)).
to
eq
[
next_project
,
project
]
end
context
'with shard restriction'
do
subject
{
described_class
.
new
(
shard_name:
project
.
repository_storage
)
}
it
'does not return projects on other shards'
do
project_other_shard
=
create
(
:project
)
project_other_shard
.
update_column
(
:repository_storage
,
'other'
)
create
(
:repository_state
,
:repository_failed
,
project:
project
)
create
(
:repository_state
,
:repository_failed
,
project:
project_other_shard
)
expect
(
subject
.
find_failed_repositories
(
batch_size:
10
))
.
to
match_array
(
project
)
end
end
end
describe
'#find_failed_wikis'
do
it
'returns projects where wiki verification failed'
do
create
(
:repository_state
,
:repository_verified
,
:wiki_failed
,
project:
project
)
expect
(
subject
.
find_failed_
project
s
(
batch_size:
10
))
expect
(
subject
.
find_failed_
wiki
s
(
batch_size:
10
))
.
to
match_array
(
project
)
end
it
'does no
n
return projects where wiki verification is outdated'
do
it
'does no
t
return projects where wiki verification is outdated'
do
create
(
:repository_state
,
:wiki_outdated
,
project:
project
)
expect
(
subject
.
find_failed_
project
s
(
batch_size:
10
)).
to
be_empty
expect
(
subject
.
find_failed_
wiki
s
(
batch_size:
10
)).
to
be_empty
end
it
'does not return projects where wiki verification is pending'
do
create
(
:repository_state
,
:repository_verified
,
project:
project
)
expect
(
subject
.
find_failed_
project
s
(
batch_size:
10
)).
to
be_empty
expect
(
subject
.
find_failed_
wiki
s
(
batch_size:
10
)).
to
be_empty
end
it
'returns less active projects first'
do
less_active_project
=
create
(
:project
)
create
(
:repository_state
,
:repository_failed
,
project:
project
)
create
(
:repository_state
,
:repository_failed
,
project:
less_active_project
)
project
.
update_column
(
:last_repository_updated_at
,
30
.
minutes
.
ago
)
less_active_project
.
update_column
(
:last_repository_updated_at
,
2
.
days
.
ago
)
it
'returns projects ordered by next retry time'
do
next_project
=
create
(
:project
)
create
(
:repository_state
,
:wiki_failed
,
wiki_retry_at:
1
.
hour
.
from_now
,
project:
project
)
create
(
:repository_state
,
:wiki_failed
,
wiki_retry_at:
30
.
minutes
.
from_now
,
project:
next_project
)
expect
(
subject
.
find_failed_
projects
(
batch_size:
10
)).
to
eq
[
less_active
_project
,
project
]
expect
(
subject
.
find_failed_
wikis
(
batch_size:
10
)).
to
eq
[
next
_project
,
project
]
end
context
'with shard restriction'
do
...
...
@@ -58,10 +80,10 @@ describe Geo::RepositoryVerificationFinder, :postgresql do
it
'does not return projects on other shards'
do
project_other_shard
=
create
(
:project
)
project_other_shard
.
update_column
(
:repository_storage
,
'other'
)
create
(
:repository_state
,
:
repository
_failed
,
project:
project
)
create
(
:repository_state
,
:
repository
_failed
,
project:
project_other_shard
)
create
(
:repository_state
,
:
wiki
_failed
,
project:
project
)
create
(
:repository_state
,
:
wiki
_failed
,
project:
project_other_shard
)
expect
(
subject
.
find_failed_
project
s
(
batch_size:
10
))
expect
(
subject
.
find_failed_
wiki
s
(
batch_size:
10
))
.
to
match_array
(
project
)
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