Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema migration not retried when a new replica is added and there are DNS resolution errors #1627

Open
noelaugustin opened this issue Jan 30, 2025 · 11 comments

Comments

@noelaugustin
Copy link

noelaugustin commented Jan 30, 2025

Hello folks,
I have been playing with Altinity operator in my local machine in a kind cluster, and it is generally great.
However when I create a cluster initially with 2 replicas, and later change to 3 replicas, I often see that the databases, and other tables are not added to the new replica.
Upon inspecting the logs, I find an error on the operator logs, which mentions below:

E0130 11:26:35.495125       1 connection.go:145] QueryContext():FAILED Query(http://clickhouse_operator:***@chi-my-ch-replcluster2-1-2.ch.svc.cluster.local:8123/) doRequest: transport failed to send a request to ClickHouse: dial tcp: lookup chi-my-ch-replcluster2-1-2.ch.svc.cluster.local on 10.96.0.10:53: no such host for SQL: SELECT
	count()
FROM
	system.clusters
WHERE
	cluster='replcluster2' AND is_local
W0130 11:26:35.495139       1 cluster.go:91] QueryAny():FAILED to run query on: chi-my-ch-replcluster2-1-2.ch.svc.cluster.local of [chi-my-ch-replcluster2-1-2.ch.svc.cluster.local] skip to next. err: doRequest: transport failed to send a request to ClickHouse: dial tcp: lookup chi-my-ch-replcluster2-1-2.ch.svc.cluster.local on 10.96.0.10:53: no such host
E0130 11:26:35.495146       1 cluster.go:95] QueryAny():FAILED to run query on all hosts [chi-my-ch-replcluster2-1-2.ch.svc.cluster.local]
I0130 11:26:35.495158       1 schemer.go:139] IsHostInCluster():The host 1-2 is outside of the cluster
I0130 11:26:35.887732       1 worker-config-map.go:81] updateConfigMap():ch/my-ch/d736dd80-df79-464a-87d8-193534f52721:Update ConfigMap ch/chi-my-ch-common-usersd
I0130 11:26:40.496332       1 cluster.go:84] Run query on: chi-my-ch-replcluster2-1-2.ch.svc.cluster.local of [chi-my-ch-replcluster2-1-2.ch.svc.cluster.local]
E0130 11:26:40.499465       1 connection.go:145] QueryContext():FAILED Query(http://clickhouse_operator:***@chi-my-ch-replcluster2-1-2.ch.svc.cluster.local:8123/) doRequest: transport failed to send a request to ClickHouse: dial tcp: lookup chi-my-ch-replcluster2-1-2.ch.svc.cluster.local on 10.96.0.10:53: no such host for SQL: SELECT
	count()
FROM
	system.clusters
WHERE
	cluster='replcluster2' AND is_local
W0130 11:26:40.499502       1 cluster.go:91] QueryAny():FAILED to run query on: chi-my-ch-replcluster2-1-2.ch.svc.cluster.local of [chi-my-ch-replcluster2-1-2.ch.svc.cluster.local] skip to next. err: doRequest: transport failed to send a request to ClickHouse: dial tcp: lookup chi-my-ch-replcluster2-1-2.ch.svc.cluster.local on 10.96.0.10:53: no such host

Due to this error, the further steps(create table, etc) don't seem to work.
This seems to be a problem with the dns service that my cluster uses. However, the operator not being able to retry looks like an issue to me . What do you think?

The yaml for the service manifest is as follows(It was created around 9-13 seconds before this connection was attempted, please check the log timestamp and the creationTimestamp in the manifest)

apiVersion: v1
kind: Service
metadata:
  annotations:
    clickhouse.altinity.com/ready: "yes"
  creationTimestamp: "2025-01-30T11:26:27Z"
  labels:
    clickhouse.altinity.com/Service: host
    clickhouse.altinity.com/app: chop
    clickhouse.altinity.com/chi: my-ch
    clickhouse.altinity.com/cluster: replcluster2
    clickhouse.altinity.com/namespace: ch
    clickhouse.altinity.com/object-version: f83434cd012342a2afdc2027c734780554ea0340
    clickhouse.altinity.com/replica: "2"
    clickhouse.altinity.com/shard: "1"
  name: chi-my-ch-replcluster2-1-2
  namespace: ch
  ownerReferences:
  - apiVersion: clickhouse.altinity.com/v1
    blockOwnerDeletion: true
    controller: true
    kind: ClickHouseInstallation
    name: my-ch
    uid: cd3a8563-d64d-4b99-95e4-657c73e0c8c6
  resourceVersion: "92951"
  uid: 39535681-f136-4de2-8ed5-6fd5e7402045
