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
059b1f92
Commit
059b1f92
authored
Nov 13, 2017
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Hashed Storage migration to add additional migration steps
parent
c97b60cb
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
96 additions
and
82 deletions
+96
-82
app/models/storage/hashed_project.rb
app/models/storage/hashed_project.rb
+0
-1
app/services/projects/hashed_storage/migrate_repository_service.rb
...ces/projects/hashed_storage/migrate_repository_service.rb
+68
-0
app/services/projects/hashed_storage_migration_service.rb
app/services/projects/hashed_storage_migration_service.rb
+5
-60
ee/app/services/ee/projects/hashed_storage/migrate_repository_service.rb
.../ee/projects/hashed_storage/migrate_repository_service.rb
+20
-0
ee/app/services/ee/projects/hashed_storage_migration_service.rb
.../services/ee/projects/hashed_storage_migration_service.rb
+0
-18
spec/ee/spec/services/ee/projects/hashed_storage/migrate_repository_service_spec.rb
...rojects/hashed_storage/migrate_repository_service_spec.rb
+2
-2
spec/services/projects/hashed_storage/migrate_repository_service_spec.rb
...rojects/hashed_storage/migrate_repository_service_spec.rb
+1
-1
No files found.
app/models/storage/hashed_project.rb
View file @
059b1f92
...
...
@@ -4,7 +4,6 @@ module Storage
delegate
:gitlab_shell
,
:repository_storage_path
,
to: :project
ROOT_PATH_PREFIX
=
'@hashed'
.
freeze
STORAGE_VERSION
=
1
def
initialize
(
project
)
@project
=
project
...
...
app/services/projects/hashed_storage/migrate_repository_service.rb
0 → 100644
View file @
059b1f92
module
Projects
module
HashedStorage
class
MigrateRepositoryService
<
BaseService
include
Gitlab
::
ShellAdapter
prepend
::
EE
::
Projects
::
HashedStorage
::
MigrateRepositoryService
attr_reader
:old_disk_path
,
:new_disk_path
,
:old_wiki_disk_path
,
:old_storage_version
,
:logger
def
initialize
(
project
,
logger
=
nil
)
@project
=
project
@logger
=
logger
||
Rails
.
logger
end
def
execute
@old_disk_path
=
project
.
disk_path
has_wiki
=
project
.
wiki
.
repository_exists?
@old_storage_version
=
project
.
storage_version
project
.
storage_version
=
::
Project
::
HASHED_STORAGE_FEATURES
[
:repository
]
project
.
ensure_storage_path_exists
@new_disk_path
=
project
.
disk_path
result
=
move_repository
(
@old_disk_path
,
@new_disk_path
)
if
has_wiki
@old_wiki_disk_path
=
"
#{
@old_disk_path
}
.wiki"
result
&&=
move_repository
(
"
#{
@old_wiki_disk_path
}
"
,
"
#{
@new_disk_path
}
.wiki"
)
end
unless
result
rollback_folder_move
return
result
end
project
.
repository_read_only
=
false
project
.
save!
block_given?
?
yield
:
result
end
private
def
move_repository
(
from_name
,
to_name
)
from_exists
=
gitlab_shell
.
exists?
(
project
.
repository_storage_path
,
"
#{
from_name
}
.git"
)
to_exists
=
gitlab_shell
.
exists?
(
project
.
repository_storage_path
,
"
#{
to_name
}
.git"
)
# If we don't find the repository on either original or target we should log that as it could be an issue if the
# project was not originally empty.
if
!
from_exists
&&
!
to_exists
logger
.
warn
"Can't find a repository on either source or target paths for
#{
project
.
full_path
}
(ID=
#{
project
.
id
}
) ..."
return
false
elsif
!
from_exists
# Repository have been moved already.
return
true
end
gitlab_shell
.
mv_repository
(
project
.
repository_storage_path
,
from_name
,
to_name
)
end
def
rollback_folder_move
move_repository
(
@new_disk_path
,
@old_disk_path
)
move_repository
(
"
#{
@new_disk_path
}
.wiki"
,
"
#{
@old_disk_path
}
.wiki"
)
end
end
end
end
app/services/projects/hashed_storage_migration_service.rb
View file @
059b1f92
module
Projects
class
HashedStorageMigrationService
<
BaseService
include
Gitlab
::
ShellAdapter
prepend
::
EE
::
Projects
::
HashedStorageMigrationService
attr_reader
:old_disk_path
,
:new_disk_path
,
:old_wiki_disk_path
,
:old_storage_version
attr_reader
:logger
def
initialize
(
project
,
logger
=
nil
)
@project
=
project
@logger
||=
Rails
.
logger
@logger
=
logger
||
Rails
.
logger
end
def
execute
return
if
project
.
hashed_storage?
(
:repository
)
@old_disk_path
=
project
.
disk_path
has_wiki
=
project
.
wiki
.
repository_exists?
@old_storage_version
=
project
.
storage_version
project
.
storage_version
=
Storage
::
HashedProject
::
STORAGE_VERSION
project
.
ensure_storage_path_exists
@new_disk_path
=
project
.
disk_path
result
=
move_repository
(
@old_disk_path
,
@new_disk_path
)
if
has_wiki
@old_wiki_disk_path
=
"
#{
@old_disk_path
}
.wiki"
result
&&=
move_repository
(
@old_wiki_disk_path
,
"
#{
@new_disk_path
}
.wiki"
)
end
unless
result
rollback_folder_move
return
# Migrate repository from Legacy to Hashed Storage
unless
project
.
hashed_storage?
(
:repository
)
return
unless
HashedStorage
::
MigrateRepositoryService
.
new
(
project
,
logger
).
execute
end
project
.
repository_read_only
=
false
project
.
save!
block_given?
?
yield
:
result
end
private
def
move_repository
(
from_name
,
to_name
)
from_exists
=
gitlab_shell
.
exists?
(
project
.
repository_storage_path
,
"
#{
from_name
}
.git"
)
to_exists
=
gitlab_shell
.
exists?
(
project
.
repository_storage_path
,
"
#{
to_name
}
.git"
)
# If we don't find the repository on either original or target we should log that as it could be an issue if the
# project was not originally empty.
if
!
from_exists
&&
!
to_exists
logger
.
warn
"Can't find a repository on either source or target paths for
#{
project
.
full_path
}
(ID=
#{
project
.
id
}
) ..."
return
false
elsif
!
from_exists
# Repository have been moved already.
return
true
end
gitlab_shell
.
mv_repository
(
project
.
repository_storage_path
,
from_name
,
to_name
)
end
def
rollback_folder_move
move_repository
(
@new_disk_path
,
@old_disk_path
)
move_repository
(
"
#{
@new_disk_path
}
.wiki"
,
"
#{
@old_disk_path
}
.wiki"
)
end
def
logger
@logger
end
end
end
ee/app/services/ee/projects/hashed_storage/migrate_repository_service.rb
0 → 100644
View file @
059b1f92
module
EE
module
Projects
module
HashedStorage
module
MigrateRepositoryService
def
execute
raise
NotImplementedError
.
new
unless
defined?
(
super
)
super
do
::
Geo
::
HashedStorageMigratedEventStore
.
new
(
project
,
old_storage_version:
old_storage_version
,
old_disk_path:
old_disk_path
,
old_wiki_disk_path:
old_wiki_disk_path
).
create
end
end
end
end
end
end
ee/app/services/ee/projects/hashed_storage_migration_service.rb
deleted
100644 → 0
View file @
c97b60cb
module
EE
module
Projects
module
HashedStorageMigrationService
def
execute
raise
NotImplementedError
.
new
unless
defined?
(
super
)
super
do
::
Geo
::
HashedStorageMigratedEventStore
.
new
(
project
,
old_storage_version:
old_storage_version
,
old_disk_path:
old_disk_path
,
old_wiki_disk_path:
old_wiki_disk_path
).
create
end
end
end
end
end
spec/ee/spec/services/ee/projects/hashed_storage
_migration
_service_spec.rb
→
spec/ee/spec/services/ee/projects/hashed_storage
/migrate_repository
_service_spec.rb
View file @
059b1f92
require
'spec_helper'
describe
Projects
::
HashedStorage
Migration
Service
do
describe
Projects
::
HashedStorage
::
MigrateRepository
Service
do
let
(
:project
)
{
create
(
:project
,
:empty_repo
,
:wiki_repo
)
}
let
(
:service
)
{
described_class
.
new
(
project
)
}
let
(
:legacy_storage
)
{
Storage
::
LegacyProject
.
new
(
project
)
}
...
...
@@ -18,7 +18,7 @@ describe Projects::HashedStorageMigrationService do
expect
(
event
).
to
be_a
(
Geo
::
HashedStorageMigratedEvent
)
expect
(
event
).
to
have_attributes
(
old_storage_version:
nil
,
new_storage_version:
Storage
::
HashedProject
::
STORAGE_VERSION
,
new_storage_version:
::
Project
::
HASHED_STORAGE_FEATURES
[
:repository
]
,
old_disk_path:
legacy_storage
.
disk_path
,
new_disk_path:
hashed_storage
.
disk_path
,
old_wiki_disk_path:
legacy_storage
.
disk_path
+
'.wiki'
,
...
...
spec/services/projects/hashed_storage
_migration
_service_spec.rb
→
spec/services/projects/hashed_storage
/migrate_repository
_service_spec.rb
View file @
059b1f92
require
'spec_helper'
describe
Projects
::
HashedStorage
Migration
Service
do
describe
Projects
::
HashedStorage
::
MigrateRepository
Service
do
let
(
:gitlab_shell
)
{
Gitlab
::
Shell
.
new
}
let
(
:project
)
{
create
(
:project
,
:empty_repo
,
:wiki_repo
)
}
let
(
:service
)
{
described_class
.
new
(
project
)
}
...
...
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