ChenSammi commented on code in PR #3201:
URL: https://github.com/apache/ozone/pull/3201#discussion_r871332213
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/protocolPB/OMPBHelper.java:
##########
@@ -196,6 +216,165 @@ public static HddsProtos.DefaultReplicationConfig convert(
return builder.build();
}
+ public static FileChecksum convert(FileChecksumProto proto) {
+ if (proto == null) {
+ return null;
+ }
+ try {
+ switch (proto.getChecksumType()) {
+ case MD5CRC:
+ if (proto.hasMd5Crc()) {
+ return convertMD5MD5FileChecksum(proto.getMd5Crc());
+ } else {
+ LOG.warn("The field md5Crc is not set.");
+ return null;
+ }
+ case COMPOSITE_CRC:
+ if (proto.hasCompositeCrc()) {
+ return convertCompositeCrcChecksum(proto.getCompositeCrc());
+ } else {
+ LOG.warn("The field CompositeCrc is not set.");
+ return null;
+ }
+ default:
+ return null;
+ }
+ } catch (IOException ioe) {
+ LOG.warn("Unable to convert FileChecksumProto.", ioe);
+ return null;
+ }
+ }
+
+ public static MD5MD5CRC32FileChecksum convertMD5MD5FileChecksum(
+ MD5MD5Crc32FileChecksumProto proto) throws IOException {
+ ChecksumTypeProto checksumTypeProto = proto.getChecksumType();
+ int bytesPerCRC = proto.getBytesPerCRC();
+ long crcPerBlock = proto.getCrcPerBlock();
+ ByteString md5 = proto.getMd5();
+ DataInputStream inputStream = new DataInputStream(
+ new ByteArrayInputStream(md5.toByteArray()));
+ MD5Hash md5Hash = MD5Hash.read(inputStream);
+ switch (checksumTypeProto) {
+ case CHECKSUM_CRC32:
+ return new MD5MD5CRC32GzipFileChecksum(bytesPerCRC, crcPerBlock,
md5Hash);
+ case CHECKSUM_CRC32C:
+ return new MD5MD5CRC32CastagnoliFileChecksum(bytesPerCRC, crcPerBlock,
+ md5Hash);
+ default:
+ return null;
Review Comment:
Better throw exception here to reveal any potential issue.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]