Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
50345432
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,发现更多精彩内容 >>
提交
50345432
编写于
5月 01, 2018
作者:
S
Shinya Maeda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename path_type to file_location. Fix JobArtifactUploader to look up correct file location.
上级
4f7e3503
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
86 addition
and
43 deletion
+86
-43
app/models/ci/job_artifact.rb
app/models/ci/job_artifact.rb
+7
-3
app/uploaders/job_artifact_uploader.rb
app/uploaders/job_artifact_uploader.rb
+4
-4
db/migrate/20180427160409_add_legacy_path_to_ci_job_artifacts.rb
...ate/20180427160409_add_legacy_path_to_ci_job_artifacts.rb
+1
-1
db/post_migrate/20180427161409_migrate_legacy_artifacts_to_job_artifacts.rb
...180427161409_migrate_legacy_artifacts_to_job_artifacts.rb
+5
-1
db/schema.rb
db/schema.rb
+1
-1
lib/gitlab/background_migration/migrate_legacy_artifacts.rb
lib/gitlab/background_migration/migrate_legacy_artifacts.rb
+68
-33
未找到文件。
app/models/ci/job_artifact.rb
浏览文件 @
50345432
...
...
@@ -25,9 +25,13 @@ module Ci
trace:
3
}
enum
path_type:
{
era_2:
nil
,
era_1:
1
##
# File location of the file
# Location 1: File.join(model.created_at.utc.strftime('%Y_%m'), model.project_id.to_s, model.id.to_s)
# Location 2: File.join(disk_hash[0..1], disk_hash[2..3], disk_hash, creation_date, model.job_id.to_s, model.id.to_s)
enum
file_location:
{
location_2:
nil
,
location_1:
1
}
def
update_file_store
...
...
app/uploaders/job_artifact_uploader.rb
浏览文件 @
50345432
...
...
@@ -31,15 +31,15 @@ class JobArtifactUploader < GitlabUploader
creation_date
=
model
.
created_at
.
utc
.
strftime
(
'%Y_%m_%d'
)
if
model
.
era_2
if
model
.
location_2?
File
.
join
(
disk_hash
[
0
..
1
],
disk_hash
[
2
..
3
],
disk_hash
,
creation_date
,
model
.
job_id
.
to_s
,
model
.
id
.
to_s
)
elsif
model
.
era_1
File
.
join
(
model
.
created_at
.
utc
.
strftime
(
'%Y_%m'
),
model
.
project_id
.
to_s
,
model
.
id
.
to_s
)
elsif
model
.
location_1?
File
.
join
(
model
.
created_at
.
utc
.
strftime
(
'%Y_%m'
),
model
.
project_id
.
to_s
,
model
.
job_
id
.
to_s
)
end
end
def
disk_hash
@disk_hash
||=
Digest
::
SHA2
.
hexdigest
(
c
project_id
.
to_s
)
@disk_hash
||=
Digest
::
SHA2
.
hexdigest
(
model
.
project_id
.
to_s
)
end
end
db/migrate/20180427160409_add_legacy_path_to_ci_job_artifacts.rb
浏览文件 @
50345432
...
...
@@ -4,6 +4,6 @@ class AddLegacyPathToCiJobArtifacts < ActiveRecord::Migration
DOWNTIME
=
false
def
change
add_column
:ci_job_artifacts
,
:
path_type
,
:integer
add_column
:ci_job_artifacts
,
:
file_location
,
:integer
end
end
db/post_migrate/20180427161409_migrate_legacy_artifacts_to_job_artifacts.rb
浏览文件 @
50345432
...
...
@@ -12,7 +12,11 @@ class MigrateLegacyArtifactsToJobArtifacts < ActiveRecord::Migration
self
.
table_name
=
'ci_builds'
self
.
inheritance_column
=
:_type_disabled
# disable STI
scope
:legacy_artifacts
,
->
{
where
(
'artifacts_file IS NOT NULL AND artifacts_file <> ?'
,
''
)
}
##
# TODO: Consider when unique constraint violation of job_artifacts (i.e. duplicates inserts)
scope
:legacy_artifacts
,
->
do
where
(
'artifacts_file IS NOT NULL AND artifacts_file <> ?'
,
''
)
end
end
def
up
...
...
db/schema.rb
浏览文件 @
50345432
...
...
@@ -382,7 +382,7 @@ ActiveRecord::Schema.define(version: 20180603190921) do
t
.
datetime_with_timezone
"expire_at"
t
.
string
"file"
t
.
binary
"file_sha256"
t
.
integer
"
path_type
"
t
.
integer
"
file_location
"
end
add_index
"ci_job_artifacts"
,
[
"expire_at"
,
"job_id"
],
name:
"index_ci_job_artifacts_on_expire_at_and_job_id"
,
using: :btree
...
...
lib/gitlab/background_migration/migrate_legacy_artifacts.rb
浏览文件 @
50345432
...
...
@@ -9,61 +9,96 @@ module Gitlab
self
.
table_name
=
'ci_builds'
self
.
inheritance_column
=
:_type_disabled
scope
:legacy_artifacts
,
->
{
where
(
'artifacts_file IS NOT NULL
AND
artifacts_file <> ?'
,
''
)
}
scope
:legacy_artifacts
,
->
{
where
(
'artifacts_file IS NOT NULL
OR
artifacts_file <> ?'
,
''
)
}
end
class
JobArtifact
<
ActiveRecord
::
Base
self
.
table_name
=
'ci_job_artifacts'
LOCAL_STORE
=
1
# Equavalant to ObjectStorage::Store::LOCAL
enum
file_type:
{
archive:
1
,
metadata:
2
,
trace:
3
}
enum
path_type:
{
era_2:
nil
,
era_1:
1
##
# File location of the file
# Location 1: File.join(model.created_at.utc.strftime('%Y_%m'), model.project_id.to_s, model.id.to_s)
# Location 2: File.join(disk_hash[0..1], disk_hash[2..3], disk_hash, creation_date, model.job_id.to_s, model.id.to_s)
enum
file_location:
{
location_2:
nil
,
location_1:
1
}
end
def
perform
(
start_id
,
stop_id
)
rows
=
[]
Gitlab
::
BackgroundMigration
::
MigrateLegacyArtifacts
::
Build
.
legacy_artifacts
.
where
(
id:
(
start_id
..
stop_id
))
.
each
do
|
build
|
base_param
=
{
project_id:
build
.
project_id
,
job_id:
build
.
id
,
expire_at:
build
.
artifacts_expire_at
,
path_type:
Gitlab
::
BackgroundMigration
::
MigrateLegacyArtifacts
::
JobArtifact
.
path_types
[
'era
_1'
],
created_at:
build
.
created_at
,
updated_at:
build
.
created_at
}
Gitlab
::
BackgroundMigration
::
MigrateLegacyArtifacts
::
Build
.
legacy_artifacts
.
where
(
id:
(
start_id
..
stop_id
)).
each
do
|
build
|
base_param
=
{
project_id:
build
.
project_id
,
job_id:
build
.
id
,
expire_at:
build
.
artifacts_expire_at
,
file_location:
Gitlab
::
BackgroundMigration
::
MigrateLegacyArtifacts
::
JobArtifact
.
file_locations
[
'location
_1'
],
created_at:
build
.
created_at
,
updated_at:
build
.
created_at
}
rows
<<
base_param
.
merge
({
size:
build
.
artifacts_size
,
file:
build
.
artifacts_file
,
file_store:
build
.
artifacts_file_store
||
JobArtifact
::
LOCAL_STORE
,
file_type:
Gitlab
::
BackgroundMigration
::
MigrateLegacyArtifacts
::
JobArtifact
.
file_types
[
'archive'
],
file_sha256:
nil
# `file_sha256` of legacy artifacts had not been persisted
})
if
build
.
artifacts_metadata
rows
<<
base_param
.
merge
({
size:
build
.
artifacts_size
,
file:
build
.
artifacts_
file
,
file_store:
build
.
artifacts_
file_store
,
file_type:
Gitlab
::
BackgroundMigration
::
MigrateLegacyArtifacts
::
JobArtifact
.
file_types
[
'
archive
'
],
size:
get_file_size_of_legacy_metadata
(
build
),
# `size` of legacy metadatas had not been persisted
file:
build
.
artifacts_
metadata
,
file_store:
build
.
artifacts_
metadata_store
||
JobArtifact
::
LOCAL_STORE
,
file_type:
Gitlab
::
BackgroundMigration
::
MigrateLegacyArtifacts
::
JobArtifact
.
file_types
[
'
metadata
'
],
file_sha256:
nil
# `file_sha256` of legacy artifacts had not been persisted
})
if
build
.
legacy_artifacts_metadata
.
exists?
rows
<<
base_param
.
merge
({
size:
nil
,
# `size`` of legacy metadatas had not been persisted
file:
build
.
artifacts_metadata
,
file_store:
build
.
artifacts_metadata_store
,
file_type:
Gitlab
::
BackgroundMigration
::
MigrateLegacyArtifacts
::
JobArtifact
.
file_types
[
'metadata'
],
file_sha256:
nil
# `file_sha256` of legacy artifacts had not been persisted
})
end
end
end
Gitlab
::
Database
.
bulk_insert
(
Gitlab
::
BackgroundMigration
::
MigrateLegacyArtifacts
::
JobArtifact
.
table_name
,
rows
)
# TODO: Do we need to verify the file existance with created job artifacts?
# Clean columns of ci_builds
#
# Targets
# "artifacts_file"
# "artifacts_metadata"
# "artifacts_size"
# "artifacts_file_store"
# Ignore
# "artifacts_expire_at" ,,, This is widely used for showing expiration time of artifacts
Gitlab
::
BackgroundMigration
::
MigrateLegacyArtifacts
::
Build
.
legacy_artifacts
.
where
(
id:
(
start_id
..
stop_id
))
.
update_all
(
artifacts_file:
nil
,
artifacts_metadata:
nil
,
artifacts_size:
nil
,
artifacts_file_store:
nil
)
end
private
##
# This method is efficient that request with HEAD method and get content-length,
# instead of pulling the whole data
def
get_file_size_of_legacy_metadata
(
build
)
legacy_file_path
=
File
.
join
(
build
.
created_at
.
utc
.
strftime
(
'%Y_%m'
),
build
.
project_id
.
to_s
,
build
.
id
.
to_s
,
build
.
legacy_artifacts_metadata
)
Gitlab
::
Database
.
bulk_insert
(
Gitlab
::
BackgroundMigration
::
MigrateLegacyArtifacts
::
JobArtifact
.
table_name
,
rows
)
10
# TODO:
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录