From 394087fd3449a696ef1d9d9da594b6b6761a7bec Mon Sep 17 00:00:00 2001 From: zhiru Date: Sun, 30 Jun 2019 10:43:06 +0800 Subject: [PATCH] update Former-commit-id: 471118fe238938668b89db35a46db446a21758a3 --- cpp/conf/server_config.yaml | 4 ++-- cpp/src/db/DBImpl.cpp | 2 +- cpp/src/db/Factories.cpp | 13 +++++++------ cpp/src/db/Factories.h | 2 +- cpp/src/db/MySQLMetaImpl.cpp | 17 +++++++++++++---- cpp/src/db/MySQLMetaImpl.h | 3 ++- cpp/src/server/DBWrapper.cpp | 4 ++++ 7 files changed, 30 insertions(+), 15 deletions(-) diff --git a/cpp/conf/server_config.yaml b/cpp/conf/server_config.yaml index 6829a44181..35f3747a07 100644 --- a/cpp/conf/server_config.yaml +++ b/cpp/conf/server_config.yaml @@ -1,8 +1,8 @@ server_config: address: 0.0.0.0 - port: 19531 # the port milvus listen to, default: 19530, range: 1025 ~ 65534 + port: 19530 # the port milvus listen to, default: 19530, range: 1025 ~ 65534 gpu_index: 0 # the gpu milvus use, default: 0, range: 0 ~ gpu number - 1 - mode: cluster # milvus deployment type: single, cluster + mode: single # milvus deployment type: single, cluster, read_only db_config: db_path: /tmp/milvus diff --git a/cpp/src/db/DBImpl.cpp b/cpp/src/db/DBImpl.cpp index fec7035c1f..def216358b 100644 --- a/cpp/src/db/DBImpl.cpp +++ b/cpp/src/db/DBImpl.cpp @@ -136,7 +136,7 @@ DBImpl::DBImpl(const Options& options) shutting_down_(false), compact_thread_pool_(1, 1), index_thread_pool_(1, 1) { - meta_ptr_ = DBMetaImplFactory::Build(options.meta); + meta_ptr_ = DBMetaImplFactory::Build(options.meta, options.mode); mem_mgr_ = std::make_shared(meta_ptr_, options_); // mem_mgr_ = (MemManagerPtr)(new MemManager(meta_ptr_, options_)); if (options.mode != "read_only") { diff --git a/cpp/src/db/Factories.cpp b/cpp/src/db/Factories.cpp index a6998d10dc..97e89e0994 100644 --- a/cpp/src/db/Factories.cpp +++ b/cpp/src/db/Factories.cpp @@ -53,7 +53,8 @@ std::shared_ptr DBMetaImplFactory::Build() { return std::shared_ptr(new meta::DBMetaImpl(options)); } -std::shared_ptr DBMetaImplFactory::Build(const DBMetaOptions& metaOptions) { +std::shared_ptr DBMetaImplFactory::Build(const DBMetaOptions& metaOptions, + const std::string& mode) { std::string uri = metaOptions.backend_uri; // if (uri.empty()) { @@ -81,21 +82,21 @@ std::shared_ptr DBMetaImplFactory::Build(const DBMetaOptions& metaOp 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_DEBUG << "Using MySQL"; - return std::make_shared(meta::MySQLMetaImpl(metaOptions)); + ENGINE_LOG_INFO << "Using MySQL"; + return std::make_shared(meta::MySQLMetaImpl(metaOptions, mode)); } else if (dialect.find("sqlite") != std::string::npos) { ENGINE_LOG_DEBUG << "Using SQLite"; return std::make_shared(meta::DBMetaImpl(metaOptions)); } else { - LOG(ERROR) << "Invalid dialect in URI: dialect = " << dialect; + ENGINE_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"); + ENGINE_LOG_ERROR << "Wrong URI format: URI = " << uri; + throw InvalidArgumentException("Wrong URI format "); } } diff --git a/cpp/src/db/Factories.h b/cpp/src/db/Factories.h index 31afd2b5ba..48bea9b291 100644 --- a/cpp/src/db/Factories.h +++ b/cpp/src/db/Factories.h @@ -28,7 +28,7 @@ struct OptionsFactory { struct DBMetaImplFactory { static std::shared_ptr Build(); - static std::shared_ptr Build(const DBMetaOptions& metaOptions); + static std::shared_ptr Build(const DBMetaOptions& metaOptions, const std::string& mode); }; struct DBFactory { diff --git a/cpp/src/db/MySQLMetaImpl.cpp b/cpp/src/db/MySQLMetaImpl.cpp index 5c0725ef93..7ee9231b41 100644 --- a/cpp/src/db/MySQLMetaImpl.cpp +++ b/cpp/src/db/MySQLMetaImpl.cpp @@ -103,8 +103,9 @@ namespace meta { return Status::OK(); } - MySQLMetaImpl::MySQLMetaImpl(const DBMetaOptions &options_) - : options_(options_) { + MySQLMetaImpl::MySQLMetaImpl(const DBMetaOptions &options_, const std::string& mode) + : options_(options_), + mode_(mode) { Initialize(); } @@ -424,6 +425,14 @@ namespace meta { } } //Scoped Connection + + +// ConfigNode& serverConfig = ServerConfig::GetInstance().GetConfig(CONFIG_SERVER); +// opt.mode = serverConfig.GetValue(CONFIG_CLUSTER_MODE, "single"); + if (mode_ != "single") { + DeleteTableFiles(table_id); + } + } catch (const BadQuery& er) { // Handle any query errors ENGINE_LOG_ERROR << "GENERAL ERROR WHEN DELETING TABLE" << ": " << er.what(); @@ -448,10 +457,10 @@ namespace meta { Query deleteTableFilesQuery = connectionPtr->query(); // deleteTableFilesQuery << "UPDATE TableFiles " << - "SET file_type = " << std::to_string(TableSchema::TO_DELETE) << ", " << + "SET file_type = " << std::to_string(TableFileSchema::TO_DELETE) << ", " << "updated_time = " << std::to_string(utils::GetMicroSecTimeStamp()) << " " << "WHERE table_id = " << quote << table_id << " AND " << - "file_type <> " << std::to_string(TableSchema::TO_DELETE) << ";"; + "file_type <> " << std::to_string(TableFileSchema::TO_DELETE) << ";"; if (!deleteTableFilesQuery.exec()) { ENGINE_LOG_ERROR << "QUERY ERROR WHEN DELETING TABLE FILES"; diff --git a/cpp/src/db/MySQLMetaImpl.h b/cpp/src/db/MySQLMetaImpl.h index 033fa99453..4805076d45 100644 --- a/cpp/src/db/MySQLMetaImpl.h +++ b/cpp/src/db/MySQLMetaImpl.h @@ -22,7 +22,7 @@ namespace meta { class MySQLMetaImpl : public Meta { public: - MySQLMetaImpl(const DBMetaOptions& options_); + MySQLMetaImpl(const DBMetaOptions& options_, const std::string& mode); virtual Status CreateTable(TableSchema& table_schema) override; virtual Status DescribeTable(TableSchema& group_info_) override; @@ -77,6 +77,7 @@ namespace meta { Status Initialize(); const DBMetaOptions options_; + const std::string mode_; std::shared_ptr mySQLConnectionPool_; bool safe_grab = false; diff --git a/cpp/src/server/DBWrapper.cpp b/cpp/src/server/DBWrapper.cpp index 1c56ece0e3..ceaa6e8130 100644 --- a/cpp/src/server/DBWrapper.cpp +++ b/cpp/src/server/DBWrapper.cpp @@ -25,6 +25,10 @@ DBWrapper::DBWrapper() { } ConfigNode& serverConfig = ServerConfig::GetInstance().GetConfig(CONFIG_SERVER); opt.mode = serverConfig.GetValue(CONFIG_CLUSTER_MODE, "single"); + if (opt.mode != "single" && opt.mode != "cluster" && opt.mode != "read_only") { + std::cout << "ERROR: mode specified in server_config is not one of ['single', 'cluster', 'read_only']" << std::endl; + kill(0, SIGUSR1); + } //set archive config engine::ArchiveConf::CriteriaT criterial;