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
1f2d7bd3
Commit
1f2d7bd3
authored
Nov 29, 2018
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename the finder methods to make clear its real intent
parent
5da58325
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
107 deletions
+65
-107
ee/app/finders/geo/repository_verification_finder.rb
ee/app/finders/geo/repository_verification_finder.rb
+15
-21
ee/app/workers/geo/repository_verification/primary/shard_worker.rb
...rkers/geo/repository_verification/primary/shard_worker.rb
+6
-6
ee/spec/finders/geo/repository_verification_finder_spec.rb
ee/spec/finders/geo/repository_verification_finder_spec.rb
+44
-80
No files found.
ee/app/finders/geo/repository_verification_finder.rb
View file @
1f2d7bd3
...
...
@@ -29,9 +29,9 @@ module Geo
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
find_
out
dated_projects
(
batch_size
:)
query
=
build_query_to_find_
out
dated_projects
(
batch_size:
batch_size
)
cte
=
Gitlab
::
SQL
::
CTE
.
new
(
:
out
dated_projects
,
query
)
def
find_
recently_up
dated_projects
(
batch_size
:)
query
=
build_query_to_find_
recently_up
dated_projects
(
batch_size:
batch_size
)
cte
=
Gitlab
::
SQL
::
CTE
.
new
(
:
recently_up
dated_projects
,
query
)
Project
.
with
(
cte
.
to_arel
)
.
from
(
cte
.
alias_to
(
projects_table
))
...
...
@@ -40,12 +40,12 @@ module Geo
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
find_
un
verified_projects
(
batch_size
:)
def
find_
never_
verified_projects
(
batch_size
:)
relation
=
Project
.
select
(
:id
)
.
with_route
.
joins
(
left_join_repository_state
)
.
where
(
repository_
never_verified
)
.
where
(
repository_
state_table
[
:project_id
].
eq
(
nil
)
)
.
limit
(
batch_size
)
apply_shard_restriction
(
relation
)
...
...
@@ -96,12 +96,20 @@ module Geo
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
build_query_to_find_outdated_projects
(
batch_size
:)
def
build_query_to_find_recently_updated_projects
(
batch_size
:)
repository_recently_updated
=
repository_state_table
[
:repository_verification_checksum
].
eq
(
nil
)
.
and
(
repository_state_table
[
:last_repository_verification_failure
].
eq
(
nil
))
wiki_recently_updated
=
repository_state_table
[
:wiki_verification_checksum
].
eq
(
nil
)
.
and
(
repository_state_table
[
:last_wiki_verification_failure
].
eq
(
nil
))
query
=
projects_table
.
join
(
repository_state_table
).
on
(
project_id_matcher
)
.
project
(
projects_table
[
:id
],
projects_table
[
:last_repository_updated_at
])
.
where
(
repository_
outdated
.
or
(
wiki_out
dated
))
.
where
(
repository_
recently_updated
.
or
(
wiki_recently_up
dated
))
.
take
(
batch_size
)
apply_shard_restriction
(
query
)
...
...
@@ -149,20 +157,6 @@ module Geo
.
join_sources
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_outdated
repository_state_table
[
:wiki_verification_checksum
].
eq
(
nil
)
.
and
(
repository_state_table
[
:last_wiki_verification_failure
].
eq
(
nil
))
end
def
repository_never_verified
repository_state_table
[
:project_id
].
eq
(
nil
)
end
def
last_repository_updated_at_asc
Gitlab
::
Database
.
nulls_last_order
(
'projects.last_repository_updated_at'
,
'ASC'
)
end
...
...
ee/app/workers/geo/repository_verification/primary/shard_worker.rb
View file @
1f2d7bd3
...
...
@@ -44,11 +44,11 @@ module Geo
end
def
load_pending_resources
resources
=
find_
un
verified_project_ids
(
batch_size:
db_retrieve_batch_size
)
resources
=
find_
never_
verified_project_ids
(
batch_size:
db_retrieve_batch_size
)
remaining_capacity
=
db_retrieve_batch_size
-
resources
.
size
return
resources
if
remaining_capacity
.
zero?
resources
+=
find_
out
dated_project_ids
(
batch_size:
remaining_capacity
)
resources
+=
find_
recently_up
dated_project_ids
(
batch_size:
remaining_capacity
)
remaining_capacity
=
db_retrieve_batch_size
-
resources
.
size
return
resources
if
remaining_capacity
.
zero?
...
...
@@ -56,14 +56,14 @@ module Geo
end
# rubocop: disable CodeReuse/ActiveRecord
def
find_
un
verified_project_ids
(
batch_size
:)
finder
.
find_
un
verified_projects
(
batch_size:
batch_size
).
pluck
(
:id
)
def
find_
never_
verified_project_ids
(
batch_size
:)
finder
.
find_
never_
verified_projects
(
batch_size:
batch_size
).
pluck
(
:id
)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
find_
out
dated_project_ids
(
batch_size
:)
finder
.
find_
out
dated_projects
(
batch_size:
batch_size
).
pluck
(
:id
)
def
find_
recently_up
dated_project_ids
(
batch_size
:)
finder
.
find_
recently_up
dated_projects
(
batch_size:
batch_size
).
pluck
(
:id
)
end
# rubocop: enable CodeReuse/ActiveRecord
...
...
ee/spec/finders/geo/repository_verification_finder_spec.rb
View file @
1f2d7bd3
...
...
@@ -17,7 +17,7 @@ describe Geo::RepositoryVerificationFinder, :postgresql do
expect
(
subject
.
find_failed_repositories
(
batch_size:
10
)).
to
be_empty
end
it
'does not return projects where repository
verification is out
dated'
do
it
'does not return projects where repository
was recently up
dated'
do
create
(
:repository_state
,
:repository_outdated
,
project:
project
)
expect
(
subject
.
find_failed_repositories
(
batch_size:
10
)).
to
be_empty
...
...
@@ -66,7 +66,7 @@ describe Geo::RepositoryVerificationFinder, :postgresql do
expect
(
subject
.
find_failed_wikis
(
batch_size:
10
)).
to
be_empty
end
it
'does not return projects where wiki
verification is out
dated'
do
it
'does not return projects where wiki
was recently up
dated'
do
create
(
:repository_state
,
:wiki_outdated
,
project:
project
)
expect
(
subject
.
find_failed_wikis
(
batch_size:
10
)).
to
be_empty
...
...
@@ -101,45 +101,45 @@ describe Geo::RepositoryVerificationFinder, :postgresql do
end
end
describe
'#find_
out
dated_projects'
do
it
'returns projects where repository
verification is out
dated'
do
describe
'#find_
recently_up
dated_projects'
do
it
'returns projects where repository
was recently up
dated'
do
create
(
:repository_state
,
:repository_outdated
,
project:
project
)
expect
(
subject
.
find_
out
dated_projects
(
batch_size:
10
))
expect
(
subject
.
find_
recently_up
dated_projects
(
batch_size:
10
))
.
to
match_array
(
project
)
end
it
'returns projects where repository verification is pending'
do
create
(
:repository_state
,
:wiki_verified
,
project:
project
)
expect
(
subject
.
find_
out
dated_projects
(
batch_size:
10
))
expect
(
subject
.
find_
recently_up
dated_projects
(
batch_size:
10
))
.
to
match_array
(
project
)
end
it
'does not return projects where repository verification failed'
do
create
(
:repository_state
,
:repository_failed
,
:wiki_verified
,
project:
project
)
expect
(
subject
.
find_
out
dated_projects
(
batch_size:
10
)).
to
be_empty
expect
(
subject
.
find_
recently_up
dated_projects
(
batch_size:
10
)).
to
be_empty
end
it
'returns projects where wiki
verification is out
dated'
do
it
'returns projects where wiki
was recently up
dated'
do
create
(
:repository_state
,
:wiki_outdated
,
project:
project
)
expect
(
subject
.
find_
out
dated_projects
(
batch_size:
10
))
expect
(
subject
.
find_
recently_up
dated_projects
(
batch_size:
10
))
.
to
match_array
(
project
)
end
it
'returns projects where wiki verification is pending'
do
create
(
:repository_state
,
:repository_verified
,
project:
project
)
expect
(
subject
.
find_
out
dated_projects
(
batch_size:
10
))
expect
(
subject
.
find_
recently_up
dated_projects
(
batch_size:
10
))
.
to
match_array
(
project
)
end
it
'does not return projects where wiki verification failed'
do
create
(
:repository_state
,
:repository_verified
,
:wiki_failed
,
project:
project
)
expect
(
subject
.
find_
out
dated_projects
(
batch_size:
10
)).
to
be_empty
expect
(
subject
.
find_
recently_up
dated_projects
(
batch_size:
10
)).
to
be_empty
end
it
'returns less active projects first'
do
...
...
@@ -149,7 +149,7 @@ describe Geo::RepositoryVerificationFinder, :postgresql do
project
.
update_column
(
:last_repository_updated_at
,
30
.
minutes
.
ago
)
less_active_project
.
update_column
(
:last_repository_updated_at
,
2
.
days
.
ago
)
expect
(
subject
.
find_
out
dated_projects
(
batch_size:
10
)).
to
eq
[
less_active_project
,
project
]
expect
(
subject
.
find_
recently_up
dated_projects
(
batch_size:
10
)).
to
eq
[
less_active_project
,
project
]
end
context
'with shard restriction'
do
...
...
@@ -161,18 +161,18 @@ describe Geo::RepositoryVerificationFinder, :postgresql do
create
(
:repository_state
,
:repository_outdated
,
project:
project
)
create
(
:repository_state
,
:repository_outdated
,
project:
project_other_shard
)
expect
(
subject
.
find_
out
dated_projects
(
batch_size:
10
))
expect
(
subject
.
find_
recently_up
dated_projects
(
batch_size:
10
))
.
to
match_array
(
project
)
end
end
end
describe
'#find_
un
verified_projects'
do
describe
'#find_
never_
verified_projects'
do
it
'returns projects that never have been verified'
do
create
(
:repository_state
,
:repository_outdated
)
create
(
:repository_state
,
:wiki_outdated
)
expect
(
subject
.
find_
un
verified_projects
(
batch_size:
10
))
expect
(
subject
.
find_
never_
verified_projects
(
batch_size:
10
))
.
to
match_array
(
project
)
end
...
...
@@ -183,44 +183,50 @@ describe Geo::RepositoryVerificationFinder, :postgresql do
project_other_shard
=
create
(
:project
)
project_other_shard
.
update_column
(
:repository_storage
,
'other'
)
expect
(
subject
.
find_
un
verified_projects
(
batch_size:
10
))
expect
(
subject
.
find_
never_
verified_projects
(
batch_size:
10
))
.
to
match_array
(
project
)
end
end
end
describe
'#find_reverifiable_repositories'
do
it
'returns projects where repository was verified before the minimum re-verification interval'
do
shared_examples
'find reverifiable projects'
do
|
type
|
let
(
:failed
)
{
"
#{
type
}
_failed"
.
to_sym
}
let
(
:verified
)
{
"
#{
type
}
_verified"
.
to_sym
}
let
(
:outdated
)
{
"
#{
type
}
_outdated"
.
to_sym
}
let
(
:last_verification_ran_at
)
{
"last_
#{
type
}
_verification_ran_at"
}
let
(
:finder_method
)
{
"find_reverifiable_
#{
type
.
to_s
.
pluralize
}
"
}
it
"returns projects where
#{
type
}
was verified before the minimum re-verification interval"
do
project_recently_verified
=
create
(
:project
)
create
(
:repository_state
,
:repository_verified
,
project:
project
,
last_repository_verification_ran_at:
2
.
days
.
ago
)
create
(
:repository_state
,
:repository_verified
,
project:
project_recently_verified
,
last_repository_verification_ran_at:
Time
.
now
)
create
(
:repository_state
,
verified
,
project:
project
,
last_verification_ran_at
=>
2
.
days
.
ago
)
create
(
:repository_state
,
verified
,
project:
project_recently_verified
,
last_verification_ran_at
=>
Time
.
now
)
expect
(
subject
.
find_reverifiable_repositories
(
interval:
1
.
day
.
ago
,
batch_size:
10
))
expect
(
subject
.
public_send
(
finder_method
,
interval:
1
.
day
.
ago
,
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
,
last_repository_verification_ran_at:
2
.
days
.
ago
)
it
"does not return projects where
#{
type
}
was recently updated"
do
create
(
:repository_state
,
outdated
,
project:
project
,
last_verification_ran_at
=>
2
.
days
.
ago
)
expect
(
subject
.
find_reverifiable_repositories
(
interval:
1
.
day
.
ago
,
batch_size:
10
))
expect
(
subject
.
public_send
(
finder_method
,
interval:
1
.
day
.
ago
,
batch_size:
10
))
.
to
be_empty
end
it
'does not return projects where repository verification failed'
do
create
(
:repository_state
,
:repository_failed
,
project:
project
,
last_repository_verification_ran_at:
2
.
days
.
ago
)
it
"does not return projects where
#{
type
}
verification failed"
do
create
(
:repository_state
,
failed
,
project:
project
,
last_verification_ran_at
=>
2
.
days
.
ago
)
expect
(
subject
.
find_reverifiable_repositories
(
interval:
1
.
day
.
ago
,
batch_size:
10
))
expect
(
subject
.
public_send
(
finder_method
,
interval:
1
.
day
.
ago
,
batch_size:
10
))
.
to
be_empty
end
it
'returns less active projects first'
do
less_active_project
=
create
(
:project
)
create
(
:repository_state
,
:repository_verified
,
project:
project
,
last_repository_verification_ran_at:
2
.
days
.
ago
)
create
(
:repository_state
,
:repository_verified
,
project:
less_active_project
,
last_repository_verification_ran_at:
2
.
days
.
ago
)
create
(
:repository_state
,
verified
,
project:
project
,
last_verification_ran_at
=>
2
.
days
.
ago
)
create
(
:repository_state
,
verified
,
project:
less_active_project
,
last_verification_ran_at
=>
2
.
days
.
ago
)
project
.
update_column
(
:last_repository_updated_at
,
30
.
minutes
.
ago
)
less_active_project
.
update_column
(
:last_repository_updated_at
,
2
.
days
.
ago
)
expect
(
subject
.
find_reverifiable_repositories
(
interval:
1
.
day
.
ago
,
batch_size:
10
))
expect
(
subject
.
public_send
(
finder_method
,
interval:
1
.
day
.
ago
,
batch_size:
10
))
.
to
eq
[
less_active_project
,
project
]
end
...
...
@@ -230,62 +236,20 @@ 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_verified
,
project:
project
,
last_repository_verification_ran_at:
2
.
days
.
ago
)
create
(
:repository_state
,
:repository_verified
,
project:
project_other_shard
,
last_repository_verification_ran_at:
2
.
days
.
ago
)
create
(
:repository_state
,
verified
,
project:
project
,
last_verification_ran_at
=>
2
.
days
.
ago
)
create
(
:repository_state
,
verified
,
project:
project_other_shard
,
last_verification_ran_at
=>
2
.
days
.
ago
)
expect
(
subject
.
find_reverifiable_repositories
(
interval:
1
.
day
.
ago
,
batch_size:
10
))
expect
(
subject
.
public_send
(
finder_method
,
interval:
1
.
day
.
ago
,
batch_size:
10
))
.
to
match_array
(
project
)
end
end
end
describe
'#find_reverifiable_wikis'
do
it
'returns projects where wiki was verified before the minimum re-verification interval'
do
project_recently_verified
=
create
(
:project
)
create
(
:repository_state
,
:wiki_verified
,
project:
project
,
last_wiki_verification_ran_at:
2
.
days
.
ago
)
create
(
:repository_state
,
:wiki_verified
,
project:
project_recently_verified
,
last_wiki_verification_ran_at:
Time
.
now
)
expect
(
subject
.
find_reverifiable_wikis
(
interval:
1
.
day
.
ago
,
batch_size:
10
))
.
to
match_array
(
project
)
end
it
'does not return projects where wiki verification is outdated'
do
create
(
:repository_state
,
:wiki_outdated
,
project:
project
,
last_wiki_verification_ran_at:
2
.
days
.
ago
)
expect
(
subject
.
find_reverifiable_wikis
(
interval:
1
.
day
.
ago
,
batch_size:
10
))
.
to
be_empty
end
it
'does not return projects where wiki verification failed'
do
create
(
:repository_state
,
:wiki_failed
,
project:
project
,
last_wiki_verification_ran_at:
2
.
days
.
ago
)
expect
(
subject
.
find_reverifiable_wikis
(
interval:
1
.
day
.
ago
,
batch_size:
10
))
.
to
be_empty
end
it
'returns less active projects first'
do
less_active_project
=
create
(
:project
)
create
(
:repository_state
,
:wiki_verified
,
project:
project
,
last_wiki_verification_ran_at:
2
.
days
.
ago
)
create
(
:repository_state
,
:wiki_verified
,
project:
less_active_project
,
last_wiki_verification_ran_at:
2
.
days
.
ago
)
project
.
update_column
(
:last_repository_updated_at
,
30
.
minutes
.
ago
)
less_active_project
.
update_column
(
:last_repository_updated_at
,
2
.
days
.
ago
)
expect
(
subject
.
find_reverifiable_wikis
(
interval:
1
.
day
.
ago
,
batch_size:
10
))
.
to
eq
[
less_active_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
,
:wiki_verified
,
project:
project
,
last_wiki_verification_ran_at:
2
.
days
.
ago
)
create
(
:repository_state
,
:wiki_verified
,
project:
project_other_shard
,
last_wiki_verification_ran_at:
2
.
days
.
ago
)
describe
'#find_reverifiable_repositories'
do
it_behaves_like
'find reverifiable projects'
,
:repository
end
expect
(
subject
.
find_reverifiable_wikis
(
interval:
1
.
day
.
ago
,
batch_size:
10
))
.
to
match_array
(
project
)
end
end
describe
'#find_reverifiable_wikis'
do
it_behaves_like
'find reverifiable projects'
,
:wiki
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