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
1802e343
Commit
1802e343
authored
Mar 16, 2021
by
Quang-Minh Nguyen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address feedback in the reviews
Issue
https://gitlab.com/gitlab-org/gitlab/-/issues/322133
parent
e693ec99
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
36 deletions
+23
-36
ee/app/models/ee/application_record_helpers.rb
ee/app/models/ee/application_record_helpers.rb
+1
-5
ee/lib/gitlab/database/load_balancing/session.rb
ee/lib/gitlab/database/load_balancing/session.rb
+5
-9
ee/spec/lib/gitlab/database/load_balancing_spec.rb
ee/spec/lib/gitlab/database/load_balancing_spec.rb
+17
-22
No files found.
ee/app/models/ee/application_record_helpers.rb
View file @
1802e343
...
@@ -11,11 +11,7 @@ module EE
...
@@ -11,11 +11,7 @@ module EE
override
:with_fast_read_statement_timeout
override
:with_fast_read_statement_timeout
def
with_fast_read_statement_timeout
(
timeout_ms
=
5000
)
def
with_fast_read_statement_timeout
(
timeout_ms
=
5000
)
::
Gitlab
::
Database
::
LoadBalancing
::
Session
.
current
.
use_replica_if_possible
do
::
Gitlab
::
Database
::
LoadBalancing
::
Session
.
current
.
use_replica_if_possible
do
transaction
(
requires_new:
true
)
do
super
connection
.
exec_query
(
"SET LOCAL statement_timeout =
#{
timeout_ms
}
"
)
yield
end
end
end
end
end
end
end
...
...
ee/lib/gitlab/database/load_balancing/session.rb
View file @
1802e343
...
@@ -62,15 +62,11 @@ module Gitlab
...
@@ -62,15 +62,11 @@ module Gitlab
# - The current session already performed writes
# - The current session already performed writes
# - It prefers to use primary, aka, use_primary or use_primary! were called
# - It prefers to use primary, aka, use_primary or use_primary! were called
def
use_replica_if_possible
(
&
blk
)
def
use_replica_if_possible
(
&
blk
)
return
yield
if
use_primary?
||
performed_write?
begin
used_replica
=
@use_replica
used_replica
=
@use_replica
@use_replica
=
true
@use_replica
=
true
yield
yield
ensure
ensure
@use_replica
=
used_replica
&&
!
use_primary?
&&
!
performed_write?
@use_replica
=
used_replica
end
end
end
def
use_replica?
def
use_replica?
...
...
ee/spec/lib/gitlab/database/load_balancing_spec.rb
View file @
1802e343
...
@@ -409,14 +409,27 @@ RSpec.describe Gitlab::Database::LoadBalancing do
...
@@ -409,14 +409,27 @@ RSpec.describe Gitlab::Database::LoadBalancing do
# of the load balancer.
# of the load balancer.
# - A real model with a table backed behind is defined
# - A real model with a table backed behind is defined
# - The load balancing module is set up for this module only, as to prevent
# - The load balancing module is set up for this module only, as to prevent
# breaking other tests. The replica configura
it
on is cloned from the test
# breaking other tests. The replica configura
ti
on is cloned from the test
# configuraiton.
# configuraiton.
# - In each test, we listen to the SQL queries (via sql.active_record
# - In each test, we listen to the SQL queries (via sql.active_record
# instrumenta
it
on) while triggering real queries from the defined model.
# instrumenta
ti
on) while triggering real queries from the defined model.
# - We assert the desinations (replica/primary) of the queries in order.
# - We assert the desinations (replica/primary) of the queries in order.
describe
'LoadBalancing integration tests'
,
:delete
do
describe
'LoadBalancing integration tests'
,
:delete
do
before
(
:all
)
do
ActiveRecord
::
Schema
.
define
do
create_table
:load_balancing_test
,
force:
true
do
|
t
|
t
.
string
:name
,
null:
true
end
end
end
after
(
:all
)
do
ActiveRecord
::
Schema
.
define
do
drop_table
:load_balancing_test
,
force:
true
end
end
shared_context
'LoadBalancing setup'
do
shared_context
'LoadBalancing setup'
do
let!
(
:license
)
{
create
(
:license
,
plan:
::
License
::
PREMIUM_PLAN
)
}
let
(
:hosts
)
{
[
ActiveRecord
::
Base
.
configurations
[
"development"
][
'host'
]]
}
let
(
:hosts
)
{
[
ActiveRecord
::
Base
.
configurations
[
"development"
][
'host'
]]
}
let
(
:model
)
do
let
(
:model
)
do
Class
.
new
(
ApplicationRecord
)
do
Class
.
new
(
ApplicationRecord
)
do
...
@@ -425,11 +438,7 @@ RSpec.describe Gitlab::Database::LoadBalancing do
...
@@ -425,11 +438,7 @@ RSpec.describe Gitlab::Database::LoadBalancing do
end
end
before
do
before
do
ActiveRecord
::
Schema
.
define
do
stub_licensed_features
(
db_load_balancing:
true
)
create_table
:load_balancing_test
,
force:
true
do
|
t
|
t
.
string
:name
,
null:
true
end
end
# Preloading testing class
# Preloading testing class
model
.
singleton_class
.
prepend
::
Gitlab
::
Database
::
LoadBalancing
::
ActiveRecordProxy
model
.
singleton_class
.
prepend
::
Gitlab
::
Database
::
LoadBalancing
::
ActiveRecordProxy
...
@@ -446,9 +455,6 @@ RSpec.describe Gitlab::Database::LoadBalancing do
...
@@ -446,9 +455,6 @@ RSpec.describe Gitlab::Database::LoadBalancing do
after
do
after
do
subject
.
clear_configuration
subject
.
clear_configuration
ActiveRecord
::
Schema
.
define
do
drop_table
:load_balancing_test
,
force:
true
end
end
end
end
end
...
@@ -531,17 +537,6 @@ RSpec.describe Gitlab::Database::LoadBalancing do
...
@@ -531,17 +537,6 @@ RSpec.describe Gitlab::Database::LoadBalancing do
true
,
[
:primary
,
:primary
,
:primary
,
:primary
]
true
,
[
:primary
,
:primary
,
:primary
,
:primary
]
],
],
# Read-only transaction
[
->
{
model
.
transaction
do
model
.
first
model
.
where
(
name:
'test1'
).
to_a
end
},
true
,
[
:primary
,
:primary
,
:primary
,
:primary
]
],
# use_primary
# use_primary
[
[
->
{
->
{
...
...
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