spec:
  clusterIP: None
  clusterIPs:
  - None
  internalTrafficPolicy: Cluster
  ipFamilies:
  - IPv4
  ipFamilyPolicy: SingleStack
  ports:
  - name: tcp
    port: 9000
    protocol: TCP
    targetPort: 9000
  - name: http
    port: 8123
    protocol: TCP
    targetPort: 8123
  - name: interserver
    port: 9009
    protocol: TCP
    targetPort: 9009
  publishNotReadyAddresses: true
  selector:
    clickhouse.altinity.com/app: chop
    clickhouse.altinity.com/chi: my-ch
    clickhouse.altinity.com/cluster: replcluster2
    clickhouse.altinity.com/namespace: ch
    clickhouse.altinity.com/replica: "2"
    clickhouse.altinity.com/shard: "1"
  sessionAffinity: None
  type: ClusterIP
status:
  loadBalancer: {}

Also, please find the Clickhouse installation's manifest below, after increasing the replica count to 3. I am using the default recommended configuration for the operator

apiVersion: "clickhouse.altinity.com/v1"
kind: "ClickHouseInstallation"

metadata:
  name: "my-ch"

spec:
  configuration:
    zookeeper:
      nodes:
        - host: zookeeper-0.zookeepers.zk
    clusters:
      - name: replcluster2
        zookeeper:
          nodes:
            - host: zookeeper-0.zookeepers.zk
        layout:
          replicasCount: 3
          shardsCount: 2

It would be great to know if this is a bug. I would be happy to pick it up and fix the bug, thanks

@noelaugustin noelaugustin changed the title Schema migration not working when a new replica is added Schema migration not working when a new replica is added and there are DNS resolution errors Jan 31, 2025
@noelaugustin noelaugustin changed the title Schema migration not working when a new replica is added and there are DNS resolution errors Schema migration not retried when a new replica is added and there are DNS resolution errors Jan 31, 2025
@Slach
Copy link
Collaborator

Slach commented Jan 31, 2025

check your pod status first, maybe some pods in pending status
kubectl get pods --all-namespaces -l clickhouse.altinity.com/cluster=replcluster2

second
check status of chi
kubectl get chi --all-namespaces
is this Aborted or Completed?

@noelaugustin
Copy link
Author

Thanks for your response,
Please find my screenshot here. It also shows the replica list for both shards

In short, when I move from replicasCount=2, shardsCount=2 to replicasCount=3, shardsCount=2. the first shard is causing the problem. I can see that the new replica is not added to system.replica.
kubectl get chi gives me Completed status, and all pods are alive and ready

Image

@Slach
Copy link
Collaborator

Slach commented Jan 31, 2025

could you share text information as text without sensitive credentials?

this is hard to understand your pictures

@Slach
Copy link
Collaborator

Slach commented Jan 31, 2025

lookup chi-my-ch-replcluster2-1-2.ch.svc.cluster.local on 10.96.0.10:53: no such host

means no ready pods chi-my-ch-replcluster2-1-2-0 under service chi-my-ch-replcluster2-1-2

what is your kubernetes provider?

@noelaugustin
Copy link
Author

I am using kind as my provider.
I also wanted to show some other findings as well.

I see the DNS related errors for almost every scale out, but it recovers most of the time and the replicas show up in the query

but it is when I has two shards, that I start facing issues when I scale from a lower number to a higher number and the new replicas don't show up in the query. Sometimes, I see that one shard end up having all the replicas, but some other time, I see none having the replicas. I have shared the query as well

Sharing text of the output below

[naugustin@GR4PTJWQG1 ~]$ k get chi
NAME    CLUSTERS   HOSTS   STATUS      HOSTS-COMPLETED   AGE   SUSPEND
my-ch   1          6       Completed                     17m
[naugustin@GR4PTJWQG1 ~]$ kubectl get pod
NAME                           READY   STATUS    RESTARTS   AGE
chi-my-ch-replcluster2-0-0-0   1/1     Running   0          44m
chi-my-ch-replcluster2-0-1-0   1/1     Running   0          43m
chi-my-ch-replcluster2-0-2-0   1/1     Running   0          29m
chi-my-ch-replcluster2-1-0-0   1/1     Running   0          33m
chi-my-ch-replcluster2-1-1-0   1/1     Running   0          32m
chi-my-ch-replcluster2-1-2-0   1/1     Running   0          29m
[naugustin@GR4PTJWQG1 ~]$ kubectl get svc
NAME                         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                      AGE
chi-my-ch-replcluster2-0-0   ClusterIP   None         <none>        9000/TCP,8123/TCP,9009/TCP   44m
chi-my-ch-replcluster2-0-1   ClusterIP   None         <none>        9000/TCP,8123/TCP,9009/TCP   44m
chi-my-ch-replcluster2-0-2   ClusterIP   None         <none>        9000/TCP,8123/TCP,9009/TCP   30m
chi-my-ch-replcluster2-1-0   ClusterIP   None         <none>        9000/TCP,8123/TCP,9009/TCP   33m
chi-my-ch-replcluster2-1-1   ClusterIP   None         <none>        9000/TCP,8123/TCP,9009/TCP   33m
chi-my-ch-replcluster2-1-2   ClusterIP   None         <none>        9000/TCP,8123/TCP,9009/TCP   29m
clickhouse-my-ch             ClusterIP   None         <none>        8123/TCP,9000/TCP            44m

