saxenapranav commented on code in PR #6069: URL: https://github.com/apache/hadoop/pull/6069#discussion_r1329706865
########## hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java: ########## @@ -1412,6 +1421,54 @@ private void appendIfNotEmpty(StringBuilder sb, String regEx, } } + private void addCheckSumHeaderForRead(List<AbfsHttpHeader> requestHeaders, + final int bufferLength, final AbfsHttpHeader rangeHeader) { + if(getAbfsConfiguration().getIsChecksumEnabled() && + requestHeaders.contains(rangeHeader) && bufferLength <= 4 * ONE_MB) { + requestHeaders.add(new AbfsHttpHeader(X_MS_RANGE_GET_CONTENT_MD5, TRUE)); + } + } + + private void addCheckSumHeaderForWrite(List<AbfsHttpHeader> requestHeaders, + final byte[] buffer) { + if(getAbfsConfiguration().getIsChecksumEnabled()) { + try { + MessageDigest md5Digest = MessageDigest.getInstance("MD5"); + byte[] md5Bytes = md5Digest.digest(buffer); + String md5Hash = Base64.getEncoder().encodeToString(md5Bytes); + requestHeaders.add(new AbfsHttpHeader(CONTENT_MD5, md5Hash)); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + } + } + + private void verifyCheckSumForRead(final byte[] buffer, final AbfsHttpOperation result) + throws AbfsRestOperationException{ + if(getAbfsConfiguration().getIsChecksumEnabled()) { + // Number of bytes returned by server could be less than or equal to what + // caller requests. In case it is less, extra bytes will be initialized to 0 + // Server returned MD5 Hash will be computed on what server returned. + // We need to get exact data that server returned and compute its md5 hash + // Computed hash should be equal to what server returned + int numberOfBytesRead = (int)result.getBytesReceived(); Review Comment: DataRead may be 0. In case of that, we should return back without any check -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-issues-h...@hadoop.apache.org