Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
milvus
milvus
提交
187aff68
M
milvus
项目概览
milvus
/
milvus
大约 1 年 前同步成功
通知
261
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,发现更多精彩内容 >>
未验证
提交
187aff68
编写于
1月 10, 2023
作者:
J
jaime
提交者:
GitHub
1月 10, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Cherry-Pick]Remove redundant LoadPrefix requests for Catalog ListCollections (#21551) (#21594)
Signed-off-by:
N
jaime
<
yun.zhang@zilliz.com
>
上级
780fbc5e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
159 addition
and
43 deletion
+159
-43
internal/metastore/kv/rootcoord/kv_catalog.go
internal/metastore/kv/rootcoord/kv_catalog.go
+16
-9
internal/metastore/kv/rootcoord/kv_catalog_test.go
internal/metastore/kv/rootcoord/kv_catalog_test.go
+143
-34
未找到文件。
internal/metastore/kv/rootcoord/kv_catalog.go
浏览文件 @
187aff68
...
...
@@ -274,11 +274,8 @@ func (kc *Catalog) listFieldsAfter210(ctx context.Context, collectionID typeutil
return
fields
,
nil
}
func
(
kc
*
Catalog
)
GetCollectionByID
(
ctx
context
.
Context
,
collectionID
typeutil
.
UniqueID
,
ts
typeutil
.
Timestamp
)
(
*
model
.
Collection
,
error
)
{
collMeta
,
err
:=
kc
.
loadCollection
(
ctx
,
collectionID
,
ts
)
if
err
!=
nil
{
return
nil
,
err
}
func
(
kc
*
Catalog
)
appendPartitionAndFieldsInfo
(
ctx
context
.
Context
,
collMeta
*
pb
.
CollectionInfo
,
ts
typeutil
.
Timestamp
)
(
*
model
.
Collection
,
error
)
{
collection
:=
model
.
UnmarshalCollectionModel
(
collMeta
)
...
...
@@ -286,13 +283,13 @@ func (kc *Catalog) GetCollectionByID(ctx context.Context, collectionID typeutil.
return
collection
,
nil
}
partitions
,
err
:=
kc
.
listPartitionsAfter210
(
ctx
,
collectionID
,
ts
)
partitions
,
err
:=
kc
.
listPartitionsAfter210
(
ctx
,
collection
.
Collection
ID
,
ts
)
if
err
!=
nil
{
return
nil
,
err
}
collection
.
Partitions
=
partitions
fields
,
err
:=
kc
.
listFieldsAfter210
(
ctx
,
collectionID
,
ts
)
fields
,
err
:=
kc
.
listFieldsAfter210
(
ctx
,
collection
.
Collection
ID
,
ts
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -301,6 +298,16 @@ func (kc *Catalog) GetCollectionByID(ctx context.Context, collectionID typeutil.
return
collection
,
nil
}
func
(
kc
*
Catalog
)
GetCollectionByID
(
ctx
context
.
Context
,
collectionID
typeutil
.
UniqueID
,
ts
typeutil
.
Timestamp
)
(
*
model
.
Collection
,
error
)
{
collMeta
,
err
:=
kc
.
loadCollection
(
ctx
,
collectionID
,
ts
)
if
err
!=
nil
{
return
nil
,
err
}
return
kc
.
appendPartitionAndFieldsInfo
(
ctx
,
collMeta
,
ts
)
}
func
(
kc
*
Catalog
)
CollectionExists
(
ctx
context
.
Context
,
collectionID
typeutil
.
UniqueID
,
ts
typeutil
.
Timestamp
)
bool
{
_
,
err
:=
kc
.
GetCollectionByID
(
ctx
,
collectionID
,
ts
)
return
err
==
nil
...
...
@@ -501,7 +508,7 @@ func (kc *Catalog) ListCollections(ctx context.Context, ts typeutil.Timestamp) (
zap
.
String
(
"prefix"
,
CollectionMetaPrefix
),
zap
.
Uint64
(
"timestamp"
,
ts
),
zap
.
Error
(
err
))
return
nil
,
nil
return
nil
,
err
}
colls
:=
make
(
map
[
string
]
*
model
.
Collection
)
...
...
@@ -512,7 +519,7 @@ func (kc *Catalog) ListCollections(ctx context.Context, ts typeutil.Timestamp) (
log
.
Warn
(
"unmarshal collection info failed"
,
zap
.
Error
(
err
))
continue
}
collection
,
err
:=
kc
.
GetCollectionByID
(
ctx
,
collMeta
.
GetID
()
,
ts
)
collection
,
err
:=
kc
.
appendPartitionAndFieldsInfo
(
ctx
,
&
collMeta
,
ts
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
internal/metastore/kv/rootcoord/kv_catalog_test.go
浏览文件 @
187aff68
...
...
@@ -31,20 +31,6 @@ import (
"github.com/milvus-io/milvus/internal/util/typeutil"
)
type
MockedTxnKV
struct
{
kv
.
TxnKV
loadWithPrefixFn
func
(
key
string
)
([]
string
,
[]
string
,
error
)
}
func
(
mc
*
MockedTxnKV
)
LoadWithPrefix
(
key
string
)
([]
string
,
[]
string
,
error
)
{
return
mc
.
loadWithPrefixFn
(
key
)
}
type
MockedSnapShotKV
struct
{
mock
.
Mock
kv
.
SnapShotKV
}
var
(
indexName
=
"idx"
IndexID
=
1
...
...
@@ -58,29 +44,152 @@ var (
}
)
func
getStrIndexPb
(
t
*
testing
.
T
)
string
{
idxPB
:=
model
.
MarshalIndexModel
(
&
index
)
msg
,
err
:=
proto
.
Marshal
(
idxPB
)
assert
.
Nil
(
t
,
err
)
return
string
(
msg
)
}
func
TestCatalog_ListCollections
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
func
getStrSegIdxPb
(
idx
model
.
Index
,
newSegIdx
model
.
SegmentIndex
)
(
string
,
error
)
{
segIdxInfo
:=
&
pb
.
SegmentIndexInfo
{
CollectionID
:
idx
.
CollectionID
,
PartitionID
:
newSegIdx
.
PartitionID
,
SegmentID
:
newSegIdx
.
SegmentID
,
BuildID
:
newSegIdx
.
BuildID
,
//EnableIndex: newSegIdx.EnableIndex,
CreateTime
:
newSegIdx
.
CreateTime
,
FieldID
:
idx
.
FieldID
,
IndexID
:
idx
.
IndexID
,
coll1
:=
&
pb
.
CollectionInfo
{
ID
:
1
,
PartitionIDs
:
[]
int64
{
100
},
PartitionNames
:
[]
string
{
"0"
},
PartitionCreatedTimestamps
:
[]
uint64
{
1
},
Schema
:
&
schemapb
.
CollectionSchema
{
Name
:
"c1"
,
Fields
:
[]
*
schemapb
.
FieldSchema
{
{
FieldID
:
1
,
Name
:
"f1"
,
},
},
},
}
msg
,
err
:=
proto
.
Marshal
(
segIdxInfo
)
if
err
!=
nil
{
return
""
,
err
coll2
:=
&
pb
.
CollectionInfo
{
ID
:
2
,
Schema
:
&
schemapb
.
CollectionSchema
{
Name
:
"c1"
,
Fields
:
[]
*
schemapb
.
FieldSchema
{
{},
},
},
}
return
string
(
msg
),
nil
targetErr
:=
errors
.
New
(
"fail"
)
t
.
Run
(
"load collection with prefix fail"
,
func
(
t
*
testing
.
T
)
{
kv
:=
mocks
.
NewSnapShotKV
(
t
)
ts
:=
uint64
(
1
)
kv
.
On
(
"LoadWithPrefix"
,
CollectionMetaPrefix
,
ts
)
.
Return
(
nil
,
nil
,
targetErr
)
kc
:=
Catalog
{
Snapshot
:
kv
}
ret
,
err
:=
kc
.
ListCollections
(
ctx
,
ts
)
assert
.
ErrorIs
(
t
,
err
,
targetErr
)
assert
.
Nil
(
t
,
ret
)
})
t
.
Run
(
"list partition fail"
,
func
(
t
*
testing
.
T
)
{
kv
:=
mocks
.
NewSnapShotKV
(
t
)
ts
:=
uint64
(
1
)
bColl
,
err
:=
proto
.
Marshal
(
coll2
)
assert
.
NoError
(
t
,
err
)
kv
.
On
(
"LoadWithPrefix"
,
CollectionMetaPrefix
,
ts
)
.
Return
(
nil
,
[]
string
{
string
(
bColl
)},
nil
)
kv
.
On
(
"LoadWithPrefix"
,
mock
.
MatchedBy
(
func
(
prefix
string
)
bool
{
return
strings
.
HasPrefix
(
prefix
,
PartitionMetaPrefix
)
}),
ts
)
.
Return
(
nil
,
nil
,
targetErr
)
kc
:=
Catalog
{
Snapshot
:
kv
}
ret
,
err
:=
kc
.
ListCollections
(
ctx
,
ts
)
assert
.
ErrorIs
(
t
,
err
,
targetErr
)
assert
.
Nil
(
t
,
ret
)
})
t
.
Run
(
"list fields fail"
,
func
(
t
*
testing
.
T
)
{
kv
:=
mocks
.
NewSnapShotKV
(
t
)
ts
:=
uint64
(
1
)
bColl
,
err
:=
proto
.
Marshal
(
coll2
)
assert
.
NoError
(
t
,
err
)
kv
.
On
(
"LoadWithPrefix"
,
CollectionMetaPrefix
,
ts
)
.
Return
(
nil
,
[]
string
{
string
(
bColl
)},
nil
)
partitionMeta
:=
&
pb
.
PartitionInfo
{}
pm
,
err
:=
proto
.
Marshal
(
partitionMeta
)
assert
.
NoError
(
t
,
err
)
kv
.
On
(
"LoadWithPrefix"
,
mock
.
MatchedBy
(
func
(
prefix
string
)
bool
{
return
strings
.
HasPrefix
(
prefix
,
PartitionMetaPrefix
)
}),
ts
)
.
Return
(
nil
,
[]
string
{
string
(
pm
)},
nil
)
kv
.
On
(
"LoadWithPrefix"
,
mock
.
MatchedBy
(
func
(
prefix
string
)
bool
{
return
strings
.
HasPrefix
(
prefix
,
FieldMetaPrefix
)
}),
ts
)
.
Return
(
nil
,
nil
,
targetErr
)
kc
:=
Catalog
{
Snapshot
:
kv
}
ret
,
err
:=
kc
.
ListCollections
(
ctx
,
ts
)
assert
.
ErrorIs
(
t
,
err
,
targetErr
)
assert
.
Nil
(
t
,
ret
)
})
t
.
Run
(
"list collection ok for 210 version"
,
func
(
t
*
testing
.
T
)
{
kv
:=
mocks
.
NewSnapShotKV
(
t
)
ts
:=
uint64
(
1
)
bColl
,
err
:=
proto
.
Marshal
(
coll1
)
assert
.
NoError
(
t
,
err
)
kv
.
On
(
"LoadWithPrefix"
,
CollectionMetaPrefix
,
ts
)
.
Return
(
nil
,
[]
string
{
string
(
bColl
)},
nil
)
kc
:=
Catalog
{
Snapshot
:
kv
}
ret
,
err
:=
kc
.
ListCollections
(
ctx
,
ts
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
1
,
len
(
ret
))
modCol
:=
ret
[
"c1"
]
assert
.
Equal
(
t
,
coll1
.
ID
,
modCol
.
CollectionID
)
})
t
.
Run
(
"list collection ok for the newest version"
,
func
(
t
*
testing
.
T
)
{
kv
:=
mocks
.
NewSnapShotKV
(
t
)
ts
:=
uint64
(
1
)
bColl
,
err
:=
proto
.
Marshal
(
coll2
)
assert
.
NoError
(
t
,
err
)
kv
.
On
(
"LoadWithPrefix"
,
CollectionMetaPrefix
,
ts
)
.
Return
(
nil
,
[]
string
{
string
(
bColl
)},
nil
)
partitionMeta
:=
&
pb
.
PartitionInfo
{}
pm
,
err
:=
proto
.
Marshal
(
partitionMeta
)
assert
.
NoError
(
t
,
err
)
kv
.
On
(
"LoadWithPrefix"
,
mock
.
MatchedBy
(
func
(
prefix
string
)
bool
{
return
strings
.
HasPrefix
(
prefix
,
PartitionMetaPrefix
)
}),
ts
)
.
Return
(
nil
,
[]
string
{
string
(
pm
)},
nil
)
fieldMeta
:=
&
schemapb
.
FieldSchema
{}
fm
,
err
:=
proto
.
Marshal
(
fieldMeta
)
assert
.
NoError
(
t
,
err
)
kv
.
On
(
"LoadWithPrefix"
,
mock
.
MatchedBy
(
func
(
prefix
string
)
bool
{
return
strings
.
HasPrefix
(
prefix
,
FieldMetaPrefix
)
}),
ts
)
.
Return
(
nil
,
[]
string
{
string
(
fm
)},
nil
)
kc
:=
Catalog
{
Snapshot
:
kv
}
ret
,
err
:=
kc
.
ListCollections
(
ctx
,
ts
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
ret
)
assert
.
Equal
(
t
,
1
,
len
(
ret
))
})
}
func
TestCatalog_loadCollection
(
t
*
testing
.
T
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录