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
0d00d02e
Commit
0d00d02e
authored
Jun 03, 2018
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Directly refer application code from migration code
parent
b626fcc0
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
84 deletions
+21
-84
app/models/ci/build.rb
app/models/ci/build.rb
+5
-0
db/post_migrate/20180529152628_archive_legacy_traces.rb
db/post_migrate/20180529152628_archive_legacy_traces.rb
+4
-15
lib/gitlab/background_migration/archive_legacy_traces.rb
lib/gitlab/background_migration/archive_legacy_traces.rb
+11
-66
lib/tasks/gitlab/traces.rake
lib/tasks/gitlab/traces.rake
+1
-3
No files found.
app/models/ci/build.rb
View file @
0d00d02e
...
@@ -55,6 +55,11 @@ module Ci
...
@@ -55,6 +55,11 @@ module Ci
where
(
'(artifacts_file IS NOT NULL AND artifacts_file <> ?) OR EXISTS (?)'
,
where
(
'(artifacts_file IS NOT NULL AND artifacts_file <> ?) OR EXISTS (?)'
,
''
,
Ci
::
JobArtifact
.
select
(
1
).
where
(
'ci_builds.id = ci_job_artifacts.job_id'
).
archive
)
''
,
Ci
::
JobArtifact
.
select
(
1
).
where
(
'ci_builds.id = ci_job_artifacts.job_id'
).
archive
)
end
end
scope
:without_archived_trace
,
->
()
do
where
(
'NOT EXISTS (?)'
,
Ci
::
JobArtifact
.
select
(
1
).
where
(
'ci_builds.id = ci_job_artifacts.job_id'
).
trace
)
end
scope
:with_artifacts_stored_locally
,
->
{
with_artifacts_archive
.
where
(
artifacts_file_store:
[
nil
,
LegacyArtifactUploader
::
Store
::
LOCAL
])
}
scope
:with_artifacts_stored_locally
,
->
{
with_artifacts_archive
.
where
(
artifacts_file_store:
[
nil
,
LegacyArtifactUploader
::
Store
::
LOCAL
])
}
scope
:with_artifacts_not_expired
,
->
()
{
with_artifacts_archive
.
where
(
'artifacts_expire_at IS NULL OR artifacts_expire_at > ?'
,
Time
.
now
)
}
scope
:with_artifacts_not_expired
,
->
()
{
with_artifacts_archive
.
where
(
'artifacts_expire_at IS NULL OR artifacts_expire_at > ?'
,
Time
.
now
)
}
scope
:with_expired_artifacts
,
->
()
{
with_artifacts_archive
.
where
(
'artifacts_expire_at < ?'
,
Time
.
now
)
}
scope
:with_expired_artifacts
,
->
()
{
with_artifacts_archive
.
where
(
'artifacts_expire_at < ?'
,
Time
.
now
)
}
...
...
db/post_migrate/20180529152628_archive_legacy_traces.rb
View file @
0d00d02e
...
@@ -2,7 +2,7 @@ class ArchiveLegacyTraces < ActiveRecord::Migration
...
@@ -2,7 +2,7 @@ class ArchiveLegacyTraces < ActiveRecord::Migration
include
Gitlab
::
Database
::
MigrationHelpers
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
DOWNTIME
=
false
BATCH_SIZE
=
10_
000
BATCH_SIZE
=
5
000
BACKGROUND_MIGRATION_CLASS
=
'ArchiveLegacyTraces'
BACKGROUND_MIGRATION_CLASS
=
'ArchiveLegacyTraces'
disable_ddl_transaction!
disable_ddl_transaction!
...
@@ -14,25 +14,14 @@ class ArchiveLegacyTraces < ActiveRecord::Migration
...
@@ -14,25 +14,14 @@ class ArchiveLegacyTraces < ActiveRecord::Migration
scope
:finished
,
->
{
where
(
status:
[
:success
,
:failed
,
:canceled
])
}
scope
:finished
,
->
{
where
(
status:
[
:success
,
:failed
,
:canceled
])
}
scope
:without_new_traces
,
->
()
do
scope
:without_archived_trace
,
->
do
where
(
'NOT EXISTS (?)'
,
where
(
'NOT EXISTS (SELECT 1 FROM ci_job_artifacts WHERE ci_builds.id = ci_job_artifacts.job_id AND ci_job_artifacts.file_type = 3)'
)
::
ArchiveLegacyTraces
::
JobArtifact
.
select
(
1
).
trace
.
where
(
'ci_builds.id = ci_job_artifacts.job_id'
))
end
end
end
end
class
JobArtifact
<
ActiveRecord
::
Base
self
.
table_name
=
'ci_job_artifacts'
enum
file_type:
{
archive:
1
,
metadata:
2
,
trace:
3
}
end
def
up
def
up
queue_background_migration_jobs_by_range_at_intervals
(
queue_background_migration_jobs_by_range_at_intervals
(
::
ArchiveLegacyTraces
::
Build
.
finished
.
without_
new_traces
,
::
ArchiveLegacyTraces
::
Build
.
finished
.
without_
archived_trace
,
BACKGROUND_MIGRATION_CLASS
,
BACKGROUND_MIGRATION_CLASS
,
5
.
minutes
,
5
.
minutes
,
batch_size:
BATCH_SIZE
)
batch_size:
BATCH_SIZE
)
...
...
lib/gitlab/background_migration/archive_legacy_traces.rb
View file @
0d00d02e
...
@@ -5,73 +5,18 @@
...
@@ -5,73 +5,18 @@
module
Gitlab
module
Gitlab
module
BackgroundMigration
module
BackgroundMigration
class
ArchiveLegacyTraces
class
ArchiveLegacyTraces
class
Build
<
ActiveRecord
::
Base
include
::
HasStatus
self
.
table_name
=
'ci_builds'
self
.
inheritance_column
=
:_type_disabled
# Disable STI
belongs_to
:project
,
foreign_key: :project_id
,
class_name:
'ArchiveLegacyTraces::Project'
has_one
:job_artifacts_trace
,
->
()
{
where
(
file_type:
ArchiveLegacyTraces
::
JobArtifact
.
file_types
[
:trace
])
},
class_name:
'ArchiveLegacyTraces::JobArtifact'
,
foreign_key: :job_id
has_many
:trace_chunks
,
foreign_key: :build_id
,
class_name:
'ArchiveLegacyTraces::BuildTraceChunk'
scope
:finished
,
->
{
where
(
status:
[
:success
,
:failed
,
:canceled
])
}
scope
:without_new_traces
,
->
()
do
finished
.
where
(
'NOT EXISTS (?)'
,
BackgroundMigration
::
ArchiveLegacyTraces
::
JobArtifact
.
select
(
1
).
trace
.
where
(
'ci_builds.id = ci_job_artifacts.job_id'
))
end
def
trace
::
Gitlab
::
Ci
::
Trace
.
new
(
self
)
end
def
trace
=
(
data
)
raise
NotImplementedError
end
def
old_trace
read_attribute
(
:trace
)
end
def
erase_old_trace!
update_column
(
:trace
,
nil
)
end
end
class
JobArtifact
<
ActiveRecord
::
Base
self
.
table_name
=
'ci_job_artifacts'
belongs_to
:build
belongs_to
:project
mount_uploader
:file
,
JobArtifactUploader
enum
file_type:
{
archive:
1
,
metadata:
2
,
trace:
3
}
end
class
BuildTraceChunk
<
ActiveRecord
::
Base
self
.
table_name
=
'ci_build_trace_chunks'
belongs_to
:build
end
class
Project
<
ActiveRecord
::
Base
self
.
table_name
=
'projects'
has_many
:builds
,
foreign_key: :project_id
,
class_name:
'ArchiveLegacyTraces::Build'
end
def
perform
(
start_id
,
stop_id
)
def
perform
(
start_id
,
stop_id
)
BackgroundMigration
::
ArchiveLegacyTraces
::
Build
# This background migrations directly refer ::Ci::Build model which is defined in application code.
.
finished
# In general, migration code should be isolated as much as possible in order to be idempotent.
.
without_new_traces
# However, `archive!` logic is too complicated to be replicated. So we chose a way to refer ::Ci::Build directly
.
where
(
id:
(
start_id
..
stop_id
)).
find_each
do
|
build
|
# and we don't change the `archive!` logic until 11.1
::
Ci
::
Build
.
finished
.
without_archived_trace
.
where
(
id:
start_id
..
stop_id
).
find_each
do
|
build
|
begin
build
.
trace
.
archive!
build
.
trace
.
archive!
rescue
=>
e
Rails
.
logger
.
error
"Failed to archive live trace. id:
#{
build
.
id
}
message:
#{
e
.
message
}
"
end
end
end
end
end
end
end
...
...
lib/tasks/gitlab/traces.rake
View file @
0d00d02e
...
@@ -8,9 +8,7 @@ namespace :gitlab do
...
@@ -8,9 +8,7 @@ namespace :gitlab do
logger
=
Logger
.
new
(
STDOUT
)
logger
=
Logger
.
new
(
STDOUT
)
logger
.
info
(
'Archiving legacy traces'
)
logger
.
info
(
'Archiving legacy traces'
)
Ci
::
Build
.
finished
Ci
::
Build
.
finished
.
without_archived_trace
.
where
(
'NOT EXISTS (?)'
,
Ci
::
JobArtifact
.
select
(
1
).
trace
.
where
(
'ci_builds.id = ci_job_artifacts.job_id'
))
.
order
(
id: :asc
)
.
order
(
id: :asc
)
.
find_in_batches
(
batch_size:
1000
)
do
|
jobs
|
.
find_in_batches
(
batch_size:
1000
)
do
|
jobs
|
job_ids
=
jobs
.
map
{
|
job
|
[
job
.
id
]
}
job_ids
=
jobs
.
map
{
|
job
|
[
job
.
id
]
}
...
...
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