Replica information from first shard:

SELECT
    replica_name,
    total_replicas,
    active_replicas,
    replica_is_active
FROM system.replicas

Query id: 4ba9933c-a0d4-49b5-ad5c-aa7f60a43387

Connecting to database dataset at localhost:9000 as user default.
Connected to ClickHouse server version 25.1.2.

ClickHouse client version is older than ClickHouse server. It may lack support for new features.

   ┌─replica_name───────────────┬─total_replicas─┬─active_replicas─┬─replica_is_active───────────────────────────────────────────────┐
1. │ chi-my-ch-replcluster2-0-0 │              2 │               2 │ {'chi-my-ch-replcluster2-0-0':1,'chi-my-ch-replcluster2-0-1':1} │
   └────────────────────────────┴────────────────┴─────────────────┴─────────────────────────────────────────────────────────────────┘


Replica information from second shard

SELECT
    replica_name,
    total_replicas,
    active_replicas,
    replica_is_active
FROM system.replicas

Query id: 28475600-340c-4824-b0e8-238c071c2cf2

   ┌─replica_name───────────────┬─total_replicas─┬─active_replicas─┬─replica_is_active──────────────────────────────────────────────────────────────────────────────┐
1. │ chi-my-ch-replcluster2-1-0 │              3 │               3 │ {'chi-my-ch-replcluster2-1-2':1,'chi-my-ch-replcluster2-1-1':1,'chi-my-ch-replcluster2-1-0':1} │
   └────────────────────────────┴────────────────┴─────────────────┴────────────────────────────────────────────────────────────────────────────────────────────────┘

@Slach
Copy link
Collaborator

Slach commented Jan 31, 2025

system.replicas is table which represented ReplicatedMergeTree tables only not "whole server replicas"

could you share
SELECT hostName(), * FROM cluster('all-sharded',system.replicas) FORMAT Vertical

also which clickhouse-operator version do you use? and how exactly did you install it inside kind?

@noelaugustin
Copy link
Author

This is when I have 3 replicas and two shards

SELECT
    hostName(),
    *
FROM cluster('replcluster2', system.replicas)
FORMAT Vertical

Query id: 5f54ee92-538e-4977-981b-4808cd7ca0c6

Row 1:
──────
hostName():                  chi-my-ch-replcluster2-0-0-0
database:                    dataset
table:                       uk_price_paid_v4
engine:                      ReplicatedMergeTree
is_leader:                   1
can_become_leader:           1
is_readonly:                 0
readonly_start_time:         ᴺᵁᴸᴸ
is_session_expired:          0
future_parts:                0
parts_to_check:              0
zookeeper_name:              default
zookeeper_path:              /clickhouse/tables/0/uk_price_paid_v4
replica_name:                chi-my-ch-replcluster2-0-0
replica_path:                /clickhouse/tables/0/uk_price_paid_v4/replicas/chi-my-ch-replcluster2-0-0
columns_version:             -1
queue_size:                  0
inserts_in_queue:            0
merges_in_queue:             0
part_mutations_in_queue:     0
queue_oldest_time:           1970-01-01 00:00:00
inserts_oldest_time:         1970-01-01 00:00:00
merges_oldest_time:          1970-01-01 00:00:00
part_mutations_oldest_time:  1970-01-01 00:00:00
oldest_part_to_get:
oldest_part_to_merge_to:
oldest_part_to_mutate_to:
log_max_index:               0
log_pointer:                 1
last_queue_update:           2025-01-31 09:28:24
absolute_delay:              0
total_replicas:              1
active_replicas:             1
lost_part_count:             0
last_queue_update_exception:
zookeeper_exception:
replica_is_active:           {'chi-my-ch-replcluster2-0-0':1}

1 row in set. Elapsed: 0.014 sec.

I used kubectl apply -f https://raw.githubusercontent.com/Altinity/clickhouse-operator/master/deploy/operator/clickhouse-operator-install-bundle.yaml from operator installation instructions

