mirror of https://github.com/milvus-io/milvus.git
fix(db): fix mem runtime error
Former-commit-id: c12e6e99c8c7de1b62c2d2e7f9fecf3775715326pull/191/head
parent
8eebbf65b4
commit
803686b8c6
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue