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
41c5f5a6
Commit
41c5f5a6
authored
Jun 25, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
acfa84f0
32806aee
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
16 deletions
+18
-16
config/initializers/forbid_sidekiq_in_transactions.rb
config/initializers/forbid_sidekiq_in_transactions.rb
+1
-1
lib/after_commit_queue.rb
lib/after_commit_queue.rb
+1
-13
lib/gitlab/database.rb
lib/gitlab/database.rb
+16
-2
No files found.
config/initializers/forbid_sidekiq_in_transactions.rb
View file @
41c5f5a6
...
...
@@ -17,7 +17,7 @@ module Sidekiq
module
NoEnqueueingFromTransactions
%i(perform_async perform_at perform_in)
.
each
do
|
name
|
define_method
(
name
)
do
|*
args
|
if
!
Sidekiq
::
Worker
.
skip_transaction_check
&&
AfterCommitQueu
e
.
inside_transaction?
if
!
Sidekiq
::
Worker
.
skip_transaction_check
&&
Gitlab
::
Databas
e
.
inside_transaction?
begin
raise
Sidekiq
::
Worker
::
EnqueueFromTransactionError
,
<<~
MSG
`
#{
self
}
.
#{
name
}
` cannot be called inside a transaction as this can lead to
...
...
lib/after_commit_queue.rb
View file @
41c5f5a6
...
...
@@ -15,7 +15,7 @@ module AfterCommitQueue
end
def
run_after_commit_or_now
(
&
block
)
if
AfterCommitQueu
e
.
inside_transaction?
if
Gitlab
::
Databas
e
.
inside_transaction?
if
ActiveRecord
::
Base
.
connection
.
current_transaction
.
records
.
include?
(
self
)
run_after_commit
(
&
block
)
else
...
...
@@ -32,18 +32,6 @@ module AfterCommitQueue
true
end
def
self
.
open_transactions_baseline
if
::
Rails
.
env
.
test?
return
DatabaseCleaner
.
connections
.
count
{
|
conn
|
conn
.
strategy
.
is_a?
(
DatabaseCleaner
::
ActiveRecord
::
Transaction
)
}
end
0
end
def
self
.
inside_transaction?
ActiveRecord
::
Base
.
connection
.
open_transactions
>
open_transactions_baseline
end
protected
def
_run_after_commit_queue
...
...
lib/gitlab/database.rb
View file @
41c5f5a6
...
...
@@ -234,6 +234,7 @@ module Gitlab
def
self
.
connection
ActiveRecord
::
Base
.
connection
end
private_class_method
:connection
def
self
.
cached_column_exists?
(
table_name
,
column_name
)
connection
.
schema_cache
.
columns_hash
(
table_name
).
has_key?
(
column_name
.
to_s
)
...
...
@@ -243,8 +244,6 @@ module Gitlab
connection
.
schema_cache
.
data_source_exists?
(
table_name
)
end
private_class_method
:connection
def
self
.
database_version
row
=
connection
.
execute
(
"SELECT VERSION()"
).
first
...
...
@@ -272,6 +271,21 @@ module Gitlab
end
end
end
# inside_transaction? will return true if the caller is running within a transaction. Handles special cases
# when running inside a test environment, in which the entire test is running with a DatabaseCleaner transaction
def
self
.
inside_transaction?
ActiveRecord
::
Base
.
connection
.
open_transactions
>
open_transactions_baseline
end
def
self
.
open_transactions_baseline
if
::
Rails
.
env
.
test?
return
DatabaseCleaner
.
connections
.
count
{
|
conn
|
conn
.
strategy
.
is_a?
(
DatabaseCleaner
::
ActiveRecord
::
Transaction
)
}
end
0
end
private_class_method
:open_transactions_baseline
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