It might be worth asking if I should do anything manually before setting the replicasCount, shardsCount perhaps in ZK/ existing nodes, which when missed causes this issue?

@Slach
Copy link
Collaborator

Slach commented Feb 1, 2025

ok. thanks but you shared a little bit different query
i asked about different auto-generated all-sharded cluster

could you share
SELECT hostName(), * FROM cluster('all-sharded',system.replicas) FORMAT Vertical

let me time i will try to rerpoduce kind DNS error behaviors

@noelaugustin
Copy link
Author

Hi, sorry about that,
I had lost my setup and I have created the cluster again. Please find the files here:

Environment: kind cluster
Operator installation : kubectl apply -f https://raw.githubusercontent.com/Altinity/clickhouse-operator/master/deploy/operator/clickhouse-operator-install-bundle.yaml

Zookeeper manifest:

# Setup Service to provide access to Zookeeper for clients
apiVersion: v1
kind: Service
metadata:
  # DNS would be like zookeeper.zoons
  name: zookeeper
  labels:
    app: zookeeper
spec:
  ports:
    - port: 2181
      name: client
    - port: 7000
      name: prometheus
  selector:
    app: zookeeper
    what: node
---
# Setup Headless Service for StatefulSet
apiVersion: v1
kind: Service
metadata:
  # DNS would be like zookeeper-0.zookeepers.etc
  name: zookeepers
  labels:
    app: zookeeper
spec:
  ports:
    - port: 2888
      name: server
    - port: 3888
      name: leader-election
  clusterIP: None
  selector:
    app: zookeeper
    what: node
---
# Setup max number of unavailable pods in StatefulSet
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: zookeeper-pod-disruption-budget
spec:
  selector:
    matchLabels:
      app: zookeeper
  maxUnavailable: 1
---
# Setup Zookeeper StatefulSet
# Possible params:
# 1. replicas
# 2. memory
# 3. cpu
# 4. storage
# 5. storageClassName
# 6. user to run app
apiVersion: apps/v1
kind: StatefulSet
metadata:
  # nodes would be named as zookeeper-0, zookeeper-1, zookeeper-2
  name: zookeeper
  labels:
    app: zookeeper
spec:
  selector:
    matchLabels:
      app: zookeeper
  serviceName: zookeepers
  replicas: 1
  updateStrategy:
    type: RollingUpdate
  podManagementPolicy: OrderedReady
  template:
    metadata:
      labels:
        app: zookeeper
        what: node
      annotations:
        prometheus.io/port: '7000'
        prometheus.io/scrape: 'true'
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values:
                      - zookeeper
              # TODO think about multi-AZ EKS
              # topologyKey: topology.kubernetes.io/zone
              topologyKey: "kubernetes.io/hostname"
      containers:
        - name: kubernetes-zookeeper
          imagePullPolicy: IfNotPresent
          image: "docker.io/zookeeper:3.8.4"
          resources:
            requests:
              memory: "512M"
              cpu: "1"
            limits:
              memory: "4Gi"
              cpu: "2"
          ports:
            - containerPort: 2181
              name: client
            - containerPort: 2888
              name: server
            - containerPort: 3888
              name: leader-election
            - containerPort: 7000
              name: prometheus
          env:
            - name: SERVERS
              value: "1"

