Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
GitLab
管理
动态
成员
标记
计划
议题
议题看板
里程碑
迭代
需求
代码
合并请求
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
锁定的文件
构建
流水线
作业
流水线计划
测试用例
产物
部署
发布
Package registry
Container registry
模型注册表
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
贡献者分析
CI/CD 分析
仓库分析
代码评审分析
议题分析
洞察
模型实验
效能分析
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
显示更多面包屑
gitlab-cn
GitLab
提交
732ea3e8
提交
732ea3e8
编辑于
3 years ago
作者:
Kamil Trzciński
浏览文件
操作
下载
差异文件
Merge branch 'sidekiq-server-middleware-fix' into 'master'
Delayed job should retry only once See merge request gitlab-org/gitlab!60635
上级
ae97abdf
3e1a3de5
No related branches found
分支 包含提交
No related tags found
标签 包含提交
无相关合并请求
变更
2
隐藏空白变更内容
行内
左右并排
显示
2 个更改的文件
ee/lib/gitlab/database/load_balancing/sidekiq_server_middleware.rb
+7
-1
7 个添加, 1 个删除
...tlab/database/load_balancing/sidekiq_server_middleware.rb
ee/spec/lib/gitlab/database/load_balancing/sidekiq_server_middleware_spec.rb
+31
-10
31 个添加, 10 个删除
...database/load_balancing/sidekiq_server_middleware_spec.rb
有
38 个添加
和
11 个删除
ee/lib/gitlab/database/load_balancing/sidekiq_server_middleware.rb
+
7
−
1
浏览文件 @
732ea3e8
...
@@ -35,7 +35,7 @@ def requires_primary?(worker_class, job)
...
@@ -35,7 +35,7 @@ def requires_primary?(worker_class, job)
if
replica_caught_up?
(
location
)
if
replica_caught_up?
(
location
)
job
[
:database_chosen
]
=
'replica'
job
[
:database_chosen
]
=
'replica'
false
false
elsif
worker_class
.
get_data_consistency
==
:delayed
&&
job
[
'retry_count'
].
to_i
==
0
elsif
worker_class
.
get_data_consistency
==
:delayed
&&
not_yet_retried?
(
job
)
job
[
:database_chosen
]
=
'retry'
job
[
:database_chosen
]
=
'retry'
raise
JobReplicaNotUpToDate
,
"Sidekiq job
#{
worker_class
}
JID-
#{
job
[
'jid'
]
}
couldn't use the replica."
\
raise
JobReplicaNotUpToDate
,
"Sidekiq job
#{
worker_class
}
JID-
#{
job
[
'jid'
]
}
couldn't use the replica."
\
" Replica was not up to date."
" Replica was not up to date."
...
@@ -45,6 +45,12 @@ def requires_primary?(worker_class, job)
...
@@ -45,6 +45,12 @@ def requires_primary?(worker_class, job)
end
end
end
end
def
not_yet_retried?
(
job
)
# if `retry_count` is `nil` it indicates that this job was never retried
# the `0` indicates that this is a first retry
job
[
'retry_count'
].
nil?
end
def
load_balancer
def
load_balancer
LoadBalancing
.
proxy
.
load_balancer
LoadBalancing
.
proxy
.
load_balancer
end
end
...
...
此差异已折叠。
点击以展开。
ee/spec/lib/gitlab/database/load_balancing/sidekiq_server_middleware_spec.rb
+
31
−
10
浏览文件 @
732ea3e8
...
@@ -100,7 +100,7 @@ def perform(*args)
...
@@ -100,7 +100,7 @@ def perform(*args)
let
(
:queue
)
{
'default'
}
let
(
:queue
)
{
'default'
}
let
(
:redis_pool
)
{
Sidekiq
.
redis_pool
}
let
(
:redis_pool
)
{
Sidekiq
.
redis_pool
}
let
(
:worker
)
{
worker_class
.
new
}
let
(
:worker
)
{
worker_class
.
new
}
let
(
:job
)
{
{
"job_id"
=>
"a180b47c-3fd6-41b8-81e9-34da61c3400e"
,
'database_replica_location'
=>
'0/D525E3A8'
}
}
let
(
:job
)
{
{
"retry"
=>
3
,
"job_id"
=>
"a180b47c-3fd6-41b8-81e9-34da61c3400e"
,
'database_replica_location'
=>
'0/D525E3A8'
}
}
let
(
:block
)
{
10
}
let
(
:block
)
{
10
}
before
do
before
do
...
@@ -127,22 +127,37 @@ def perform(*args)
...
@@ -127,22 +127,37 @@ def perform(*args)
context
'when replica is not up to date'
do
context
'when replica is not up to date'
do
before
do
before
do
allow
(
middleware
).
to
receive
(
:replica_caught_up?
).
and_return
(
false
)
allow
(
::
Gitlab
::
Database
::
LoadBalancing
).
to
receive_message_chain
(
:proxy
,
:load_balancer
,
:release_host
)
allow
(
::
Gitlab
::
Database
::
LoadBalancing
).
to
receive_message_chain
(
:proxy
,
:load_balancer
,
:host
,
:caught_up?
).
and_return
(
false
)
end
end
context
'when job is retried once'
do
around
do
|
example
|
it
'raise an error and retries'
do
with_sidekiq_server_middleware
do
|
chain
|
expect
{
middleware
.
call
(
worker
,
job
,
double
(
:queue
))
{
block
}
}.
to
raise_error
(
Gitlab
::
Database
::
LoadBalancing
::
SidekiqServerMiddleware
::
JobReplicaNotUpToDate
)
chain
.
add
described_class
Sidekiq
::
Testing
.
disable!
{
example
.
run
}
end
end
end
end
context
'when job is retried more then once'
do
context
'when job is executed first'
do
before
do
it
'raise an error and retries'
,
:aggregate_failures
do
job
[
'retry_count'
]
=
1
expect
do
process_job
(
job
)
end
.
to
raise_error
(
Sidekiq
::
JobRetry
::
Skip
)
expect
(
job
[
'error_class'
]).
to
eq
(
'Gitlab::Database::LoadBalancing::SidekiqServerMiddleware::JobReplicaNotUpToDate'
)
expect
(
job
[
:database_chosen
]).
to
eq
(
'retry'
)
end
end
end
context
'when job is retried'
do
it
'stick to the primary'
,
:aggregate_failures
do
expect
do
process_job
(
job
)
end
.
to
raise_error
(
Sidekiq
::
JobRetry
::
Skip
)
include_examples
'stick to the primary'
process_job
(
job
)
include_examples
'job marked with chosen database'
expect
(
job
[
:database_chosen
]).
to
eq
(
'primary'
)
end
end
end
end
end
end
end
...
@@ -160,4 +175,10 @@ def perform(*args)
...
@@ -160,4 +175,10 @@ def perform(*args)
end
end
end
end
end
end
def
process_job
(
job
)
Sidekiq
::
JobRetry
.
new
.
local
(
worker_class
,
job
,
queue
)
do
worker_class
.
process_job
(
job
)
end
end
end
end
此差异已折叠。
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录