From f3d8265582df88278dccf02e8e63cf0d2ba5286f Mon Sep 17 00:00:00 2001 From: Shashikant Banerjee Date: Thu, 24 Jan 2019 16:37:05 +0530 Subject: [PATCH] HDDS-996. Incorrect data length gets updated in OM by client in case it hits exception in multiple successive block writes. Contributed by Shashikant Banerjee. --- .../hadoop/ozone/client/io/KeyOutputStream.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/io/KeyOutputStream.java b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/io/KeyOutputStream.java index 22efab3eaf..042aceef1a 100644 --- a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/io/KeyOutputStream.java +++ b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/io/KeyOutputStream.java @@ -286,7 +286,7 @@ private void handleWrite(byte[] b, int off, long len, boolean retry) BlockOutputStreamEntry current = streamEntries.get(currentStreamIndex); // length(len) will be in int range if the call is happening through - // write API of chunkOutputStream. Length can be in long range if it comes + // write API of blockOutputStream. Length can be in long range if it comes // via Exception path. int writeLen = Math.min((int)len, (int) current.getRemaining()); long currentPos = current.getWrittenDataLength(); @@ -302,7 +302,14 @@ private void handleWrite(byte[] b, int off, long len, boolean retry) || retryFailure) { // for the current iteration, totalDataWritten - currentPos gives the // amount of data already written to the buffer - writeLen = (int) (current.getWrittenDataLength() - currentPos); + + // In the retryPath, the total data to be written will always be equal + // to or less than the max length of the buffer allocated. + // The len specified here is the combined sum of the data length of + // the buffers + Preconditions.checkState(!retry || len <= streamBufferMaxSize); + writeLen = retry ? (int) len : + (int) (current.getWrittenDataLength() - currentPos); LOG.debug("writeLen {}, total len {}", writeLen, len); handleException(current, currentStreamIndex, retryFailure); } else {