diff --git a/cpp/src/db/memvectors.cpp b/cpp/src/db/memvectors.cpp index f76589a628f60f62adaca9c0e95b3fd449d5da62..abc6b67dfd8066666eab2b4e24948073f57eb9d9 100644 --- a/cpp/src/db/memvectors.cpp +++ b/cpp/src/db/memvectors.cpp @@ -1,19 +1,21 @@ -#include -#include -#include +#include +#include +#include #include "memvectors.h" #include "db_meta.h" -namespace vecengine { +namespace zilliz { +namespace vecwise { +namespace engine { MemVectors::MemVectors(size_t dimension_, const std::string& file_location_) : - _file_location(file_location_), + _file_location(file_location_.c_str()), _pIdGenerator(new SimpleIDGenerator()), _dimension(dimension_), _pInnerIndex(new faiss::IndexFlat(_dimension)), - _pIdMapIndex = new faiss::IndexIDMap(_pInnerIndex) { + _pIdMapIndex(new faiss::IndexIDMap(_pInnerIndex)) { } void MemVectors::add(size_t n_, const float* vectors_, IDNumbers& vector_ids_) { @@ -52,14 +54,14 @@ MemVectors::~MemVectors() { * MemManager */ -VectorsPtr MemManager::get_mem_by_group(const std::string& group_id_) { - auto memIt = _memMap.find(group_id_); - if memIt != _memMap.end() { - return &(memIt->second); +VectorsPtr MemManager::get_mem_by_group(const std::string& group_id) { + auto memIt = _memMap.find(group_id); + if (memIt != _memMap.end()) { + return memIt->second; } GroupSchema group_info; - Status status = _pMeta->get_group(group_id_, group_info); + Status status = _pMeta->get_group(group_id, group_info); if (!status.ok()) { return nullptr; } @@ -76,15 +78,17 @@ Status MemManager::add_vectors(const std::string& group_id_, return add_vectors_no_lock(group_id_, n_, vectors_, vector_ids_); } -Status MemManager::add_vectors_no_lock(const std::string& group_id_, +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_); + IDNumbers& vector_ids) { + auto mem = get_mem_by_group(group_id); if (mem == nullptr) { - return Status::NotFound("Group " + group_id_ " not found!"); + return Status::NotFound("Group " + group_id + " not found!"); } - return mem->add(n, vectors, vector_ids_); + mem->add(n, vectors, vector_ids); + + return Status::OK(); } Status MemManager::mark_memory_as_immutable() { @@ -111,11 +115,13 @@ Status MemManager::mark_memory_as_immutable() { Status MemManager::serialize() { mark_memory_as_immutable(); for (auto& mem : _immMems) { - mem->serialize() + mem->serialize(); } _immMems.clear(); /* _last_compact_time = std::time(nullptr); */ } -} // namespace vecengine +} // namespace engine +} // namespace vecwise +} // namespace zilliz diff --git a/cpp/src/db/memvectors.h b/cpp/src/db/memvectors.h index 034d039010be0ab5771fdc7ae1607d4a264e25f9..f60f37af88651e67c2732b0497c58e9bcf8442d3 100644 --- a/cpp/src/db/memvectors.h +++ b/cpp/src/db/memvectors.h @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include "id_generators.h" #include "status.h" @@ -21,7 +23,7 @@ class MemVectors { public: explicit MemVectors(size_t dimension_, const std::string& file_location_); - IDNumbers&& add(size_t n, const float* vectors); + void add(size_t n_, const float* vectors_, IDNumbers& vector_ids_); size_t total() const; @@ -32,7 +34,7 @@ public: ~MemVectors(); private: - std::string _file_location; + const char* _file_location; IDGenerator* _pIdGenerator; size_t _dimension; faiss::Index* _pInnerIndex; @@ -42,10 +44,10 @@ private: class Meta; +typedef std::shared_ptr VectorsPtr; class MemManager { public: - typedef std::shared_ptr VectorsPtr; MemManager(const std::shared_ptr& meta_) : _pMeta(meta_), _last_compact_time(std::time(nullptr)) {} @@ -59,6 +61,7 @@ public: private: Status add_vectors_no_lock(const std::string& group_id_, size_t n_, const float* vectors_, IDNumbers& vector_ids_); + Status mark_memory_as_immutable(); typedef std::map MemMap; typedef std::vector ImmMemPool; diff --git a/cpp/src/db/options.cpp b/cpp/src/db/options.cpp index dd28cdb7ddab78977463552a9d3273a032eb1c6e..be572c232f62d87af019d2e098c9d49c68ab0421 100644 --- a/cpp/src/db/options.cpp +++ b/cpp/src/db/options.cpp @@ -1,4 +1,5 @@ #include "options.h" +#include "env.h" namespace zilliz { namespace vecwise { diff --git a/cpp/src/db/options.h b/cpp/src/db/options.h index aefd094edfc5e584ebb152bb45a44dabace39361..807bae38b256830a1f8a8e9cb132b849d76a562d 100644 --- a/cpp/src/db/options.h +++ b/cpp/src/db/options.h @@ -1,5 +1,4 @@ -#ifndef VECENGINE_OPTIONS_H_ -#define VECENGINE_OPTIONS_H_ +#pragma once #include #include @@ -12,6 +11,7 @@ class MetaOptions; class Env; struct Options { + Options(); uint16_t memory_sync_interval = 10; uint16_t raw_file_merge_trigger_number = 100; size_t raw_to_index_trigger_size = 100000; @@ -39,5 +39,3 @@ struct DBMetaOptions : public MetaOptions { } // namespace engine } // namespace vecwise } // namespace zilliz - -#endif // VECENGINE_OPTIONS_H_ diff --git a/cpp/src/db/types.h b/cpp/src/db/types.h index 7fd33a0787ff74833d9ef03b9a22aa4f19d9d0cf..c9ed274defe7537baf471a42d43a37fa674dc1d6 100644 --- a/cpp/src/db/types.h +++ b/cpp/src/db/types.h @@ -6,7 +6,7 @@ namespace zilliz { namespace vecwise { namespace engine { -typedef uint64_t IDNumber; +typedef long IDNumber; typedef IDNumber* IDNumberPtr; typedef std::vector IDNumbers;