client-v2 retries an insert with the same query id after NoHttpResponseException, causing QUERY_WITH_SAME_ID_IS_ALREADY_RUNNING

Đang mở
#3,174 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java
Lĩnh vực
api, databases

Hướng nghiên cứu

Start in Client.java at Client.lambda$insert$3, Client.insert, and runAsyncOperation, then trace HttpAPIClientHelper.executeRequest around retry handling. Reproduce the NoHttpResponseException path with the stated async-insert settings; done means a delivered insert can be retried without reusing an in-flight query ID or turning the transient fault into code 216.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Description

Client.insert reuses requestSettings.getQueryId() across every retry attempt. After NoHttpResponseException (retried by default via ClientFaultCause.NoHttpResponse) the first request may already have reached the server and still be executing. The second attempt is then rejected with Code: 216 QUERY_WITH_SAME_ID_IS_ALREADY_RUNNING, which is not retryable, so a transient transport fault becomes a hard failure.

https://github.com/ClickHouse/clickhouse-java/pull/1721 introduced the retry and noted that "not every request may be retried safely". This is that case.

Steps to reproduce
  1. client.insert(table, data, format, settings) with default retry settings through a proxy or load balancer.
  2. The proxy closes the keep-alive connection after forwarding the request, while the server is still executing the insert (async_insert=1, wait_for_async_insert=1 makes the window at least the busy timeout).
  3. The client gets NoHttpResponseException, logs Retrying., and resends with the same query id. The server answers 216.
Error Log or Exception StackTrace
WARN Retrying. (com.clickhouse.client.api.Client)
org.apache.hc.core5.http.NoHttpResponseException: <host>:8443 failed to respond
    at org.apache.hc.core5.http.impl.io.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:333)
    ...
    at com.clickhouse.client.api.internal.HttpAPIClientHelper.executeRequest(HttpAPIClientHelper.java:453)
    at com.clickhouse.client.api.Client.lambda$insert$3(Client.java:1474)
    at com.clickhouse.client.api.Client.runAsyncOperation(Client.java:2012)
    at com.clickhouse.client.api.Client.insert(Client.java:1518)

com.clickhouse.client.api.ServerException: Code: 216. DB::Exception: Query with id = b266240e-d406-4874-ba3b-cd1b0bd969f8 is already running. (QUERY_WITH_SAME_ID_IS_ALREADY_RUNNING) (version 26.4.1.2359 (official build))
    at com.clickhouse.client.api.internal.HttpAPIClientHelper.readError(HttpAPIClientHelper.java:403)
    at com.clickhouse.client.api.internal.HttpAPIClientHelper.executeRequest(HttpAPIClientHelper.java:467)
    at com.clickhouse.client.api.Client.lambda$insert$3(Client.java:1474)
    at com.clickhouse.client.api.Client.runAsyncOperation(Client.java:2012)
    at com.clickhouse.client.api.Client.insert(Client.java:1518)
    at com.clickhouse.client.api.Client.insert(Client.java:1408)
Expected Behaviour

A retry after a fault where the first request may have been delivered does not collide with its own earlier attempt. Either the retry uses a fresh query id, or the client does not retry once the request body has been sent.

Configuration
Client Configuration

Defaults: retry=3, retryOnFailures = [NoHttpResponse, ConnectTimeout, ConnectionRequestTimeout, ServerRetryable]. Caller sets queryId and insert_deduplication_token per insert (clickhouse-kafka-connect v1.6.0).

Environment
  • Cloud
  • Client version: client-v2 0.9.5 (insert loop unchanged on 0.9.6, 0.10.0 and main)
  • Language version: Java 21.0.10
  • OS: Linux
ClickHouse Server
  • ClickHouse Server version: 26.4.1 and 26.6.1
  • Non-default settings: async_insert=1, wait_for_async_insert=1, async_insert_busy_timeout_ms=200

Related: https://github.com/ClickHouse/clickhouse-java/issues/1529 (same code, different cause). Downstream: https://github.com/ClickHouse/clickhouse-kafka-connect/issues/847.

Ngôn ngữ chính
Java
Star
1.6k
Fork
649
Merge trung bình
1 ngày 20 giờ
Pull request đã merge (30 ngày)
39

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ClickHouse/clickhouse-java

Tất cả issue của ClickHouse/clickhouse-java

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.