Skip to content

Commit a76058a

Browse files
authored
Merge pull request ClickHouse#63397 from kirillgarbar/mysql
Allow to create MaterializedMySQL database without connection to MySQL
2 parents e8d43fa + a20ef2a commit a76058a

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

docs/en/engines/database-engines/materialized-mysql.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ ENGINE = MaterializedMySQL('host:port', ['database' | database], 'user', 'passwo
5151
### allows_query_when_mysql_lost
5252
`allows_query_when_mysql_lost` — Allows to query a materialized table when MySQL is lost. Default: `0` (`false`).
5353

54+
### allow_startup_database_without_connection_to_mysql
55+
`allow_startup_database_without_connection_to_mysql` — Allow to create and attach database without available connection to MySQL. Default: `0` (`false`).
56+
5457
### materialized_mysql_tables_list
5558

5659
`materialized_mysql_tables_list` — a comma-separated list of mysql database tables, which will be replicated by MaterializedMySQL database engine. Default value: empty list — means whole tables will be replicated.

src/Databases/MySQL/DatabaseMaterializedMySQL.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ LoadTaskPtr DatabaseMaterializedMySQL::startupDatabaseAsync(AsyncLoader & async_
8484
[this, mode] (AsyncLoader &, const LoadJobPtr &)
8585
{
8686
LOG_TRACE(log, "Starting MaterializeMySQL database");
87-
if (mode < LoadingStrictnessLevel::FORCE_ATTACH)
87+
if (!settings->allow_startup_database_without_connection_to_mysql
88+
&& mode < LoadingStrictnessLevel::FORCE_ATTACH)
8889
materialize_thread.assertMySQLAvailable();
8990

9091
materialize_thread.startSynchronization();

src/Databases/MySQL/MaterializedMySQLSettings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class ASTStorage;
2222
M(UInt64, max_milliseconds_to_wait_in_binlog_queue, 10000, "Max milliseconds to wait when max bytes exceeded in a binlog queue.", 0) \
2323
M(UInt64, max_bytes_in_binlog_dispatcher_buffer, DBMS_DEFAULT_BUFFER_SIZE, "Max bytes in the binlog dispatcher's buffer before it is flushed to attached binlogs.", 0) \
2424
M(UInt64, max_flush_milliseconds_in_binlog_dispatcher, 1000, "Max milliseconds in the binlog dispatcher's buffer to wait before it is flushed to attached binlogs.", 0) \
25+
M(Bool, allow_startup_database_without_connection_to_mysql, false, "Allow to create and attach database without available connection to MySQL.", 0) \
2526

2627
DECLARE_SETTINGS_TRAITS(MaterializedMySQLSettingsTraits, LIST_OF_MATERIALIZE_MODE_SETTINGS)
2728

tests/integration/test_materialized_mysql_database/materialized_with_ddl.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3413,3 +3413,42 @@ def gtid_after_attach_test(clickhouse_node, mysql_node, replication):
34133413
interval_seconds=1,
34143414
retry_count=300,
34153415
)
3416+
3417+
3418+
def mysql_create_database_without_connection(clickhouse_node, mysql_node, service_name):
3419+
mysql_node.query("DROP DATABASE IF EXISTS create_without_connection")
3420+
clickhouse_node.query("DROP DATABASE IF EXISTS create_without_connection")
3421+
mysql_node.query("CREATE DATABASE create_without_connection")
3422+
mysql_node.query(
3423+
"CREATE TABLE create_without_connection.test ( `id` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB;"
3424+
)
3425+
3426+
clickhouse_node.cluster.pause_container(service_name)
3427+
3428+
assert "ConnectionFailed:" in clickhouse_node.query_and_get_error(
3429+
"""
3430+
CREATE DATABASE create_without_connection
3431+
ENGINE = MaterializedMySQL('{}:3306', 'create_without_connection', 'root', 'clickhouse')
3432+
""".format(
3433+
service_name
3434+
)
3435+
)
3436+
3437+
clickhouse_node.query(
3438+
"""
3439+
CREATE DATABASE create_without_connection
3440+
ENGINE = MaterializedMySQL('{}:3306', 'create_without_connection', 'root', 'clickhouse')
3441+
SETTINGS allow_startup_database_without_connection_to_mysql=1
3442+
""".format(
3443+
service_name
3444+
)
3445+
)
3446+
3447+
clickhouse_node.cluster.unpause_container(service_name)
3448+
mysql_node.alloc_connection()
3449+
3450+
check_query(
3451+
clickhouse_node,
3452+
"SHOW TABLES FROM create_without_connection FORMAT TSV",
3453+
"test\n",
3454+
)

tests/integration/test_materialized_mysql_database/test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,3 +721,11 @@ def test_binlog_client(started_cluster, started_mysql_8_0, replication):
721721
materialized_with_ddl.gtid_after_attach_test(
722722
node_db, started_mysql_8_0, replication
723723
)
724+
725+
726+
def test_create_database_without_mysql_connection(
727+
started_cluster, started_mysql_8_0, clickhouse_node: ClickHouseInstance
728+
):
729+
materialized_with_ddl.mysql_create_database_without_connection(
730+
clickhouse_node, started_mysql_8_0, "mysql80"
731+
)

0 commit comments

Comments
 (0)