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
e0cf5941
Commit
e0cf5941
authored
Dec 28, 2018
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
083337f1
bd268a1e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
10 deletions
+55
-10
config/initializers/active_record_avoid_type_casting_in_uniqueness_validator.rb
...tive_record_avoid_type_casting_in_uniqueness_validator.rb
+1
-1
config/initializers/active_record_locking.rb
config/initializers/active_record_locking.rb
+7
-8
spec/initializers/active_record_locking_spec.rb
spec/initializers/active_record_locking_spec.rb
+44
-0
spec/services/ci/register_job_service_spec.rb
spec/services/ci/register_job_service_spec.rb
+3
-1
No files found.
config/initializers/active_record_avoid_type_casting_in_uniqueness_validator.rb
View file @
e0cf5941
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
#
#
# This bug was fixed in Rails 5.1 by https://github.com/rails/rails/pull/24745/commits/aa062318c451512035c10898a1af95943b1a3803
# This bug was fixed in Rails 5.1 by https://github.com/rails/rails/pull/24745/commits/aa062318c451512035c10898a1af95943b1a3803
if
Rails
.
version
.
start_with?
(
"5.1"
)
if
Rails
.
gem_version
>=
Gem
::
Version
.
new
(
"5.1"
)
raise
"Remove this monkey patch:
#{
__FILE__
}
"
raise
"Remove this monkey patch:
#{
__FILE__
}
"
end
end
...
...
config/initializers/active_record_locking.rb
View file @
e0cf5941
# rubocop:disable Lint/RescueException
# rubocop:disable Lint/RescueException
# Remove this monkey-patch when all lock_version values are converted from NULLs to zeros.
# Remove this monkey patch when we move to Rails 5.1, because the bug has been fixed in https://github.com/rails/rails/pull/26050.
# See https://gitlab.com/gitlab-org/gitlab-ce/issues/25228
if
Rails
.
gem_version
>=
Gem
::
Version
.
new
(
"5.1"
)
raise
"Remove this monkey patch:
#{
__FILE__
}
"
end
module
ActiveRecord
module
ActiveRecord
module
Locking
module
Locking
module
Optimistic
module
Optimistic
...
@@ -16,12 +19,7 @@ module ActiveRecord
...
@@ -16,12 +19,7 @@ module ActiveRecord
return
0
if
attribute_names
.
empty?
return
0
if
attribute_names
.
empty?
lock_col
=
self
.
class
.
locking_column
lock_col
=
self
.
class
.
locking_column
previous_lock_value
=
send
(
lock_col
).
to_i
previous_lock_value
=
send
(
lock_col
).
to_i
# This line is added as a patch
previous_lock_value
=
nil
if
previous_lock_value
==
'0'
||
previous_lock_value
==
0
increment_lock
increment_lock
attribute_names
+=
[
lock_col
]
attribute_names
+=
[
lock_col
]
...
@@ -32,7 +30,8 @@ module ActiveRecord
...
@@ -32,7 +30,8 @@ module ActiveRecord
affected_rows
=
relation
.
where
(
affected_rows
=
relation
.
where
(
self
.
class
.
primary_key
=>
id
,
self
.
class
.
primary_key
=>
id
,
lock_col
=>
previous_lock_value
# Patched because when `lock_version` is read as `0`, it may actually be `NULL` in the DB.
lock_col
=>
previous_lock_value
==
0
?
[
nil
,
0
]
:
previous_lock_value
).
update_all
(
).
update_all
(
attributes_for_update
(
attribute_names
).
map
do
|
name
|
attributes_for_update
(
attribute_names
).
map
do
|
name
|
[
name
,
_read_attribute
(
name
)]
[
name
,
_read_attribute
(
name
)]
...
...
spec/initializers/active_record_locking_spec.rb
0 → 100644
View file @
e0cf5941
# frozen_string_literal: true
require
'spec_helper'
describe
'ActiveRecord locking'
do
let
(
:issue
)
{
create
(
:issue
)
}
shared_examples
'locked model'
do
before
do
issue
.
update_column
(
:lock_version
,
start_lock_version
)
end
it
'can be updated'
do
issue
.
update
(
title:
"New title"
)
expect
(
issue
.
reload
.
lock_version
).
to
eq
(
new_lock_version
)
end
it
'can be deleted'
do
expect
{
issue
.
destroy
}.
to
change
{
Issue
.
count
}.
by
(
-
1
)
end
end
context
'when lock_version is NULL'
do
let
(
:start_lock_version
)
{
nil
}
let
(
:new_lock_version
)
{
1
}
it_behaves_like
'locked model'
end
context
'when lock_version is 0'
do
let
(
:start_lock_version
)
{
0
}
let
(
:new_lock_version
)
{
1
}
it_behaves_like
'locked model'
end
context
'when lock_version is 1'
do
let
(
:start_lock_version
)
{
1
}
let
(
:new_lock_version
)
{
2
}
it_behaves_like
'locked model'
end
end
spec/services/ci/register_job_service_spec.rb
View file @
e0cf5941
...
@@ -244,7 +244,9 @@ module Ci
...
@@ -244,7 +244,9 @@ module Ci
context
'when first build is stalled'
do
context
'when first build is stalled'
do
before
do
before
do
pending_job
.
update
(
lock_version:
0
)
allow_any_instance_of
(
Ci
::
RegisterJobService
).
to
receive
(
:assign_runner!
).
and_call_original
allow_any_instance_of
(
Ci
::
RegisterJobService
).
to
receive
(
:assign_runner!
)
.
with
(
pending_job
,
anything
).
and_raise
(
ActiveRecord
::
StaleObjectError
)
end
end
subject
{
described_class
.
new
(
specific_runner
).
execute
}
subject
{
described_class
.
new
(
specific_runner
).
execute
}
...
...
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