Skip to content

Commit

Permalink
Merge pull request #70310 from ClickHouse/fix-startup-scripts
Browse files Browse the repository at this point in the history
Fix context for startup scripts
  • Loading branch information
antonio2368 authored Oct 3, 2024
2 parents 0d08f0e + 86c0055 commit d3a6d7d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
8 changes: 6 additions & 2 deletions programs/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,9 @@ void loadStartupScripts(const Poco::Util::AbstractConfiguration & config, Contex
auto condition_write_buffer = WriteBufferFromOwnString();

LOG_DEBUG(log, "Checking startup query condition `{}`", condition);
executeQuery(condition_read_buffer, condition_write_buffer, true, context, callback, QueryFlags{ .internal = true }, std::nullopt, {});
auto startup_context = Context::createCopy(context);
startup_context->makeQueryContext();
executeQuery(condition_read_buffer, condition_write_buffer, true, startup_context, callback, QueryFlags{ .internal = true }, std::nullopt, {});

auto result = condition_write_buffer.str();

Expand All @@ -648,7 +650,9 @@ void loadStartupScripts(const Poco::Util::AbstractConfiguration & config, Contex
auto write_buffer = WriteBufferFromOwnString();

LOG_DEBUG(log, "Executing query `{}`", query);
executeQuery(read_buffer, write_buffer, true, context, callback, QueryFlags{ .internal = true }, std::nullopt, {});
auto startup_context = Context::createCopy(context);
startup_context->makeQueryContext();
executeQuery(read_buffer, write_buffer, true, startup_context, callback, QueryFlags{ .internal = true }, std::nullopt, {});
}
}
catch (...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,13 @@
<scripts>
<query>SELECT * FROM system.query_log LIMIT 1</query>
</scripts>
<scripts>
<query>SELECT 1 SETTINGS skip_unavailable_shards = 1</query>
<condition>SELECT 1;</condition>
</scripts>
<scripts>
<query>SELECT 1 SETTINGS skip_unavailable_shards = 1</query>
<condition>SELECT 1;</condition>
</scripts>
</startup_scripts>
</clickhouse>
6 changes: 6 additions & 0 deletions tests/integration/test_startup_scripts/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ def test_startup_scripts():
try:
cluster.start()
assert node.query("SHOW TABLES") == "TestTable\n"
assert (
node.query(
"SELECT value, changed FROM system.settings WHERE name = 'skip_unavailable_shards'"
)
== "0\t0\n"
)

finally:
cluster.shutdown()

0 comments on commit d3a6d7d

Please sign in to comment.