create database test on cluster ' {cluster}' Engine= Ordinary;
create table test .test on cluster ' {cluster}' (A Int64)
Engine = ReplicatedMergeTree(' /clickhouse/{cluster}/tables/{database}/{table}' , ' {replica}' ) order by A;
create table test .test_b on cluster ' {cluster}' as test .test
Engine = Buffer(test, test, 1 , 1 , 2 , 10 , 100 , 10000000 , 100000000 );
Replica1:
-- emulate RO ReplicatedMergeTree
detach table test .test ;
attach table test .test (A Int64) Engine = ReplicatedMergeTree(' /clickhouse/{cluster}/tables/{database}/xxxxx' , ' {replica}' order by A;
for i in ` seq 1 5000` ; do clickhouse- client - q " insert into test.test_b values ($i)" ; done;
Received exception from server (version 22 .8 .13 ):
Code: 242 . DB::Exception: Received from localhost:9000 . DB::Exception: Table is in readonly mode (replica path : / clickhouse/ ch/ tables/ test/ xxxxx/ replicas/ Replica1). (TABLE_IS_READ_ONLY)
(query: insert into test .test_b values (86 ))
Received exception from server (version 22 .8 .13 ):
Code: 242 . DB::Exception: Received from localhost:9000 . DB::Exception: Table is in readonly mode (replica path : / clickhouse/ ch/ tables/ test/ xxxxx/ replicas/ Replica1). (TABLE_IS_READ_ONLY)
(query: insert into test .test_b values (102 ))
Received exception from server (version 22 .8 .13 ):
select count () from test .test ;
┌─count ()─┐
│ 0 │
└─────────┘
select count () from test .test_b ;
┌─count ()─┐
│ 100 │ -- 100 rows in the Buffer table
└─────────┘
Replica2:
select count () from test .test ;
┌─count ()─┐
│ 0 │
└─────────┘
select count () from test .test_b ;
┌─count ()─┐
│ 0 │
└─────────┘
Buffer -> Distributed -> Replicated
cat /etc/clickhouse-server/users.d/prefer_localhost_replica.xml
<?xml version =" 1.0" ?>
<clickhouse >
<profiles >
<default >
<load_balancing >random</load_balancing >
<prefer_localhost_replica >0</prefer_localhost_replica >
</default >
</profiles >
</clickhouse >
create table test .test on cluster ' {cluster}' (A Int64)
Engine = ReplicatedMergeTree(' /clickhouse/{cluster}/tables/{database}/{table}' , ' {replica}' )
order by A;
create table test .test_d on cluster ' {cluster}' as test .test
Engine = Distributed (' {cluster}' , test, test, rand());
create table test .test_b on cluster ' {cluster}' as test .test
Engine = Buffer(test, test_d, 1 , 1 , 2 , 10 , 100 , 10000000 , 100000000 );
Replica1:
-- emulate RO ReplicatedMergeTree
detach table test .test ;
attach table test .test (A Int64)
Engine = ReplicatedMergeTree(' /clickhouse/{cluster}/tables/{database}/xxxxx' , ' {replica}' ) order by A;
for i in ` seq 1 5000` ; do clickhouse- client - q " insert into test.test_b values ($i)" ; done;
No errors
select count () from test .test ;
┌─count ()─┐
│ 0 │
└─────────┘
Replica2:
select count () from test .test ;
┌─count ()─┐
│ 5000 │
└─────────┘