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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
12711de2
Commit
12711de2
authored
Apr 24, 2018
by
Kamil Trzciński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement efficient destroy of job_trace_chunks
parent
4887b1b7
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
4 deletions
+38
-4
app/models/ci/job_trace_chunk.rb
app/models/ci/job_trace_chunk.rb
+24
-0
app/models/project.rb
app/models/project.rb
+9
-0
app/workers/build_finished_worker.rb
app/workers/build_finished_worker.rb
+1
-0
lib/gitlab/ci/trace.rb
lib/gitlab/ci/trace.rb
+1
-1
lib/gitlab/ci/trace/chunked_io.rb
lib/gitlab/ci/trace/chunked_io.rb
+3
-3
No files found.
app/models/ci/job_trace_chunk.rb
View file @
12711de2
...
...
@@ -19,6 +19,30 @@ module Ci
db:
2
}
def
self
.
delayed_cleanup_blk
ids
=
all
.
redis
.
pluck
(
:job_id
,
:chunk_index
).
map
do
|
data
|
"gitlab:ci:trace:
#{
data
.
first
}
:chunks:
#{
data
.
second
}
:data"
end
puts
"before cleanup:
#{
ids
.
count
}
"
Proc
.
new
do
puts
"after cleanup:
#{
ids
.
count
}
"
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
redis
.
del
(
ids
)
end
unless
ids
.
empty?
true
end
end
def
self
.
fast_destroy_all
delayed_cleanup_blk
.
tap
do
|
cleanup
|
delete_all
cleanup
.
call
end
end
def
data
if
redis?
redis_data
...
...
app/models/project.rb
View file @
12711de2
...
...
@@ -209,12 +209,21 @@ class Project < ActiveRecord::Base
has_many
:commit_statuses
has_many
:pipelines
,
class_name:
'Ci::Pipeline'
,
inverse_of: :project
# This has to be defined before `has_many :builds, depenedent: :destroy`,
# otherwise we will not delete any data, due to trace chunks
# going through :builds
before_destroy
do
puts
"destroying all chunks"
self
.
run_after_commit
(
&
build_trace_chunks
.
delayed_cleanup_blk
)
end
# Ci::Build objects store data on the file system such as artifact files and
# build traces. Currently there's no efficient way of removing this data in
# bulk that doesn't involve loading the rows into memory. As a result we're
# still using `dependent: :destroy` here.
has_many
:builds
,
class_name:
'Ci::Build'
,
inverse_of: :project
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
has_many
:build_trace_section_names
,
class_name:
'Ci::BuildTraceSectionName'
has_many
:build_trace_chunks
,
class_name:
'Ci::JobTraceChunk'
,
foreign_key: :job_id
,
through: :builds
,
source: :chunks
has_many
:runner_projects
,
class_name:
'Ci::RunnerProject'
has_many
:runners
,
through: :runner_projects
,
source: :runner
,
class_name:
'Ci::Runner'
has_many
:variables
,
class_name:
'Ci::Variable'
...
...
app/workers/build_finished_worker.rb
View file @
12711de2
...
...
@@ -7,6 +7,7 @@ class BuildFinishedWorker
def
perform
(
build_id
)
Ci
::
Build
.
find_by
(
id:
build_id
).
try
do
|
build
|
# Swap all trace chunks to Database from Redis
# TODO: Do we need that?
build
.
chunks
.
redis
.
map
(
&
:use_database!
)
# We execute that in sync as this access the files in order to access local data, and reduce IO
...
...
lib/gitlab/ci/trace.rb
View file @
12711de2
...
...
@@ -100,7 +100,7 @@ module Gitlab
FileUtils
.
rm
(
trace_path
,
force:
true
)
end
job
.
chunks
.
delete
_all
job
.
chunks
.
fast_destroy
_all
job
.
erase_old_trace!
end
...
...
lib/gitlab/ci/trace/chunked_io.rb
View file @
12711de2
...
...
@@ -140,7 +140,7 @@ module Gitlab
@size
=
offset
# remove all next chunks
job_chunks
.
where
(
'chunk_index > ?'
,
chunk_index
).
delete
_all
job_chunks
.
where
(
'chunk_index > ?'
,
chunk_index
).
fast_destroy
_all
# truncate current chunk
current_chunk
.
truncate
(
chunk_offset
)
if
chunk_offset
!=
0
...
...
@@ -156,8 +156,8 @@ module Gitlab
true
end
def
de
lete
!
job_chunks
.
delete
_all
def
de
stroy
!
job_chunks
.
fast_destroy
_all
@tell
=
@size
=
0
ensure
invalidate_chunk_cache
...
...
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