From 34b4d72517de2cf2f6e300af0cf954c5147a1d75 Mon Sep 17 00:00:00 2001 From: Jin Hai Date: Mon, 8 Jun 2020 21:16:22 +0800 Subject: [PATCH] Add exception throw on mysql meta error (#2490) * Add exception throw on mysql meta error Signed-off-by: JinHai-CN * Fix lint Signed-off-by: JinHai-CN * [skip ci] update changelog Signed-off-by: JinHai-CN * Update Signed-off-by: JinHai-CN * Update Signed-off-by: jinhai * Fix Unit test Signed-off-by: JinHai-CN --- CHANGELOG.md | 1 + core/src/db/meta/MySQLConnectionPool.cpp | 8 ++------ core/src/db/meta/MySQLMetaImpl.cpp | 8 +++++--- core/src/db/meta/MySQLMetaImpl.h | 2 +- core/src/db/meta/SqliteMetaImpl.cpp | 2 +- core/unittest/db/test_meta.cpp | 4 ++-- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b80e2c4fbf..e7c9f608c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Please mark all change in change log and use the issue from GitHub - \#2429 Fix Milvus 0.9.1 performance degrade issue - \#2441 Improve Knowhere code coverage - \#2466 optimize k-selection implemention of faiss gpu version +- \#2489 Add exception throw on mysql meta error - \#2495 Add creating lock file failure reason. ## Task diff --git a/core/src/db/meta/MySQLConnectionPool.cpp b/core/src/db/meta/MySQLConnectionPool.cpp index ba1acf667d..104e6584fd 100644 --- a/core/src/db/meta/MySQLConnectionPool.cpp +++ b/core/src/db/meta/MySQLConnectionPool.cpp @@ -13,9 +13,7 @@ #include #include -namespace milvus { -namespace engine { -namespace meta { +namespace milvus::engine::meta { // Do a simple form of in-use connection limiting: wait to return // a connection until there are a reasonably low number in use @@ -84,6 +82,4 @@ MySQLConnectionPool::max_idle_time() { return max_idle_time_; } -} // namespace meta -} // namespace engine -} // namespace milvus +} // namespace milvus::engine::meta diff --git a/core/src/db/meta/MySQLMetaImpl.cpp b/core/src/db/meta/MySQLMetaImpl.cpp index 7cc57c1916..3e1f3de7b5 100644 --- a/core/src/db/meta/MySQLMetaImpl.cpp +++ b/core/src/db/meta/MySQLMetaImpl.cpp @@ -52,7 +52,7 @@ template void DistributeBatch(const T& id_array, std::vector>& id_groups) { std::vector temp_group; - constexpr uint64_t SQL_BATCH_SIZE = 50; + // constexpr uint64_t SQL_BATCH_SIZE = 50; // duplicate variable for (auto& id : id_array) { temp_group.push_back(id); if (temp_group.size() >= SQL_BATCH_SIZE) { @@ -246,12 +246,14 @@ MySQLMetaImpl::NextFileId(std::string& file_id) { void MySQLMetaImpl::ValidateMetaSchema() { - if (nullptr == mysql_connection_pool_) { + if (mysql_connection_pool_ == nullptr) { + throw Exception(DB_ERROR, "MySQL connection pool is invalid"); return; } mysqlpp::ScopedConnection connectionPtr(*mysql_connection_pool_, safe_grab_); if (connectionPtr == nullptr) { + throw Exception(DB_ERROR, "Can't construct MySQL connection"); return; } @@ -336,7 +338,7 @@ MySQLMetaImpl::Initialize() { // step 3: connect mysql unsigned int thread_hint = std::thread::hardware_concurrency(); - int max_pool_size = (thread_hint > 8) ? thread_hint : 8; + int max_pool_size = (thread_hint > 8) ? static_cast(thread_hint) : 8; int port = 0; if (!uri_info.port_.empty()) { port = std::stoi(uri_info.port_); diff --git a/core/src/db/meta/MySQLMetaImpl.h b/core/src/db/meta/MySQLMetaImpl.h index e15564f6c6..dce46e637c 100644 --- a/core/src/db/meta/MySQLMetaImpl.h +++ b/core/src/db/meta/MySQLMetaImpl.h @@ -182,7 +182,7 @@ class MySQLMetaImpl : public Meta { const int mode_; std::shared_ptr mysql_connection_pool_; - bool safe_grab_ = false; + bool safe_grab_ = false; // Safely graps a connection from mysql pool std::mutex meta_mutex_; std::mutex genid_mutex_; diff --git a/core/src/db/meta/SqliteMetaImpl.cpp b/core/src/db/meta/SqliteMetaImpl.cpp index eef66c6fe9..87cf7a6556 100644 --- a/core/src/db/meta/SqliteMetaImpl.cpp +++ b/core/src/db/meta/SqliteMetaImpl.cpp @@ -153,7 +153,7 @@ SqliteMetaImpl::ValidateMetaSchema() { bool is_null_connector{ConnectorPtr == nullptr}; fiu_do_on("SqliteMetaImpl.ValidateMetaSchema.NullConnection", is_null_connector = true); if (is_null_connector) { - return; + throw Exception(DB_ERROR, "Connector is null pointer"); } // old meta could be recreated since schema changed, throw exception if meta schema is not compatible diff --git a/core/unittest/db/test_meta.cpp b/core/unittest/db/test_meta.cpp index e10ad0ffb0..a331e65fb3 100644 --- a/core/unittest/db/test_meta.cpp +++ b/core/unittest/db/test_meta.cpp @@ -56,7 +56,7 @@ TEST_F(MetaTest, COLLECTION_TEST) { ASSERT_TRUE(status.ok()); } -TEST_F(MetaTest, FALID_TEST) { +TEST_F(MetaTest, FAILED_TEST) { fiu_init(0); auto options = GetOptions(); auto collection_id = "meta_test_table"; @@ -66,7 +66,7 @@ TEST_F(MetaTest, FALID_TEST) { { FIU_ENABLE_FIU("SqliteMetaImpl.ValidateMetaSchema.NullConnection"); - milvus::engine::meta::SqliteMetaImpl impl(options.meta_); + ASSERT_ANY_THROW(milvus::engine::meta::SqliteMetaImpl impl(options.meta_)); fiu_disable("SqliteMetaImpl.ValidateMetaSchema.NullConnection"); } {