You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by ij...@apache.org on 2016/12/20 00:39:49 UTC
kafka git commit: MINOR: Fix exception handling in case of file
record truncation during write
Repository: kafka
Updated Branches:
refs/heads/trunk 8dbdc90ba -> 8b84d14c6
MINOR: Fix exception handling in case of file record truncation during write
In case of file record truncation during write due to improper types usage
(`AtomicInteger` in place of `int`) `IllegalFormatConversionException` would
be thrown instead of `KafkaException`
Author: Kamil Szymanski <ka...@gmail.com>
Reviewers: Ismael Juma <is...@juma.me.uk>
Closes #2275 from kamilszymanski/file_record_truncation_during_write
Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/8b84d14c
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/8b84d14c
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/8b84d14c
Branch: refs/heads/trunk
Commit: 8b84d14c6fb338e9e6a6d41fe0a6298a63cfc5c0
Parents: 8dbdc90
Author: Kamil Szymanski <ka...@gmail.com>
Authored: Tue Dec 20 00:30:36 2016 +0000
Committer: Ismael Juma <is...@juma.me.uk>
Committed: Tue Dec 20 00:32:44 2016 +0000
----------------------------------------------------------------------
.../java/org/apache/kafka/common/record/FileRecords.java | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kafka/blob/8b84d14c/clients/src/main/java/org/apache/kafka/common/record/FileRecords.java
----------------------------------------------------------------------
diff --git a/clients/src/main/java/org/apache/kafka/common/record/FileRecords.java b/clients/src/main/java/org/apache/kafka/common/record/FileRecords.java
index 52f3103..050711d 100644
--- a/clients/src/main/java/org/apache/kafka/common/record/FileRecords.java
+++ b/clients/src/main/java/org/apache/kafka/common/record/FileRecords.java
@@ -233,11 +233,14 @@ public class FileRecords extends AbstractRecords implements Closeable {
@Override
public long writeTo(GatheringByteChannel destChannel, long offset, int length) throws IOException {
long newSize = Math.min(channel.size(), end) - start;
- if (newSize < size.get())
- throw new KafkaException(String.format("Size of FileRecords %s has been truncated during write: old size %d, new size %d", file.getAbsolutePath(), size, newSize));
+ int oldSize = sizeInBytes();
+ if (newSize < oldSize)
+ throw new KafkaException(String.format(
+ "Size of FileRecords %s has been truncated during write: old size %d, new size %d",
+ file.getAbsolutePath(), oldSize, newSize));
long position = start + offset;
- long count = Math.min(length, size.get());
+ int count = Math.min(length, oldSize);
final long bytesTransferred;
if (destChannel instanceof TransportLayer) {
TransportLayer tl = (TransportLayer) destChannel;