Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
milvus
milvus
提交
803686b8
M
milvus
项目概览
milvus
/
milvus
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
803686b8
编写于
4月 15, 2019
作者:
X
Xu Peng
提交者:
xj.lin
4月 16, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(db): fix mem runtime error
Former-commit-id: c12e6e99c8c7de1b62c2d2e7f9fecf3775715326
上级
8eebbf65
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
25 addition
and
7 deletion
+25
-7
cpp/src/db/memvectors.cpp
cpp/src/db/memvectors.cpp
+16
-4
cpp/src/db/memvectors.h
cpp/src/db/memvectors.h
+9
-3
未找到文件。
cpp/src/db/memvectors.cpp
浏览文件 @
803686b8
...
...
@@ -2,6 +2,8 @@
#include <faiss/MetaIndexes.h>
#include <faiss/index_io.h>
#include <iostream>
#include <sstream>
#include <thread>
#include "memvectors.h"
#include "db_meta.h"
...
...
@@ -12,7 +14,7 @@ namespace vecwise {
namespace
engine
{
MemVectors
::
MemVectors
(
size_t
dimension_
,
const
std
::
string
&
file_location_
)
:
_file_location
(
file_location_
.
c_str
()
),
_file_location
(
file_location_
),
_pIdGenerator
(
new
SimpleIDGenerator
()),
_dimension
(
dimension_
),
_pInnerIndex
(
new
faiss
::
IndexFlat
(
_dimension
)),
...
...
@@ -20,8 +22,11 @@ MemVectors::MemVectors(size_t dimension_, const std::string& file_location_) :
}
void
MemVectors
::
add
(
size_t
n_
,
const
float
*
vectors_
,
IDNumbers
&
vector_ids_
)
{
vector_ids_
=
_pIdGenerator
->
getNextIDNumbers
(
n
_
);
_pIdGenerator
->
getNextIDNumbers
(
n_
,
vector_ids
_
);
_pIdMapIndex
->
add_with_ids
(
n_
,
vectors_
,
&
vector_ids_
[
0
]);
for
(
auto
i
=
0
;
i
<
n_
;
i
++
)
{
vector_ids_
.
push_back
(
i
);
}
}
size_t
MemVectors
::
total
()
const
{
...
...
@@ -33,7 +38,12 @@ size_t MemVectors::approximate_size() const {
}
void
MemVectors
::
serialize
()
{
faiss
::
write_index
(
_pIdMapIndex
,
_file_location
);
/* std::stringstream ss; */
/* ss << "/tmp/test/" << _pIdGenerator->getNextIDNumber(); */
/* faiss::write_index(_pIdMapIndex, ss.str().c_str()); */
/* std::cout << _pIdMapIndex->ntotal << std::endl; */
/* std::cout << _file_location << std::endl; */
faiss
::
write_index
(
_pIdMapIndex
,
_file_location
.
c_str
());
}
MemVectors
::~
MemVectors
()
{
...
...
@@ -66,6 +76,7 @@ VectorsPtr MemManager::get_mem_by_group(const std::string& group_id) {
if
(
!
status
.
ok
())
{
return
nullptr
;
}
_memMap
[
group_id
]
=
std
::
shared_ptr
<
MemVectors
>
(
new
MemVectors
(
group_info
.
dimension
,
group_info
.
next_file_location
));
return
_memMap
[
group_id
];
...
...
@@ -83,7 +94,7 @@ Status MemManager::add_vectors_no_lock(const std::string& group_id,
size_t
n
,
const
float
*
vectors
,
IDNumbers
&
vector_ids
)
{
auto
mem
=
get_mem_by_group
(
group_id
);
std
::
shared_ptr
<
MemVectors
>
mem
=
get_mem_by_group
(
group_id
);
if
(
mem
==
nullptr
)
{
return
Status
::
NotFound
(
"Group "
+
group_id
+
" not found!"
);
}
...
...
@@ -97,6 +108,7 @@ Status MemManager::mark_memory_as_immutable() {
for
(
auto
&
kv
:
_memMap
)
{
_immMems
.
push_back
(
kv
.
second
);
}
_memMap
.
clear
();
return
Status
::
OK
();
}
...
...
cpp/src/db/memvectors.h
浏览文件 @
803686b8
...
...
@@ -33,8 +33,14 @@ public:
~
MemVectors
();
const
std
::
string
&
location
()
const
{
return
_file_location
;
}
private:
const
char
*
_file_location
;
MemVectors
()
=
delete
;
MemVectors
(
const
MemVectors
&
)
=
delete
;
MemVectors
&
operator
=
(
const
MemVectors
&
)
=
delete
;
const
std
::
string
_file_location
;
IDGenerator
*
_pIdGenerator
;
size_t
_dimension
;
faiss
::
Index
*
_pInnerIndex
;
...
...
@@ -49,7 +55,7 @@ typedef std::shared_ptr<MemVectors> VectorsPtr;
class
MemManager
{
public:
MemManager
(
const
std
::
shared_ptr
<
Meta
>&
meta_
)
:
_pMeta
(
meta_
)
,
_last_compact_time
(
std
::
time
(
nullptr
))
{}
:
_pMeta
(
meta_
)
/*_last_compact_time(std::time(nullptr))*/
{}
VectorsPtr
get_mem_by_group
(
const
std
::
string
&
group_id_
);
...
...
@@ -68,7 +74,7 @@ private:
MemMap
_memMap
;
ImmMemPool
_immMems
;
std
::
shared_ptr
<
Meta
>
_pMeta
;
std
::
time_t
_last_compact_time
;
/* std::time_t _last_compact_time; */
std
::
mutex
_mutex
;
};
// MemManager
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录