Skip to main content
A log pipeline that buffers events and re-sends them when a request fails or times out (for example Vector agents that feed a central processor such as Cribl) delivers every event at least once. That is correct behavior, but it produces three symptoms that look like ClickHouse problems: The pipeline-side fixes are the ones that remove the cause. Their names differ between products, so look for the retry, concurrency, batch and buffer settings of your shipper.

Duplicate rows

Every hop that delivers at least once can create copies. ClickHouse removes only the copies that it can recognize: a retry of the same INSERT with the same data. A copy that an earlier hop re-sent arrives inside a different batch and is inserted again:
If the events carry a unique id, count the copies per time interval. Copies of an event have the same event time, so they fall into the same interval:
What helps:
  • Find the hop that makes the copies. If every hop adds its own metadata to the event (a processing time, a worker id), compare the copies of one id. Copies that differ in the metadata of the last hop were made before it. Copies that are identical in every column were re-sent by the last hop.
  • Acknowledge upstream early. When the central processor confirms a batch to the edge shipper only after the insert into ClickHouse, every slow insert makes the edge re-send. A durable queue on the input of the processor removes this dependency.
  • Keep retries identical. Insert deduplication works for a table that keeps a deduplication log: Replicated*MergeTree tables do by default, a plain MergeTree table needs non_replicated_deduplication_window as in the example. Since ClickHouse 26.2 it also covers asynchronous inserts by default. It only helps if the shipper re-sends the same rows in the same request.
  • Deduplicate by id. For exact results, store the events in a ReplacingMergeTree table whose sorting key contains the id, here ORDER BY (service, timestamp, event_id), and read it with FINAL or with the final setting set to 1. Merges remove the copies in the background at an unknown time, and FINAL makes reads more expensive, so decide whether your dashboards need it.

Retry storms

A retry storm starts when inserts become slow, for example because the server is short of memory or busy with merges:
  1. Requests time out in the shipper, and it sends them again while the first attempts are still running.
  2. Every running insert occupies one slot of the server limit max_concurrent_queries. In ClickHouse Cloud the limit is 1000 concurrent queries per replica.
  3. When all slots are taken, new queries fail with the error TOO_MANY_SIMULTANEOUS_QUERIES (code 202, Too many simultaneous queries. Maximum: 1000). The shipper retries them too, so the load grows while nothing completes. Dashboards and your own diagnostic queries are rejected as well.
A higher limit rarely helps: the slots are held by inserts that can’t finish, and more slots fill up the same way. A storm ends when the server completes inserts faster than they are re-sent. To prevent the next one:
  • In the shipper, limit the number of concurrent requests to ClickHouse and retry with exponential backoff, in particular after TOO_MANY_SIMULTANEOUS_QUERIES (202) and MEMORY_LIMIT_EXCEEDED (241).
  • In ClickHouse, insert as a dedicated user and set max_concurrent_queries_for_user for it, well below the limit of the server. Then the shipper alone can’t take all slots:
To see a storm from ClickHouse, count the inserts by outcome. During a storm the failures overtake the successes:
In ClickHouse Cloud, read clusterAllReplicas(default, system.query_log) instead of system.query_log to see all replicas.

Bad timestamps

One row that can’t be parsed or stored fails the insert. A batch of the usual size for a shipper is a single block, and a block is written entirely or not at all, so the whole batch is rejected. The shipper then retries a batch that can never succeed, and the share of failing requests grows. A large insert that is split into several blocks, or into several partitions, can fail after earlier blocks are already stored, see the conditions for an atomic insert; a retry of such a request inserts those rows again unless they are deduplicated. Two errors come from event timestamps:
Since ClickHouse 26.8, an unquoted number in a JSON format is a Unix timestamp in seconds, also for DateTime64, so milliseconds and nanoseconds are out of range. Before 26.8 such a number was read as a count of ticks of the column (nanoseconds for DateTime64(9)); input_format_read_datetime_number_as_raw_value restores that. The second error comes from events dated 1970 or months in the past, which spread one batch over many partitions:
Despite the error code, this isn’t the “too many parts” condition of a table. Read the text of the exception, which is in the exception column of system.query_log, to tell the two apart. The fix belongs in the pipeline: convert the timestamp to ISO 8601 or to epoch seconds, drop or clamp values outside a sensible window around the current time, and route what remains to a dead-letter output where you can see it. Settings of the inserting user can bridge the time until then:

Batch small requests on the server

Shippers send many small requests. With asynchronous inserts (enabled by default since ClickHouse 26.2) the server collects them in a buffer and writes the buffer when the first of these limits is reached: The timeout is adaptive: frequent inserts raise it step by step from async_insert_busy_timeout_min_ms (default 50) to the maximum. Every flush writes at least one part per partition, so a steady stream with the default timeouts creates several small parts per second. Higher timeouts in the profile of the inserting user, as in log_ingest above, give fewer and larger parts. With wait_for_async_insert = 1 the client gets its answer only after the flush, so set the request timeout of the shipper well above async_insert_busy_timeout_max_ms. To check how often buffers are flushed and which timeout was used: