Skip to content

Commit a8c94b3

Browse files
committed
HBASE-28061 HBaseTestingUtility failed to start MiniHbaseCluster in case of Hadoop3.3.1
1 parent 84ccae3 commit a8c94b3

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

hbase-asyncfs/src/main/java/org/apache/hadoop/hbase/io/asyncfs/FanOutOneBlockAsyncDFSOutputHelper.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,22 @@ private static FileCreator createFileCreator() throws NoSuchMethodException {
231231
return createFileCreator3();
232232
}
233233

234+
// hadoop 3.3.1 changed the return value of this method from DatanodeInfo[] to
235+
// DatanodeInfoWithStorage[], which causes the JVM can not locate the method if we are compiled
236+
// with hadoop 3.2 and then link with hadoop 3.3, so here we need to use reflection to make it
237+
// work for both hadoop versions, otherwise we need to publish more artifacts for different hadoop
238+
// versions...
239+
private static final Method GET_LOCATED_BLOCK_LOCATIONS_METHOD;
240+
241+
private static DatanodeInfo[] getLocatedBlockLocations(LocatedBlock block) {
242+
try {
243+
// DatanodeInfoWithStorage[] can be casted to DatanodeInfo[] directly
244+
return (DatanodeInfo[]) GET_LOCATED_BLOCK_LOCATIONS_METHOD.invoke(block);
245+
} catch (IllegalAccessException | InvocationTargetException e) {
246+
throw new RuntimeException(e);
247+
}
248+
}
249+
234250
// cancel the processing if DFSClient is already closed.
235251
static final class CancelOnClose implements CancelableProgressable {
236252

@@ -250,6 +266,7 @@ public boolean progress() {
250266
try {
251267
LEASE_MANAGER = createLeaseManager();
252268
FILE_CREATOR = createFileCreator();
269+
GET_LOCATED_BLOCK_LOCATIONS_METHOD = LocatedBlock.class.getMethod("getLocations");
253270
} catch (Exception e) {
254271
String msg = "Couldn't properly initialize access to HDFS internals. Please "
255272
+ "update your WAL Provider to not make use of the 'asyncfs' provider. See "
@@ -383,7 +400,7 @@ private static List<Future<Channel>> connectToDataNodes(Configuration conf, DFSC
383400
BlockConstructionStage stage, DataChecksum summer, EventLoopGroup eventLoopGroup,
384401
Class<? extends Channel> channelClass) {
385402
StorageType[] storageTypes = locatedBlock.getStorageTypes();
386-
DatanodeInfo[] datanodeInfos = locatedBlock.getLocations();
403+
DatanodeInfo[] datanodeInfos = getLocatedBlockLocations(locatedBlock);
387404
boolean connectToDnViaHostname =
388405
conf.getBoolean(DFS_CLIENT_USE_DN_HOSTNAME, DFS_CLIENT_USE_DN_HOSTNAME_DEFAULT);
389406
int timeoutMs = conf.getInt(DFS_CLIENT_SOCKET_TIMEOUT_KEY, READ_TIMEOUT);

0 commit comments

Comments
 (0)