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
Jérome Perrin
gitlab-ce
Commits
806a7e1b
Commit
806a7e1b
authored
Mar 01, 2017
by
DJ Mountney
Committed by
DJ Mountney
Mar 01, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge branch 'fix-builds-processing' into 'master'
Fix concurrent access on builds/register See merge request !9600
parent
512bf648
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
12 deletions
+69
-12
app/services/ci/register_build_service.rb
app/services/ci/register_build_service.rb
+24
-12
spec/services/ci/register_build_service_spec.rb
spec/services/ci/register_build_service_spec.rb
+45
-0
No files found.
app/services/ci/register_build_service.rb
View file @
806a7e1b
...
@@ -20,21 +20,33 @@ module Ci
...
@@ -20,21 +20,33 @@ module Ci
builds_for_specific_runner
builds_for_specific_runner
end
end
build
=
builds
.
find
do
|
build
|
valid
=
true
runner
.
can_pick?
(
build
)
end
builds
.
find
do
|
build
|
next
unless
runner
.
can_pick?
(
build
)
if
build
begin
# In case when 2 runners try to assign the same build, second runner will be declined
# In case when 2 runners try to assign the same build, second runner will be declined
# with StateMachines::InvalidTransition or StaleObjectError when doing run! or save method.
# with StateMachines::InvalidTransition or StaleObjectError when doing run! or save method.
build
.
runner_id
=
runner
.
id
build
.
runner_id
=
runner
.
id
build
.
run!
build
.
run!
end
Result
.
new
(
build
,
true
)
return
Result
.
new
(
build
,
true
)
rescue
StateMachines
::
InvalidTransition
,
ActiveRecord
::
StaleObjectError
rescue
StateMachines
::
InvalidTransition
,
ActiveRecord
::
StaleObjectError
Result
.
new
(
build
,
false
)
# We are looping to find another build that is not conflicting
# It also indicates that this build can be picked and passed to runner.
# If we don't do it, basically a bunch of runners would be competing for a build
# and thus we will generate a lot of 409. This will increase
# the number of generated requests, also will reduce significantly
# how many builds can be picked by runner in a unit of time.
# In case we hit the concurrency-access lock,
# we still have to return 409 in the end,
# to make sure that this is properly handled by runner.
valid
=
false
end
end
Result
.
new
(
nil
,
valid
)
end
end
private
private
...
...
spec/services/ci/register_build_service_spec.rb
View file @
806a7e1b
...
@@ -170,6 +170,51 @@ module Ci
...
@@ -170,6 +170,51 @@ module Ci
end
end
end
end
context
'when first build is stalled'
do
before
do
pending_build
.
lock_version
=
10
end
subject
{
described_class
.
new
(
specific_runner
).
execute
}
context
'with multiple builds are in queue'
do
let!
(
:other_build
)
{
create
:ci_build
,
pipeline:
pipeline
}
before
do
allow_any_instance_of
(
Ci
::
RegisterBuildService
).
to
receive
(
:builds_for_specific_runner
)
.
and_return
([
pending_build
,
other_build
])
end
it
"receives second build from the queue"
do
expect
(
subject
).
to
be_valid
expect
(
subject
.
build
).
to
eq
(
other_build
)
end
end
context
'when single build is in queue'
do
before
do
allow_any_instance_of
(
Ci
::
RegisterBuildService
).
to
receive
(
:builds_for_specific_runner
)
.
and_return
([
pending_build
])
end
it
"does not receive any valid result"
do
expect
(
subject
).
not_to
be_valid
end
end
context
'when there is no build in queue'
do
before
do
allow_any_instance_of
(
Ci
::
RegisterBuildService
).
to
receive
(
:builds_for_specific_runner
)
.
and_return
([])
end
it
"does not receive builds but result is valid"
do
expect
(
subject
).
to
be_valid
expect
(
subject
.
build
).
to
be_nil
end
end
end
def
execute
(
runner
)
def
execute
(
runner
)
described_class
.
new
(
runner
).
execute
.
build
described_class
.
new
(
runner
).
execute
.
build
end
end
...
...
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