diff --git a/cpp/CHANGELOG.md b/cpp/CHANGELOG.md index 3e699d8cd1ef0c30ddee8fe3b91ecc7e377425e1..a11d40d7c96b3cbcfeeb7866eff94e24c496acb3 100644 --- a/cpp/CHANGELOG.md +++ b/cpp/CHANGELOG.md @@ -19,6 +19,7 @@ Please mark all change in change log and use the ticket from JIRA. - MS-230 - Change parameter name: Maximum_memory to insert_buffer_size - MS-234 - Some case cause background merge thread stop - MS-235 - Some test cases random fail +- MS-236 - Add MySQLMetaImpl::HasNonIndexFiles ## Improvement - MS-156 - Add unittest for merge result functions diff --git a/cpp/src/db/MySQLMetaImpl.cpp b/cpp/src/db/MySQLMetaImpl.cpp index dc22c0307c4498036cfd974241332c99ab24fc4c..98394688a46c07bb28c19dcd99eef168824723f2 100644 --- a/cpp/src/db/MySQLMetaImpl.cpp +++ b/cpp/src/db/MySQLMetaImpl.cpp @@ -382,7 +382,49 @@ Status MySQLMetaImpl::CreateTable(TableSchema &table_schema) { } Status MySQLMetaImpl::HasNonIndexFiles(const std::string &table_id, bool &has) { - // TODO + + has = false; + + try { + + StoreQueryResult res; + + { + ScopedConnection connectionPtr(*mysql_connection_pool_, safe_grab); + + if (connectionPtr == nullptr) { + return Status::Error("Failed to connect to database server"); + } + + + Query hasNonIndexFilesQuery = connectionPtr->query(); + //since table_id is a unique column we just need to check whether it exists or not + hasNonIndexFilesQuery << "SELECT EXISTS " << + "(SELECT 1 FROM TableFiles " << + "WHERE table_id = " << quote << table_id << " AND " << + "(file_type = " << std::to_string(TableFileSchema::RAW) << " OR " << + "file_type = " << std::to_string(TableFileSchema::NEW) << " OR " << + "file_type = " << std::to_string(TableFileSchema::TO_INDEX) << ") " << + "AS " << quote << "check" << ";"; + + ENGINE_LOG_DEBUG << "MySQLMetaImpl::HasNonIndexFiles: " << hasNonIndexFilesQuery.str(); + + res = hasNonIndexFilesQuery.store(); + } //Scoped Connection + + int check = res[0]["check"]; + has = (check == 1); + + } catch (const BadQuery &er) { + // Handle any query errors + ENGINE_LOG_ERROR << "QUERY ERROR WHEN CHECKING IF NON INDEX FILES EXISTS" << ": " << er.what(); + return Status::DBTransactionError("QUERY ERROR WHEN CHECKING IF NON INDEX FILES EXISTS", er.what()); + } catch (const Exception &er) { + // Catch-all for any other MySQL++ exceptions + ENGINE_LOG_ERROR << "GENERAL ERROR WHEN CHECKING IF NON INDEX FILES EXISTS" << ": " << er.what(); + return Status::DBTransactionError("GENERAL ERROR WHEN CHECKING IF NON INDEX FILES EXISTS", er.what()); + } + return Status::OK(); } @@ -1382,7 +1424,7 @@ Status MySQLMetaImpl::UpdateTableFilesToIndex(const std::string &table_id) { "WHERE table_id = " << quote << table_id << " AND " << "file_type = " << std::to_string(TableFileSchema::RAW) << ";"; - ENGINE_LOG_DEBUG << "MySQLMetaImpl::UpdateTableFile: " << updateTableFilesToIndexQuery.str(); + ENGINE_LOG_DEBUG << "MySQLMetaImpl::UpdateTableFilesToIndex: " << updateTableFilesToIndexQuery.str(); } catch (const BadQuery &er) { // Handle any query errors