Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
milvus
milvus
提交
b3f965c7
M
milvus
项目概览
milvus
/
milvus
10 个月 前同步成功
通知
260
Star
22476
Fork
2472
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
milvus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
b3f965c7
编写于
9月 18, 2021
作者:
G
godchen
提交者:
GitHub
9月 18, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add unrecoverable error for retry. (#7828)
Signed-off-by:
N
godchen
<
qingxiang.chen@zilliz.com
>
上级
37715a56
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
36 addition
and
14 deletion
+36
-14
internal/rootcoord/root_coord_test.go
internal/rootcoord/root_coord_test.go
+3
-3
internal/rootcoord/suffix_snapshot.go
internal/rootcoord/suffix_snapshot.go
+1
-1
internal/util/retry/options.go
internal/util/retry/options.go
+1
-1
internal/util/retry/retry.go
internal/util/retry/retry.go
+17
-9
internal/util/retry/retry_test.go
internal/util/retry/retry_test.go
+14
-0
未找到文件。
internal/rootcoord/root_coord_test.go
浏览文件 @
b3f965c7
...
...
@@ -406,7 +406,7 @@ type loadPrefixFailKV struct {
// LoadWithPrefix override behavior
func
(
kv
*
loadPrefixFailKV
)
LoadWithPrefix
(
key
string
)
([]
string
,
[]
string
,
error
)
{
return
[]
string
{},
[]
string
{},
retry
.
NoRetryError
(
errors
.
New
(
"mocked fail"
))
return
[]
string
{},
[]
string
{},
retry
.
Unrecoverable
(
errors
.
New
(
"mocked fail"
))
}
func
TestRootCoordInit
(
t
*
testing
.
T
)
{
...
...
@@ -441,7 +441,7 @@ func TestRootCoordInit(t *testing.T) {
err
=
core
.
Register
()
assert
.
Nil
(
t
,
err
)
core
.
kvBaseCreate
=
func
(
string
)
(
kv
.
TxnKV
,
error
)
{
return
nil
,
retry
.
NoRetryError
(
errors
.
New
(
"injected"
))
return
nil
,
retry
.
Unrecoverable
(
errors
.
New
(
"injected"
))
}
err
=
core
.
Init
()
assert
.
NotNil
(
t
,
err
)
...
...
@@ -459,7 +459,7 @@ func TestRootCoordInit(t *testing.T) {
assert
.
Nil
(
t
,
err
)
core
.
kvBaseCreate
=
func
(
root
string
)
(
kv
.
TxnKV
,
error
)
{
if
root
==
Params
.
MetaRootPath
{
return
nil
,
retry
.
NoRetryError
(
errors
.
New
(
"injected"
))
return
nil
,
retry
.
Unrecoverable
(
errors
.
New
(
"injected"
))
}
return
memkv
.
NewMemoryKV
(),
nil
}
...
...
internal/rootcoord/suffix_snapshot.go
浏览文件 @
b3f965c7
...
...
@@ -76,7 +76,7 @@ var _ kv.SnapShotKV = (*suffixSnapshot)(nil)
// newSuffixSnapshot creates a newSuffixSnapshot with provided kv
func
newSuffixSnapshot
(
txnKV
kv
.
TxnKV
,
sep
,
root
,
snapshot
string
)
(
*
suffixSnapshot
,
error
)
{
if
txnKV
==
nil
{
return
nil
,
retry
.
NoRetryError
(
errors
.
New
(
"txnKV is nil"
))
return
nil
,
retry
.
Unrecoverable
(
errors
.
New
(
"txnKV is nil"
))
}
// handles trailing / logic
...
...
internal/util/retry/options.go
浏览文件 @
b3f965c7
...
...
@@ -19,7 +19,7 @@ type Config struct {
maxSleepTime
time
.
Duration
}
func
N
ewDefaultConfig
()
*
Config
{
func
n
ewDefaultConfig
()
*
Config
{
return
&
Config
{
attempts
:
uint
(
10
),
sleep
:
200
*
time
.
Millisecond
,
...
...
internal/util/retry/retry.go
浏览文件 @
b3f965c7
...
...
@@ -20,20 +20,19 @@ import (
func
Do
(
ctx
context
.
Context
,
fn
func
()
error
,
opts
...
Option
)
error
{
c
:=
N
ewDefaultConfig
()
c
:=
n
ewDefaultConfig
()
for
_
,
opt
:=
range
opts
{
opt
(
c
)
}
el
:=
make
(
ErrorList
,
c
.
attempts
)
el
:=
make
(
ErrorList
,
0
)
for
i
:=
uint
(
0
);
i
<
c
.
attempts
;
i
++
{
if
err
:=
fn
();
err
!=
nil
{
if
s
,
ok
:=
err
.
(
InterruptErro
r
);
ok
{
return
s
.
erro
r
if
ok
:=
IsUncoverable
(
er
r
);
ok
{
return
er
r
}
// TODO early termination if this is unretriable error?
el
[
i
]
=
err
el
=
append
(
el
,
err
)
select
{
case
<-
time
.
After
(
c
.
sleep
)
:
...
...
@@ -52,9 +51,11 @@ func Do(ctx context.Context, fn func() error, opts ...Option) error {
return
el
}
// ErrorList for print error log
type
ErrorList
[]
error
// TODO shouldn't print all retries, might be too much
// Error method return an string representation of retry error list.
func
(
el
ErrorList
)
Error
()
string
{
var
builder
strings
.
Builder
builder
.
WriteString
(
"All attempts results:
\n
"
)
...
...
@@ -68,10 +69,17 @@ func (el ErrorList) Error() string {
return
builder
.
String
()
}
type
Interrupt
Error
struct
{
type
unrecoverable
Error
struct
{
error
}
func
NoRetryError
(
err
error
)
InterruptError
{
return
InterruptError
{
err
}
// Unrecoverable method wrap an error to unrecoverableError. This will make retry
// quick return.
func
Unrecoverable
(
err
error
)
error
{
return
unrecoverableError
{
err
}
}
func
IsUncoverable
(
err
error
)
bool
{
_
,
isUnrecoverable
:=
err
.
(
unrecoverableError
)
return
isUnrecoverable
}
internal/util/retry/retry_test.go
浏览文件 @
b3f965c7
...
...
@@ -85,6 +85,20 @@ func TestAllError(t *testing.T) {
fmt
.
Println
(
err
)
}
func
TestUnRecoveryError
(
t
*
testing
.
T
)
{
attempts
:=
0
ctx
:=
context
.
Background
()
testFn
:=
func
()
error
{
attempts
++
return
Unrecoverable
(
fmt
.
Errorf
(
"some error"
))
}
err
:=
Do
(
ctx
,
testFn
,
Attempts
(
3
))
assert
.
NotNil
(
t
,
err
)
assert
.
Equal
(
t
,
attempts
,
1
)
}
func
TestContextDeadline
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
1
*
time
.
Second
)
defer
cancel
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录