Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
milvus
提交
bf8e7545
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,发现更多精彩内容 >>
提交
bf8e7545
编写于
5月 19, 2019
作者:
G
groot
提交者:
jinhai
5月 26, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
avoid potential multi-threads risk
Former-commit-id: 6e54134e4249003ce651eaf8ec2642d8898d34f0
上级
224fae75
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
104 addition
and
46 deletion
+104
-46
cpp/src/server/RocksIdMapper.cpp
cpp/src/server/RocksIdMapper.cpp
+90
-46
cpp/src/server/RocksIdMapper.h
cpp/src/server/RocksIdMapper.h
+14
-0
未找到文件。
cpp/src/server/RocksIdMapper.cpp
浏览文件 @
bf8e7545
...
@@ -30,6 +30,8 @@ RocksIdMapper::~RocksIdMapper() {
...
@@ -30,6 +30,8 @@ RocksIdMapper::~RocksIdMapper() {
}
}
void
RocksIdMapper
::
OpenDb
()
{
void
RocksIdMapper
::
OpenDb
()
{
std
::
lock_guard
<
std
::
mutex
>
lck
(
db_mutex_
);
if
(
db_
)
{
if
(
db_
)
{
return
;
return
;
}
}
...
@@ -81,6 +83,8 @@ void RocksIdMapper::OpenDb() {
...
@@ -81,6 +83,8 @@ void RocksIdMapper::OpenDb() {
}
}
void
RocksIdMapper
::
CloseDb
()
{
void
RocksIdMapper
::
CloseDb
()
{
std
::
lock_guard
<
std
::
mutex
>
lck
(
db_mutex_
);
for
(
auto
&
iter
:
column_handles_
)
{
for
(
auto
&
iter
:
column_handles_
)
{
delete
iter
.
second
;
delete
iter
.
second
;
}
}
...
@@ -92,9 +96,86 @@ void RocksIdMapper::CloseDb() {
...
@@ -92,9 +96,86 @@ void RocksIdMapper::CloseDb() {
}
}
}
}
//not thread-safe
ServerError
RocksIdMapper
::
AddGroup
(
const
std
::
string
&
group
)
{
ServerError
RocksIdMapper
::
AddGroup
(
const
std
::
string
&
group
)
{
if
(
!
IsGroupExist
(
group
))
{
std
::
lock_guard
<
std
::
mutex
>
lck
(
db_mutex_
);
return
AddGroupInternal
(
group
);
}
bool
RocksIdMapper
::
IsGroupExist
(
const
std
::
string
&
group
)
const
{
std
::
lock_guard
<
std
::
mutex
>
lck
(
db_mutex_
);
return
IsGroupExistInternal
(
group
);
}
ServerError
RocksIdMapper
::
Put
(
const
std
::
string
&
nid
,
const
std
::
string
&
sid
,
const
std
::
string
&
group
)
{
std
::
lock_guard
<
std
::
mutex
>
lck
(
db_mutex_
);
return
PutInternal
(
nid
,
sid
,
group
);
}
ServerError
RocksIdMapper
::
Put
(
const
std
::
vector
<
std
::
string
>&
nid
,
const
std
::
vector
<
std
::
string
>&
sid
,
const
std
::
string
&
group
)
{
if
(
nid
.
size
()
!=
sid
.
size
())
{
return
SERVER_INVALID_ARGUMENT
;
}
std
::
lock_guard
<
std
::
mutex
>
lck
(
db_mutex_
);
ServerError
err
=
SERVER_SUCCESS
;
for
(
size_t
i
=
0
;
i
<
nid
.
size
();
i
++
)
{
err
=
PutInternal
(
nid
[
i
],
sid
[
i
],
group
);
if
(
err
!=
SERVER_SUCCESS
)
{
return
err
;
}
}
return
err
;
}
ServerError
RocksIdMapper
::
Get
(
const
std
::
string
&
nid
,
std
::
string
&
sid
,
const
std
::
string
&
group
)
const
{
std
::
lock_guard
<
std
::
mutex
>
lck
(
db_mutex_
);
return
GetInternal
(
nid
,
sid
,
group
);
}
ServerError
RocksIdMapper
::
Get
(
const
std
::
vector
<
std
::
string
>&
nid
,
std
::
vector
<
std
::
string
>&
sid
,
const
std
::
string
&
group
)
const
{
sid
.
clear
();
std
::
lock_guard
<
std
::
mutex
>
lck
(
db_mutex_
);
ServerError
err
=
SERVER_SUCCESS
;
for
(
size_t
i
=
0
;
i
<
nid
.
size
();
i
++
)
{
std
::
string
str_id
;
ServerError
temp_err
=
GetInternal
(
nid
[
i
],
str_id
,
group
);
if
(
temp_err
!=
SERVER_SUCCESS
)
{
sid
.
push_back
(
""
);
SERVER_LOG_ERROR
<<
"ID mapper failed to get id: "
<<
nid
[
i
];
err
=
temp_err
;
continue
;
}
sid
.
push_back
(
str_id
);
}
return
err
;
}
ServerError
RocksIdMapper
::
Delete
(
const
std
::
string
&
nid
,
const
std
::
string
&
group
)
{
std
::
lock_guard
<
std
::
mutex
>
lck
(
db_mutex_
);
return
DeleteInternal
(
nid
,
group
);
}
ServerError
RocksIdMapper
::
DeleteGroup
(
const
std
::
string
&
group
)
{
std
::
lock_guard
<
std
::
mutex
>
lck
(
db_mutex_
);
return
DeleteGroupInternal
(
group
);
}
//internal methods(whitout lock)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ServerError
RocksIdMapper
::
AddGroupInternal
(
const
std
::
string
&
group
)
{
if
(
!
IsGroupExistInternal
(
group
))
{
if
(
db_
==
nullptr
)
{
if
(
db_
==
nullptr
)
{
return
SERVER_NULL_POINTER
;
return
SERVER_NULL_POINTER
;
}
}
...
@@ -117,8 +198,7 @@ ServerError RocksIdMapper::AddGroup(const std::string& group) {
...
@@ -117,8 +198,7 @@ ServerError RocksIdMapper::AddGroup(const std::string& group) {
return
SERVER_SUCCESS
;
return
SERVER_SUCCESS
;
}
}
//not thread-safe
bool
RocksIdMapper
::
IsGroupExistInternal
(
const
std
::
string
&
group
)
const
{
bool
RocksIdMapper
::
IsGroupExist
(
const
std
::
string
&
group
)
const
{
std
::
string
group_name
=
group
;
std
::
string
group_name
=
group
;
if
(
group_name
.
empty
()){
if
(
group_name
.
empty
()){
group_name
=
ROCKSDB_DEFAULT_GROUP
;
group_name
=
ROCKSDB_DEFAULT_GROUP
;
...
@@ -126,7 +206,7 @@ bool RocksIdMapper::IsGroupExist(const std::string& group) const {
...
@@ -126,7 +206,7 @@ bool RocksIdMapper::IsGroupExist(const std::string& group) const {
return
(
column_handles_
.
count
(
group_name
)
>
0
&&
column_handles_
[
group_name
]
!=
nullptr
);
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
)
{
ServerError
RocksIdMapper
::
Put
Internal
(
const
std
::
string
&
nid
,
const
std
::
string
&
sid
,
const
std
::
string
&
group
)
{
if
(
db_
==
nullptr
)
{
if
(
db_
==
nullptr
)
{
return
SERVER_NULL_POINTER
;
return
SERVER_NULL_POINTER
;
}
}
...
@@ -141,7 +221,7 @@ ServerError RocksIdMapper::Put(const std::string& nid, const std::string& sid, c
...
@@ -141,7 +221,7 @@ ServerError RocksIdMapper::Put(const std::string& nid, const std::string& sid, c
}
}
}
else
{
}
else
{
//try create group
//try create group
if
(
AddGroup
(
group
)
!=
SERVER_SUCCESS
){
if
(
AddGroup
Internal
(
group
)
!=
SERVER_SUCCESS
){
return
SERVER_UNEXPECTED_ERROR
;
return
SERVER_UNEXPECTED_ERROR
;
}
}
...
@@ -156,23 +236,7 @@ ServerError RocksIdMapper::Put(const std::string& nid, const std::string& sid, c
...
@@ -156,23 +236,7 @@ ServerError RocksIdMapper::Put(const std::string& nid, const std::string& sid, c
return
SERVER_SUCCESS
;
return
SERVER_SUCCESS
;
}
}
ServerError
RocksIdMapper
::
Put
(
const
std
::
vector
<
std
::
string
>&
nid
,
const
std
::
vector
<
std
::
string
>&
sid
,
const
std
::
string
&
group
)
{
ServerError
RocksIdMapper
::
GetInternal
(
const
std
::
string
&
nid
,
std
::
string
&
sid
,
const
std
::
string
&
group
)
const
{
if
(
nid
.
size
()
!=
sid
.
size
())
{
return
SERVER_INVALID_ARGUMENT
;
}
ServerError
err
=
SERVER_SUCCESS
;
for
(
size_t
i
=
0
;
i
<
nid
.
size
();
i
++
)
{
err
=
Put
(
nid
[
i
],
sid
[
i
],
group
);
if
(
err
!=
SERVER_SUCCESS
)
{
return
err
;
}
}
return
err
;
}
ServerError
RocksIdMapper
::
Get
(
const
std
::
string
&
nid
,
std
::
string
&
sid
,
const
std
::
string
&
group
)
const
{
sid
=
""
;
sid
=
""
;
if
(
db_
==
nullptr
)
{
if
(
db_
==
nullptr
)
{
return
SERVER_NULL_POINTER
;
return
SERVER_NULL_POINTER
;
...
@@ -199,28 +263,8 @@ ServerError RocksIdMapper::Get(const std::string& nid, std::string& sid, const s
...
@@ -199,28 +263,8 @@ ServerError RocksIdMapper::Get(const std::string& nid, std::string& sid, const s
return
SERVER_SUCCESS
;
return
SERVER_SUCCESS
;
}
}
ServerError
RocksIdMapper
::
Get
(
const
std
::
vector
<
std
::
string
>&
nid
,
std
::
vector
<
std
::
string
>&
sid
,
const
std
::
string
&
group
)
const
{
ServerError
RocksIdMapper
::
DeleteInternal
(
const
std
::
string
&
nid
,
const
std
::
string
&
group
)
{
sid
.
clear
();
if
(
db_
==
nullptr
)
{
ServerError
err
=
SERVER_SUCCESS
;
for
(
size_t
i
=
0
;
i
<
nid
.
size
();
i
++
)
{
std
::
string
str_id
;
ServerError
temp_err
=
Get
(
nid
[
i
],
str_id
,
group
);
if
(
temp_err
!=
SERVER_SUCCESS
)
{
sid
.
push_back
(
""
);
SERVER_LOG_ERROR
<<
"ID mapper failed to get id: "
<<
nid
[
i
];
err
=
temp_err
;
continue
;
}
sid
.
push_back
(
str_id
);
}
return
err
;
}
ServerError
RocksIdMapper
::
Delete
(
const
std
::
string
&
nid
,
const
std
::
string
&
group
)
{
if
(
db_
==
nullptr
)
{
return
SERVER_NULL_POINTER
;
return
SERVER_NULL_POINTER
;
}
}
...
@@ -244,7 +288,7 @@ ServerError RocksIdMapper::Delete(const std::string& nid, const std::string& gro
...
@@ -244,7 +288,7 @@ ServerError RocksIdMapper::Delete(const std::string& nid, const std::string& gro
return
SERVER_SUCCESS
;
return
SERVER_SUCCESS
;
}
}
ServerError
RocksIdMapper
::
DeleteGroup
(
const
std
::
string
&
group
)
{
ServerError
RocksIdMapper
::
DeleteGroup
Internal
(
const
std
::
string
&
group
)
{
if
(
db_
==
nullptr
)
{
if
(
db_
==
nullptr
)
{
return
SERVER_NULL_POINTER
;
return
SERVER_NULL_POINTER
;
}
}
...
...
cpp/src/server/RocksIdMapper.h
浏览文件 @
bf8e7545
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
#include <string>
#include <string>
#include <vector>
#include <vector>
#include <unordered_map>
#include <unordered_map>
#include <mutex>
namespace
zilliz
{
namespace
zilliz
{
namespace
vecwise
{
namespace
vecwise
{
...
@@ -39,9 +40,22 @@ private:
...
@@ -39,9 +40,22 @@ private:
void
OpenDb
();
void
OpenDb
();
void
CloseDb
();
void
CloseDb
();
ServerError
AddGroupInternal
(
const
std
::
string
&
group
);
bool
IsGroupExistInternal
(
const
std
::
string
&
group
)
const
;
ServerError
PutInternal
(
const
std
::
string
&
nid
,
const
std
::
string
&
sid
,
const
std
::
string
&
group
);
ServerError
GetInternal
(
const
std
::
string
&
nid
,
std
::
string
&
sid
,
const
std
::
string
&
group
)
const
;
ServerError
DeleteInternal
(
const
std
::
string
&
nid
,
const
std
::
string
&
group
);
ServerError
DeleteGroupInternal
(
const
std
::
string
&
group
);
private:
private:
rocksdb
::
DB
*
db_
;
rocksdb
::
DB
*
db_
;
mutable
std
::
unordered_map
<
std
::
string
,
rocksdb
::
ColumnFamilyHandle
*>
column_handles_
;
mutable
std
::
unordered_map
<
std
::
string
,
rocksdb
::
ColumnFamilyHandle
*>
column_handles_
;
mutable
std
::
mutex
db_mutex_
;
};
};
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录