# See those links for proper startup settings:
# https://github.com/kow3ns/kubernetes-zookeeper/blob/master/docker/scripts/start-zookeeper
# https://clickhouse.yandex/docs/en/operations/tips/#zookeeper
# https://github.com/ClickHouse/ClickHouse/issues/11781
          command:
            - bash
            - -x
            - -c
            - |
              HOST=`hostname -s` &&
              DOMAIN=`hostname -d` &&
              CLIENT_PORT=2181 &&
              SERVER_PORT=2888 &&
              ELECTION_PORT=3888 &&
              PROMETHEUS_PORT=7000 &&
              ZOO_DATA_DIR=/var/lib/zookeeper/data &&
              ZOO_DATA_LOG_DIR=/var/lib/zookeeper/datalog &&
              {
                echo "clientPort=${CLIENT_PORT}"
                echo 'tickTime=2000'
                echo 'initLimit=300'
                echo 'syncLimit=10'
                echo 'maxClientCnxns=2000'
                echo 'maxTimeToWaitForEpoch=2000'
                echo 'maxSessionTimeout=60000000'
                echo "dataDir=${ZOO_DATA_DIR}"
                echo "dataLogDir=${ZOO_DATA_LOG_DIR}"
                echo 'autopurge.snapRetainCount=10'
                echo 'autopurge.purgeInterval=1'
                echo 'preAllocSize=131072'
                echo 'snapCount=3000000'
                echo 'leaderServes=yes'
                echo 'standaloneEnabled=false'
                echo '4lw.commands.whitelist=*'
                echo 'metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider'
                echo "metricsProvider.httpPort=${PROMETHEUS_PORT}"
                echo "skipACL=true"
                echo "fastleader.maxNotificationInterval=10000"
              } > /conf/zoo.cfg &&
              {
                echo "zookeeper.root.logger=CONSOLE"
                echo "zookeeper.console.threshold=INFO"
                echo "log4j.rootLogger=\${zookeeper.root.logger}"
                echo "log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender"
                echo "log4j.appender.CONSOLE.Threshold=\${zookeeper.console.threshold}"
                echo "log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout"
                echo "log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n"
              } > /conf/log4j.properties &&
              echo 'JVMFLAGS="-Xms128M -Xmx4G -XX:ActiveProcessorCount=8 -XX:+AlwaysPreTouch -Djute.maxbuffer=8388608 -XX:MaxGCPauseMillis=50"' > /conf/java.env &&
              if [[ $HOST =~ (.*)-([0-9]+)$ ]]; then
                  NAME=${BASH_REMATCH[1]} &&
                  ORD=${BASH_REMATCH[2]};
              else
                  echo "Failed to parse name and ordinal of Pod" &&
                  exit 1;
              fi &&
              mkdir -pv ${ZOO_DATA_DIR} &&
              mkdir -pv ${ZOO_DATA_LOG_DIR} &&
              whoami &&
              chown -Rv zookeeper "$ZOO_DATA_DIR" "$ZOO_DATA_LOG_DIR" &&
              export MY_ID=$((ORD+1)) &&
              echo $MY_ID > $ZOO_DATA_DIR/myid &&
              for (( i=1; i<=$SERVERS; i++ )); do
                  echo "server.$i=$NAME-$((i-1)).$DOMAIN:$SERVER_PORT:$ELECTION_PORT" >> /conf/zoo.cfg;
              done &&
              if [[ $SERVERS -eq 1 ]]; then
                  echo "group.1=1" >> /conf/zoo.cfg;
              else
                  echo "group.1=1:2:3" >> /conf/zoo.cfg;
              fi &&
              for (( i=1; i<=$SERVERS; i++ )); do
                  WEIGHT=1
                  if [[ $i == 1 ]]; then
                    WEIGHT=10
                  fi
                  echo "weight.$i=$WEIGHT" >> /conf/zoo.cfg;
              done &&
              zkServer.sh start-foreground
          readinessProbe:
            exec:
              command:
                - bash
                - -c
                - |
                  IFS=; 
                  MNTR=$(exec 3<>/dev/tcp/127.0.0.1/2181 ; printf "mntr" >&3 ; tee <&3; exec 3<&- ;);
                  while [[ "$MNTR" == "This ZooKeeper instance is not currently serving requests" ]];
                  do
                    echo "wait mntr works";
                    sleep 1;
                    MNTR=$(exec 3<>/dev/tcp/127.0.0.1/2181 ; printf "mntr" >&3 ; tee <&3; exec 3<&- ;);
                  done;
                  STATE=$(echo -e $MNTR | grep zk_server_state | cut -d " " -f 2);
                  if [[ "$STATE" =~ "leader" ]]; then
                    echo "check leader state";
                    SYNCED_FOLLOWERS=$(echo -e $MNTR | grep zk_synced_followers | awk -F"[[:space:]]+" "{print \$2}" | cut -d "." -f 1);
                    if [[ "$SYNCED_FOLLOWERS" != "0" ]]; then
                      ./bin/zkCli.sh ls /;
                      exit $?;
                    else
                      exit 0;
                    fi;
                  elif [[ "$STATE" =~ "follower" ]]; then
                    echo "check follower state";
                    PEER_STATE=$(echo -e $MNTR | grep zk_peer_state);
                    if [[ "$PEER_STATE" =~ "following - broadcast" ]]; then
                      ./bin/zkCli.sh ls /;
                      exit $?;
                    else
                      exit 1;
                    fi;
                  else
                    exit 1;  
                  fi
            initialDelaySeconds: 15
            periodSeconds: 10
            timeoutSeconds: 60
          livenessProbe:
            exec:
              command:
                - bash
                - -xc
                - 'date && OK=$(exec 3<>/dev/tcp/127.0.0.1/2181 ; printf "ruok" >&3 ; IFS=; tee <&3; exec 3<&- ;); if [[ "$OK" == "imok" ]]; then exit 0; else exit 1; fi'
            initialDelaySeconds: 10
            periodSeconds: 30
            timeoutSeconds: 5
          volumeMounts:
            - name: datadir-volume
              mountPath: /var/lib/zookeeper
      # Run as a non-privileged user
      securityContext:
        runAsUser: 1000
        fsGroup: 1000
  volumeClaimTemplates:
    - metadata:
        name: datadir-volume
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 25Gi

