diff --git a/cpp/conf/server_config.yaml b/cpp/conf/server_config.yaml index 6829a441816a5755d9a16805b7f20f9f8048db95..35f3747a07cae38f009097fdf4f73c5c6a7f4bfc 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 fec7035c1fe044ad053432fa87bd7094a246d1ac..def216358bad26ed56f986549c2e719dc55731cb 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 a6998d10dc02670d236f3fde90507cb298db42e6..97e89e0994c200d004c5456c2139bf192641f1ba 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 31afd2b5bacfc32d591f615804a0bf02032124c0..48bea9b2911c4ddebc31fa571249e220df940457 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 5c0725ef93694efc2d97e02bf05d4f1690919678..7ee9231b41beb25189f8183506ec3e27872d3e98 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 033fa99453238e551b037279f4d4873120898856..4805076d450ac3f9bb8bfa06527c02838229a378 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 1c56ece0e3b59bd83b764d2b8f67599256775f01..ceaa6e813053c7c6a473735d569a8c6ddcc5a3cd 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;