Skip to content

Instantly share code, notes, and snippets.

@den-crane
Last active June 1, 2022 16:49
Show Gist options
  • Select an option

  • Save den-crane/7e70d04a9f3014acf1bf369e5c57677a to your computer and use it in GitHub Desktop.

Select an option

Save den-crane/7e70d04a9f3014acf1bf369e5c57677a to your computer and use it in GitHub Desktop.
max_replica_delay_for_distributed_queries_test.sql
-- SERVER A
create table test_r(a Int64) Engine=ReplicatedMergeTree('/clickhouse/{cluster}/tables/{table}','{replica}') order by a;
insert into test_r select number from numbers(1e6);
create table test_d as test_r Engine=Distributed('replicated', dw,test_r);
select count() from test_r;
1000000
select count() from test_d;
1000000
system stop REPLICATED sends test_r; -- artificially stop replication to emulate replication lag
system stop FETCHES test_r;
-------------------------------------------------------------------------------------------------------------------
-- SERVER B
create table test_r(a Int64) Engine=ReplicatedMergeTree('/clickhouse/{cluster}/tables/{table}','{replica}') order by a;
select count() from test_r;
0 -- replication does not work (stop REPLICATED sends)
create table test_d as test_r Engine=Distributed('replicated', dw,test_r);
select count() from test_d;
0 -- incorrect result because max_replica_delay_for_distributed_queries = 300, and replication lag is less < 300
set max_replica_delay_for_distributed_queries=10;
select count() from test_d;
1000000 -- correct result max_replica_delay_for_distributed_queries=10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment