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
5754557d
Commit
5754557d
authored
Nov 09, 2017
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Geo: Implement a download to a temporary repo
parent
06fb09da
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
50 deletions
+54
-50
app/models/geo/project_registry.rb
app/models/geo/project_registry.rb
+1
-1
app/services/geo/base_sync_service.rb
app/services/geo/base_sync_service.rb
+19
-0
app/services/geo/repository_sync_service.rb
app/services/geo/repository_sync_service.rb
+17
-26
app/services/geo/wiki_sync_service.rb
app/services/geo/wiki_sync_service.rb
+17
-23
No files found.
app/models/geo/project_registry.rb
View file @
5754557d
...
@@ -19,7 +19,7 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
...
@@ -19,7 +19,7 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
where
(
where
(
arel_table
[
:repository_retry_at
].
lt
(
Time
.
now
)
arel_table
[
:repository_retry_at
].
lt
(
Time
.
now
)
.
or
(
arel_table
[
:wiki_retry_at
].
lt
(
Time
.
now
))
.
or
(
arel_table
[
:wiki_retry_at
].
lt
(
Time
.
now
))
.
or
(
arel_table
[
:
wiki
_retry_at
].
eq
(
nil
))
.
or
(
arel_table
[
:
repository
_retry_at
].
eq
(
nil
))
.
or
(
arel_table
[
:wiki_retry_at
].
eq
(
nil
))
.
or
(
arel_table
[
:wiki_retry_at
].
eq
(
nil
))
)
)
end
end
...
...
app/services/geo/base_sync_service.rb
View file @
5754557d
...
@@ -170,5 +170,24 @@ module Geo
...
@@ -170,5 +170,24 @@ module Geo
def
last_synced_at
def
last_synced_at
registry
.
public_send
(
"last_
#{
type
}
_synced_at"
)
# rubocop:disable GitlabSecurity/PublicSend
registry
.
public_send
(
"last_
#{
type
}
_synced_at"
)
# rubocop:disable GitlabSecurity/PublicSend
end
end
def
disk_path_temp
"
#{
repository
.
disk_path
}
_temp"
end
def
build_temporary_repository
gitlab_shell
.
add_repository
(
project
.
repository_storage
,
disk_path_temp
)
repository
.
clone
.
tap
{
|
repo
|
repo
.
disk_path
=
disk_path_temp
}
end
def
clean_up_temporary_repository
gitlab_shell
.
remove_repository
(
project
.
repository_storage_path
,
disk_path_temp
)
end
def
set_temp_repository_as_main
log_info
(
"Setting newly downloaded
#{
type
}
as a main one"
)
gitlab_shell
.
remove_repository
(
project
.
repository_storage_path
,
repository
.
disk_path
)
gitlab_shell
.
mv_repository
(
project
.
repository_storage_path
,
disk_path_temp
,
repository
.
disk_path
)
end
end
end
end
end
app/services/geo/repository_sync_service.rb
View file @
5754557d
require
'tmpdir'
module
Geo
module
Geo
class
RepositorySyncService
<
BaseSyncService
class
RepositorySyncService
<
BaseSyncService
include
Gitlab
::
ShellAdapter
self
.
type
=
:repository
self
.
type
=
:repository
private
private
def
sync_repository
(
with_backup
=
false
)
def
sync_repository
(
redownload
=
false
)
fetch_project_repository
(
with_backup
)
fetch_project_repository
(
redownload
)
expire_repository_caches
expire_repository_caches
end
end
def
fetch_project_repository
(
with_backup
)
def
fetch_project_repository
(
redownload
)
log_info
(
'Trying to fetch project repository'
)
log_info
(
'Trying to fetch project repository'
)
update_registry
(
started_at:
DateTime
.
now
)
update_registry
(
started_at:
DateTime
.
now
)
if
with_backup
if
redownload
log_info
(
'Backup enabled'
)
log_info
(
'Redownloading repository'
)
actual_path
=
project
.
repository
.
path_to_repo
clean_up_temporary_repository
backup_path
=
File
.
join
(
Dir
.
mktmpdir
,
project
.
path
)
fetch_geo_mirror
(
build_temporary_repository
)
set_temp_repository_as_main
# Creating a backup copy and removing the main repo
else
FileUtils
.
mv
(
actual_path
,
backup_path
)
project
.
ensure_repository
end
fetch_geo_mirror
(
project
.
repository
)
project
.
ensure_repository
fetch_geo_mirror
(
project
.
repository
)
if
with_backup
log_info
(
'Removing backup copy as the repository was redownloaded successfully'
)
FileUtils
.
rm_rf
(
backup_path
)
end
end
update_registry
(
finished_at:
DateTime
.
now
)
update_registry
(
finished_at:
DateTime
.
now
)
...
@@ -44,12 +37,6 @@ module Geo
...
@@ -44,12 +37,6 @@ module Geo
log_error
(
'Invalid repository'
,
e
)
log_error
(
'Invalid repository'
,
e
)
registry
.
update
(
force_to_redownload_repository:
true
)
registry
.
update
(
force_to_redownload_repository:
true
)
expire_repository_caches
expire_repository_caches
ensure
# Backup can only exist if redownload was unsuccessful
if
with_backup
&&
File
.
exist?
(
backup_path
)
FileUtils
.
rm_rf
(
actual_path
)
FileUtils
.
mv
(
backup_path
,
actual_path
)
end
end
end
def
expire_repository_caches
def
expire_repository_caches
...
@@ -60,5 +47,9 @@ module Geo
...
@@ -60,5 +47,9 @@ module Geo
def
ssh_url_to_repo
def
ssh_url_to_repo
"
#{
primary_ssh_path_prefix
}#{
project
.
full_path
}
.git"
"
#{
primary_ssh_path_prefix
}#{
project
.
full_path
}
.git"
end
end
def
repository
project
.
repository
end
end
end
end
end
app/services/geo/wiki_sync_service.rb
View file @
5754557d
module
Geo
module
Geo
class
WikiSyncService
<
BaseSyncService
class
WikiSyncService
<
BaseSyncService
include
Gitlab
::
ShellAdapter
self
.
type
=
:wiki
self
.
type
=
:wiki
private
private
def
sync_repository
(
with_backup
=
false
)
def
sync_repository
(
redownload
=
false
)
fetch_wiki_repository
(
with_backup
)
fetch_wiki_repository
(
redownload
)
end
end
def
fetch_wiki_repository
(
with_backup
)
def
fetch_wiki_repository
(
redownload
)
log_info
(
'Fetching wiki repository'
)
log_info
(
'Fetching wiki repository'
)
update_registry
(
started_at:
DateTime
.
now
)
update_registry
(
started_at:
DateTime
.
now
)
if
with_backup
if
redownload
log_info
(
'Backup enabled'
)
log_info
(
'Redownloading wiki'
)
actual_path
=
project
.
wiki
.
path_to_repo
clean_up_temporary_repository
backup_path
=
File
.
join
(
Dir
.
mktmpdir
,
'wiki'
)
fetch_geo_mirror
(
build_temporary_repository
)
set_temp_repository_as_main
# Creating a backup copy and removing the main wiki
else
FileUtils
.
mv
(
actual_path
,
backup_path
)
project
.
wiki
.
ensure_repository
end
fetch_geo_mirror
(
project
.
wiki
.
repository
)
project
.
wiki
.
ensure_repository
fetch_geo_mirror
(
project
.
wiki
.
repository
)
if
with_backup
log_info
(
'Removing backup copy as the repository was redownloaded successfully'
)
FileUtils
.
rm_r
(
backup_path
)
end
end
update_registry
(
finished_at:
DateTime
.
now
)
update_registry
(
finished_at:
DateTime
.
now
)
...
@@ -42,15 +37,14 @@ module Geo
...
@@ -42,15 +37,14 @@ module Geo
rescue
Gitlab
::
Git
::
Repository
::
NoRepository
=>
e
rescue
Gitlab
::
Git
::
Repository
::
NoRepository
=>
e
log_error
(
'Invalid wiki'
,
e
)
log_error
(
'Invalid wiki'
,
e
)
registry
.
update
(
force_to_redownload_wiki:
true
)
registry
.
update
(
force_to_redownload_wiki:
true
)
ensure
# Backup can only exist if redownload was unsuccessful
if
with_backup
&&
File
.
exist?
(
backup_path
)
FileUtils
.
mv
(
backup_path
,
actual_path
)
end
end
end
def
ssh_url_to_wiki
def
ssh_url_to_wiki
"
#{
primary_ssh_path_prefix
}#{
project
.
full_path
}
.wiki.git"
"
#{
primary_ssh_path_prefix
}#{
project
.
full_path
}
.wiki.git"
end
end
def
repository
project
.
wiki
.
repository
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