KAFKA-9835; Protect FileRecords.slice from concurrent write#8451
Conversation
| // handle integer overflow or if end is beyond the end of the file | ||
| if (end < 0 || end >= start + sizeInBytes()) | ||
| end = start + sizeInBytes(); | ||
| if (end < 0 || end > start + currentSizeInBytes) |
There was a problem hiding this comment.
Was the boundary check wrong? You changed >= to >.
There was a problem hiding this comment.
The common case that we would see this is when the limit matches the file end exactly. So changing this to > would also have fixed this problem for that case. I decided to remove it here though just because the equality check is redundant (if end == start + currentSizeInBytes, then there's no need to update it).
ijuma
left a comment
There was a problem hiding this comment.
Nice catch, LGTM.
Let's please mention in the PR description that the common case for triggering this would be a read to the end of the log where the if check was interleaved with an append to the log.
| writerCompletion.get(); | ||
| readerCompletion.get(); | ||
| } finally { | ||
| executor.shutdownNow(); |
There was a problem hiding this comment.
It fails consistently for me without the fix.
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>
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>
…#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>
…#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>
A read from the end of the log interleaved with a concurrent write can result in reading data above the expected limit. In particular, this would allow a read above the high watermark. The root of the problem is consecutive calls to
sizeInBytesinFileRecords.slicewhich do not account for an increase in size. This patch fixes the problem by using a single call tosizeInBytesand caching the result.Committer Checklist (excluded from commit message)