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
b15f7229
Commit
b15f7229
authored
Aug 18, 2021
by
Thong Kuah
Committed by
Matthias Käppler
Aug 18, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set db name when creating connection with new pool size
Changelog: fixed
parent
2597de6c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
45 additions
and
9 deletions
+45
-9
config/initializers/database_config.rb
config/initializers/database_config.rb
+1
-6
lib/gitlab/database/connection.rb
lib/gitlab/database/connection.rb
+11
-0
spec/initializers/database_config_spec.rb
spec/initializers/database_config_spec.rb
+8
-0
spec/lib/gitlab/database/connection_spec.rb
spec/lib/gitlab/database/connection_spec.rb
+14
-0
spec/support/shared_examples/metrics/active_record_subscriber_shared_examples.rb
...mples/metrics/active_record_subscriber_shared_examples.rb
+11
-3
No files found.
config/initializers/database_config.rb
View file @
b15f7229
...
...
@@ -20,12 +20,7 @@ Gitlab.ee do
end
end
db_config
=
Gitlab
::
Database
.
main
.
config
||
Rails
.
application
.
config
.
database_configuration
[
Rails
.
env
]
ActiveRecord
::
Base
.
establish_connection
(
db_config
.
merge
(
pool:
Gitlab
::
Database
.
main
.
default_pool_size
)
)
ActiveRecord
::
Base
.
establish_connection
(
Gitlab
::
Database
.
main
.
db_config_with_default_pool_size
)
Gitlab
.
ee
do
if
Gitlab
::
Runtime
.
sidekiq?
&&
Gitlab
::
Geo
.
geo_database_configured?
...
...
lib/gitlab/database/connection.rb
View file @
b15f7229
...
...
@@ -75,6 +75,17 @@ module Gitlab
adapter_name
.
casecmp
(
'postgresql'
)
==
0
end
def
db_config_with_default_pool_size
db_config_object
=
scope
.
connection_db_config
config
=
db_config_object
.
configuration_hash
.
merge
(
pool:
default_pool_size
)
ActiveRecord
::
DatabaseConfigurations
::
HashConfig
.
new
(
db_config_object
.
env_name
,
db_config_object
.
name
,
config
)
end
# Disables prepared statements for the current database connection.
def
disable_prepared_statements
scope
.
establish_connection
(
config
.
merge
(
prepared_statements:
false
))
...
...
spec/initializers/database_config_spec.rb
View file @
b15f7229
...
...
@@ -21,6 +21,14 @@ RSpec.describe 'Database config initializer' do
let
(
:max_threads
)
{
8
}
it
'retains the correct database name for the connection'
do
previous_db_name
=
Gitlab
::
Database
.
main
.
scope
.
connection
.
pool
.
db_config
.
name
subject
expect
(
Gitlab
::
Database
.
main
.
scope
.
connection
.
pool
.
db_config
.
name
).
to
eq
(
previous_db_name
)
end
context
'when no custom headroom is specified'
do
it
'sets the pool size based on the number of worker threads'
do
old
=
ActiveRecord
::
Base
.
connection_db_config
.
pool
...
...
spec/lib/gitlab/database/connection_spec.rb
View file @
b15f7229
...
...
@@ -127,6 +127,20 @@ RSpec.describe Gitlab::Database::Connection do
end
end
describe
'#db_config_with_default_pool_size'
do
it
'returns db_config with our default pool size'
do
allow
(
connection
).
to
receive
(
:default_pool_size
).
and_return
(
9
)
expect
(
connection
.
db_config_with_default_pool_size
.
pool
).
to
eq
(
9
)
end
it
'returns db_config with the correct database name'
do
db_name
=
connection
.
scope
.
connection
.
pool
.
db_config
.
name
expect
(
connection
.
db_config_with_default_pool_size
.
name
).
to
eq
(
db_name
)
end
end
describe
'#disable_prepared_statements'
do
around
do
|
example
|
original_config
=
::
Gitlab
::
Database
.
main
.
config
...
...
spec/support/shared_examples/metrics/active_record_subscriber_shared_examples.rb
View file @
b15f7229
# frozen_string_literal: true
RSpec
.
shared_examples
'store ActiveRecord info in RequestStore'
do
|
db_role
|
let
(
:db_config_name
)
{
::
Gitlab
::
Database
.
db_config_name
(
ApplicationRecord
.
connection
)
}
let
(
:db_config_name
)
{
::
Gitlab
::
Database
.
db_config_name
s
.
first
}
let
(
:expected_payload_defaults
)
do
metrics
=
...
...
@@ -14,13 +14,21 @@ RSpec.shared_examples 'store ActiveRecord info in RequestStore' do |db_role|
end
end
def
transform_hash
(
hash
,
another_hash
)
another_hash
.
each
do
|
key
,
value
|
raise
"Unexpected key:
#{
key
}
"
unless
hash
[
key
]
end
hash
.
merge
(
another_hash
)
end
it
'prevents db counters from leaking to the next transaction'
do
2
.
times
do
Gitlab
::
WithRequestStore
.
with_request_store
do
subscriber
.
sql
(
event
)
expected
=
if
db_role
==
:primary
expected_payload_defaults
.
merge
(
{
transform_hash
(
expected_payload_defaults
,
{
db_count:
record_query
?
1
:
0
,
db_write_count:
record_write_query
?
1
:
0
,
db_cached_count:
record_cached_query
?
1
:
0
,
...
...
@@ -36,7 +44,7 @@ RSpec.shared_examples 'store ActiveRecord info in RequestStore' do |db_role|
"db_primary_
#{
db_config_name
}
_wal_cached_count"
:
record_wal_query
&&
record_cached_query
?
1
:
0
})
elsif
db_role
==
:replica
expected_payload_defaults
.
merge
(
{
transform_hash
(
expected_payload_defaults
,
{
db_count:
record_query
?
1
:
0
,
db_write_count:
record_write_query
?
1
:
0
,
db_cached_count:
record_cached_query
?
1
:
0
,
...
...
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