Monedula

Markdown

Part VI · Reference

Kafka troubleshooting

KafkaStorageException (KAFKA_STORAGE_ERROR)

Kafka error · KAFKA_STORAGE_ERROR · retriable

org.apache.kafka.common.errors.KafkaStorageException

A broker answered KAFKA_STORAGE_ERROR (error code 56) because it could not use the storage behind the request. In Apache Kafka that is a failed log directory, a disk the broker can no longer read or write. In Aiven Inkless it is also what diskless produce and fetch get while PostgreSQL, the batch coordinator, is unavailable. The client refreshes metadata and retries.

Reproduce it in the playground

The moment it happensThe upload fails: KAFKA_STORAGE_ERROR. t+4.100s

wal-0002's upload failed: no object was written, the coordinator committed nothing and click-2 got no offset. At 4050 ms p-clicks got KAFKA_STORAGE_ERROR. The draft says only that the pending produce requests receive errors and that produce fails retriably; the error code is the simulator's choice. It is retriable, so p-clicks sends click-2 again after its 500 ms backoff.

Open at this step: step 3, The upload fails: KAFKA_STORAGE_ERROR

What it means

The Kafka protocol describes KAFKA_STORAGE_ERROR as "Disk error when trying to access log file on the disk", and the KafkaStorageException javadoc calls it a disk-related IOException met while handling a request, after which the client should request a metadata update and retry. A broker with several log directories (JBOD) does not stop when one of them fails, unless that directory holds the cluster metadata log in KRaft: it marks that directory offline, the partitions stored there stop being served by that broker, and their leadership moves to other in-sync replicas, while partitions in the other directories carry on. A client that was talking to the old leader gets KAFKA_STORAGE_ERROR, refreshes its metadata and finds the new leader. Aiven Inkless, a fork of Apache Kafka that runs diskless topics, keeps the order and offsets of diskless batches in PostgreSQL; its documentation says that while that control plane is unavailable, diskless produce and fetch fail with KAFKA_STORAGE_ERROR, a retriable error, and classic topics in the same cluster keep working. Nisshi (formerly Tansu), a Kafka-compatible broker that keeps no data itself, answers it too while its storage engine is unavailable: on its PostgreSQL engine a produce request is one transaction, and when PostgreSQL cannot be reached the transaction stores nothing and the producer gets KAFKA_STORAGE_ERROR, which is retriable (the storage layer of Nisshi 0.8.2). Nothing was taken, so the retry leaves no gap. Scenario 12.1.6 shows it. Inkless returns the same error when object storage fails a write: a broker uploads the diskless batches it buffered as one file, tries it max.upload.attempts times (3 by default), and if every attempt fails it answers every produce request in that file with KAFKA_STORAGE_ERROR, before anything reaches PostgreSQL (Inkless's code at inkless-release-0.51). Its S3 client gives each attempt 1 second and each call 2 seconds, so a bucket that is only slow fails the same way as one that is down. Scenario 07.1.4 shows it. The diskless topics proposal (KIP-1163, a draft) says that when a WAL upload to object storage fails, the pending produce requests get errors, and its test plan (KIP-1165) that produce fails retriably; it names no error code. Scenario 06.1.4 uses KAFKA_STORAGE_ERROR for it, which is the simulator's choice. KafScale, a Kafka-protocol broker that keeps every topic in S3, returns it too in KafScale, while the broker's S3 health monitor reports S3 unavailable: 60% or more of the S3 calls in its last 60 seconds failed. Between 20% and 60% it reports S3 degraded and answers REQUEST_TIMED_OUT instead; both are retriable. Offsets move on only after the upload and the etcd write both succeed, so the retry writes the records at the same offsets and leaves no gap. Scenario 08.2.3 shows both codes.

Likely causes, most common first

  1. A broker disk or log directory failed. An I/O error on one of the directories in log.dirs, a full or read-only filesystem, or a disk that went away makes the broker take that directory offline. Every partition replica stored there is offline on that broker until it is restarted with the directory repaired or removed.
  2. The broker has only one log directory. With a single directory a log directory failure takes all of the broker's storage with it, and the broker shuts down. Clients get KAFKA_STORAGE_ERROR or connection errors until the partitions move to other brokers.
  3. Aiven Inkless: PostgreSQL is unavailable. On an Inkless cluster, diskless topics need PostgreSQL to commit and to find batches. While it is down or unreachable, diskless produce and fetch fail with KAFKA_STORAGE_ERROR; classic topics are unaffected. Clients keep retrying until it is back.
  4. Nisshi: its storage engine is unavailable. On a Nisshi cluster every record, watermark, group and offset is in the storage engine (PostgreSQL, or S3 on its experimental engine). While it is down every produce request fails with KAFKA_STORAGE_ERROR and the producer retries; no broker change helps, since no broker holds the data. Once the engine is back the next retry commits.
  5. Aiven Inkless: object storage down or too slow. On an Inkless cluster, a diskless upload that fails all its attempts, because the bucket is unreachable or answers slower than the S3 client timeouts, fails every produce request in that file with KAFKA_STORAGE_ERROR. The records got no offsets, so the producer's retry writes them once; Inkless 0.51 has no back-pressure, so the broker keeps accepting produce requests while the attempts run.
  6. KafScale: S3 unavailable or an upload failed. On a KafScale cluster (not Apache Kafka), every produce and fetch gets KAFKA_STORAGE_ERROR while the S3 health monitor reports S3 unavailable (60% or more of the S3 calls in the last 60 seconds failed), and so does a failed segment upload that leaves the monitor below 20% (a busy broker with many good calls). Between 20% and 60% the answer is REQUEST_TIMED_OUT. The monitor does not probe S3: it reports healthy again only when its 60 second window holds no failed call, so the refusals go on for up to a minute after S3 is back, and on a quiet broker the code can change from REQUEST_TIMED_OUT to KAFKA_STORAGE_ERROR as the good calls from before the outage leave the window first. A segment upload also gets it when another broker's upload created the same segment first: segment uploads are conditional (If-None-Match), so nothing acked is overwritten, and the broker whose upload lost drops its partition log, restores the winning segment and writes on after it (PR #353). The conflict does not count as an S3 failure (PR #345). Scenario 08.2.6 shows a new owner's upload losing to the segment of the owner that stopped before it.

How to fix it

  • Check the broker log for the failed directory: the broker logs the I/O error and that it marked the directory offline, so the log names the disk to look at.
  • Replace or repair the disk, or remove the failed path from log.dirs, then restart the broker so its replicas come back and catch up from the leaders.
  • Make sure the topics on it have a replication factor of at least 3 and a min.insync.replicas below it, so another replica can lead while the disk is replaced.
  • On Aiven Inkless, bring PostgreSQL back; the clients retry on their own and diskless traffic resumes.
  • On Nisshi, bring the storage engine back (PostgreSQL, or the bucket on the S3 engine) and let the producers retry: a failed write stored nothing.
  • On Aiven Inkless, check the object storage the brokers write to, including its latency: a bucket slower than the S3 client timeouts fails uploads as if it were down.
  • On KafScale, bring S3 back and let the clients retry: expect refusals for up to 60 seconds after the last failed S3 call, then the records land at the offsets they first took.

What not to do

  • Raising retries alone to hide a failed disk: the replicas on it stay offline and the partition runs on fewer copies until the disk is dealt with.

Does the client retry it?

Yes, the client retries. KAFKA_STORAGE_ERROR (error code 56) is a retriable protocol error, and KafkaStorageException extends InvalidMetadataException: the client refreshes its metadata and tries again, so it finds the partition's new leader after a disk failure, or succeeds once Inkless's PostgreSQL is back. It surfaces to the application only when retries or delivery.timeout.ms run out first.

Reproduce it in the simulator

Sources

All troubleshooting pages