Repository: ClickHouse/ClickHouse
File: tests/integration/test_s3_cluster_restart/test.py (Python)

Code before:
    )

    node2.stop()
    node2.start()

    uuid = str(uuid4())
    result = node1.query(
        f"""
        SELECT count(*) from s3Cluster(
            'cluster_simple',
            'http://minio1:9001/root/data/generated/*.csv',
            'minio', '{minio_secret_key}', 'CSV', 'a String, b UInt64')
        """
        ,query_id=uuid
    )

    assert result == "14950\n"

    node1.query("system flush logs query_log")

    result = node1.query(
            f"""SELECT ProfileEvents['DistributedConnectionReconnectCount'], ProfileEvents['DistributedConnectionFailTry'] FROM system.query_log WHERE query_id = '{uuid}' and type = 'QueryFinish';"""
        ).strip().split('\t')
    reconnect_count = int(result[0])
    fail_try = int(result[1])
    assert reconnect_count == 1
    # DistributedConnectionFailTry can be 0 if node2 restarted fast enough before the reconnection attempt
    assert fail_try <= 1

    # avoid leaving the test w/o started node, so next test will start with fully runnning cluster
    node2.wait_for_start(30)


def createTable(table, missing_table):
    node1.query(
        f"""
    CREATE TABLE {table} (a String, b UInt64)
    ENGINE=ReplicatedMergeTree('/clickhouse/tables/f15b1936-ae89-416b-8626-7c88d9fbe6a3/{table}', '{{replica}}')
    ORDER BY (a, b);
        """
    )
    node2.query(
        f"""
    CREATE TABLE {table} (a String, b UInt64)
    ENGINE=ReplicatedMergeTree('/clickhouse/tables/f15b1936-ae89-416b-8626-7c88d9fbe6a3/{table}', '{{replica}}')
    ORDER BY (a, b);
        """
    )
    if (not missing_table):
        node3.query(
            f"""

Review comment (bug):
But in case of `DistributedConnectionFailTry=0` then `DistributedConnectionReconnectCount` should be also `0`?

Code after:
    )

    node2.stop()
    node2.start()

    uuid = str(uuid4())
    result = node1.query(
        f"""
        SELECT count(*) from s3Cluster(
            'cluster_simple',
            'http://minio1:9001/root/data/generated/*.csv',
            'minio', '{minio_secret_key}', 'CSV', 'a String, b UInt64')
        """
        ,query_id=uuid
    )

    assert result == "14950\n"

    # avoid leaving the test w/o started node, so next test will start with fully runnning cluster
    node2.wait_for_start(30)


def createTable(table, missing_table):
    node1.query(
        f"""
    CREATE TABLE {table} (a String, b UInt64)
    ENGINE=ReplicatedMergeTree('/clickhouse/tables/f15b1936-ae89-416b-8626-7c88d9fbe6a3/{table}', '{{replica}}')
    ORDER BY (a, b);
        """
    )
    node2.query(
        f"""
    CREATE TABLE {table} (a String, b UInt64)
    ENGINE=ReplicatedMergeTree('/clickhouse/tables/f15b1936-ae89-416b-8626-7c88d9fbe6a3/{table}', '{{replica}}')
    ORDER BY (a, b);
        """
    )
    if (not missing_table):
        node3.query(
            f"""
        CREATE TABLE {table} (a String, b UInt64)
        ENGINE=ReplicatedMergeTree('/clickhouse/tables/f15b1936-ae89-416b-8626-7c88d9fbe6a3/{table}', '{{replica}}')
        ORDER BY (a, b);
            """
        )


@pytest.mark.parametrize(
    "wait_restart, missing_table",
    [
        pytest.param(False, False),