Skip to content

Commit aa02020

Browse files
authored
Merge pull request ClickHouse#78277 from XuJia0210/feature_refreshable_mv_ignore_RO
bugfix: should not schedule RefreshMV task to read_only node
2 parents b84c383 + 26c77e2 commit aa02020

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

src/Storages/MaterializedView/RefreshTask.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ namespace ServerSetting
4242
{
4343
extern const ServerSettingsString default_replica_name;
4444
extern const ServerSettingsString default_replica_path;
45+
extern const ServerSettingsBool disable_insertion_and_mutation;
4546
}
4647

4748
namespace RefreshSetting
@@ -87,6 +88,10 @@ RefreshTask::RefreshTask(
8788

8889
auto zookeeper = context->getZooKeeper();
8990
String replica_path = coordination.path + "/replicas/" + coordination.replica_name;
91+
92+
if (server_settings[ServerSetting::disable_insertion_and_mutation])
93+
coordination.read_only = true;
94+
9095
if (attach)
9196
{
9297
/// Check that this replica is registered in keeper.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<clickhouse>
2+
<disable_insertion_and_mutation>true</disable_insertion_and_mutation>
3+
</clickhouse>

tests/integration/test_refreshable_mv/test.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@
2929
keeper_required_feature_flags=["multi_read", "create_if_not_exists"],
3030
macros={"shard": "shard1", "replica": "2"},
3131
)
32+
33+
reading_node = cluster.add_instance(
34+
"reading_node",
35+
main_configs=["configs/read_only.xml"],
36+
user_configs=["configs/users.xml"],
37+
with_zookeeper=True,
38+
keeper_required_feature_flags=["multi_read", "create_if_not_exists"],
39+
macros={"shard": "shard1", "replica": "3"},
40+
)
3241
nodes = [node1, node2]
3342

3443

@@ -223,6 +232,60 @@ def test_refreshable_mv_in_system_db(started_cluster):
223232

224233
node1.query("drop table system.a")
225234

235+
def test_refreshable_mv_in_read_only_node(started_cluster):
236+
# writable node
237+
node1.query(
238+
"create database re engine = Replicated('/test/re', 'shard1', '{replica}');"
239+
)
240+
241+
# read_only node
242+
reading_node.query(
243+
"create database re engine = Replicated('/test/re', 'shard1', '{replica}');"
244+
)
245+
246+
# disable view sync on writable node, see if there's RefreshTask on read_only node
247+
node1.query(
248+
"system stop view sync"
249+
)
250+
251+
# clear text_log ensure all logs are related to this test
252+
reading_node.query(
253+
"system flush logs;"
254+
"truncate table system.text_log;"
255+
)
256+
257+
# this MV will be replicated to read_only node
258+
node1.query(
259+
"create materialized view re.a refresh every 1 second (x Int64) engine ReplicatedMergeTree order by x as select number*10 as x from numbers(2)"
260+
)
261+
262+
# refresh the view manually
263+
reading_node.query("system refresh view re.a")
264+
265+
# slepp 3 seconds to make sure the view is refreshed
266+
reading_node.query("select sleep(3)")
267+
268+
# check if there's RefreshTask on read_only node
269+
reading_node.query("system flush logs")
270+
assert reading_node.query("select count() from system.text_log where message like '%QUERY_IS_PROHIBITED%'") == "0\n"
271+
assert reading_node.query("select count() from system.view_refreshes where exception != ''") == "0\n"
272+
273+
# start sync and chek refresh task works well on node1
274+
node1.query("system start view sync")
275+
node1.query("system refresh view re.a")
276+
assert_eq_with_retry(
277+
node1,
278+
"select * from re.a order by x",
279+
"0\n10\n",
280+
)
281+
assert_eq_with_retry(
282+
node1,
283+
"select count() from system.view_refreshes where exception = '' and last_refresh_replica = '1'",
284+
"1\n",
285+
)
286+
287+
reading_node.query("drop database re sync")
288+
node1.query("drop database re sync")
226289

227290
def test_refresh_vs_shutdown_smoke(started_cluster):
228291
for node in nodes:

0 commit comments

Comments
 (0)