Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
milvus
提交
65583daa
milvus
项目概览
BaiXuePrincess
/
milvus
与 Fork 源项目一致
从无法访问的项目Fork
通知
7
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
milvus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
65583daa
编写于
5月 15, 2019
作者:
G
groot
提交者:
jinhai
5月 26, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
avoid add vector to invalid group
Former-commit-id: f5d04e510b5d743488be82f492aad2b95929d9e1
上级
bef742c0
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
69 addition
and
15 deletion
+69
-15
cpp/src/server/RocksIdMapper.cpp
cpp/src/server/RocksIdMapper.cpp
+40
-14
cpp/src/server/RocksIdMapper.h
cpp/src/server/RocksIdMapper.h
+4
-1
cpp/src/server/VecIdMapper.cpp
cpp/src/server/VecIdMapper.cpp
+11
-0
cpp/src/server/VecIdMapper.h
cpp/src/server/VecIdMapper.h
+6
-0
cpp/src/server/VecServiceTask.cpp
cpp/src/server/VecServiceTask.cpp
+8
-0
未找到文件。
cpp/src/server/RocksIdMapper.cpp
浏览文件 @
65583daa
...
...
@@ -18,6 +18,8 @@ namespace zilliz {
namespace
vecwise
{
namespace
server
{
static
const
std
::
string
ROCKSDB_DEFAULT_GROUP
=
"default"
;
RocksIdMapper
::
RocksIdMapper
()
:
db_
(
nullptr
)
{
OpenDb
();
...
...
@@ -90,36 +92,60 @@ void RocksIdMapper::CloseDb() {
}
}
ServerError
RocksIdMapper
::
Put
(
const
std
::
string
&
nid
,
const
std
::
string
&
sid
,
const
std
::
string
&
group
)
{
//not thread-safe
ServerError
RocksIdMapper
::
AddGroup
(
const
std
::
string
&
group
)
{
if
(
!
IsGroupExist
(
group
))
{
if
(
db_
==
nullptr
)
{
return
SERVER_NULL_POINTER
;
}
rocksdb
::
Slice
key
(
nid
);
rocksdb
::
Slice
value
(
sid
);
if
(
group
.
empty
())
{
//to default group
rocksdb
::
Status
s
=
db_
->
Put
(
rocksdb
::
WriteOptions
(),
key
,
value
);
if
(
!
s
.
ok
())
{
SERVER_LOG_ERROR
<<
"ID mapper failed to put:"
<<
s
.
ToString
();
return
SERVER_UNEXPECTED_ERROR
;
}
}
else
{
rocksdb
::
ColumnFamilyHandle
*
cfh
=
nullptr
;
if
(
column_handles_
.
count
(
group
)
==
0
)
{
try
{
//add group
rocksdb
::
ColumnFamilyHandle
*
cfh
=
nullptr
;
rocksdb
::
Status
s
=
db_
->
CreateColumnFamily
(
rocksdb
::
ColumnFamilyOptions
(),
group
,
&
cfh
);
if
(
!
s
.
ok
())
{
SERVER_LOG_ERROR
<<
"ID mapper failed to create group:"
<<
s
.
ToString
();
return
SERVER_UNEXPECTED_ERROR
;
}
else
{
column_handles_
.
insert
(
std
::
make_pair
(
group
,
cfh
));
}
}
catch
(
std
::
exception
&
ex
)
{
std
::
cout
<<
ex
.
what
()
<<
std
::
endl
;
SERVER_LOG_ERROR
<<
"ID mapper failed to create group: "
<<
ex
.
what
();
return
SERVER_UNEXPECTED_ERROR
;
}
}
return
SERVER_SUCCESS
;
}
//not thread-safe
bool
RocksIdMapper
::
IsGroupExist
(
const
std
::
string
&
group
)
const
{
std
::
string
group_name
=
group
;
if
(
group_name
.
empty
()){
group_name
=
ROCKSDB_DEFAULT_GROUP
;
}
return
(
column_handles_
.
count
(
group_name
)
>
0
&&
column_handles_
[
group_name
]
!=
nullptr
);
}
ServerError
RocksIdMapper
::
Put
(
const
std
::
string
&
nid
,
const
std
::
string
&
sid
,
const
std
::
string
&
group
)
{
if
(
db_
==
nullptr
)
{
return
SERVER_NULL_POINTER
;
}
rocksdb
::
Slice
key
(
nid
);
rocksdb
::
Slice
value
(
sid
);
if
(
group
.
empty
())
{
//to default group
rocksdb
::
Status
s
=
db_
->
Put
(
rocksdb
::
WriteOptions
(),
key
,
value
);
if
(
!
s
.
ok
())
{
SERVER_LOG_ERROR
<<
"ID mapper failed to put:"
<<
s
.
ToString
();
return
SERVER_UNEXPECTED_ERROR
;
}
}
else
{
cfh
=
column_handles_
[
group
];
//try create group
if
(
AddGroup
(
group
)
!=
SERVER_SUCCESS
){
return
SERVER_UNEXPECTED_ERROR
;
}
rocksdb
::
ColumnFamilyHandle
*
cfh
=
column_handles_
[
group
];
rocksdb
::
Status
s
=
db_
->
Put
(
rocksdb
::
WriteOptions
(),
cfh
,
key
,
value
);
if
(
!
s
.
ok
())
{
SERVER_LOG_ERROR
<<
"ID mapper failed to put:"
<<
s
.
ToString
();
...
...
cpp/src/server/RocksIdMapper.h
浏览文件 @
65583daa
...
...
@@ -23,6 +23,9 @@ public:
RocksIdMapper
();
~
RocksIdMapper
();
ServerError
AddGroup
(
const
std
::
string
&
group
)
override
;
bool
IsGroupExist
(
const
std
::
string
&
group
)
const
override
;
ServerError
Put
(
const
std
::
string
&
nid
,
const
std
::
string
&
sid
,
const
std
::
string
&
group
=
""
)
override
;
ServerError
Put
(
const
std
::
vector
<
std
::
string
>&
nid
,
const
std
::
vector
<
std
::
string
>&
sid
,
const
std
::
string
&
group
=
""
)
override
;
...
...
@@ -38,7 +41,7 @@ private:
private:
rocksdb
::
DB
*
db_
;
std
::
unordered_map
<
std
::
string
,
rocksdb
::
ColumnFamilyHandle
*>
column_handles_
;
mutable
std
::
unordered_map
<
std
::
string
,
rocksdb
::
ColumnFamilyHandle
*>
column_handles_
;
};
}
...
...
cpp/src/server/VecIdMapper.cpp
浏览文件 @
65583daa
...
...
@@ -39,6 +39,17 @@ SimpleIdMapper::~SimpleIdMapper() {
}
ServerError
SimpleIdMapper
::
AddGroup
(
const
std
::
string
&
group
)
{
if
(
id_groups_
.
count
(
group
)
==
0
)
{
id_groups_
.
insert
(
std
::
make_pair
(
group
,
ID_MAPPING
()));
}
}
//not thread-safe
bool
SimpleIdMapper
::
IsGroupExist
(
const
std
::
string
&
group
)
const
{
return
id_groups_
.
count
(
group
)
>
0
;
}
//not thread-safe
ServerError
SimpleIdMapper
::
Put
(
const
std
::
string
&
nid
,
const
std
::
string
&
sid
,
const
std
::
string
&
group
)
{
ID_MAPPING
&
mapping
=
id_groups_
[
group
];
...
...
cpp/src/server/VecIdMapper.h
浏览文件 @
65583daa
...
...
@@ -25,6 +25,9 @@ public:
virtual
~
IVecIdMapper
(){}
virtual
ServerError
AddGroup
(
const
std
::
string
&
group
)
=
0
;
virtual
bool
IsGroupExist
(
const
std
::
string
&
group
)
const
=
0
;
virtual
ServerError
Put
(
const
std
::
string
&
nid
,
const
std
::
string
&
sid
,
const
std
::
string
&
group
=
""
)
=
0
;
virtual
ServerError
Put
(
const
std
::
vector
<
std
::
string
>&
nid
,
const
std
::
vector
<
std
::
string
>&
sid
,
const
std
::
string
&
group
=
""
)
=
0
;
...
...
@@ -41,6 +44,9 @@ public:
SimpleIdMapper
();
~
SimpleIdMapper
();
ServerError
AddGroup
(
const
std
::
string
&
group
)
override
;
bool
IsGroupExist
(
const
std
::
string
&
group
)
const
override
;
ServerError
Put
(
const
std
::
string
&
nid
,
const
std
::
string
&
sid
,
const
std
::
string
&
group
=
""
)
override
;
ServerError
Put
(
const
std
::
vector
<
std
::
string
>&
nid
,
const
std
::
vector
<
std
::
string
>&
sid
,
const
std
::
string
&
group
=
""
)
override
;
...
...
cpp/src/server/VecServiceTask.cpp
浏览文件 @
65583daa
...
...
@@ -87,6 +87,7 @@ BaseTaskPtr AddGroupTask::Create(int32_t dimension,
ServerError
AddGroupTask
::
OnExecute
()
{
try
{
IVecIdMapper
::
GetInstance
()
->
AddGroup
(
group_id_
);
engine
::
meta
::
GroupSchema
group_info
;
group_info
.
dimension
=
(
size_t
)
dimension_
;
group_info
.
group_id
=
group_id_
;
...
...
@@ -243,6 +244,13 @@ const AttribMap& AddVectorTask::GetVecAttrib() const {
ServerError
AddVectorTask
::
OnExecute
()
{
try
{
if
(
!
IVecIdMapper
::
GetInstance
()
->
IsGroupExist
(
group_id_
))
{
error_code_
=
SERVER_UNEXPECTED_ERROR
;
error_msg_
=
"group not exist"
;
SERVER_LOG_ERROR
<<
error_msg_
;
return
error_code_
;
}
uint64_t
vec_dim
=
GetVecDimension
();
std
::
vector
<
float
>
vec_f
;
vec_f
.
resize
(
vec_dim
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录