提交 28cc9e45 编写于 作者: S starlord

refine code


Former-commit-id: 1d9e51080453544da5a6032a87618ef944bf3594
上级 dff6a341
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "Types.h" #include "Types.h"
#include <string> #include <string>
#include <memory>
namespace zilliz { namespace zilliz {
namespace milvus { namespace milvus {
...@@ -61,6 +62,8 @@ public: ...@@ -61,6 +62,8 @@ public:
}; // DB }; // DB
using DBPtr = std::shared_ptr<DB>;
} // namespace engine } // namespace engine
} // namespace milvus } // namespace milvus
} // namespace zilliz } // namespace zilliz
...@@ -3,43 +3,34 @@ ...@@ -3,43 +3,34 @@
// Unauthorized copying of this file, via any medium is strictly prohibited. // Unauthorized copying of this file, via any medium is strictly prohibited.
// Proprietary and confidential. // Proprietary and confidential.
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "DB.h" #include "DBFactory.h"
#include "src/db/meta/SqliteMetaImpl.h" #include "DBImpl.h"
#include "Exception.h"
#include "meta/MetaFactory.h"
#include "meta/SqliteMetaImpl.h"
#include "meta/MySQLMetaImpl.h" #include "meta/MySQLMetaImpl.h"
#include "Options.h"
#include "src/db/insert/MemManager.h"
#include <stdlib.h>
#include <time.h>
#include <sstream>
#include <cstdlib>
#include <string> #include <string>
#include <memory>
namespace zilliz { namespace zilliz {
namespace milvus { namespace milvus {
namespace engine { namespace engine {
struct DBMetaOptionsFactory { Options DBFactory::BuildOption() {
static DBMetaOptions Build(const std::string &path = ""); auto meta = MetaFactory::BuildOption();
}; Options options;
options.meta = meta;
struct OptionsFactory { return options;
static Options Build(); }
};
struct DBMetaImplFactory {
static std::shared_ptr<meta::SqliteMetaImpl> Build();
static std::shared_ptr<meta::Meta> Build(const DBMetaOptions &metaOptions, const int &mode);
};
struct DBFactory {
//static std::shared_ptr<DB> Build();
static DB *Build(const Options &);
};
struct MemManagerFactory { DBPtr DBFactory::Build(const Options& options) {
static MemManagerAbstractPtr Build(const std::shared_ptr<meta::Meta> &meta, const Options &options); return std::make_shared<DBImpl>(options);
}; }
} // namespace engine } // namespace engine
} // namespace milvus } // namespace milvus
......
////////////////////////////////////////////////////////////////////////////////
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
// Unauthorized copying of this file, via any medium is strictly prohibited.
// Proprietary and confidential.
////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "DB.h"
#include "Options.h"
#include <string>
#include <memory>
namespace zilliz {
namespace milvus {
namespace engine {
class DBFactory {
public:
static Options BuildOption();
static DBPtr Build(const Options& options);
};
}
}
}
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
#include "Log.h" #include "Log.h"
#include "Utils.h" #include "Utils.h"
#include "engine/EngineFactory.h" #include "engine/EngineFactory.h"
#include "Factories.h" #include "insert/MemMenagerFactory.h"
#include "meta/MetaFactory.h"
#include "metrics/Metrics.h" #include "metrics/Metrics.h"
#include "scheduler/TaskScheduler.h" #include "scheduler/TaskScheduler.h"
...@@ -44,7 +45,7 @@ DBImpl::DBImpl(const Options& options) ...@@ -44,7 +45,7 @@ DBImpl::DBImpl(const Options& options)
shutting_down_(true), shutting_down_(true),
compact_thread_pool_(1, 1), compact_thread_pool_(1, 1),
index_thread_pool_(1, 1) { index_thread_pool_(1, 1) {
meta_ptr_ = DBMetaImplFactory::Build(options.meta, options.mode); meta_ptr_ = MetaFactory::Build(options.meta, options.mode);
mem_mgr_ = MemManagerFactory::Build(meta_ptr_, options_); mem_mgr_ = MemManagerFactory::Build(meta_ptr_, options_);
Start(); Start();
} }
......
...@@ -32,8 +32,6 @@ class Meta; ...@@ -32,8 +32,6 @@ class Meta;
class DBImpl : public DB { class DBImpl : public DB {
public: public:
using MetaPtr = meta::Meta::Ptr;
explicit DBImpl(const Options &options); explicit DBImpl(const Options &options);
~DBImpl(); ~DBImpl();
...@@ -126,8 +124,8 @@ class DBImpl : public DB { ...@@ -126,8 +124,8 @@ class DBImpl : public DB {
std::thread bg_timer_thread_; std::thread bg_timer_thread_;
MetaPtr meta_ptr_; meta::MetaPtr meta_ptr_;
MemManagerAbstractPtr mem_mgr_; MemManagerPtr mem_mgr_;
std::mutex mem_serialize_mutex_; std::mutex mem_serialize_mutex_;
server::ThreadPool compact_thread_pool_; server::ThreadPool compact_thread_pool_;
......
////////////////////////////////////////////////////////////////////////////////
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
// Unauthorized copying of this file, via any medium is strictly prohibited.
// Proprietary and confidential.
////////////////////////////////////////////////////////////////////////////////
#include "Factories.h"
#include "DBImpl.h"
#include "src/db/insert/MemManagerImpl.h"
#include "Exception.h"
#include <stdlib.h>
#include <time.h>
#include <sstream>
#include <iostream>
#include <vector>
#include <assert.h>
#include <easylogging++.h>
#include <regex>
#include <cstdlib>
#include <string>
#include <algorithm>
namespace zilliz {
namespace milvus {
namespace engine {
DBMetaOptions DBMetaOptionsFactory::Build(const std::string& path) {
auto p = path;
if(p == "") {
srand(time(nullptr));
std::stringstream ss;
ss << "/tmp/" << rand();
p = ss.str();
}
DBMetaOptions meta;
meta.path = p;
return meta;
}
Options OptionsFactory::Build() {
auto meta = DBMetaOptionsFactory::Build();
Options options;
options.meta = meta;
return options;
}
std::shared_ptr<meta::SqliteMetaImpl> DBMetaImplFactory::Build() {
DBMetaOptions options = DBMetaOptionsFactory::Build();
return std::shared_ptr<meta::SqliteMetaImpl>(new meta::SqliteMetaImpl(options));
}
std::shared_ptr<meta::Meta> DBMetaImplFactory::Build(const DBMetaOptions& metaOptions,
const int& mode) {
std::string uri = metaOptions.backend_uri;
std::string dialectRegex = "(.*)";
std::string usernameRegex = "(.*)";
std::string passwordRegex = "(.*)";
std::string hostRegex = "(.*)";
std::string portRegex = "(.*)";
std::string dbNameRegex = "(.*)";
std::string uriRegexStr = dialectRegex + "\\:\\/\\/" +
usernameRegex + "\\:" +
passwordRegex + "\\@" +
hostRegex + "\\:" +
portRegex + "\\/" +
dbNameRegex;
std::regex uriRegex(uriRegexStr);
std::smatch pieces_match;
if (std::regex_match(uri, pieces_match, uriRegex)) {
std::string dialect = pieces_match[1].str();
std::transform(dialect.begin(), dialect.end(), dialect.begin(), ::tolower);
if (dialect.find("mysql") != std::string::npos) {
ENGINE_LOG_INFO << "Using MySQL";
return std::make_shared<meta::MySQLMetaImpl>(metaOptions, mode);
} else if (dialect.find("sqlite") != std::string::npos) {
ENGINE_LOG_INFO << "Using SQLite";
return std::make_shared<meta::SqliteMetaImpl>(metaOptions);
} else {
ENGINE_LOG_ERROR << "Invalid dialect in URI: dialect = " << dialect;
throw InvalidArgumentException("URI dialect is not mysql / sqlite");
}
} else {
ENGINE_LOG_ERROR << "Wrong URI format: URI = " << uri;
throw InvalidArgumentException("Wrong URI format ");
}
}
//std::shared_ptr<DB> DBFactory::Build() {
// auto options = OptionsFactory::Build();
// auto db = DBFactory::Build(options);
// return std::shared_ptr<DB>(db);
//}
DB* DBFactory::Build(const Options& options) {
return new DBImpl(options);
}
MemManagerAbstractPtr MemManagerFactory::Build(const std::shared_ptr<meta::Meta>& meta,
const Options& options) {
return std::make_shared<MemManagerImpl>(meta, options);
}
} // namespace engine
} // namespace milvus
} // namespace zilliz
...@@ -320,8 +320,8 @@ Status ExecutionEngineImpl::GpuCache(uint64_t gpu_id) { ...@@ -320,8 +320,8 @@ Status ExecutionEngineImpl::GpuCache(uint64_t gpu_id) {
Status ExecutionEngineImpl::Init() { Status ExecutionEngineImpl::Init() {
using namespace zilliz::milvus::server; using namespace zilliz::milvus::server;
ServerConfig &config = ServerConfig::GetInstance(); ServerConfig &config = ServerConfig::GetInstance();
ConfigNode server_config = config.GetConfig(CONFIG_SERVER); ConfigNode server_config = config.GetConfig(CONFIG_DB);
gpu_num_ = server_config.GetInt32Value("gpu_index", 0); gpu_num_ = server_config.GetInt32Value(CONFIG_DB_BUILD_INDEX_GPU, 0);
return Status::OK(); return Status::OK();
} }
......
#pragma once #pragma once
#include <set> #include "db/Status.h"
#include "db/Types.h"
#include <set>
#include <memory>
namespace zilliz { namespace zilliz {
namespace milvus { namespace milvus {
...@@ -25,7 +28,7 @@ class MemManager { ...@@ -25,7 +28,7 @@ class MemManager {
}; // MemManagerAbstract }; // MemManagerAbstract
using MemManagerAbstractPtr = std::shared_ptr<MemManager>; using MemManagerPtr = std::shared_ptr<MemManager>;
} // namespace engine } // namespace engine
} // namespace milvus } // namespace milvus
......
...@@ -10,7 +10,7 @@ namespace zilliz { ...@@ -10,7 +10,7 @@ namespace zilliz {
namespace milvus { namespace milvus {
namespace engine { namespace engine {
MemManagerImpl::MemTablePtr MemManagerImpl::GetMemByTable(const std::string &table_id) { MemTablePtr MemManagerImpl::GetMemByTable(const std::string &table_id) {
auto memIt = mem_id_map_.find(table_id); auto memIt = mem_id_map_.find(table_id);
if (memIt != mem_id_map_.end()) { if (memIt != mem_id_map_.end()) {
return memIt->second; return memIt->second;
...@@ -40,7 +40,7 @@ Status MemManagerImpl::InsertVectorsNoLock(const std::string &table_id, ...@@ -40,7 +40,7 @@ Status MemManagerImpl::InsertVectorsNoLock(const std::string &table_id,
IDNumbers &vector_ids) { IDNumbers &vector_ids) {
MemTablePtr mem = GetMemByTable(table_id); MemTablePtr mem = GetMemByTable(table_id);
VectorSource::Ptr source = std::make_shared<VectorSource>(n, vectors); VectorSourcePtr source = std::make_shared<VectorSource>(n, vectors);
auto status = mem->Add(source, vector_ids); auto status = mem->Add(source, vector_ids);
if (status.ok()) { if (status.ok()) {
......
...@@ -18,11 +18,9 @@ namespace engine { ...@@ -18,11 +18,9 @@ namespace engine {
class MemManagerImpl : public MemManager { class MemManagerImpl : public MemManager {
public: public:
using MetaPtr = meta::Meta::Ptr;
using Ptr = std::shared_ptr<MemManagerImpl>; using Ptr = std::shared_ptr<MemManagerImpl>;
using MemTablePtr = typename MemTable::Ptr;
MemManagerImpl(const std::shared_ptr<meta::Meta> &meta, const Options &options) MemManagerImpl(const meta::MetaPtr &meta, const Options &options)
: meta_(meta), options_(options) {} : meta_(meta), options_(options) {}
Status InsertVectors(const std::string &table_id, Status InsertVectors(const std::string &table_id,
...@@ -49,7 +47,7 @@ class MemManagerImpl : public MemManager { ...@@ -49,7 +47,7 @@ class MemManagerImpl : public MemManager {
using MemList = std::vector<MemTablePtr>; using MemList = std::vector<MemTablePtr>;
MemIdMap mem_id_map_; MemIdMap mem_id_map_;
MemList immu_mem_list_; MemList immu_mem_list_;
MetaPtr meta_; meta::MetaPtr meta_;
Options options_; Options options_;
std::mutex mutex_; std::mutex mutex_;
std::mutex serialization_mtx_; std::mutex serialization_mtx_;
......
////////////////////////////////////////////////////////////////////////////////
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
// Unauthorized copying of this file, via any medium is strictly prohibited.
// Proprietary and confidential.
////////////////////////////////////////////////////////////////////////////////
#include "MemMenagerFactory.h"
#include "MemManagerImpl.h"
#include "db/Log.h"
#include "db/Exception.h"
#include <stdlib.h>
#include <time.h>
#include <sstream>
#include <cstdlib>
#include <string>
#include <regex>
namespace zilliz {
namespace milvus {
namespace engine {
MemManagerPtr MemManagerFactory::Build(const std::shared_ptr<meta::Meta>& meta,
const Options& options) {
return std::make_shared<MemManagerImpl>(meta, options);
}
} // namespace engine
} // namespace milvus
} // namespace zilliz
////////////////////////////////////////////////////////////////////////////////
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
// Unauthorized copying of this file, via any medium is strictly prohibited.
// Proprietary and confidential.
////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "MemManager.h"
#include "db/meta/Meta.h"
namespace zilliz {
namespace milvus {
namespace engine {
class MemManagerFactory {
public:
static MemManagerPtr Build(const std::shared_ptr<meta::Meta> &meta, const Options &options);
};
}
}
}
...@@ -7,7 +7,7 @@ namespace milvus { ...@@ -7,7 +7,7 @@ namespace milvus {
namespace engine { namespace engine {
MemTable::MemTable(const std::string &table_id, MemTable::MemTable(const std::string &table_id,
const std::shared_ptr<meta::Meta> &meta, const meta::MetaPtr &meta,
const Options &options) : const Options &options) :
table_id_(table_id), table_id_(table_id),
meta_(meta), meta_(meta),
...@@ -15,18 +15,18 @@ MemTable::MemTable(const std::string &table_id, ...@@ -15,18 +15,18 @@ MemTable::MemTable(const std::string &table_id,
} }
Status MemTable::Add(VectorSource::Ptr &source, IDNumbers &vector_ids) { Status MemTable::Add(VectorSourcePtr &source, IDNumbers &vector_ids) {
while (!source->AllAdded()) { while (!source->AllAdded()) {
MemTableFile::Ptr current_mem_table_file; MemTableFilePtr current_mem_table_file;
if (!mem_table_file_list_.empty()) { if (!mem_table_file_list_.empty()) {
current_mem_table_file = mem_table_file_list_.back(); current_mem_table_file = mem_table_file_list_.back();
} }
Status status; Status status;
if (mem_table_file_list_.empty() || current_mem_table_file->IsFull()) { if (mem_table_file_list_.empty() || current_mem_table_file->IsFull()) {
MemTableFile::Ptr new_mem_table_file = std::make_shared<MemTableFile>(table_id_, meta_, options_); MemTableFilePtr new_mem_table_file = std::make_shared<MemTableFile>(table_id_, meta_, options_);
status = new_mem_table_file->Add(source, vector_ids); status = new_mem_table_file->Add(source, vector_ids);
if (status.ok()) { if (status.ok()) {
mem_table_file_list_.emplace_back(new_mem_table_file); mem_table_file_list_.emplace_back(new_mem_table_file);
...@@ -44,7 +44,7 @@ Status MemTable::Add(VectorSource::Ptr &source, IDNumbers &vector_ids) { ...@@ -44,7 +44,7 @@ Status MemTable::Add(VectorSource::Ptr &source, IDNumbers &vector_ids) {
return Status::OK(); return Status::OK();
} }
void MemTable::GetCurrentMemTableFile(MemTableFile::Ptr &mem_table_file) { void MemTable::GetCurrentMemTableFile(MemTableFilePtr &mem_table_file) {
mem_table_file = mem_table_file_list_.back(); mem_table_file = mem_table_file_list_.back();
} }
......
...@@ -12,18 +12,14 @@ namespace milvus { ...@@ -12,18 +12,14 @@ namespace milvus {
namespace engine { namespace engine {
class MemTable { class MemTable {
public: public:
using MemTableFileList = std::vector<MemTableFilePtr>;
using Ptr = std::shared_ptr<MemTable>; MemTable(const std::string &table_id, const meta::MetaPtr &meta, const Options &options);
using MemTableFileList = std::vector<MemTableFile::Ptr>;
using MetaPtr = meta::Meta::Ptr;
MemTable(const std::string &table_id, const std::shared_ptr<meta::Meta> &meta, const Options &options);
Status Add(VectorSource::Ptr &source, IDNumbers &vector_ids); Status Add(VectorSourcePtr &source, IDNumbers &vector_ids);
void GetCurrentMemTableFile(MemTableFile::Ptr &mem_table_file); void GetCurrentMemTableFile(MemTableFilePtr &mem_table_file);
size_t GetTableFileCount(); size_t GetTableFileCount();
...@@ -40,7 +36,7 @@ class MemTable { ...@@ -40,7 +36,7 @@ class MemTable {
MemTableFileList mem_table_file_list_; MemTableFileList mem_table_file_list_;
MetaPtr meta_; meta::MetaPtr meta_;
Options options_; Options options_;
...@@ -48,6 +44,8 @@ class MemTable { ...@@ -48,6 +44,8 @@ class MemTable {
}; //MemTable }; //MemTable
using MemTablePtr = std::shared_ptr<MemTable>;
} // namespace engine } // namespace engine
} // namespace milvus } // namespace milvus
} // namespace zilliz } // namespace zilliz
\ No newline at end of file
...@@ -12,7 +12,7 @@ namespace milvus { ...@@ -12,7 +12,7 @@ namespace milvus {
namespace engine { namespace engine {
MemTableFile::MemTableFile(const std::string &table_id, MemTableFile::MemTableFile(const std::string &table_id,
const std::shared_ptr<meta::Meta> &meta, const meta::MetaPtr &meta,
const Options &options) : const Options &options) :
table_id_(table_id), table_id_(table_id),
meta_(meta), meta_(meta),
...@@ -43,7 +43,7 @@ Status MemTableFile::CreateTableFile() { ...@@ -43,7 +43,7 @@ Status MemTableFile::CreateTableFile() {
return status; return status;
} }
Status MemTableFile::Add(const VectorSource::Ptr &source, IDNumbers& vector_ids) { Status MemTableFile::Add(const VectorSourcePtr &source, IDNumbers& vector_ids) {
if (table_file_schema_.dimension_ <= 0) { if (table_file_schema_.dimension_ <= 0) {
std::string err_msg = "MemTableFile::Add: table_file_schema dimension = " + std::string err_msg = "MemTableFile::Add: table_file_schema dimension = " +
......
...@@ -13,13 +13,9 @@ namespace engine { ...@@ -13,13 +13,9 @@ namespace engine {
class MemTableFile { class MemTableFile {
public: public:
MemTableFile(const std::string &table_id, const meta::MetaPtr &meta, const Options &options);
using Ptr = std::shared_ptr<MemTableFile>; Status Add(const VectorSourcePtr &source, IDNumbers& vector_ids);
using MetaPtr = meta::Meta::Ptr;
MemTableFile(const std::string &table_id, const std::shared_ptr<meta::Meta> &meta, const Options &options);
Status Add(const VectorSource::Ptr &source, IDNumbers& vector_ids);
size_t GetCurrentMem(); size_t GetCurrentMem();
...@@ -37,7 +33,7 @@ class MemTableFile { ...@@ -37,7 +33,7 @@ class MemTableFile {
meta::TableFileSchema table_file_schema_; meta::TableFileSchema table_file_schema_;
MetaPtr meta_; meta::MetaPtr meta_;
Options options_; Options options_;
...@@ -47,6 +43,8 @@ class MemTableFile { ...@@ -47,6 +43,8 @@ class MemTableFile {
}; //MemTableFile }; //MemTableFile
using MemTableFilePtr = std::shared_ptr<MemTableFile>;
} // namespace engine } // namespace engine
} // namespace milvus } // namespace milvus
} // namespace zilliz } // namespace zilliz
\ No newline at end of file
...@@ -11,11 +11,7 @@ namespace milvus { ...@@ -11,11 +11,7 @@ namespace milvus {
namespace engine { namespace engine {
class VectorSource { class VectorSource {
public: public:
using Ptr = std::shared_ptr<VectorSource>;
VectorSource(const size_t &n, const float *vectors); VectorSource(const size_t &n, const float *vectors);
Status Add(const ExecutionEnginePtr &execution_engine, Status Add(const ExecutionEnginePtr &execution_engine,
...@@ -42,6 +38,8 @@ class VectorSource { ...@@ -42,6 +38,8 @@ class VectorSource {
}; //VectorSource }; //VectorSource
using VectorSourcePtr = std::shared_ptr<VectorSource>;
} // namespace engine } // namespace engine
} // namespace milvus } // namespace milvus
} // namespace zilliz } // namespace zilliz
\ No newline at end of file
...@@ -20,8 +20,6 @@ namespace meta { ...@@ -20,8 +20,6 @@ namespace meta {
class Meta { class Meta {
public: public:
using Ptr = std::shared_ptr<Meta>;
virtual ~Meta() = default; virtual ~Meta() = default;
virtual Status CreateTable(TableSchema &table_schema) = 0; virtual Status CreateTable(TableSchema &table_schema) = 0;
...@@ -85,6 +83,8 @@ class Meta { ...@@ -85,6 +83,8 @@ class Meta {
}; // MetaData }; // MetaData
using MetaPtr = std::shared_ptr<Meta>;
} // namespace meta } // namespace meta
} // namespace engine } // namespace engine
} // namespace milvus } // namespace milvus
......
////////////////////////////////////////////////////////////////////////////////
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
// Unauthorized copying of this file, via any medium is strictly prohibited.
// Proprietary and confidential.
////////////////////////////////////////////////////////////////////////////////
#include "MetaFactory.h"
#include "SqliteMetaImpl.h"
#include "MySQLMetaImpl.h"
#include "db/Log.h"
#include "db/Exception.h"
#include <stdlib.h>
#include <time.h>
#include <sstream>
#include <cstdlib>
#include <string>
#include <regex>
namespace zilliz {
namespace milvus {
namespace engine {
DBMetaOptions MetaFactory::BuildOption(const std::string &path) {
auto p = path;
if(p == "") {
srand(time(nullptr));
std::stringstream ss;
ss << "/tmp/" << rand();
p = ss.str();
}
DBMetaOptions meta;
meta.path = p;
return meta;
}
meta::MetaPtr MetaFactory::Build(const DBMetaOptions &metaOptions, const int &mode) {
std::string uri = metaOptions.backend_uri;
std::string dialectRegex = "(.*)";
std::string usernameRegex = "(.*)";
std::string passwordRegex = "(.*)";
std::string hostRegex = "(.*)";
std::string portRegex = "(.*)";
std::string dbNameRegex = "(.*)";
std::string uriRegexStr = dialectRegex + "\\:\\/\\/" +
usernameRegex + "\\:" +
passwordRegex + "\\@" +
hostRegex + "\\:" +
portRegex + "\\/" +
dbNameRegex;
std::regex uriRegex(uriRegexStr);
std::smatch pieces_match;
if (std::regex_match(uri, pieces_match, uriRegex)) {
std::string dialect = pieces_match[1].str();
std::transform(dialect.begin(), dialect.end(), dialect.begin(), ::tolower);
if (dialect.find("mysql") != std::string::npos) {
ENGINE_LOG_INFO << "Using MySQL";
return std::make_shared<meta::MySQLMetaImpl>(metaOptions, mode);
} else if (dialect.find("sqlite") != std::string::npos) {
ENGINE_LOG_INFO << "Using SQLite";
return std::make_shared<meta::SqliteMetaImpl>(metaOptions);
} else {
ENGINE_LOG_ERROR << "Invalid dialect in URI: dialect = " << dialect;
throw InvalidArgumentException("URI dialect is not mysql / sqlite");
}
} else {
ENGINE_LOG_ERROR << "Wrong URI format: URI = " << uri;
throw InvalidArgumentException("Wrong URI format ");
}
}
} // namespace engine
} // namespace milvus
} // namespace zilliz
////////////////////////////////////////////////////////////////////////////////
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
// Unauthorized copying of this file, via any medium is strictly prohibited.
// Proprietary and confidential.
////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "Meta.h"
#include "db/Options.h"
namespace zilliz {
namespace milvus {
namespace engine {
class MetaFactory {
public:
static DBMetaOptions BuildOption(const std::string &path = "");
static meta::MetaPtr Build(const DBMetaOptions &metaOptions, const int &mode);
};
}
}
}
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "db/Utils.h" #include "db/Utils.h"
#include "db/Log.h" #include "db/Log.h"
#include "MetaConsts.h" #include "MetaConsts.h"
#include "db/Factories.h"
#include "metrics/Metrics.h" #include "metrics/Metrics.h"
#include <unistd.h> #include <unistd.h>
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "db/Utils.h" #include "db/Utils.h"
#include "db/Log.h" #include "db/Log.h"
#include "MetaConsts.h" #include "MetaConsts.h"
#include "db/Factories.h"
#include "metrics/Metrics.h" #include "metrics/Metrics.h"
#include <unistd.h> #include <unistd.h>
......
...@@ -11,7 +11,7 @@ namespace zilliz { ...@@ -11,7 +11,7 @@ namespace zilliz {
namespace milvus { namespace milvus {
namespace engine { namespace engine {
DeleteContext::DeleteContext(const std::string &table_id, meta::Meta::Ptr &meta_ptr, uint64_t num_resource) DeleteContext::DeleteContext(const std::string &table_id, meta::MetaPtr &meta_ptr, uint64_t num_resource)
: IScheduleContext(ScheduleContextType::kDelete), : IScheduleContext(ScheduleContextType::kDelete),
table_id_(table_id), table_id_(table_id),
meta_ptr_(meta_ptr), meta_ptr_(meta_ptr),
......
...@@ -16,16 +16,16 @@ namespace engine { ...@@ -16,16 +16,16 @@ namespace engine {
class DeleteContext : public IScheduleContext { class DeleteContext : public IScheduleContext {
public: public:
DeleteContext(const std::string& table_id, meta::Meta::Ptr& meta_ptr, uint64_t num_resource); DeleteContext(const std::string& table_id, meta::MetaPtr& meta_ptr, uint64_t num_resource);
std::string table_id() const { return table_id_; } std::string table_id() const { return table_id_; }
meta::Meta::Ptr meta() const { return meta_ptr_; } meta::MetaPtr meta() const { return meta_ptr_; }
void WaitAndDelete(); void WaitAndDelete();
void ResourceDone(); void ResourceDone();
private: private:
std::string table_id_; std::string table_id_;
meta::Meta::Ptr meta_ptr_; meta::MetaPtr meta_ptr_;
uint64_t num_resource_; uint64_t num_resource_;
uint64_t done_resource = 0; uint64_t done_resource = 0;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "DBWrapper.h" #include "DBWrapper.h"
#include "ServerConfig.h" #include "ServerConfig.h"
#include "db/Factories.h" #include "db/DBFactory.h"
#include "utils/CommonUtil.h" #include "utils/CommonUtil.h"
#include "utils/Log.h" #include "utils/Log.h"
#include "utils/StringHelpFunctions.h" #include "utils/StringHelpFunctions.h"
...@@ -96,8 +96,7 @@ ErrorCode DBWrapper::StartService() { ...@@ -96,8 +96,7 @@ ErrorCode DBWrapper::StartService() {
//create db instance //create db instance
std::string msg = opt.meta.path; std::string msg = opt.meta.path;
try { try {
engine::DB* db = engine::DBFactory::Build(opt); db_ = engine::DBFactory::Build(opt);
db_.reset(db);
} catch(std::exception& ex) { } catch(std::exception& ex) {
msg = ex.what(); msg = ex.what();
} }
......
...@@ -25,19 +25,19 @@ public: ...@@ -25,19 +25,19 @@ public:
return wrapper; return wrapper;
} }
static std::shared_ptr<engine::DB> DB() { static engine::DBPtr DB() {
return GetInstance().EngineDB(); return GetInstance().EngineDB();
} }
ErrorCode StartService(); ErrorCode StartService();
ErrorCode StopService(); ErrorCode StopService();
std::shared_ptr<engine::DB> EngineDB() { engine::DBPtr EngineDB() {
return db_; return db_;
} }
private: private:
std::shared_ptr<engine::DB> db_; engine::DBPtr db_;
}; };
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "db/DB.h" #include "db/DB.h"
#include "db/DBImpl.h" #include "db/DBImpl.h"
#include "db/meta/MetaConsts.h" #include "db/meta/MetaConsts.h"
#include "db/Factories.h" #include "db/DBFactory.h"
#include "cache/CpuCacheMgr.h" #include "cache/CpuCacheMgr.h"
#include "utils/CommonUtil.h" #include "utils/CommonUtil.h"
...@@ -467,11 +467,6 @@ TEST_F(DBTest2, DELETE_TEST) { ...@@ -467,11 +467,6 @@ TEST_F(DBTest2, DELETE_TEST) {
}; };
TEST_F(DBTest2, DELETE_BY_RANGE_TEST) { TEST_F(DBTest2, DELETE_BY_RANGE_TEST) {
auto options = engine::OptionsFactory::Build();
options.meta.path = "/tmp/milvus_test";
options.meta.backend_uri = "sqlite://:@:/";
auto db_ = engine::DBFactory::Build(options);
engine::meta::TableSchema table_info = BuildTableSchema(); engine::meta::TableSchema table_info = BuildTableSchema();
engine::Status stat = db_->CreateTable(table_info); engine::Status stat = db_->CreateTable(table_info);
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#include "db/insert/VectorSource.h" #include "db/insert/VectorSource.h"
#include "db/insert/MemTableFile.h" #include "db/insert/MemTableFile.h"
#include "db/insert/MemTable.h" #include "db/insert/MemTable.h"
#include "db/Factories.h"
#include "db/Constants.h" #include "db/Constants.h"
#include "db/engine/EngineFactory.h" #include "db/engine/EngineFactory.h"
#include "db/meta/MetaConsts.h" #include "db/meta/MetaConsts.h"
...@@ -106,7 +105,7 @@ TEST_F(MemManagerTest, MEM_TABLE_FILE_TEST) { ...@@ -106,7 +105,7 @@ TEST_F(MemManagerTest, MEM_TABLE_FILE_TEST) {
std::vector<float> vectors_100; std::vector<float> vectors_100;
BuildVectors(n_100, vectors_100); BuildVectors(n_100, vectors_100);
engine::VectorSource::Ptr source = std::make_shared<engine::VectorSource>(n_100, vectors_100.data()); engine::VectorSourcePtr source = std::make_shared<engine::VectorSource>(n_100, vectors_100.data());
engine::IDNumbers vector_ids; engine::IDNumbers vector_ids;
status = mem_table_file.Add(source, vector_ids); status = mem_table_file.Add(source, vector_ids);
...@@ -124,7 +123,7 @@ TEST_F(MemManagerTest, MEM_TABLE_FILE_TEST) { ...@@ -124,7 +123,7 @@ TEST_F(MemManagerTest, MEM_TABLE_FILE_TEST) {
std::vector<float> vectors_128M; std::vector<float> vectors_128M;
BuildVectors(n_max, vectors_128M); BuildVectors(n_max, vectors_128M);
engine::VectorSource::Ptr source_128M = std::make_shared<engine::VectorSource>(n_max, vectors_128M.data()); engine::VectorSourcePtr source_128M = std::make_shared<engine::VectorSource>(n_max, vectors_128M.data());
vector_ids.clear(); vector_ids.clear();
status = mem_table_file.Add(source_128M, vector_ids); status = mem_table_file.Add(source_128M, vector_ids);
...@@ -145,7 +144,7 @@ TEST_F(MemManagerTest, MEM_TABLE_TEST) { ...@@ -145,7 +144,7 @@ TEST_F(MemManagerTest, MEM_TABLE_TEST) {
std::vector<float> vectors_100; std::vector<float> vectors_100;
BuildVectors(n_100, vectors_100); BuildVectors(n_100, vectors_100);
engine::VectorSource::Ptr source_100 = std::make_shared<engine::VectorSource>(n_100, vectors_100.data()); engine::VectorSourcePtr source_100 = std::make_shared<engine::VectorSource>(n_100, vectors_100.data());
engine::MemTable mem_table(TABLE_NAME, impl_, options); engine::MemTable mem_table(TABLE_NAME, impl_, options);
...@@ -155,7 +154,7 @@ TEST_F(MemManagerTest, MEM_TABLE_TEST) { ...@@ -155,7 +154,7 @@ TEST_F(MemManagerTest, MEM_TABLE_TEST) {
vector_ids = source_100->GetVectorIds(); vector_ids = source_100->GetVectorIds();
ASSERT_EQ(vector_ids.size(), 100); ASSERT_EQ(vector_ids.size(), 100);
engine::MemTableFile::Ptr mem_table_file; engine::MemTableFilePtr mem_table_file;
mem_table.GetCurrentMemTableFile(mem_table_file); mem_table.GetCurrentMemTableFile(mem_table_file);
size_t singleVectorMem = sizeof(float) * TABLE_DIM; size_t singleVectorMem = sizeof(float) * TABLE_DIM;
ASSERT_EQ(mem_table_file->GetCurrentMem(), n_100 * singleVectorMem); ASSERT_EQ(mem_table_file->GetCurrentMem(), n_100 * singleVectorMem);
...@@ -165,7 +164,7 @@ TEST_F(MemManagerTest, MEM_TABLE_TEST) { ...@@ -165,7 +164,7 @@ TEST_F(MemManagerTest, MEM_TABLE_TEST) {
BuildVectors(n_max, vectors_128M); BuildVectors(n_max, vectors_128M);
vector_ids.clear(); vector_ids.clear();
engine::VectorSource::Ptr source_128M = std::make_shared<engine::VectorSource>(n_max, vectors_128M.data()); engine::VectorSourcePtr source_128M = std::make_shared<engine::VectorSource>(n_max, vectors_128M.data());
status = mem_table.Add(source_128M, vector_ids); status = mem_table.Add(source_128M, vector_ids);
ASSERT_TRUE(status.ok()); ASSERT_TRUE(status.ok());
...@@ -181,7 +180,7 @@ TEST_F(MemManagerTest, MEM_TABLE_TEST) { ...@@ -181,7 +180,7 @@ TEST_F(MemManagerTest, MEM_TABLE_TEST) {
std::vector<float> vectors_1G; std::vector<float> vectors_1G;
BuildVectors(n_1G, vectors_1G); BuildVectors(n_1G, vectors_1G);
engine::VectorSource::Ptr source_1G = std::make_shared<engine::VectorSource>(n_1G, vectors_1G.data()); engine::VectorSourcePtr source_1G = std::make_shared<engine::VectorSource>(n_1G, vectors_1G.data());
vector_ids.clear(); vector_ids.clear();
status = mem_table.Add(source_1G, vector_ids); status = mem_table.Add(source_1G, vector_ids);
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "utils.h" #include "utils.h"
#include "db/meta/SqliteMetaImpl.h" #include "db/meta/SqliteMetaImpl.h"
#include "db/Factories.h"
#include "db/Utils.h" #include "db/Utils.h"
#include "db/meta/MetaConsts.h" #include "db/meta/MetaConsts.h"
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "db/DB.h" #include "db/DB.h"
#include "db/DBImpl.h" #include "db/DBImpl.h"
#include "db/meta/MetaConsts.h" #include "db/meta/MetaConsts.h"
#include "db/Factories.h"
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <easylogging++.h> #include <easylogging++.h>
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "utils.h" #include "utils.h"
#include "db/meta/MySQLMetaImpl.h" #include "db/meta/MySQLMetaImpl.h"
#include "db/Factories.h"
#include "db/Utils.h" #include "db/Utils.h"
#include "db/meta/MetaConsts.h" #include "db/meta/MetaConsts.h"
......
...@@ -99,7 +99,7 @@ TEST(DBSchedulerTest, DELETE_SCHEDULER_TEST) { ...@@ -99,7 +99,7 @@ TEST(DBSchedulerTest, DELETE_SCHEDULER_TEST) {
task_list.push_back(task_ptr); task_list.push_back(task_ptr);
} }
engine::meta::Meta::Ptr meta_ptr; engine::meta::MetaPtr meta_ptr;
engine::DeleteContextPtr context_ptr = std::make_shared<engine::DeleteContext>(table_id, meta_ptr, 0); engine::DeleteContextPtr context_ptr = std::make_shared<engine::DeleteContext>(table_id, meta_ptr, 0);
ret = engine::TaskDispatchStrategy::Schedule(context_ptr, task_list); ret = engine::TaskDispatchStrategy::Schedule(context_ptr, task_list);
ASSERT_TRUE(ret); ASSERT_TRUE(ret);
......
...@@ -5,12 +5,11 @@ ...@@ -5,12 +5,11 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <iostream> #include <iostream>
#include <easylogging++.h>
#include <thread> #include <thread>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include "utils.h" #include "utils.h"
#include "db/Factories.h" #include "db/DBFactory.h"
#include "db/Options.h" #include "db/Options.h"
#include "server/ServerConfig.h" #include "server/ServerConfig.h"
#include "knowhere/index/vector_index/gpu_ivf.h" #include "knowhere/index/vector_index/gpu_ivf.h"
...@@ -56,7 +55,7 @@ void BaseTest::TearDown() { ...@@ -56,7 +55,7 @@ void BaseTest::TearDown() {
} }
engine::Options BaseTest::GetOptions() { engine::Options BaseTest::GetOptions() {
auto options = engine::OptionsFactory::Build(); auto options = engine::DBFactory::BuildOption();
options.meta.path = "/tmp/milvus_test"; options.meta.path = "/tmp/milvus_test";
options.meta.backend_uri = "sqlite://:@:/"; options.meta.backend_uri = "sqlite://:@:/";
return options; return options;
...@@ -86,7 +85,6 @@ void DBTest::SetUp() { ...@@ -86,7 +85,6 @@ void DBTest::SetUp() {
void DBTest::TearDown() { void DBTest::TearDown() {
db_->Stop(); db_->Stop();
db_->DropAll(); db_->DropAll();
delete db_;
BaseTest::TearDown(); BaseTest::TearDown();
...@@ -99,7 +97,7 @@ void DBTest::TearDown() { ...@@ -99,7 +97,7 @@ void DBTest::TearDown() {
///////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
engine::Options DBTest2::GetOptions() { engine::Options DBTest2::GetOptions() {
auto options = engine::OptionsFactory::Build(); auto options = engine::DBFactory::BuildOption();
options.meta.path = "/tmp/milvus_test"; options.meta.path = "/tmp/milvus_test";
options.meta.archive_conf = engine::ArchiveConf("delete", "disk:1"); options.meta.archive_conf = engine::ArchiveConf("delete", "disk:1");
options.meta.backend_uri = "sqlite://:@:/"; options.meta.backend_uri = "sqlite://:@:/";
...@@ -125,7 +123,7 @@ void MetaTest::TearDown() { ...@@ -125,7 +123,7 @@ void MetaTest::TearDown() {
///////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
engine::Options MySqlDBTest::GetOptions() { engine::Options MySqlDBTest::GetOptions() {
auto options = engine::OptionsFactory::Build(); auto options = engine::DBFactory::BuildOption();
options.meta.path = "/tmp/milvus_test"; options.meta.path = "/tmp/milvus_test";
options.meta.backend_uri = DBTestEnvironment::getURI(); options.meta.backend_uri = DBTestEnvironment::getURI();
...@@ -154,7 +152,7 @@ void MySqlMetaTest::TearDown() { ...@@ -154,7 +152,7 @@ void MySqlMetaTest::TearDown() {
} }
zilliz::milvus::engine::Options MySqlMetaTest::GetOptions() { zilliz::milvus::engine::Options MySqlMetaTest::GetOptions() {
auto options = engine::OptionsFactory::Build(); auto options = engine::DBFactory::BuildOption();
options.meta.path = "/tmp/milvus_test"; options.meta.path = "/tmp/milvus_test";
options.meta.backend_uri = DBTestEnvironment::getURI(); options.meta.backend_uri = DBTestEnvironment::getURI();
......
...@@ -44,7 +44,7 @@ protected: ...@@ -44,7 +44,7 @@ protected:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class DBTest : public BaseTest { class DBTest : public BaseTest {
protected: protected:
zilliz::milvus::engine::DB *db_; zilliz::milvus::engine::DBPtr db_;
virtual void SetUp() override; virtual void SetUp() override;
virtual void TearDown() override; virtual void TearDown() override;
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "utils.h" #include "utils.h"
#include "db/DB.h" #include "db/DB.h"
#include "db/meta/SqliteMetaImpl.h" #include "db/meta/SqliteMetaImpl.h"
#include "db/Factories.h"
using namespace zilliz::milvus; using namespace zilliz::milvus;
......
...@@ -5,13 +5,11 @@ ...@@ -5,13 +5,11 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <iostream> #include <iostream>
#include <easylogging++.h>
#include <thread> #include <thread>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include "utils.h" #include "utils.h"
#include "db/Factories.h" #include "db/DBFactory.h"
#include "db/Options.h"
INITIALIZE_EASYLOGGINGPP INITIALIZE_EASYLOGGINGPP
...@@ -43,7 +41,7 @@ void MetricTest::InitLog() { ...@@ -43,7 +41,7 @@ void MetricTest::InitLog() {
} }
engine::Options MetricTest::GetOptions() { engine::Options MetricTest::GetOptions() {
auto options = engine::OptionsFactory::Build(); auto options = engine::DBFactory::BuildOption();
options.meta.path = "/tmp/milvus_test"; options.meta.path = "/tmp/milvus_test";
options.meta.backend_uri = "sqlite://:@:/"; options.meta.backend_uri = "sqlite://:@:/";
return options; return options;
...@@ -56,7 +54,7 @@ void MetricTest::SetUp() { ...@@ -56,7 +54,7 @@ void MetricTest::SetUp() {
} }
void MetricTest::TearDown() { void MetricTest::TearDown() {
delete db_; db_->Stop();
boost::filesystem::remove_all("/tmp/milvus_test"); boost::filesystem::remove_all("/tmp/milvus_test");
} }
......
...@@ -55,7 +55,7 @@ void ASSERT_STATS(zilliz::milvus::engine::Status& stat); ...@@ -55,7 +55,7 @@ void ASSERT_STATS(zilliz::milvus::engine::Status& stat);
class MetricTest : public ::testing::Test { class MetricTest : public ::testing::Test {
protected: protected:
zilliz::milvus::engine::DB* db_; zilliz::milvus::engine::DBPtr db_;
void InitLog(); void InitLog();
virtual void SetUp() override; virtual void SetUp() override;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册