From e1c6aea6a4b4d23cdf40d2d4c19f88af3f54c667 Mon Sep 17 00:00:00 2001 From: groot Date: Thu, 28 Nov 2019 12:29:34 +0800 Subject: [PATCH 1/2] #561 Milvus server should report exception/error message or terminate on mysql metadata backend error --- CHANGELOG.md | 1 + core/src/db/meta/MySQLMetaImpl.cpp | 64 ++++++++++++++++-------------- 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e235ca3f3..9a577763ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ Please mark all change in change log and use the ticket from JIRA. - \#533 - NSG build failed with MetricType Inner Product - \#543 - client raise exception in shards when search results is empty - \#545 - Avoid dead circle of build index thread when error occurs +- \#561 - Milvus server should report exception/error message or terminate on mysql metadata backend error ## Feature - \#12 - Pure CPU version for Milvus diff --git a/core/src/db/meta/MySQLMetaImpl.cpp b/core/src/db/meta/MySQLMetaImpl.cpp index 193a34e4f6..c5a2946926 100644 --- a/core/src/db/meta/MySQLMetaImpl.cpp +++ b/core/src/db/meta/MySQLMetaImpl.cpp @@ -290,45 +290,49 @@ MySQLMetaImpl::Initialize() { // step 4: validate to avoid open old version schema ValidateMetaSchema(); - // step 5: create meta tables - try { - if (mode_ != DBOptions::MODE::CLUSTER_READONLY) { - CleanUpShadowFiles(); - } + // step 5: clean shadow files + if (mode_ != DBOptions::MODE::CLUSTER_READONLY) { + CleanUpShadowFiles(); + } - { - mysqlpp::ScopedConnection connectionPtr(*mysql_connection_pool_, safe_grab_); + // step 6: try connect mysql server + mysqlpp::ScopedConnection connectionPtr(*mysql_connection_pool_, safe_grab_); - if (connectionPtr == nullptr) { - return Status(DB_ERROR, "Failed to connect to meta server(mysql)"); - } + if (connectionPtr == nullptr) { + std::string msg = "Failed to connect mysql meta server: " + uri; + ENGINE_LOG_ERROR << msg; + throw Exception(DB_INVALID_META_URI, msg); + } - if (!connectionPtr->thread_aware()) { - ENGINE_LOG_ERROR << "MySQL++ wasn't built with thread awareness! Can't run without it."; - return Status(DB_ERROR, "MySQL++ wasn't built with thread awareness! Can't run without it."); - } - mysqlpp::Query InitializeQuery = connectionPtr->query(); + if (!connectionPtr->thread_aware()) { + std::string msg = "MySQL++ wasn't built with thread awareness! Can't run without it."; + ENGINE_LOG_ERROR << msg; + throw Exception(DB_INVALID_META_URI, msg); + } - InitializeQuery << "CREATE TABLE IF NOT EXISTS " << TABLES_SCHEMA.name() << " (" - << TABLES_SCHEMA.ToString() + ");"; + // step 7: create meta table Tables + mysqlpp::Query InitializeQuery = connectionPtr->query(); - ENGINE_LOG_DEBUG << "MySQLMetaImpl::Initialize: " << InitializeQuery.str(); + InitializeQuery << "CREATE TABLE IF NOT EXISTS " << TABLES_SCHEMA.name() << " (" << TABLES_SCHEMA.ToString() + ");"; - if (!InitializeQuery.exec()) { - return HandleException("Initialization Error", InitializeQuery.error()); - } + ENGINE_LOG_DEBUG << "MySQLMetaImpl::Initialize: " << InitializeQuery.str(); - InitializeQuery << "CREATE TABLE IF NOT EXISTS " << TABLEFILES_SCHEMA.name() << " (" - << TABLEFILES_SCHEMA.ToString() + ");"; + if (!InitializeQuery.exec()) { + std::string msg = "Failed to create meta table 'Tables' in mysql"; + ENGINE_LOG_ERROR << msg; + throw Exception(DB_META_TRANSACTION_FAILED, msg); + } - ENGINE_LOG_DEBUG << "MySQLMetaImpl::Initialize: " << InitializeQuery.str(); + // step 8: create meta table TableFiles + InitializeQuery << "CREATE TABLE IF NOT EXISTS " << TABLEFILES_SCHEMA.name() << " (" + << TABLEFILES_SCHEMA.ToString() + ");"; - if (!InitializeQuery.exec()) { - return HandleException("Initialization Error", InitializeQuery.error()); - } - } // Scoped Connection - } catch (std::exception& e) { - return HandleException("GENERAL ERROR DURING INITIALIZATION", e.what()); + ENGINE_LOG_DEBUG << "MySQLMetaImpl::Initialize: " << InitializeQuery.str(); + + if (!InitializeQuery.exec()) { + std::string msg = "Failed to create meta table 'TableFiles' in mysql"; + ENGINE_LOG_ERROR << msg; + throw Exception(DB_META_TRANSACTION_FAILED, msg); } return Status::OK(); From 05655580c15be3d332f7ab9394ac9b90ccc7134a Mon Sep 17 00:00:00 2001 From: groot Date: Thu, 28 Nov 2019 14:25:50 +0800 Subject: [PATCH 2/2] fix message typo --- core/src/db/meta/MySQLMetaImpl.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/src/db/meta/MySQLMetaImpl.cpp b/core/src/db/meta/MySQLMetaImpl.cpp index c5a2946926..10aac72b1a 100644 --- a/core/src/db/meta/MySQLMetaImpl.cpp +++ b/core/src/db/meta/MySQLMetaImpl.cpp @@ -299,13 +299,14 @@ MySQLMetaImpl::Initialize() { mysqlpp::ScopedConnection connectionPtr(*mysql_connection_pool_, safe_grab_); if (connectionPtr == nullptr) { - std::string msg = "Failed to connect mysql meta server: " + uri; + std::string msg = "Failed to connect MySQL meta server: " + uri; ENGINE_LOG_ERROR << msg; throw Exception(DB_INVALID_META_URI, msg); } if (!connectionPtr->thread_aware()) { - std::string msg = "MySQL++ wasn't built with thread awareness! Can't run without it."; + std::string msg = + "Failed to initialize MySQL meta backend: MySQL client component wasn't built with thread awareness"; ENGINE_LOG_ERROR << msg; throw Exception(DB_INVALID_META_URI, msg); } @@ -318,7 +319,7 @@ MySQLMetaImpl::Initialize() { ENGINE_LOG_DEBUG << "MySQLMetaImpl::Initialize: " << InitializeQuery.str(); if (!InitializeQuery.exec()) { - std::string msg = "Failed to create meta table 'Tables' in mysql"; + std::string msg = "Failed to create meta table 'Tables' in MySQL"; ENGINE_LOG_ERROR << msg; throw Exception(DB_META_TRANSACTION_FAILED, msg); } @@ -330,7 +331,7 @@ MySQLMetaImpl::Initialize() { ENGINE_LOG_DEBUG << "MySQLMetaImpl::Initialize: " << InitializeQuery.str(); if (!InitializeQuery.exec()) { - std::string msg = "Failed to create meta table 'TableFiles' in mysql"; + std::string msg = "Failed to create meta table 'TableFiles' in MySQL"; ENGINE_LOG_ERROR << msg; throw Exception(DB_META_TRANSACTION_FAILED, msg); }