clickhouse-go icon indicating copy to clipboard operation
clickhouse-go copied to clipboard

batch.Send marks batch as sent even there are errors

Open leonidboykov opened this issue 4 years ago • 6 comments

Issue description

The Send method marks batch as sent with any outcome, even if there is some error occurred. There is no way to retry batch sending in case of any issues.

https://github.com/ClickHouse/clickhouse-go/blob/202ca18e6dd39d9720f3fd60530ab1569c78d378/conn_batch.go#L128-L154

Is it an expected behaviour?

Configuration

OS: unrelated

Interface: native

Driver version: v2.0.12 (latest)

Go version: unrelated

ClickHouse Server version: unrelated

leonidboykov avatar Mar 24 '22 16:03 leonidboykov

Thanks, @leonidboykov, for raising this. We return an err if a batch is not successful. Are you looking for automatic retries if a batch is not successful?

or would you prefer the send flag be more granular i.e. don't set the send flag if errors occur before the encoder is flushed?

gingerwizard avatar May 03 '22 16:05 gingerwizard

@gingerwizard I think that leaving send flag as false in case of any error is fine.

leonidboykov avatar May 03 '22 16:05 leonidboykov

ok we'll improve @leonidboykov i think we'll try to make it as close to accurate as possible - if the stream is flushed we'll set it. Any errors before it will be false.

gingerwizard avatar May 09 '22 17:05 gingerwizard

So alittle more complexity here than i initially thought. Whilst we can in theory be more accurate on the sent flag it's there for a very good reason - when the Send method finishes the connection is released (acquired in PrepareBatch). Subsequent sends therefore fail - bad stuff happens due to memory references now nil. Now we could conditionally release the connection if sent is set to true, but this introduces other interesting questions i.e. the user is now responsible for releasing the connection on the batch. This seems potentially leaky and highly unintuitive. We could introduce a batch Close() method the user always has to call, but this is quite a breaking change.

@genzgd

gingerwizard avatar May 10 '22 12:05 gingerwizard

Присоединяюсь. В случае обрыва соединения, повтор не возможен (( clickhouse: batch has already been sent image

Arnowt avatar Nov 26 '22 22:11 Arnowt

Hi, I'd like to learn the best way of retrying a failed Batch... by leveraging its data to construct a new Batch? Currently I don't see any easy way to achieve that. It can get BatchColumn's out but no obvious way to construct a Batch from BatchColumn's. Did I miss anything? Thanks!

ns-gzhang avatar Feb 06 '24 20:02 ns-gzhang