Replica already exists

3,632 views
Skip to first unread message

gba...@gmail.com

unread,
Dec 14, 2020, 1:57:34 PM12/14/20
to ClickHouse
Hi all,

Testing my application, I automatically create and destroy several tables in a cluster environment.

To create tables
CREATE TABLE IF NOT EXISTS databaseSchema.tableTestName on cluster '{cluster}' (...) ENGINE = ENGINE = ReplicatedMergeTree ('/ clickhouse / tables / {shard} / {table}', '{replica}') PARTITION ...
and to eliminate
DROP TABLE IF EXISTS databaseSchema.tableTestName on cluster '{cluster}';

This apparently works correctly. But when I recreate the same table (in another test) I get the error.

 DB :: Exception: Replica / clickhouse / tables / 01 / STATS_USERTEST / replicas / node1 already exists. (version 20.11.4.13 (official build))
 
How can I avoid this error programmatically? (I have seen that I can manually delete the replica file)

Thanks

Denis Zhuravlev

unread,
Dec 14, 2020, 7:33:53 PM12/14/20
to ClickHouse
This is a behavior related to Atomic database engine.
When a table in Atomic database been dropped it is not removed immediately but after 480s.

```
config.xml
<database_atomic_delay_before_drop_table_sec>480</database_atomic_delay_before_drop_table_sec>
```
https://github.com/ClickHouse/ClickHouse/blob/master/tests/config/config.d/database_atomic.xml

You can
1. use ordinary database instead of atomic. `create database ... Engine=Ordinary.`
2. use uniq ZK path `/clickhouse/tables/{layer}-{shard}-{uuid}/streams.streams_apps_ext_log_test`
3. reduce `database_atomic_delay_before_drop_table_sec = 0;` &  `drop table ... sync`


Reply all
Reply to author
Forward
0 new messages