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
e09cbde6
Commit
e09cbde6
authored
Aug 25, 2021
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lower subtransactions loggging thresholds
parent
3458f39e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
46 deletions
+9
-46
lib/gitlab/database/transaction/context.rb
lib/gitlab/database/transaction/context.rb
+9
-20
spec/lib/gitlab/database/transaction/context_spec.rb
spec/lib/gitlab/database/transaction/context_spec.rb
+0
-26
No files found.
lib/gitlab/database/transaction/context.rb
View file @
e09cbde6
...
...
@@ -6,9 +6,8 @@ module Gitlab
class
Context
attr_reader
:context
LOG_DEPTH_THRESHOLD
=
4
# 3 nested subtransactions + 1 real transaction
LOG_SAVEPOINTS_THRESHOLD
=
5
# 5 `SAVEPOINTS` created in sequence or nested
LOG_DURATION_S_THRESHOLD
=
120
# 2 minutes long transaction
LOG_SAVEPOINTS_THRESHOLD
=
1
# 1 `SAVEPOINT` created in a transaction
LOG_DURATION_S_THRESHOLD
=
120
# transaction that is running for 2 minutes or longer
LOG_THROTTLE_DURATION
=
1
def
initialize
...
...
@@ -19,6 +18,10 @@ module Gitlab
@context
[
:start_time
]
=
current_timestamp
end
def
set_depth
(
depth
)
@context
[
:depth
]
=
[
@context
[
:depth
].
to_i
,
depth
].
max
end
def
increment_savepoints
@context
[
:savepoints
]
=
@context
[
:savepoints
].
to_i
+
1
end
...
...
@@ -31,10 +34,6 @@ module Gitlab
@context
[
:releases
]
=
@context
[
:releases
].
to_i
+
1
end
def
set_depth
(
depth
)
@context
[
:depth
]
=
[
@context
[
:depth
].
to_i
,
depth
].
max
end
def
track_sql
(
sql
)
(
@context
[
:queries
]
||=
[]).
push
(
sql
)
end
...
...
@@ -45,10 +44,6 @@ module Gitlab
current_timestamp
-
@context
[
:start_time
]
end
def
depth_threshold_exceeded?
@context
[
:depth
].
to_i
>=
LOG_DEPTH_THRESHOLD
end
def
savepoints_threshold_exceeded?
@context
[
:savepoints
].
to_i
>=
LOG_SAVEPOINTS_THRESHOLD
end
...
...
@@ -57,16 +52,10 @@ module Gitlab
duration
.
to_i
>=
LOG_DURATION_S_THRESHOLD
end
def
log_savepoints?
depth_threshold_exceeded?
||
savepoints_threshold_exceeded?
end
def
log_duration?
duration_threshold_exceeded?
end
def
should_log?
!
logged_already?
&&
(
log_savepoints?
||
log_duration?
)
return
false
if
logged_already?
savepoints_threshold_exceeded?
||
duration_threshold_exceeded?
end
def
commit
...
...
spec/lib/gitlab/database/transaction/context_spec.rb
View file @
e09cbde6
...
...
@@ -70,24 +70,6 @@ RSpec.describe Gitlab::Database::Transaction::Context do
it
{
expect
(
subject
.
duration
).
to
be
>=
0
}
end
context
'when depth is low'
do
it
'does not log data upon COMMIT'
do
expect
(
subject
).
not_to
receive
(
:application_info
)
subject
.
commit
end
it
'does not log data upon ROLLBACK'
do
expect
(
subject
).
not_to
receive
(
:application_info
)
subject
.
rollback
end
it
'#should_log? returns false'
do
expect
(
subject
.
should_log?
).
to
be
false
end
end
shared_examples
'logs transaction data'
do
it
'logs once upon COMMIT'
do
expect
(
subject
).
to
receive
(
:application_info
).
and_call_original
...
...
@@ -116,14 +98,6 @@ RSpec.describe Gitlab::Database::Transaction::Context do
end
end
context
'when depth exceeds threshold'
do
before
do
subject
.
set_depth
(
described_class
::
LOG_DEPTH_THRESHOLD
+
1
)
end
it_behaves_like
'logs transaction data'
end
context
'when savepoints count exceeds threshold'
do
before
do
data
[
:savepoints
]
=
described_class
::
LOG_SAVEPOINTS_THRESHOLD
+
1
...
...
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