提交 b102998a 编写于 作者: Z zhiru

update


Former-commit-id: 865e3d32a9cc754345b1ed89bdbe95cfd8232fc8
上级 c119bc36
......@@ -8,6 +8,7 @@
#include "Env.h"
#include "Log.h"
#include "EngineFactory.h"
#include "Factories.h"
#include "metrics/Metrics.h"
#include "scheduler/SearchScheduler.h"
#include "utils/TimeRecorder.h"
......@@ -130,8 +131,9 @@ DBImpl::DBImpl(const Options& options)
bg_compaction_scheduled_(false),
shutting_down_(false),
bg_build_index_started_(false),
pMeta_(new meta::DBMetaImpl(options_.meta)),
// pMeta_(new meta::DBMetaImpl(options_.meta)),
pMemMgr_(new MemManager(pMeta_, options_)) {
pMeta_ = DBMetaImplFactory::Build(options.meta);
StartTimerTasks(options_.memory_sync_interval);
}
......
......@@ -13,6 +13,8 @@
#include <vector>
#include <assert.h>
#include <easylogging++.h>
#include <regex>
#include "Exception.h"
namespace zilliz {
namespace milvus {
......@@ -43,6 +45,52 @@ std::shared_ptr<meta::DBMetaImpl> DBMetaImplFactory::Build() {
return std::shared_ptr<meta::DBMetaImpl>(new meta::DBMetaImpl(options));
}
std::shared_ptr<meta::Meta> DBMetaImplFactory::Build(const DBMetaOptions& metaOptions) {
std::string uri = metaOptions.backend_uri;
if (uri.empty()) {
//Default to sqlite if uri is empty
// return std::make_shared<meta::DBMetaImpl>(new meta::DBMetaImpl(metaOptions));
return std::shared_ptr<meta::DBMetaImpl>(new meta::DBMetaImpl(metaOptions));
}
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) {
// return std::make_shared<meta::MySQLMetaImpl>(new meta::MySQLMetaImpl(metaOptions));
return std::shared_ptr<meta::MySQLMetaImpl>(new meta::MySQLMetaImpl(metaOptions));
}
else if (dialect.find("sqlite") != std::string::npos) {
// return std::make_shared<meta::DBMetaImpl>(new meta::DBMetaImpl(metaOptions));
return std::shared_ptr<meta::DBMetaImpl>(new meta::DBMetaImpl(metaOptions));
}
else {
LOG(ERROR) << "Invalid dialect in URI: dialect = " << dialect;
throw InvalidArgumentException("URI dialect is not mysql / sqlite");
}
}
else {
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);
......
......@@ -7,6 +7,7 @@
#include "DB.h"
#include "DBMetaImpl.h"
#include "MySQLMetaImpl.h"
#include "Options.h"
#include "ExecutionEngine.h"
......@@ -27,6 +28,7 @@ struct OptionsFactory {
struct DBMetaImplFactory {
static std::shared_ptr<meta::DBMetaImpl> Build();
static std::shared_ptr<meta::Meta> Build(const DBMetaOptions& metaOptions);
};
struct DBFactory {
......
......@@ -32,11 +32,11 @@ using namespace zilliz::milvus::engine;
//}
TEST_F(MySQLTest, core) {
DBMetaOptions options;
//dialect+driver://username:password@host:port/database
options.backend_uri = "mysql://root:1234@:/test";
options.path = "/tmp/vecwise_test";
meta::MySQLMetaImpl impl(options);
// DBMetaOptions options;
// //dialect+driver://username:password@host:port/database
// options.backend_uri = "mysql://root:1234@:/test";
// options.path = "/tmp/vecwise_test";
meta::MySQLMetaImpl impl(getDBMetaOptions());
// auto status = impl.Initialize();
// ASSERT_TRUE(status.ok());
......@@ -185,10 +185,10 @@ TEST_F(MySQLTest, core) {
TEST_F(MySQLTest, GROUP_TEST) {
DBMetaOptions options;
options.backend_uri = "mysql://root:1234@:/test";
options.path = "/tmp/vecwise_test";
meta::MySQLMetaImpl impl(options);
// DBMetaOptions options;
// options.backend_uri = "mysql://root:1234@:/test";
// options.path = "/tmp/vecwise_test";
meta::MySQLMetaImpl impl(getDBMetaOptions());
auto table_id = "meta_test_group";
......@@ -219,10 +219,10 @@ TEST_F(MySQLTest, GROUP_TEST) {
TEST_F(MySQLTest, table_file_TEST) {
DBMetaOptions options;
options.backend_uri = "mysql://root:1234@:/test";
options.path = "/tmp/vecwise_test";
meta::MySQLMetaImpl impl(options);
// DBMetaOptions options;
// options.backend_uri = "mysql://root:1234@:/test";
// options.path = "/tmp/vecwise_test";
meta::MySQLMetaImpl impl(getDBMetaOptions());
auto table_id = "meta_test_group";
......@@ -277,13 +277,13 @@ TEST_F(MySQLTest, table_file_TEST) {
TEST_F(MySQLTest, ARCHIVE_TEST_DAYS) {
srand(time(0));
DBMetaOptions options;
options.path = "/tmp/vecwise_test";
DBMetaOptions options = getDBMetaOptions();
// options.path = "/tmp/vecwise_test";
int days_num = rand() % 100;
std::stringstream ss;
ss << "days:" << days_num;
options.archive_conf = ArchiveConf("delete", ss.str());
options.backend_uri = "mysql://root:1234@:/test";
// options.backend_uri = "mysql://root:1234@:/test";
meta::MySQLMetaImpl impl(options);
......@@ -329,10 +329,10 @@ TEST_F(MySQLTest, ARCHIVE_TEST_DAYS) {
}
TEST_F(MySQLTest, ARCHIVE_TEST_DISK) {
DBMetaOptions options;
options.path = "/tmp/vecwise_test";
DBMetaOptions options = getDBMetaOptions();
// options.path = "/tmp/vecwise_test";
options.archive_conf = ArchiveConf("delete", "disk:11");
options.backend_uri = "mysql://root:1234@:/test";
// options.backend_uri = "mysql://root:1234@:/test";
meta::MySQLMetaImpl impl(options);
......@@ -376,10 +376,10 @@ TEST_F(MySQLTest, ARCHIVE_TEST_DISK) {
TEST_F(MySQLTest, TABLE_FILES_TEST) {
DBMetaOptions options;
options.backend_uri = "mysql://root:1234@:/test";
options.path = "/tmp/vecwise_test";
meta::MySQLMetaImpl impl(options);
// DBMetaOptions options;
// options.backend_uri = "mysql://root:1234@:/test";
// options.path = "/tmp/vecwise_test";
meta::MySQLMetaImpl impl(getDBMetaOptions());
auto table_id = "meta_test_group";
......
......@@ -11,6 +11,7 @@
#include "utils.h"
#include "db/Factories.h"
#include "db/Options.h"
using namespace zilliz::milvus;
......@@ -61,3 +62,11 @@ void MetaTest::SetUp() {
void MetaTest::TearDown() {
impl_->DropAll();
}
zilliz::milvus::engine::DBMetaOptions MySQLTest::getDBMetaOptions() {
engine::DBMetaOptions options;
options.backend_uri = "mysql://root:1234@:/test";
options.path = "/tmp/milvus_test";
return options;
}
......@@ -8,10 +8,11 @@
#include <gtest/gtest.h>
#include <chrono>
#include <src/db/MySQLMetaImpl.h>
//#include <src/db/MySQLMetaImpl.h>
#include "db/DB.h"
#include "db/DBMetaImpl.h"
#include "db/MySQLMetaImpl.h"
#define TIMING
......@@ -60,4 +61,9 @@ protected:
class MySQLTest : public ::testing::Test {
protected:
// std::shared_ptr<zilliz::milvus::engine::meta::MySQLMetaImpl> impl_;
zilliz::milvus::engine::DBMetaOptions getDBMetaOptions();
};
class MySQLDBTest : public ::testing::Test {
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册