Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
0a4d55a1
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0a4d55a1
编写于
11月 13, 2017
作者:
G
Gabriel Mazetto
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor Hashed Storage migration to add additional migration steps
上级
6369db01
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
73 addition
and
59 deletion
+73
-59
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
+66
-0
app/services/projects/hashed_storage_migration_service.rb
app/services/projects/hashed_storage_migration_service.rb
+6
-57
spec/services/projects/hashed_storage/migrate_repository_service_spec.rb
...rojects/hashed_storage/migrate_repository_service_spec.rb
+1
-1
未找到文件。
app/models/storage/hashed_project.rb
浏览文件 @
0a4d55a1
...
...
@@ -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
浏览文件 @
0a4d55a1
module
Projects
module
HashedStorage
class
MigrateRepositoryService
<
BaseService
include
Gitlab
::
ShellAdapter
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!
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
浏览文件 @
0a4d55a1
module
Projects
class
HashedStorageMigrationService
<
BaseService
include
Gitlab
::
ShellAdapter
attr_reader
:old_disk_path
,
:new_disk_path
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?
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
result
&&=
move_repository
(
"
#{
@old_disk_path
}
.wiki"
,
"
#{
@new_disk_path
}
.wiki"
)
end
unless
result
rollback_folder_move
return
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
# Migrate repository from Legacy to Hashed Storage
unless
project
.
hashed_storage?
(
:repository
)
return
unless
HashedStorage
::
MigrateRepositoryService
.
new
(
project
,
logger
).
execute
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
spec/services/projects/hashed_storage
_migration
_service_spec.rb
→
spec/services/projects/hashed_storage
/migrate_repository
_service_spec.rb
浏览文件 @
0a4d55a1
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
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录