Skip to content

Commit 39e8b90

Browse files
committed
refactor duplicated functions
1 parent e696065 commit 39e8b90

File tree

3 files changed

+33
-73
lines changed

3 files changed

+33
-73
lines changed

hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/checksum/BaseFileChecksumHelper.java

+33-2
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@ protected void setChecksumType(ContainerProtos.ChecksumType type) {
156156
protected abstract AbstractBlockChecksumComputer getBlockChecksumComputer(List<ContainerProtos.ChunkInfo> chunkInfos,
157157
long blockLength);
158158

159-
protected abstract String populateBlockChecksumBuf(ByteBuffer blockChecksumByteBuffer) throws IOException;
160-
161159
protected abstract List<ContainerProtos.ChunkInfo> getChunkInfos(
162160
OmKeyLocationInfo keyLocationInfo) throws IOException;
163161

@@ -167,6 +165,39 @@ protected ByteBuffer getBlockChecksumFromChunkChecksums(AbstractBlockChecksumCom
167165
return blockChecksumComputer.getOutByteBuffer();
168166
}
169167

168+
/**
169+
* Parses out the raw blockChecksum bytes from {@code checksumData} byte
170+
* buffer according to the blockChecksumType and populates the cumulative
171+
* blockChecksumBuf with it.
172+
*
173+
* @return a debug-string representation of the parsed checksum if
174+
* debug is enabled, otherwise null.
175+
*/
176+
177+
protected String populateBlockChecksumBuf(ByteBuffer blockChecksumByteBuffer) throws IOException{
178+
String blockChecksumForDebug = null;
179+
switch (getCombineMode()) {
180+
case MD5MD5CRC:
181+
final MD5Hash md5 = new MD5Hash(blockChecksumByteBuffer.array());
182+
md5.write(getBlockChecksumBuf());
183+
if (LOG.isDebugEnabled()) {
184+
blockChecksumForDebug = md5.toString();
185+
}
186+
break;
187+
case COMPOSITE_CRC:
188+
byte[] crcBytes = blockChecksumByteBuffer.array();
189+
if (LOG.isDebugEnabled()) {
190+
blockChecksumForDebug = CrcUtil.toSingleCrcString(crcBytes);
191+
}
192+
getBlockChecksumBuf().write(crcBytes);
193+
break;
194+
default:
195+
throw new IOException(
196+
"Unknown combine mode: " + getCombineMode());
197+
}
198+
return blockChecksumForDebug;
199+
};
200+
170201
/**
171202
* Compute block checksums block by block and append the raw bytes of the
172203
* block checksums into getBlockChecksumBuf().

hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/checksum/ECFileChecksumHelper.java

-27
Original file line numberDiff line numberDiff line change
@@ -60,33 +60,6 @@ protected AbstractBlockChecksumComputer getBlockChecksumComputer(List<ContainerP
6060
return new ECBlockChecksumComputer(chunkInfos, getKeyInfo(), blockLength);
6161
}
6262

63-
@Override
64-
protected String populateBlockChecksumBuf(
65-
ByteBuffer blockChecksumByteBuffer) throws IOException {
66-
String blockChecksumForDebug = null;
67-
switch (getCombineMode()) {
68-
case MD5MD5CRC:
69-
final MD5Hash md5 = new MD5Hash(blockChecksumByteBuffer.array());
70-
md5.write(getBlockChecksumBuf());
71-
if (LOG.isDebugEnabled()) {
72-
blockChecksumForDebug = md5.toString();
73-
}
74-
break;
75-
case COMPOSITE_CRC:
76-
byte[] crcBytes = blockChecksumByteBuffer.array();
77-
if (LOG.isDebugEnabled()) {
78-
blockChecksumForDebug = CrcUtil.toSingleCrcString(crcBytes);
79-
}
80-
getBlockChecksumBuf().write(crcBytes);
81-
break;
82-
default:
83-
throw new IOException(
84-
"Unknown combine mode: " + getCombineMode());
85-
}
86-
87-
return blockChecksumForDebug;
88-
}
89-
9063
@Override
9164
protected List<ContainerProtos.ChunkInfo> getChunkInfos(OmKeyLocationInfo
9265
keyLocationInfo) throws IOException {

hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/checksum/ReplicatedFileChecksumHelper.java

-44
Original file line numberDiff line numberDiff line change
@@ -107,48 +107,4 @@ protected List<ContainerProtos.ChunkInfo> getChunkInfos(
107107

108108
return chunks;
109109
}
110-
111-
/**
112-
* Parses out the raw blockChecksum bytes from {@code checksumData} byte
113-
* buffer according to the blockChecksumType and populates the cumulative
114-
* blockChecksumBuf with it.
115-
*
116-
* @return a debug-string representation of the parsed checksum if
117-
* debug is enabled, otherwise null.
118-
*/
119-
@Override
120-
protected String populateBlockChecksumBuf(ByteBuffer checksumData)
121-
throws IOException {
122-
String blockChecksumForDebug = null;
123-
switch (getCombineMode()) {
124-
case MD5MD5CRC:
125-
//read md5
126-
final MD5Hash md5 = new MD5Hash(checksumData.array());
127-
md5.write(getBlockChecksumBuf());
128-
if (LOG.isDebugEnabled()) {
129-
blockChecksumForDebug = md5.toString();
130-
}
131-
break;
132-
case COMPOSITE_CRC:
133-
// TODO: abort if chunk checksum type is not CRC32/CRC32C
134-
//BlockChecksumType returnedType = PBHelperClient.convert(
135-
// checksumData.getBlockChecksumOptions().getBlockChecksumType());
136-
/*if (returnedType != BlockChecksumType.COMPOSITE_CRC) {
137-
throw new IOException(String.format(
138-
"Unexpected blockChecksumType '%s', expecting COMPOSITE_CRC",
139-
returnedType));
140-
}*/
141-
byte[] crcBytes = checksumData.array();
142-
if (LOG.isDebugEnabled()) {
143-
blockChecksumForDebug = CrcUtil.toMultiCrcString(crcBytes);
144-
}
145-
getBlockChecksumBuf().write(crcBytes);
146-
break;
147-
default:
148-
throw new IOException(
149-
"Unknown combine mode: " + getCombineMode());
150-
}
151-
152-
return blockChecksumForDebug;
153-
}
154110
}

0 commit comments

Comments
 (0)