ClickhouseInstallation manifest:

apiVersion: "clickhouse.altinity.com/v1"
kind: "ClickHouseInstallation"

metadata:
  name: "test"

spec:
  configuration:
    zookeeper:
      nodes:
        - host: zookeeper-0.zookeepers.zk
    clusters:
      - name: r1
        zookeeper:
          nodes:
            - host: zookeeper-0.zookeepers.zk
        layout:
          replicasCount: 2
          shardsCount: 2

the commands used for creating the tables:

CREATE database if not exists dataset on cluster r1 
CREATE TABLE if not exists uk_price_paid_v1 on cluster r1
(
    price UInt32,
    date Date,
    postcode1 LowCardinality(String),
    postcode2 LowCardinality(String),
    type Enum8('terraced' = 1, 'semi-detached' = 2, 'detached' = 3, 'flat' = 4, 'other' = 0),
    is_new UInt8,
    duration Enum8('freehold' = 1, 'leasehold' = 2, 'unknown' = 0),
    addr1 String,
    addr2 String,
    street LowCardinality(String),
    locality LowCardinality(String),
    town LowCardinality(String),
    district LowCardinality(String),
    county LowCardinality(String)
)
ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/uk_price_paid_v1', '{replica}')
ORDER BY (postcode1, postcode2, addr1, addr2);



INSERT INTO uk_price_paid
WITH
   splitByChar(' ', postcode) AS p
SELECT
    toUInt32(price_string) AS price,
    parseDateTimeBestEffortUS(time) AS date,
    p[1] AS postcode1,
    p[2] AS postcode2,
    transform(a, ['T', 'S', 'D', 'F', 'O'], ['terraced', 'semi-detached', 'detached', 'flat', 'other']) AS type,
    b = 'Y' AS is_new,
    transform(c, ['F', 'L', 'U'], ['freehold', 'leasehold', 'unknown']) AS duration,
    addr1,
    addr2,
    street,
    locality,
    town,
    district,
    county
FROM url(
    'http://prod.publicdata.landregistry.gov.uk.s3-website-eu-west-1.amazonaws.com/pp-complete.csv',
    'CSV',
    'uuid_string String,
    price_string String,
    time String,
    postcode String,
    a String,
    b String,
    c String,
    addr1 String,
    addr2 String,
    street String,
    locality String,
    town String,
    district String,
    county String,
    d String,
    e String'
) limit 5000 SETTINGS max_http_get_redirects=10;

Increase the replicas to 3(I start getting the issues after this)

apiVersion: "clickhouse.altinity.com/v1"
kind: "ClickHouseInstallation"

metadata:
  name: "test"

spec:
  configuration:
    zookeeper:
      nodes:
        - host: zookeeper-0.zookeepers.zk
    clusters:
      - name: r1
        zookeeper:
          nodes:
            - host: zookeeper-0.zookeepers.zk
        layout:
          replicasCount: 3
          shardsCount: 2

kubectl outputs:

[naugustin@GR4PTJWQG1 ~]$ kubectl get pod
NAME                READY   STATUS    RESTARTS   AGE
chi-test-r1-0-0-0   1/1     Running   0          43m
chi-test-r1-0-1-0   1/1     Running   0          42m
chi-test-r1-0-2-0   1/1     Running   0          15m
chi-test-r1-1-0-0   1/1     Running   0          18m
chi-test-r1-1-1-0   1/1     Running   0          17m
chi-test-r1-1-2-0   1/1     Running   0          15m
[naugustin@GR4PTJWQG1 ~]$ kubectl get chi
NAME   CLUSTERS   HOSTS   STATUS      HOSTS-COMPLETED   AGE   SUSPEND
test   1          6       Completed                     43m
[naugustin@GR4PTJWQG1 ~]$ kubectl get svc
NAME              TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                      AGE
chi-test-r1-0-0   ClusterIP   None         <none>        9000/TCP,8123/TCP,9009/TCP   42m
chi-test-r1-0-1   ClusterIP   None         <none>        9000/TCP,8123/TCP,9009/TCP   42m
chi-test-r1-0-2   ClusterIP   None         <none>        9000/TCP,8123/TCP,9009/TCP   15m
chi-test-r1-1-0   ClusterIP   None         <none>        9000/TCP,8123/TCP,9009/TCP   18m
chi-test-r1-1-1   ClusterIP   None         <none>        9000/TCP,8123/TCP,9009/TCP   17m
chi-test-r1-1-2   ClusterIP   None         <none>        9000/TCP,8123/TCP,9009/TCP   15m
clickhouse-test   ClusterIP   None         <none>        8123/TCP,9000/TCP            42m

