Skip to content

Backport fixes for offsets management concurrency issues to Kafka 2.4.1#1

Merged
andrey-klochkov-liftoff merged 4 commits into
2.4.1-liftofffrom
andrey.2.4.1-concurrency-patches
Aug 17, 2020
Merged

Backport fixes for offsets management concurrency issues to Kafka 2.4.1#1
andrey-klochkov-liftoff merged 4 commits into
2.4.1-liftofffrom
andrey.2.4.1-concurrency-patches

Conversation

@andrey-klochkov-liftoff

Copy link
Copy Markdown
Collaborator

Kafka 2.4.1 has a number of known concurrency issues which result in Kafka clients getting the "offset out of range" error. This PR backports fixes for 3 of such issues from 2.5.1 to 2.4.1 by cherry picking corresponding commits.

List of cherry-picked fixed:

  1. KAFKA-9807; Protect LSO reads from concurrent high-watermark updates (KAFKA-9807; Protect LSO reads from concurrent high-watermark updates apache/kafka#8418)
  2. KAFKA-9835; Protect FileRecords.slice from concurrent write (KAFKA-9835; Protect FileRecords.slice from concurrent write apache/kafka#8451)
  3. KAFKA-9838; Add log concurrency test and fix minor race condition (KAFKA-9838; Add log concurrency test and fix minor race condition apache/kafka#8476)

How the testing was done:

  1. During an attempt upgrade to Kafka 2.4.1 in production we hit many issues with clients getting "offset out of range" errors while Kafka clusters seemed to be perfectly healthy.
  2. We identified known concurrency issues with 2.4.1, see the list above.
  3. Kafka 2.4.1 was deployed to a stage Kafka cluster, and the concurrency issues were reproduced there. In order to make the issue reproduce more frequently, the max segment size was reduced from default 1G to 100M, by setting property log.segment.bytes=104857600 at the broker level.
  4. The non-patched Kafka 2.4.1 was used for ~2 days and produced the "offset out of range" error a few times. The symptoms of failures matched the description of defect KAFKA-9543 (patch zkclient and scalatest library updates apache/kafka#3 from the list above is a fix for this).
  5. Kafka 2.4.1 with 3 patches listed above was deployed to stage, it kept running for 1.5 days and didn't produce errors.

hachikuji and others added 4 commits August 14, 2020 22:02
…ache#8476)

The patch adds a new test case for validating concurrent read/write behavior in the `Log` implementation. In the process of verifying this, we found a race condition in `read`. The previous logic checks whether the start offset is equal to the end offset before collecting the high watermark. It is possible that the log is truncated in between these two conditions which could cause the high watermark to be equal to the log end offset. When this happens, `LogSegment.read` fails because it is unable to find the starting position to read from.

Reviewers: Guozhang Wang <wangguoz@gmail.com>
…#8451)

A read from the end of the log interleaved with a concurrent write can result in reading data above the expected read limit. In particular, this would allow a read above the high watermark. The root of the problem is consecutive calls to `sizeInBytes` in `FileRecords.slice` which do not account for an increase in size due to a concurrent write. This patch fixes the problem by using a single call to `sizeInBytes` and caching the result.

Reviewers: Ismael Juma <ismael@juma.me.uk>
…pache#8418)

If the high-watermark is updated in the middle of a read with the `read_committed` isolation level, it is possible to return data above the LSO. In the worst case, this can lead to the read of an aborted transaction. The root cause is that the logic depends on reading the high-watermark twice. We fix the problem by reading it once and caching the value.

Reviewers: David Arthur <mumrah@gmail.com>, Guozhang Wang <wangguoz@gmail.com>, Ismael Juma <ismael@juma.me.uk>
@andrey-klochkov-liftoff andrey-klochkov-liftoff changed the title Apply fixes for Log management concurrency issues to Kafka 2.4.1 Backport fixes for offsets management concurrency issues to Kafka 2.4.1 Aug 17, 2020

@PleasingFungus PleasingFungus left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@andrey-klochkov-liftoff
andrey-klochkov-liftoff merged commit f9569d1 into 2.4.1-liftoff Aug 17, 2020
@andrey-klochkov-liftoff
andrey-klochkov-liftoff deleted the andrey.2.4.1-concurrency-patches branch August 17, 2020 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants