Jae
Jae

Reputation: 91

count() query on ClickHouse replication

Hello ClickHouse expects,

I am testing ClickHouse replications without zookeeper to understand how it works and have 2 questions.

How I tested:

(Q1) After the insertion, I query count() of log_local from all 3 servers and the total number is as expected (i.e. 200M). However, when I query using log_all, the outcomes are different among servers (close to 200M but not exact). And even stranger, the count changes even within the same server. Can you please explain this behavior? Can it be a configuration issue? With no replica (3shards_1replica) test, I don’t see this count difference.

I see this is not a recommended so, eventually, I’d use a cluster coordinator - hoping clickhouse-keeper is in production by then. Before that stage, I am assessing if I can use this as a temporary solution with explainable shortcomings.

(Q2) This is more a generic question on replication. The count of log_all is 200M which include replica’s. What is the practical way that I query it without replica? I.e., select count() from log_all (or a different name) yields 100M not 200M.

Configs (I have modified some names from the original for not showing private information):

    # remote_servers
    <log_3shards_2replicas>
     <shard>
         <replica>
             <host>CH1</host>
             <port>9000</port>
         </replica>
         <replica>
             <host>CH2</host>
             <port>9000</port>
         </replica>
     </shard>
     <shard>
         <replica>
             <host>CH2</host>
             <port>9000</port>
         </replica>
         <replica>
             <host>CH3</host>
             <port>9000</port>
         </replica>
     </shard>
     <shard>
         <replica>
             <host>CH3</host>
             <port>9000</port>
         </replica>
         <replica>
             <host>CH1</host>
             <port>9000</port>
         </replica>
     </shard>
    </log_3shards_2replicas>

    ENGINE = MergeTree
    PARTITION BY toYYYYMMDD(my_time)
    ORDER BY my_time
    SETTINGS index_granularity = 8192

    ENGINE = Distributed(‘log_3shards_2replicas', ‘my_db’, ‘log_local', rand()) 

Some references:

Similar issue discussions:

Thanks in advance.

Upvotes: 0

Views: 1336

Answers (1)

Denny Crane
Denny Crane

Reputation: 13310

You have configured a "circle-replication". God help you.

THIS CONFIGURATION IS NOT SUPPORTED and is not covered by tests in CI.

Circle-replication is hard to configure, very unobvious for newbies.

Circle-replication provides a lot of issues and hardiness to debug.

A lot queries yield incorrect results.

The most of users who used circle-replication in the past moved to usual setup N shards * M replica and happy now.

https://kb.altinity.com/engines/

https://youtu.be/4DlQ6sVKQaA

In your configuration DEFAULT_DATABASE attribute is missing, circle-replication unable to work without it.

Upvotes: 2

Related Questions