Skip to content

Commit 44e9e1a

Browse files
Merge pull request ClickHouse#87239 from ClickHouse/backport/25.8/87043
Backport ClickHouse#87043 to 25.8: Fix lightweight updates on cluster
2 parents faf7be5 + fb5132c commit 44e9e1a

File tree

3 files changed

+77
-4
lines changed

3 files changed

+77
-4
lines changed

src/Interpreters/InterpreterUpdateQuery.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <Storages/MutationCommands.h>
1919
#include <Core/Settings.h>
2020
#include <Core/ServerSettings.h>
21+
#include <Interpreters/executeDDLQueryOnCluster.h>
2122

2223

2324
namespace DB
@@ -73,14 +74,24 @@ BlockIO InterpreterUpdateQuery::execute()
7374
if (!settings[Setting::enable_lightweight_update])
7475
throw Exception(ErrorCodes::SUPPORT_IS_DISABLED, "Lightweight updates are not allowed. Set 'enable_lightweight_update = 1' to allow them");
7576

77+
FunctionNameNormalizer::visit(query_ptr.get());
78+
auto & update_query = query_ptr->as<ASTUpdateQuery &>();
79+
80+
AccessRightsElements required_access;
81+
required_access.emplace_back(AccessType::ALTER_UPDATE, update_query.getDatabase(), update_query.getTable());
82+
83+
if (!update_query.cluster.empty())
84+
{
85+
DDLQueryOnClusterParams params;
86+
params.access_to_check = std::move(required_access);
87+
return executeDDLQueryOnCluster(query_ptr, getContext(), params);
88+
}
89+
7690
if (getContext()->getGlobalContext()->getServerSettings()[ServerSetting::disable_insertion_and_mutation])
7791
throw Exception(ErrorCodes::QUERY_IS_PROHIBITED, "Update queries are prohibited");
7892

79-
FunctionNameNormalizer::visit(query_ptr.get());
80-
auto & update_query = query_ptr->as<ASTUpdateQuery &>();
93+
getContext()->checkAccess(required_access);
8194
auto table_id = getContext()->resolveStorageID(update_query, Context::ResolveOrdinary);
82-
83-
getContext()->checkAccess(AccessType::ALTER_UPDATE, table_id);
8495
update_query.setDatabase(table_id.database_name);
8596

8697
/// First check table storage for validations.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<clickhouse>
2+
<remote_servers>
3+
<test_cluster>
4+
<shard>
5+
<replica>
6+
<host>node1</host>
7+
<port>9000</port>
8+
</replica>
9+
</shard>
10+
<shard>
11+
<replica>
12+
<host>node2</host>
13+
<port>9000</port>
14+
</replica>
15+
</shard>
16+
</test_cluster>
17+
</remote_servers>
18+
</clickhouse>

tests/integration/test_lightweight_updates/test.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
node1 = cluster.add_instance(
1010
"node1",
1111
with_zookeeper=True,
12+
main_configs=["configs/remote_servers.xml"],
1213
)
1314

1415
node2 = cluster.add_instance(
1516
"node2",
1617
with_zookeeper=True,
18+
main_configs=["configs/remote_servers.xml"],
1719
)
1820

1921
node3 = cluster.add_instance(
@@ -183,3 +185,45 @@ def test_lwu_upgrade(started_cluster, table_engine):
183185
)
184186
== "100000\n"
185187
)
188+
189+
190+
def test_lwu_on_cluster(started_cluster):
191+
node1.query("DROP TABLE IF EXISTS t_lwu_on_cluster")
192+
node2.query("DROP TABLE IF EXISTS t_lwu_on_cluster")
193+
194+
create_query = """
195+
CREATE TABLE t_lwu_on_cluster
196+
(
197+
`id` UInt32,
198+
`value` String,
199+
)
200+
ENGINE = MergeTree
201+
ORDER BY id
202+
SETTINGS enable_block_number_column = 1, enable_block_offset_column = 1
203+
"""
204+
205+
node1.query(create_query)
206+
node2.query(create_query)
207+
208+
node1.query(
209+
"INSERT INTO t_lwu_on_cluster SELECT number, '' FROM numbers(10000) WHERE number % 4 != 0"
210+
)
211+
node2.query(
212+
"INSERT INTO t_lwu_on_cluster SELECT number, '' FROM numbers(10000) WHERE number % 4 != 1"
213+
)
214+
215+
assert (
216+
node1.query(
217+
"SELECT count() from remote(test_cluster, currentDatabase(), t_lwu_on_cluster)"
218+
)
219+
== "15000\n"
220+
)
221+
node1.query(
222+
"UPDATE t_lwu_on_cluster ON CLUSTER test_cluster SET value = 'updated' WHERE id >= 2000 AND id < 3000"
223+
)
224+
assert (
225+
node1.query(
226+
"SELECT count() from remote(test_cluster, currentDatabase(), t_lwu_on_cluster) WHERE value = 'updated'"
227+
)
228+
== "1500\n"
229+
)

0 commit comments

Comments
 (0)