Replica query as you asked:

chi-test-r1-0-0-0.chi-test-r1-0-0.ch.svc.cluster.local :) SELECT hostName(), * FROM cluster('all-sharded',system.replicas) FORMAT Vertical

SELECT
    hostName(),
    *
FROM cluster('all-sharded', system.replicas)
FORMAT Vertical

Query id: eb492592-45d7-4e65-ac61-40af0e38dd84

Row 1:
──────
hostName():                  chi-test-r1-1-1-0
database:                    default
table:                       uk_price_paid_v1
engine:                      ReplicatedMergeTree
is_leader:                   1
can_become_leader:           1
is_readonly:                 0
readonly_start_time:         ᴺᵁᴸᴸ
is_session_expired:          0
future_parts:                0
parts_to_check:              0
zookeeper_name:              default
zookeeper_path:              /clickhouse/tables/1/uk_price_paid_v1
replica_name:                chi-test-r1-1-1
replica_path:                /clickhouse/tables/1/uk_price_paid_v1/replicas/chi-test-r1-1-1
columns_version:             -1
queue_size:                  0
inserts_in_queue:            0
merges_in_queue:             0
part_mutations_in_queue:     0
queue_oldest_time:           1970-01-01 00:00:00
inserts_oldest_time:         1970-01-01 00:00:00
merges_oldest_time:          1970-01-01 00:00:00
part_mutations_oldest_time:  1970-01-01 00:00:00
oldest_part_to_get:
oldest_part_to_merge_to:
oldest_part_to_mutate_to:
log_max_index:               0
log_pointer:                 0
last_queue_update:           1970-01-01 00:00:00
absolute_delay:              0
total_replicas:              3
active_replicas:             3
lost_part_count:             0
last_queue_update_exception:
zookeeper_exception:
replica_is_active:           {'chi-test-r1-1-2':1,'chi-test-r1-1-0':1,'chi-test-r1-1-1':1}

Row 2:
──────
hostName():                  chi-test-r1-0-1-0
database:                    default
table:                       uk_price_paid_v1
engine:                      ReplicatedMergeTree
is_leader:                   1
can_become_leader:           1
is_readonly:                 0
readonly_start_time:         ᴺᵁᴸᴸ
is_session_expired:          0
future_parts:                0
parts_to_check:              0
zookeeper_name:              default
zookeeper_path:              /clickhouse/tables/0/uk_price_paid_v1
replica_name:                chi-test-r1-0-1
replica_path:                /clickhouse/tables/0/uk_price_paid_v1/replicas/chi-test-r1-0-1
columns_version:             -1
queue_size:                  0
inserts_in_queue:            0
merges_in_queue:             0
part_mutations_in_queue:     0
queue_oldest_time:           1970-01-01 00:00:00
inserts_oldest_time:         1970-01-01 00:00:00
merges_oldest_time:          1970-01-01 00:00:00
part_mutations_oldest_time:  1970-01-01 00:00:00
oldest_part_to_get:
oldest_part_to_merge_to:
oldest_part_to_mutate_to:
log_max_index:               0
log_pointer:                 1
last_queue_update:           2025-02-04 04:03:44
absolute_delay:              0
total_replicas:              2
active_replicas:             2
lost_part_count:             0
last_queue_update_exception:
zookeeper_exception:
replica_is_active:           {'chi-test-r1-0-1':1,'chi-test-r1-0-0':1}

Row 3:
──────
hostName():                  chi-test-r1-1-2-0
database:                    default
table:                       uk_price_paid_v1
engine:                      ReplicatedMergeTree
is_leader:                   1
can_become_leader:           1
is_readonly:                 0
readonly_start_time:         ᴺᵁᴸᴸ
is_session_expired:          0
future_parts:                0
parts_to_check:              0
zookeeper_name:              default
zookeeper_path:              /clickhouse/tables/1/uk_price_paid_v1
replica_name:                chi-test-r1-1-2
replica_path:                /clickhouse/tables/1/uk_price_paid_v1/replicas/chi-test-r1-1-2
columns_version:             -1
queue_size:                  0
inserts_in_queue:            0
merges_in_queue:             0
part_mutations_in_queue:     0
queue_oldest_time:           1970-01-01 00:00:00
inserts_oldest_time:         1970-01-01 00:00:00
merges_oldest_time:          1970-01-01 00:00:00
part_mutations_oldest_time:  1970-01-01 00:00:00
oldest_part_to_get:
oldest_part_to_merge_to:
oldest_part_to_mutate_to:
log_max_index:               0
log_pointer:                 0
last_queue_update:           1970-01-01 00:00:00
absolute_delay:              0
total_replicas:              3
active_replicas:             3
lost_part_count:             0
last_queue_update_exception:
zookeeper_exception:
replica_is_active:           {'chi-test-r1-1-2':1,'chi-test-r1-1-0':1,'chi-test-r1-1-1':1}

