From ff120dba166e3503f5e669fe333630731744f34e Mon Sep 17 00:00:00 2001 From: Xu Peng Date: Mon, 15 Apr 2019 15:45:33 +0800 Subject: [PATCH] fix(db): fix compile error Former-commit-id: dbf6519efd3a0bac6f8ef2c617fcc08b879543f4 --- cpp/src/db/memvectors.cpp | 42 ++++++++++++++++++++++----------------- cpp/src/db/memvectors.h | 9 ++++++--- cpp/src/db/options.cpp | 1 + cpp/src/db/options.h | 6 ++---- cpp/src/db/types.h | 2 +- 5 files changed, 34 insertions(+), 26 deletions(-) diff --git a/cpp/src/db/memvectors.cpp b/cpp/src/db/memvectors.cpp index f76589a6..abc6b67d 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 034d0390..f60f37af 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 dd28cdb7..be572c23 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 aefd094e..807bae38 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 7fd33a07..c9ed274d 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; -- GitLab