diff --git a/cpp/src/db/DB.cpp b/cpp/src/db/DB.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b30f48146454c56d591167f5ce3e87015e8713d0 --- /dev/null +++ b/cpp/src/db/DB.cpp @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved + * Unauthorized copying of this file, via any medium is strictly prohibited. + * Proprietary and confidential. + ******************************************************************************/ + +#include "DBImpl.h" +#include "DBMetaImpl.h" +#include "Env.h" +/* #include "FaissExecutionEngine.h" */ +/* #include "Traits.h" */ +#include "Factories.h" + +namespace zilliz { +namespace vecwise { +namespace engine { + +DB::~DB() {} + +void DB::Open(const Options& options, DB** dbptr) { + *dbptr = nullptr; + /* *dbptr = new DBImpl>(options); */ + *dbptr = DBFactory::Build(options); + return; +} + +} // namespace engine +} // namespace vecwise +} // namespace zilliz diff --git a/cpp/src/db/DBImpl.cpp b/cpp/src/db/DBImpl.cpp index 10d1d58463419d9119a38c423918d488ee8f7d61..80f433e98b4e8d454fe28510e4d26c507ab4f736 100644 --- a/cpp/src/db/DBImpl.cpp +++ b/cpp/src/db/DBImpl.cpp @@ -3,6 +3,8 @@ * Unauthorized copying of this file, via any medium is strictly prohibited. * Proprietary and confidential. ******************************************************************************/ +#ifndef DBIMPL_CPP__ +#define DBIMPL_CPP__ #include #include @@ -16,8 +18,6 @@ #include "DBImpl.h" #include "DBMetaImpl.h" #include "Env.h" -#include "FaissExecutionEngine.h" -#include "Traits.h" namespace zilliz { namespace vecwise { @@ -408,18 +408,8 @@ DBImpl::~DBImpl() { _env->Stop(); } -/* - * DB - */ - -DB::~DB() {} - -void DB::Open(const Options& options, DB** dbptr) { - *dbptr = nullptr; - *dbptr = new DBImpl>(options); - return; -} - } // namespace engine } // namespace vecwise } // namespace zilliz + +#endif diff --git a/cpp/src/db/DBImpl.h b/cpp/src/db/DBImpl.h index a03f7ffced80eb9c5df60e4212e32704409dc644..8896a1d48b3aa03ff97847e63f4866e89cc10982 100644 --- a/cpp/src/db/DBImpl.h +++ b/cpp/src/db/DBImpl.h @@ -12,6 +12,8 @@ #include "DB.h" #include "MemManager.h" #include "Types.h" +#include "FaissExecutionEngine.h" +#include "Traits.h" namespace zilliz { namespace vecwise { @@ -90,6 +92,9 @@ private: }; // DBImpl + } // namespace engine } // namespace vecwise } // namespace zilliz + +#include "DBImpl.cpp" diff --git a/cpp/src/db/Factories.cpp b/cpp/src/db/Factories.cpp index 3f508a6a0512259621efbbf37b14f3fb400d5683..87aae6afbbac91a41836d4d7e52c31eaddd17614 100644 --- a/cpp/src/db/Factories.cpp +++ b/cpp/src/db/Factories.cpp @@ -6,8 +6,15 @@ #include #include #include +#include +#include +#include +#include #include "Factories.h" +#include "DBImpl.h" +#include "FaissExecutionEngine.h" +#include "Traits.h" namespace zilliz { @@ -39,6 +46,30 @@ std::shared_ptr DBMetaImplFactory::Build() { return std::shared_ptr(new meta::DBMetaImpl(options)); } +std::shared_ptr DBFactory::Build(const std::string& db_type) { + auto options = OptionsFactory::Build(); + auto db = DBFactory::Build(options, db_type); + return std::shared_ptr(db); +} + +DB* DBFactory::Build(const Options& options, const std::string& db_type) { + std::stringstream ss(db_type); + std::string token; + std::vector tokens; + while (std::getline(ss, token, ',')) { + tokens.push_back(token); + } + + assert(tokens.size()==2); + assert(tokens[0]=="Faiss"); + if (tokens[1] == "IVF") { + return new DBImpl>(options); + } else if (tokens[1] == "IDMap") { + return new DBImpl>(options); + } + return nullptr; +} + } // namespace engine } // namespace vecwise } // namespace zilliz diff --git a/cpp/src/db/Factories.h b/cpp/src/db/Factories.h index ed584daa1e1f3483f4a77fe98297aa0e1342681e..3c9c3a99aa58192fbfff1280fbc677c165dee207 100644 --- a/cpp/src/db/Factories.h +++ b/cpp/src/db/Factories.h @@ -8,8 +8,9 @@ #include #include -#include "db/DB.h" +#include "DB.h" #include "DBMetaImpl.h" +#include "Options.h" namespace zilliz { namespace vecwise { @@ -27,6 +28,11 @@ struct DBMetaImplFactory { static std::shared_ptr Build(); }; +struct DBFactory { + static std::shared_ptr Build(const std::string& db_type = "Faiss,IVF"); + static DB* Build(const Options&, const std::string& db_type = "Faiss,IVF"); +}; + } // namespace engine } // namespace vecwise } // namespace zilliz diff --git a/cpp/unittest/db/utils.cpp b/cpp/unittest/db/utils.cpp index 5080a88cfd055a63f68bbe9e5ee30e6c074c50a4..7188e89107b30fdf2b98837f834327101f240e51 100644 --- a/cpp/unittest/db/utils.cpp +++ b/cpp/unittest/db/utils.cpp @@ -33,12 +33,11 @@ void DBTest::SetUp() { InitLog(); auto options = engine::OptionsFactory::Build(); options.meta.path = "/tmp/vecwise_test"; - engine::DB::Open(options, &db_); + db_ = engine::DBFactory::Build(options, "Faiss,IDMap"); } void DBTest::TearDown() { delete db_; - db_ = nullptr; auto options = engine::OptionsFactory::Build(); boost::filesystem::remove_all("/tmp/vecwise_test"); }