Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
milvus
milvus
提交
6663e753
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 搜索 >>
未验证
提交
6663e753
编写于
8月 03, 2023
作者:
J
jaime
提交者:
GitHub
8月 03, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Check if database exists when Connect was called (#26115)
Signed-off-by:
N
jaime
<
yun.zhang@zilliz.com
>
上级
517fb952
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
137 addition
and
2 deletion
+137
-2
internal/proxy/impl.go
internal/proxy/impl.go
+43
-0
internal/proxy/impl_test.go
internal/proxy/impl_test.go
+94
-2
未找到文件。
internal/proxy/impl.go
浏览文件 @
6663e753
...
...
@@ -48,6 +48,7 @@ import (
"github.com/milvus-io/milvus/pkg/util/commonpbutil"
"github.com/milvus-io/milvus/pkg/util/crypto"
"github.com/milvus-io/milvus/pkg/util/errorutil"
"github.com/milvus-io/milvus/pkg/util/funcutil"
"github.com/milvus-io/milvus/pkg/util/logutil"
"github.com/milvus-io/milvus/pkg/util/merr"
"github.com/milvus-io/milvus/pkg/util/metricsinfo"
...
...
@@ -5161,8 +5162,50 @@ func (node *Proxy) Connect(ctx context.Context, request *milvuspb.ConnectRequest
return
&
milvuspb
.
ConnectResponse
{
Status
:
unhealthyStatus
()},
nil
}
db
:=
GetCurDBNameFromContextOrDefault
(
ctx
)
logsToBePrinted
:=
append
(
getLoggerOfClientInfo
(
request
.
GetClientInfo
()),
zap
.
String
(
"db"
,
db
))
log
:=
log
.
Ctx
(
ctx
)
.
With
(
logsToBePrinted
...
)
log
.
Info
(
"connect received"
)
resp
,
err
:=
node
.
rootCoord
.
ListDatabases
(
ctx
,
&
milvuspb
.
ListDatabasesRequest
{
Base
:
commonpbutil
.
NewMsgBase
(
commonpbutil
.
WithMsgType
(
commonpb
.
MsgType_ListDatabases
),
),
})
if
err
!=
nil
{
log
.
Info
(
"connect failed, failed to list databases"
,
zap
.
Error
(
err
))
return
&
milvuspb
.
ConnectResponse
{
Status
:
&
commonpb
.
Status
{
ErrorCode
:
commonpb
.
ErrorCode_UnexpectedError
,
Reason
:
err
.
Error
(),
},
},
nil
}
if
resp
.
GetStatus
()
.
GetErrorCode
()
!=
commonpb
.
ErrorCode_Success
{
log
.
Info
(
"connect failed, failed to list databases"
,
zap
.
String
(
"code"
,
resp
.
GetStatus
()
.
GetErrorCode
()
.
String
()),
zap
.
String
(
"reason"
,
resp
.
GetStatus
()
.
GetReason
()))
return
&
milvuspb
.
ConnectResponse
{
Status
:
proto
.
Clone
(
resp
.
GetStatus
())
.
(
*
commonpb
.
Status
),
},
nil
}
if
!
funcutil
.
SliceContain
(
resp
.
GetDbNames
(),
db
)
{
log
.
Info
(
"connect failed, target database not exist"
)
return
&
milvuspb
.
ConnectResponse
{
Status
:
&
commonpb
.
Status
{
ErrorCode
:
commonpb
.
ErrorCode_UnexpectedError
,
// DatabaseNotExist?
Reason
:
fmt
.
Sprintf
(
"database not found: %s"
,
db
),
},
},
nil
}
ts
,
err
:=
node
.
tsoAllocator
.
AllocOne
(
ctx
)
if
err
!=
nil
{
log
.
Info
(
"connect failed, failed to allocate timestamp"
,
zap
.
Error
(
err
))
return
&
milvuspb
.
ConnectResponse
{
Status
:
&
commonpb
.
Status
{
ErrorCode
:
commonpb
.
ErrorCode_UnexpectedError
,
...
...
internal/proxy/impl_test.go
浏览文件 @
6663e753
...
...
@@ -23,6 +23,7 @@ import (
"github.com/cockroachdb/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"google.golang.org/grpc/metadata"
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
...
...
@@ -585,7 +586,80 @@ func TestProxy_Connect(t *testing.T) {
assert
.
NotEqual
(
t
,
commonpb
.
ErrorCode_Success
,
resp
.
GetStatus
()
.
GetErrorCode
())
})
t
.
Run
(
"failed to list database"
,
func
(
t
*
testing
.
T
)
{
r
:=
mocks
.
NewRootCoord
(
t
)
r
.
On
(
"ListDatabases"
,
mock
.
Anything
,
mock
.
Anything
,
)
.
Return
(
nil
,
errors
.
New
(
"error mock ListDatabases"
))
node
:=
&
Proxy
{
rootCoord
:
r
}
node
.
UpdateStateCode
(
commonpb
.
StateCode_Healthy
)
resp
,
err
:=
node
.
Connect
(
context
.
TODO
(),
nil
)
assert
.
NoError
(
t
,
err
)
assert
.
NotEqual
(
t
,
commonpb
.
ErrorCode_Success
,
resp
.
GetStatus
()
.
GetErrorCode
())
})
t
.
Run
(
"list database error"
,
func
(
t
*
testing
.
T
)
{
r
:=
mocks
.
NewRootCoord
(
t
)
r
.
On
(
"ListDatabases"
,
mock
.
Anything
,
mock
.
Anything
,
)
.
Return
(
&
milvuspb
.
ListDatabasesResponse
{
Status
:
unhealthyStatus
(),
},
nil
)
node
:=
&
Proxy
{
rootCoord
:
r
}
node
.
UpdateStateCode
(
commonpb
.
StateCode_Healthy
)
resp
,
err
:=
node
.
Connect
(
context
.
TODO
(),
nil
)
assert
.
NoError
(
t
,
err
)
assert
.
NotEqual
(
t
,
commonpb
.
ErrorCode_Success
,
resp
.
GetStatus
()
.
GetErrorCode
())
})
t
.
Run
(
"database not found"
,
func
(
t
*
testing
.
T
)
{
md
:=
metadata
.
New
(
map
[
string
]
string
{
"dbName"
:
"20230525"
,
})
ctx
:=
metadata
.
NewIncomingContext
(
context
.
TODO
(),
md
)
r
:=
mocks
.
NewRootCoord
(
t
)
r
.
On
(
"ListDatabases"
,
mock
.
Anything
,
mock
.
Anything
,
)
.
Return
(
&
milvuspb
.
ListDatabasesResponse
{
Status
:
&
commonpb
.
Status
{
ErrorCode
:
commonpb
.
ErrorCode_Success
,
},
DbNames
:
[]
string
{},
},
nil
)
node
:=
&
Proxy
{
rootCoord
:
r
}
node
.
UpdateStateCode
(
commonpb
.
StateCode_Healthy
)
resp
,
err
:=
node
.
Connect
(
ctx
,
nil
)
assert
.
NoError
(
t
,
err
)
assert
.
NotEqual
(
t
,
commonpb
.
ErrorCode_Success
,
resp
.
GetStatus
()
.
GetErrorCode
())
})
t
.
Run
(
"failed to allocate ts"
,
func
(
t
*
testing
.
T
)
{
md
:=
metadata
.
New
(
map
[
string
]
string
{
"dbName"
:
"20230525"
,
})
ctx
:=
metadata
.
NewIncomingContext
(
context
.
TODO
(),
md
)
r
:=
mocks
.
NewRootCoord
(
t
)
r
.
On
(
"ListDatabases"
,
mock
.
Anything
,
mock
.
Anything
,
)
.
Return
(
&
milvuspb
.
ListDatabasesResponse
{
Status
:
&
commonpb
.
Status
{
ErrorCode
:
commonpb
.
ErrorCode_Success
,
},
DbNames
:
[]
string
{
"20230525"
},
},
nil
)
m
:=
newMockTimestampAllocator
(
t
)
m
.
On
(
"AllocTimestamp"
,
mock
.
Anything
,
...
...
@@ -594,14 +668,31 @@ func TestProxy_Connect(t *testing.T) {
alloc
,
_
:=
newTimestampAllocator
(
m
,
199
)
node
:=
Proxy
{
tsoAllocator
:
alloc
,
rootCoord
:
r
,
}
node
.
UpdateStateCode
(
commonpb
.
StateCode_Healthy
)
resp
,
err
:=
node
.
Connect
(
c
ontext
.
TODO
()
,
nil
)
resp
,
err
:=
node
.
Connect
(
c
tx
,
nil
)
assert
.
NoError
(
t
,
err
)
assert
.
NotEqual
(
t
,
commonpb
.
ErrorCode_Success
,
resp
.
GetStatus
()
.
GetErrorCode
())
})
t
.
Run
(
"normal case"
,
func
(
t
*
testing
.
T
)
{
md
:=
metadata
.
New
(
map
[
string
]
string
{
"dbName"
:
"20230525"
,
})
ctx
:=
metadata
.
NewIncomingContext
(
context
.
TODO
(),
md
)
r
:=
mocks
.
NewRootCoord
(
t
)
r
.
On
(
"ListDatabases"
,
mock
.
Anything
,
mock
.
Anything
,
)
.
Return
(
&
milvuspb
.
ListDatabasesResponse
{
Status
:
&
commonpb
.
Status
{
ErrorCode
:
commonpb
.
ErrorCode_Success
,
},
DbNames
:
[]
string
{
"20230525"
},
},
nil
)
m
:=
newMockTimestampAllocator
(
t
)
m
.
On
(
"AllocTimestamp"
,
mock
.
Anything
,
...
...
@@ -616,9 +707,10 @@ func TestProxy_Connect(t *testing.T) {
alloc
,
_
:=
newTimestampAllocator
(
m
,
199
)
node
:=
Proxy
{
tsoAllocator
:
alloc
,
rootCoord
:
r
,
}
node
.
UpdateStateCode
(
commonpb
.
StateCode_Healthy
)
resp
,
err
:=
node
.
Connect
(
c
ontext
.
TODO
()
,
&
milvuspb
.
ConnectRequest
{
resp
,
err
:=
node
.
Connect
(
c
tx
,
&
milvuspb
.
ConnectRequest
{
ClientInfo
:
&
commonpb
.
ClientInfo
{},
})
assert
.
NoError
(
t
,
err
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录