Skip to content

Commit

Permalink
Add allow without connection setting to MaterializedMySQLSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgarbar committed May 6, 2024
1 parent cb4f78d commit a20ef2a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/en/engines/database-engines/materialized-mysql.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ ENGINE = MaterializedMySQL('host:port', ['database' | database], 'user', 'passwo
### allows_query_when_mysql_lost
`allows_query_when_mysql_lost` — Allows to query a materialized table when MySQL is lost. Default: `0` (`false`).

### allow_startup_database_without_connection_to_mysql
`allow_startup_database_without_connection_to_mysql` — Allow to create and attach database without available connection to MySQL. Default: `0` (`false`).

### materialized_mysql_tables_list

`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.
Expand Down
6 changes: 5 additions & 1 deletion src/Databases/MySQL/DatabaseMaterializedMySQL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@ LoadTaskPtr DatabaseMaterializedMySQL::startupDatabaseAsync(AsyncLoader & async_
base->goals(),
TablesLoaderBackgroundStartupPoolId,
fmt::format("startup MaterializedMySQL database {}", getDatabaseName()),
[this] (AsyncLoader &, const LoadJobPtr &)
[this, mode] (AsyncLoader &, const LoadJobPtr &)
{
LOG_TRACE(log, "Starting MaterializeMySQL database");
if (!settings->allow_startup_database_without_connection_to_mysql
&& mode < LoadingStrictnessLevel::FORCE_ATTACH)
materialize_thread.assertMySQLAvailable();

materialize_thread.startSynchronization();
started_up = true;
});
Expand Down
1 change: 1 addition & 0 deletions src/Databases/MySQL/MaterializedMySQLSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ASTStorage;
M(UInt64, max_milliseconds_to_wait_in_binlog_queue, 10000, "Max milliseconds to wait when max bytes exceeded in a binlog queue.", 0) \
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) \
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) \
M(Bool, allow_startup_database_without_connection_to_mysql, false, "Allow to create and attach database without available connection to MySQL.", 0) \

DECLARE_SETTINGS_TRAITS(MaterializedMySQLSettingsTraits, LIST_OF_MATERIALIZE_MODE_SETTINGS)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3425,8 +3425,21 @@ def mysql_create_database_without_connection(clickhouse_node, mysql_node, servic

clickhouse_node.cluster.pause_container(service_name)

assert "ConnectionFailed:" in clickhouse_node.query_and_get_error(
"""
CREATE DATABASE create_without_connection
ENGINE = MaterializedMySQL('{}:3306', 'create_without_connection', 'root', 'clickhouse')
""".format(
service_name
)
)

clickhouse_node.query(
"CREATE DATABASE create_without_connection ENGINE = MaterializedMySQL('{}:3306', 'create_without_connection', 'root', 'clickhouse') SETTINGS max_wait_time_when_mysql_unavailable=-1".format(
"""
CREATE DATABASE create_without_connection
ENGINE = MaterializedMySQL('{}:3306', 'create_without_connection', 'root', 'clickhouse')
SETTINGS allow_startup_database_without_connection_to_mysql=1
""".format(
service_name
)
)
Expand Down

0 comments on commit a20ef2a

Please sign in to comment.