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
1f8f720b
Commit
1f8f720b
authored
May 04, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove project restrictions from the repository backfill service
parent
40dac302
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
41 deletions
+58
-41
app/services/geo/repository_backfill_service.rb
app/services/geo/repository_backfill_service.rb
+0
-31
spec/services/geo/repository_backfill_service_spec.rb
spec/services/geo/repository_backfill_service_spec.rb
+58
-10
No files found.
app/services/geo/repository_backfill_service.rb
View file @
1f8f720b
...
@@ -10,18 +10,6 @@ module Geo
...
@@ -10,18 +10,6 @@ module Geo
end
end
def
execute
def
execute
# When Geo customers upgrade to 9.0, the secondaries nodes that are
# enabled will start the backfilling process automatically. We need
# to populate the tracking database correctly for projects synced
# before the process being started or projects created during the
# backfilling. Otherwise, the query to retrieve the projects will
# always return the same projects because they don't have entries
# in the tracking database
if
backfilled?
update_registry
(
DateTime
.
now
,
DateTime
.
now
)
return
end
try_obtain_lease
do
try_obtain_lease
do
log
(
'Started repository sync'
)
log
(
'Started repository sync'
)
started_at
,
finished_at
=
fetch_repositories
started_at
,
finished_at
=
fetch_repositories
...
@@ -76,7 +64,6 @@ module Geo
...
@@ -76,7 +64,6 @@ module Geo
def
try_obtain_lease
def
try_obtain_lease
log
(
'Trying to obtain lease to sync repository'
)
log
(
'Trying to obtain lease to sync repository'
)
repository_lease
=
Gitlab
::
ExclusiveLease
.
new
(
lease_key
,
timeout:
LEASE_TIMEOUT
).
try_obtain
repository_lease
=
Gitlab
::
ExclusiveLease
.
new
(
lease_key
,
timeout:
LEASE_TIMEOUT
).
try_obtain
if
repository_lease
.
nil?
if
repository_lease
.
nil?
...
@@ -93,25 +80,7 @@ module Geo
...
@@ -93,25 +80,7 @@ module Geo
Gitlab
::
ExclusiveLease
.
cancel
(
lease_key
,
repository_lease
)
Gitlab
::
ExclusiveLease
.
cancel
(
lease_key
,
repository_lease
)
end
end
def
backfilled?
return
false
unless
project
.
repository
.
exists?
return
false
if
project
.
repository
.
exists?
&&
project
.
repository
.
empty?
return
false
if
failed_registry_exists?
true
end
def
failed_registry_exists?
Geo
::
ProjectRegistry
.
failed
.
where
(
project_id:
project_id
).
any?
end
def
synced_registry_exists?
Geo
::
ProjectRegistry
.
synced
.
where
(
project_id:
project_id
).
any?
end
def
update_registry
(
started_at
,
finished_at
)
def
update_registry
(
started_at
,
finished_at
)
return
if
synced_registry_exists?
log
(
'Updating registry information'
)
log
(
'Updating registry information'
)
registry
=
Geo
::
ProjectRegistry
.
find_or_initialize_by
(
project_id:
project_id
)
registry
=
Geo
::
ProjectRegistry
.
find_or_initialize_by
(
project_id:
project_id
)
registry
.
last_repository_synced_at
=
started_at
registry
.
last_repository_synced_at
=
started_at
...
...
spec/services/geo/repository_backfill_service_spec.rb
View file @
1f8f720b
...
@@ -67,35 +67,67 @@ describe Geo::RepositoryBackfillService, services: true do
...
@@ -67,35 +67,67 @@ describe Geo::RepositoryBackfillService, services: true do
context
'when repository exists and is not empty'
do
context
'when repository exists and is not empty'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
it
'does not fetch the project repositories'
do
it
'fetches project repositories'
do
expect_any_instance_of
(
Repository
).
not_to
receive
(
:fetch_geo_mirror
)
fetch_count
=
0
allow_any_instance_of
(
Repository
).
to
receive
(
:fetch_geo_mirror
)
do
fetch_count
+=
1
end
subject
.
execute
subject
.
execute
expect
(
fetch_count
).
to
eq
2
end
end
context
'tracking database'
do
context
'tracking database'
do
it
'tracks
missing
repository sync'
do
it
'tracks repository sync'
do
expect
{
subject
.
execute
}.
to
change
(
Geo
::
ProjectRegistry
,
:count
).
by
(
1
)
expect
{
subject
.
execute
}.
to
change
(
Geo
::
ProjectRegistry
,
:count
).
by
(
1
)
end
end
it
'stores last_repository_successful_sync_at when succeed'
do
allow_any_instance_of
(
Repository
).
to
receive
(
:fetch_geo_mirror
)
{
true
}
subject
.
execute
registry
=
Geo
::
ProjectRegistry
.
find_by
(
project_id:
project
.
id
)
expect
(
registry
.
last_repository_successful_sync_at
).
not_to
be_nil
end
it
'reset last_repository_successful_sync_at when fail'
do
allow_any_instance_of
(
Repository
).
to
receive
(
:fetch_geo_mirror
)
{
raise
Gitlab
::
Shell
::
Error
}
subject
.
execute
registry
=
Geo
::
ProjectRegistry
.
find_by
(
project_id:
project
.
id
)
expect
(
registry
.
last_repository_successful_sync_at
).
to
be_nil
end
end
end
end
end
context
'when repository was backfilled successfully'
do
context
'when repository was backfilled successfully'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:last_repository_s
uccessful_sync
_at
)
{
5
.
days
.
ago
}
let
(
:last_repository_s
ynced
_at
)
{
5
.
days
.
ago
}
let!
(
:registry
)
do
let!
(
:registry
)
do
Geo
::
ProjectRegistry
.
create
(
Geo
::
ProjectRegistry
.
create
(
project:
project
,
project:
project
,
last_repository_synced_at:
5
.
days
.
ago
,
last_repository_synced_at:
last_repository_synced_at
,
last_repository_successful_sync_at:
last_repository_s
uccessful_sync
_at
last_repository_successful_sync_at:
last_repository_s
ynced
_at
)
)
end
end
it
'does not fetch the project repositories'
do
it
'fetches project repositories'
do
expect_any_instance_of
(
Repository
).
not_to
receive
(
:fetch_geo_mirror
)
fetch_count
=
0
allow_any_instance_of
(
Repository
).
to
receive
(
:fetch_geo_mirror
)
do
fetch_count
+=
1
end
subject
.
execute
subject
.
execute
expect
(
fetch_count
).
to
eq
2
end
end
context
'tracking database'
do
context
'tracking database'
do
...
@@ -103,10 +135,26 @@ describe Geo::RepositoryBackfillService, services: true do
...
@@ -103,10 +135,26 @@ describe Geo::RepositoryBackfillService, services: true do
expect
{
subject
.
execute
}.
not_to
change
(
Geo
::
ProjectRegistry
,
:count
)
expect
{
subject
.
execute
}.
not_to
change
(
Geo
::
ProjectRegistry
,
:count
)
end
end
it
'does not update last_repository_successful_sync_at'
do
it
'updates registry when succeed'
do
allow_any_instance_of
(
Repository
).
to
receive
(
:fetch_geo_mirror
)
{
true
}
subject
.
execute
subject
.
execute
expect
(
registry
.
reload
.
last_repository_successful_sync_at
).
to
be_within
(
1
.
second
).
of
(
last_repository_successful_sync_at
)
registry
.
reload
expect
(
registry
.
last_repository_synced_at
).
to
be_within
(
1
.
minute
).
of
(
Time
.
now
)
expect
(
registry
.
last_repository_successful_sync_at
).
to
be_within
(
1
.
minute
).
of
(
Time
.
now
)
end
it
'does not update registry last_repository_successful_sync_at when fail'
do
allow_any_instance_of
(
Repository
).
to
receive
(
:fetch_geo_mirror
)
{
raise
Gitlab
::
Shell
::
Error
}
subject
.
execute
registry
.
reload
expect
(
registry
.
last_repository_synced_at
).
to
be_within
(
1
.
minute
).
of
(
Time
.
now
)
expect
(
registry
.
last_repository_successful_sync_at
).
to
be_within
(
1
.
minute
).
of
(
last_repository_synced_at
)
end
end
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