| 665 | } |
| 666 | |
| 667 | void MaterializeMySQLSyncThread::executeDDLAtomic(const QueryEvent & query_event) |
| 668 | { |
| 669 | try |
| 670 | { |
| 671 | String query = query_event.query; |
| 672 | auto ddl_params = parseMySQLDDLQuery(query_event.query); |
| 673 | if (ddl_params.query_type == MySQLDDLQueryParams::UNKNOWN_TYPE) |
| 674 | { |
| 675 | LOG_DEBUG(log, "Skip unsupported MySQL DDL query: {}", query_event.query); |
| 676 | return; |
| 677 | } |
| 678 | else if (!ddl_params.execute_table.empty()) |
| 679 | { |
| 680 | auto ddl_database_name = ddl_params.execute_database.empty() ? query_event.schema: ddl_params.execute_database; |
| 681 | if (ddl_database_name != mysql_database_name |
| 682 | || (assigned_materialized_table != ddl_params.execute_table && ddl_params.query_type != MySQLDDLQueryParams::CREATE_TABLE)) |
| 683 | { |
| 684 | LOG_DEBUG(log, "Skip MySQL DDL: {}", query_event.query); |
| 685 | return; |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | auto database = DatabaseCatalog::instance().getDatabase(database_name, getContext()); |
| 690 | auto materialized_mysql = dynamic_cast<DatabaseCloudMaterializedMySQL*>(database.get()); |
| 691 | if (!materialized_mysql) |
| 692 | throw Exception("Database should be CloudMaterializedMySQL", ErrorCodes::LOGICAL_ERROR); |
| 693 | auto server_host_port = materialized_mysql->getServerClientOfManager(); |
| 694 | auto server_client = getContext()->getCnchServerClient(server_host_port.getHost(), server_host_port.rpc_port); |
| 695 | if (!server_client) |
| 696 | throw Exception("Failed to get server client for " + server_host_port.toDebugString(), ErrorCodes::LOGICAL_ERROR); |
| 697 | |
| 698 | auto pos = database_name.find("_" + thread_key); |
| 699 | if (pos == std::string::npos) |
| 700 | throw Exception( |
| 701 | "Local MaterializedMySQL database #" + database_name + " has no thread key suffix #" + thread_key, |
| 702 | ErrorCodes::LOGICAL_ERROR |
| 703 | ); |
| 704 | String cnch_database_name = database_name.substr(0, pos); |
| 705 | |
| 706 | auto position = client.getPosition(); |
| 707 | MySQLBinLogInfo binlog; |
| 708 | binlog.binlog_file = position.binlog_name; |
| 709 | binlog.binlog_position = position.binlog_pos; |
| 710 | binlog.executed_gtid_set = position.gtid_sets.toString(); |
| 711 | |
| 712 | server_client->submitMaterializedMySQLDDLQuery(cnch_database_name, thread_key, query, binlog); |
| 713 | } |
| 714 | catch (Exception & exception) |
| 715 | { |
| 716 | exception.addMessage("While executing MYSQL_QUERY_EVENT. The query: " + query_event.query); |
| 717 | |
| 718 | tryLogCurrentException(log); |
| 719 | |
| 720 | /// If some DDL query was not successfully parsed and executed |
| 721 | /// Then replication may fail on next binlog events anyway |
| 722 | if (exception.code() != ErrorCodes::SYNTAX_ERROR) |
| 723 | throw; |
| 724 | } |
nothing calls this directly
no test coverage detected