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.

This commit is contained in:
Shashikant Banerjee 2019-01-24 16:37:05 +05:30
parent 09a5859f58
commit f3d8265582
1 changed files with 9 additions and 2 deletions

View File

@ -286,7 +286,7 @@ public class KeyOutputStream extends OutputStream {
BlockOutputStreamEntry current = streamEntries.get(currentStreamIndex); BlockOutputStreamEntry current = streamEntries.get(currentStreamIndex);
// length(len) will be in int range if the call is happening through // 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. // via Exception path.
int writeLen = Math.min((int)len, (int) current.getRemaining()); int writeLen = Math.min((int)len, (int) current.getRemaining());
long currentPos = current.getWrittenDataLength(); long currentPos = current.getWrittenDataLength();
@ -302,7 +302,14 @@ public class KeyOutputStream extends OutputStream {
|| retryFailure) { || retryFailure) {
// for the current iteration, totalDataWritten - currentPos gives the // for the current iteration, totalDataWritten - currentPos gives the
// amount of data already written to the buffer // 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); LOG.debug("writeLen {}, total len {}", writeLen, len);
handleException(current, currentStreamIndex, retryFailure); handleException(current, currentStreamIndex, retryFailure);
} else { } else {