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
af84e4be
Commit
af84e4be
authored
May 06, 2021
by
Nikola Milojevic
Committed by
Kamil Trzciński
May 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't update db WAL location if already provided
parent
0ee2d125
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
0 deletions
+46
-0
ee/lib/gitlab/database/load_balancing/sidekiq_client_middleware.rb
...tlab/database/load_balancing/sidekiq_client_middleware.rb
+6
-0
ee/spec/lib/gitlab/database/load_balancing/sidekiq_client_middleware_spec.rb
...database/load_balancing/sidekiq_client_middleware_spec.rb
+40
-0
No files found.
ee/lib/gitlab/database/load_balancing/sidekiq_client_middleware.rb
View file @
af84e4be
...
...
@@ -20,6 +20,8 @@ module Gitlab
return
unless
worker_class
.
include?
(
::
ApplicationWorker
)
return
unless
worker_class
.
get_data_consistency_feature_flag_enabled?
return
if
location_already_provided?
(
job
)
job
[
'worker_data_consistency'
]
=
worker_class
.
get_data_consistency
return
if
worker_class
.
get_data_consistency
==
:always
...
...
@@ -31,6 +33,10 @@ module Gitlab
end
end
def
location_already_provided?
(
job
)
job
[
'database_replica_location'
]
||
job
[
'database_write_location'
]
end
def
load_balancer
LoadBalancing
.
proxy
.
load_balancer
end
...
...
ee/spec/lib/gitlab/database/load_balancing/sidekiq_client_middleware_spec.rb
View file @
af84e4be
...
...
@@ -82,6 +82,38 @@ RSpec.describe Gitlab::Database::LoadBalancing::SidekiqClientMiddleware do
end
end
shared_examples_for
'database location was already provided'
do
|
provided_database_location
,
other_location
|
shared_examples_for
'does not set database location again'
do
|
write_performed
|
before
do
allow
(
Gitlab
::
Database
::
LoadBalancing
::
Session
.
current
).
to
receive
(
:performed_write?
).
and_return
(
write_performed
)
end
it
'does not set database locations again'
do
middleware
.
call
(
worker_class
,
job
,
double
(
:queue
),
redis_pool
)
{
10
}
expect
(
job
[
provided_database_location
]).
to
eq
(
old_location
)
expect
(
job
[
other_location
]).
to
be_nil
end
end
let
(
:old_location
)
{
'0/D525E3A8'
}
let
(
:new_location
)
{
'AB/12345'
}
let
(
:job
)
{
{
"job_id"
=>
"a180b47c-3fd6-41b8-81e9-34da61c3400e"
,
provided_database_location
=>
old_location
}
}
before
do
allow
(
middleware
).
to
receive_message_chain
(
:load_balancer
,
:primary_write_location
).
and_return
(
new_location
)
allow
(
middleware
).
to
receive_message_chain
(
:load_balancer
,
:database_replica_location
).
and_return
(
new_location
)
end
context
"when write was performed"
do
include_examples
'does not set database location again'
,
true
end
context
"when write was not performed"
do
include_examples
'does not set database location again'
,
false
end
end
let
(
:queue
)
{
'default'
}
let
(
:redis_pool
)
{
Sidekiq
.
redis_pool
}
let
(
:worker_class
)
{
'TestDataConsistencyWorker'
}
...
...
@@ -104,6 +136,14 @@ RSpec.describe Gitlab::Database::LoadBalancing::SidekiqClientMiddleware do
include_examples
'does not pass database locations'
end
context
'database write location was already provided'
do
include_examples
'database location was already provided'
,
'database_write_location'
,
'database_replica_location'
end
context
'database replica location was already provided'
do
include_examples
'database location was already provided'
,
'database_replica_location'
,
'database_write_location'
end
context
'when worker data consistency is :always'
do
include_context
'data consistency worker class'
,
:always
,
:load_balancing_for_test_data_consistency_worker
...
...
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