diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d0e224fad..6ec7c3bb6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ Please mark all change in change log and use the issue from GitHub - \#1962 Add api HasPartition - \#1965 FAISS/NSG/HNSW/ANNOY use unified distance calculation algorithm - \#2054 Check if CPU instruction sets are illegal +- \#2057 Add a config parameter to switch off http server - \#2059 Add lock file avoid multiple instances modifying data at the same time - \#2064 Warn when use SQLite as metadata management - \#2111 Check GPU environment before start server diff --git a/core/cmake/ThirdPartyPackages.cmake b/core/cmake/ThirdPartyPackages.cmake index c1d59cfeb7..4e5103e67d 100644 --- a/core/cmake/ThirdPartyPackages.cmake +++ b/core/cmake/ThirdPartyPackages.cmake @@ -322,7 +322,7 @@ else () endif () if (DEFINED ENV{MILVUS_OATPP_URL}) - set(MILVUS_OATPP_URL "$ENV{MILVUS_OATPP_URL}") + set(OATPP_SOURCE_URL "$ENV{MILVUS_OATPP_URL}") else () # set(OATPP_SOURCE_URL "https://github.com/oatpp/oatpp/archive/${OATPP_VERSION}.tar.gz") set(OATPP_SOURCE_URL "https://github.com/BossZou/oatpp/archive/master.zip") diff --git a/core/conf/demo/server_config.yaml b/core/conf/demo/server_config.yaml index 428fcb911f..e4a6fa8e47 100644 --- a/core/conf/demo/server_config.yaml +++ b/core/conf/demo/server_config.yaml @@ -23,6 +23,8 @@ version: 0.3 #----------------------+------------------------------------------------------------+------------+-----------------+ # time_zone | Use UTC-x or UTC+x to specify a time zone. | Timezone | UTC+8 | #----------------------+------------------------------------------------------------+------------+-----------------+ +# web_enable | Enable web server or not. | Boolean | true | +#----------------------+------------------------------------------------------------+------------+-----------------+ # web_port | Port that Milvus web server monitors. | Integer | 19121 | # | Port range (1024, 65535) | | | #----------------------+------------------------------------------------------------+------------+-----------------+ @@ -31,6 +33,7 @@ server_config: port: 19530 deploy_mode: single time_zone: UTC+8 + web_enable: true web_port: 19121 #----------------------+------------------------------------------------------------+------------+-----------------+ diff --git a/core/conf/server_config.template b/core/conf/server_config.template index 57f7f49926..3115fd2fa7 100644 --- a/core/conf/server_config.template +++ b/core/conf/server_config.template @@ -23,6 +23,8 @@ version: 0.3 #----------------------+------------------------------------------------------------+------------+-----------------+ # time_zone | Use UTC-x or UTC+x to specify a time zone. | Timezone | UTC+8 | #----------------------+------------------------------------------------------------+------------+-----------------+ +# web_enable | Enable web server or not. | Boolean | true | +#----------------------+------------------------------------------------------------+------------+-----------------+ # web_port | Port that Milvus web server monitors. | Integer | 19121 | # | Port range (1024, 65535) | | | #----------------------+------------------------------------------------------------+------------+-----------------+ @@ -31,6 +33,7 @@ server_config: port: 19530 deploy_mode: single time_zone: UTC+8 + web_enable: true web_port: 19121 #----------------------+------------------------------------------------------------+------------+-----------------+ diff --git a/core/src/config/Config.cpp b/core/src/config/Config.cpp index 308dea7e7e..e759633174 100644 --- a/core/src/config/Config.cpp +++ b/core/src/config/Config.cpp @@ -50,6 +50,8 @@ const char* CONFIG_SERVER_DEPLOY_MODE = "deploy_mode"; const char* CONFIG_SERVER_DEPLOY_MODE_DEFAULT = "single"; const char* CONFIG_SERVER_TIME_ZONE = "time_zone"; const char* CONFIG_SERVER_TIME_ZONE_DEFAULT = "UTC+8"; +const char* CONFIG_SERVER_WEB_ENABLE = "web_enable"; +const char* CONFIG_SERVER_WEB_ENABLE_DEFAULT = "true"; const char* CONFIG_SERVER_WEB_PORT = "web_port"; const char* CONFIG_SERVER_WEB_PORT_DEFAULT = "19121"; @@ -241,6 +243,9 @@ Config::ValidateConfig() { std::string server_time_zone; CONFIG_CHECK(GetServerConfigTimeZone(server_time_zone)); + bool server_web_enable; + CONFIG_CHECK(GetServerConfigWebEnable(server_web_enable)); + std::string server_web_port; CONFIG_CHECK(GetServerConfigWebPort(server_web_port)); @@ -372,6 +377,7 @@ Config::ResetDefaultConfig() { CONFIG_CHECK(SetServerConfigPort(CONFIG_SERVER_PORT_DEFAULT)); CONFIG_CHECK(SetServerConfigDeployMode(CONFIG_SERVER_DEPLOY_MODE_DEFAULT)); CONFIG_CHECK(SetServerConfigTimeZone(CONFIG_SERVER_TIME_ZONE_DEFAULT)); + CONFIG_CHECK(SetServerConfigWebEnable(CONFIG_SERVER_WEB_ENABLE_DEFAULT)); CONFIG_CHECK(SetServerConfigWebPort(CONFIG_SERVER_WEB_PORT_DEFAULT)); /* db config */ @@ -860,6 +866,11 @@ Config::CheckServerConfigTimeZone(const std::string& value) { return Status::OK(); } +Status +Config::CheckServerConfigWebEnable(const std::string& value) { + return ValidationUtil::ValidateStringIsBool(value); +} + Status Config::CheckServerConfigWebPort(const std::string& value) { if (!ValidationUtil::ValidateStringIsNumber(value).ok()) { @@ -1603,6 +1614,13 @@ Config::GetServerConfigTimeZone(std::string& value) { return CheckServerConfigTimeZone(value); } +Status +Config::GetServerConfigWebEnable(bool& value) { + std::string str = GetConfigStr(CONFIG_SERVER, CONFIG_SERVER_WEB_ENABLE, CONFIG_SERVER_WEB_ENABLE_DEFAULT); + CONFIG_CHECK(CheckServerConfigWebEnable(str)); + return StringHelpFunctions::ConvertToBoolean(str, value); +} + Status Config::GetServerConfigWebPort(std::string& value) { value = GetConfigStr(CONFIG_SERVER, CONFIG_SERVER_WEB_PORT, CONFIG_SERVER_WEB_PORT_DEFAULT); @@ -1972,6 +1990,12 @@ Config::SetServerConfigTimeZone(const std::string& value) { return SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_TIME_ZONE, value); } +Status +Config::SetServerConfigWebEnable(const std::string& value) { + CONFIG_CHECK(CheckServerConfigWebEnable(value)); + return SetConfigValueInMem(CONFIG_SERVER, CONFIG_SERVER_WEB_ENABLE, value); +} + Status Config::SetServerConfigWebPort(const std::string& value) { CONFIG_CHECK(CheckServerConfigWebPort(value)); diff --git a/core/src/config/Config.h b/core/src/config/Config.h index ff6f6038a3..6dad29434c 100644 --- a/core/src/config/Config.h +++ b/core/src/config/Config.h @@ -46,6 +46,8 @@ extern const char* CONFIG_SERVER_DEPLOY_MODE; extern const char* CONFIG_SERVER_DEPLOY_MODE_DEFAULT; extern const char* CONFIG_SERVER_TIME_ZONE; extern const char* CONFIG_SERVER_TIME_ZONE_DEFAULT; +extern const char* CONFIG_SERVER_WEB_ENABLE; +extern const char* CONFIG_SERVER_WEB_ENABLE_DEFAULT; extern const char* CONFIG_SERVER_WEB_PORT; extern const char* CONFIG_SERVER_WEB_PORT_DEFAULT; @@ -208,6 +210,8 @@ class Config { Status CheckServerConfigTimeZone(const std::string& value); Status + CheckServerConfigWebEnable(const std::string& value); + Status CheckServerConfigWebPort(const std::string& value); /* db config */ @@ -319,6 +323,8 @@ class Config { Status GetServerConfigTimeZone(std::string& value); Status + GetServerConfigWebEnable(bool& value); + Status GetServerConfigWebPort(std::string& value); /* db config */ @@ -422,6 +428,8 @@ class Config { Status SetServerConfigTimeZone(const std::string& value); Status + SetServerConfigWebEnable(const std::string& value); + Status SetServerConfigWebPort(const std::string& value); /* db config */ diff --git a/core/src/server/web_impl/WebServer.cpp b/core/src/server/web_impl/WebServer.cpp index c2500eda3a..cd9f3918c4 100644 --- a/core/src/server/web_impl/WebServer.cpp +++ b/core/src/server/web_impl/WebServer.cpp @@ -22,7 +22,10 @@ namespace web { void WebServer::Start() { - if (nullptr == thread_ptr_) { + auto& config = Config::GetInstance(); + bool enable = true; + config.GetServerConfigWebEnable(enable); + if (enable && nullptr == thread_ptr_) { thread_ptr_ = std::make_shared(&WebServer::StartService, this); } } @@ -44,23 +47,21 @@ WebServer::StartService() { Config& config = Config::GetInstance(); std::string port; - CONFIG_CHECK(config.GetServerConfigWebPort(port)); { AppComponent components = AppComponent(std::stoi(port)); - auto user_controller = WebController::createShared(); - /* create ApiControllers and add endpoints to router */ - OATPP_COMPONENT(std::shared_ptr, router); + auto user_controller = WebController::createShared(); + auto router = components.http_router_.getObject(); user_controller->addEndpointsToRouter(router); /* Get connection handler component */ - OATPP_COMPONENT(std::shared_ptr, connection_handler); + auto connection_handler = components.server_connection_handler_.getObject(); /* Get connection provider component */ - OATPP_COMPONENT(std::shared_ptr, connection_provider); + auto connection_provider = components.server_connection_provider_.getObject(); /* create server */ auto server = oatpp::network::server::Server(connection_provider, connection_handler); @@ -77,12 +78,9 @@ WebServer::StartService() { // start synchronously server.run(); - connection_handler->stop(); - stop_thread.join(); } - oatpp::base::Environment::destroy(); return Status::OK(); diff --git a/core/src/server/web_impl/component/AppComponent.hpp b/core/src/server/web_impl/component/AppComponent.hpp index 7ac9b0f1d0..33f735fe20 100644 --- a/core/src/server/web_impl/component/AppComponent.hpp +++ b/core/src/server/web_impl/component/AppComponent.hpp @@ -42,7 +42,8 @@ class AppComponent { return oatpp::network::server::SimpleTCPConnectionProvider::createShared(this->port_); } catch (std::exception& e) { std::string error_msg = "Cannot bind http port " + std::to_string(this->port_) + - ". Check if the port is already used"; + ": " + e.what() + + " (errno:" + std::to_string(errno) + "details: " + strerror(errno) + ")."; std::cout << error_msg << std::endl; throw std::runtime_error(error_msg); } @@ -58,7 +59,7 @@ class AppComponent { }()); OATPP_CREATE_COMPONENT(std::shared_ptr, server_connection_handler_)([] { - OATPP_COMPONENT(std::shared_ptr, router); // get Router component + OATPP_COMPONENT(std::shared_ptr, router); return oatpp::web::server::HttpConnectionHandler::createShared(router); }()); diff --git a/core/src/utils/LogUtil.cpp b/core/src/utils/LogUtil.cpp index 1df0f71a23..f8d5e23629 100644 --- a/core/src/utils/LogUtil.cpp +++ b/core/src/utils/LogUtil.cpp @@ -120,7 +120,8 @@ LogCpuInfo() { /*CPU information*/ std::fstream fcpu("/proc/cpuinfo", std::ios::in); if (!fcpu.is_open()) { - LOG_SERVER_WARNING_ << "Cannot obtain CPU information. Open file /proc/cpuinfo fail: " << strerror(errno); + LOG_SERVER_WARNING_ << "Cannot obtain CPU information. Open file /proc/cpuinfo fail: " << strerror(errno) + << "(errno: " << errno << ")"; return; } std::stringstream cpu_info_ss; diff --git a/core/unittest/server/test_web.cpp b/core/unittest/server/test_web.cpp index 67f8c128ca..1c2cd4ffdf 100644 --- a/core/unittest/server/test_web.cpp +++ b/core/unittest/server/test_web.cpp @@ -524,6 +524,7 @@ static const char* CONTROLLER_TEST_VALID_CONFIG_STR = " port: 19530\n" " deploy_mode: single\n" " time_zone: UTC+8\n" + " web_enable: true\n" " web_port: 19121\n" "\n" "#----------------------+------------------------------------------------------------+------------+----------------"