From 5c1a01897ac79e23e5c5224605a43270750cfd4d Mon Sep 17 00:00:00 2001 From: taichong Date: Tue, 3 Nov 2020 11:12:05 +0800 Subject: [PATCH] Revise the code according to the review --- src/Databases/MySQL/MaterializeMetadata.cpp | 11 ++++++----- src/Databases/MySQL/MaterializeMySQLSyncThread.cpp | 3 ++- src/Databases/MySQL/MaterializeMySQLSyncThread.h | 2 ++ .../materialize_with_ddl.py | 5 +---- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Databases/MySQL/MaterializeMetadata.cpp b/src/Databases/MySQL/MaterializeMetadata.cpp index f672e5fb24f..01a1493fa22 100644 --- a/src/Databases/MySQL/MaterializeMetadata.cpp +++ b/src/Databases/MySQL/MaterializeMetadata.cpp @@ -107,9 +107,10 @@ static Block getShowMasterLogHeader(const String & mysql_version) }; } -static bool rightSyncUserPrivImpl(mysqlxx::PoolWithFailover::Entry & connection, std::ostream & out) +static bool checkSyncUserPrivImpl(mysqlxx::PoolWithFailover::Entry & connection, std::ostream & out) { - Block sync_user_privs_header{ + Block sync_user_privs_header + { {std::make_shared(), "current_user_grants"} }; @@ -138,10 +139,10 @@ static bool rightSyncUserPrivImpl(mysqlxx::PoolWithFailover::Entry & connection, return false; } -static void rightSyncUserPriv(mysqlxx::PoolWithFailover::Entry & connection) +static void checkSyncUserPriv(mysqlxx::PoolWithFailover::Entry & connection) { std::stringstream out; - if (!rightSyncUserPrivImpl(connection, out)) + if (!checkSyncUserPrivImpl(connection, out)) throw Exception("MySQL SYNC USER ACCESS ERR: mysql sync user needs " "at least GLOBAL PRIVILEGES:'RELOAD, REPLICATION SLAVE, REPLICATION CLIENT' " "and SELECT PRIVILEGE on MySQL Database." @@ -210,7 +211,7 @@ MaterializeMetadata::MaterializeMetadata( const String & database, bool & opened_transaction, const String & mysql_version) : persistent_path(path_) { - rightSyncUserPriv(connection); + checkSyncUserPriv(connection); if (Poco::File(persistent_path).exists()) { diff --git a/src/Databases/MySQL/MaterializeMySQLSyncThread.cpp b/src/Databases/MySQL/MaterializeMySQLSyncThread.cpp index d5d034eaa8a..f76e6b77448 100644 --- a/src/Databases/MySQL/MaterializeMySQLSyncThread.cpp +++ b/src/Databases/MySQL/MaterializeMySQLSyncThread.cpp @@ -216,7 +216,8 @@ void MaterializeMySQLSyncThread::stopSynchronization() void MaterializeMySQLSyncThread::startSynchronization() { - try{ + try + { const auto & mysql_server_version = checkVariableAndGetVersion(pool.get()); background_thread_pool = std::make_unique( diff --git a/src/Databases/MySQL/MaterializeMySQLSyncThread.h b/src/Databases/MySQL/MaterializeMySQLSyncThread.h index c1f1fc5a391..323ae5beb80 100644 --- a/src/Databases/MySQL/MaterializeMySQLSyncThread.h +++ b/src/Databases/MySQL/MaterializeMySQLSyncThread.h @@ -64,6 +64,8 @@ private: MaterializeMySQLSettings * settings; String query_prefix; + // USE MySQL ERROR CODE: + // https://dev.mysql.com/doc/mysql-errors/5.7/en/server-error-reference.html const int ER_ACCESS_DENIED_ERROR = 1045; const int ER_DBACCESS_DENIED_ERROR = 1044; const int ER_BAD_DB_ERROR = 1049; diff --git a/tests/integration/test_materialize_mysql_database/materialize_with_ddl.py b/tests/integration/test_materialize_mysql_database/materialize_with_ddl.py index 6711b36ca13..8c9256cb1c7 100644 --- a/tests/integration/test_materialize_mysql_database/materialize_with_ddl.py +++ b/tests/integration/test_materialize_mysql_database/materialize_with_ddl.py @@ -476,10 +476,7 @@ def err_sync_user_privs_with_materialize_mysql_database(clickhouse_node, mysql_n service_name)) # wait MaterializeMySQL read binlog events - time.sleep(90) - - assert "test_table_1" in clickhouse_node.query("SHOW TABLES FROM test_database") - check_query(clickhouse_node, "SELECT count() FROM test_database.test_table_1 FORMAT TSV", "6\n", 5, 5) + check_query(clickhouse_node, "SELECT count() FROM test_database.test_table_1 FORMAT TSV", "6\n", 30, 5) mysql_node.query("INSERT INTO test_database.test_table_1 VALUES(7);") check_query(clickhouse_node, "SELECT count() FROM test_database.test_table_1 FORMAT TSV", "7\n") clickhouse_node.query("DROP DATABASE test_database;")