Row 4:
──────
hostName():                  chi-test-r1-0-0-0
database:                    default
table:                       uk_price_paid_v1
engine:                      ReplicatedMergeTree
is_leader:                   1
can_become_leader:           1
is_readonly:                 0
readonly_start_time:         ᴺᵁᴸᴸ
is_session_expired:          0
future_parts:                0
parts_to_check:              0
zookeeper_name:              default
zookeeper_path:              /clickhouse/tables/0/uk_price_paid_v1
replica_name:                chi-test-r1-0-0
replica_path:                /clickhouse/tables/0/uk_price_paid_v1/replicas/chi-test-r1-0-0
columns_version:             -1
queue_size:                  0
inserts_in_queue:            0
merges_in_queue:             0
part_mutations_in_queue:     0
queue_oldest_time:           1970-01-01 00:00:00
inserts_oldest_time:         1970-01-01 00:00:00
merges_oldest_time:          1970-01-01 00:00:00
part_mutations_oldest_time:  1970-01-01 00:00:00
oldest_part_to_get:
oldest_part_to_merge_to:
oldest_part_to_mutate_to:
log_max_index:               0
log_pointer:                 1
last_queue_update:           2025-02-04 04:03:44
absolute_delay:              0
total_replicas:              2
active_replicas:             2
lost_part_count:             0
last_queue_update_exception:
zookeeper_exception:
replica_is_active:           {'chi-test-r1-0-1':1,'chi-test-r1-0-0':1}

Row 5:
──────
hostName():                  chi-test-r1-1-0-0
database:                    default
table:                       uk_price_paid_v1
engine:                      ReplicatedMergeTree
is_leader:                   1
can_become_leader:           1
is_readonly:                 0
readonly_start_time:         ᴺᵁᴸᴸ
is_session_expired:          0
future_parts:                0
parts_to_check:              0
zookeeper_name:              default
zookeeper_path:              /clickhouse/tables/1/uk_price_paid_v1
replica_name:                chi-test-r1-1-0
replica_path:                /clickhouse/tables/1/uk_price_paid_v1/replicas/chi-test-r1-1-0
columns_version:             -1
queue_size:                  0
inserts_in_queue:            0
merges_in_queue:             0
part_mutations_in_queue:     0
queue_oldest_time:           1970-01-01 00:00:00
inserts_oldest_time:         1970-01-01 00:00:00
merges_oldest_time:          1970-01-01 00:00:00
part_mutations_oldest_time:  1970-01-01 00:00:00
oldest_part_to_get:
oldest_part_to_merge_to:
oldest_part_to_mutate_to:
log_max_index:               0
log_pointer:                 0
last_queue_update:           1970-01-01 00:00:00
absolute_delay:              0
total_replicas:              3
active_replicas:             3
lost_part_count:             0
last_queue_update_exception:
zookeeper_exception:
replica_is_active:           {'chi-test-r1-1-2':1,'chi-test-r1-1-0':1,'chi-test-r1-1-1':1}

5 rows in set. Elapsed: 0.013 sec.

Replica queries on my cluster on first and second shards:

SELECT
    replica_name,
    total_replicas,
    active_replicas,
    replica_is_active
FROM cluster(r1, system.replicas)

Query id: 0f8aedba-fb3b-4cf7-9e71-e87018614fcb

   ┌─replica_name────┬─total_replicas─┬─active_replicas─┬─replica_is_active─────────────────────────────────────────────┐
1. │ chi-test-r1-0-0 │              2 │               2 │ {'chi-test-r1-0-1':1,'chi-test-r1-0-0':1}                     │
2. │ chi-test-r1-1-0 │              3 │               3 │ {'chi-test-r1-1-2':1,'chi-test-r1-1-0':1,'chi-test-r1-1-1':1} │
   └─────────────────┴────────────────┴─────────────────┴───────────────────────────────────────────────────────────────┘

Please let me know if you need more info

@Slach
Copy link
Collaborator

Slach commented Feb 4, 2025

is issue with DNS and non replicated schema still exists?
could you share full clickhouse-operator logs?

kubectl logs -l app=clickouse-operator --container=clickhouse-operator --tail=1000000

@noelaugustin
Copy link
Author

Logs are here

ch-operator.log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants