ClickHouse / ClickHouse/clickhouse-java

InputStream `reset()` can fail on retries for BufferedInputStreams

Đang mở
#2,675 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
area:docs
Ngôn ngữ chính
Java
Star
1.6k
Fork
637
Merge trung bình
2 ngày 23 giờ
Pull request đã merge (30 ngày)
29

Mô tả

## Description

The ClickHouse Java `Client` provides an `insert` method that takes an `InputStream`.

On failure, this method calls `data.reset()` https://github.com/ClickHouse/clickhouse-java/blob/f9f588d9d1b8abd8e7e8ab0eafc84b070377a68d/client-v2/src/main/java/com/clickhouse/client/api/Client.java#L1387-L1390

However, as far as I can tell, the code never sets a `mark`.

This works well on `ByteArrayInputStreams` (as is used in the unit tests), where `reset` will move the stream back to the beginning, but not one something like `BufferedInputStream`. In that case, even though `markSupported` is `true`, the mark needs to be defined.

This will also obviously fail on `InputStreams` like `GZIPInputStream` where `markSupported` is `false`, but that's to be expected.

I'm not sure if the client should set a mark, but I think it should at least mention that in the documentation.

### Steps to reproduce

Send an insert request that fails from a `BufferedInputStream`.
Note that this can simply be a `BufferedInputStream` wrapping a `ByteInputStream`.

### Error Log or Exception StackTrace

```java
Failed to reset stream before next attempt
Caused by: Exception java.io.IOException: Resetting to invalid mark
```

### Expected Behaviour

### Code Example

```java
jshell> var bais = new java.io.ByteArrayInputStream("1,2,3".getBytes())
bais ==> java.io.ByteArrayInputStream@3159c4b8

jshell> var buffered = new java.io.BufferedInputStream(bais)
buffered ==> java.io.BufferedInputStream@29ca901e

jshell> // both support marks

jshell> bais.markSupported()
$3 ==> true

jshell> buffered.markSupported()
$4 ==> true

jshell> // reset works on byte array input streams

jshell> bais.reset()

jshell> // but fails on the buffered version

jshell> buffered.reset()
| Exception java.io.IOException: Resetting to invalid mark
| at BufferedInputStream.implReset (BufferedInputStream.java:583)
| at BufferedInputStream.reset (BufferedInputStream.java:569)
| at (#6:1)

jshell> // it works as expected after setting the first mark

jshell> buffered.mark(1024)

jshell> buffered.reset()

```

### Configuration

#### Client Configuration
```java

```

#### Environment
* Client version: v0.9.4
* Language version: Java

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu với logic retry trong client-v2/src/main/java/com/clickhouse/client/api/Client.java tại các dòng được liên kết, sau đó tái hiện lỗi bằng ví dụ BufferedInputStream. Xác định hành vi reset dự kiến cho các insert có thể retry, bổ sung coverage cho trường hợp stream bị lỗi nếu phù hợp và đảm bảo rằng hành vi hoặc giới hạn cuối cùng được ghi lại trong tài liệu.

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

Đánh giá

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

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.