HBASE-26057 Remove reflections used to access Hadoop 2 API in FanOutOneBlockAsyncDFSOutputHelper (#3448)
Signed-off-by: Duo Zhang <zhangduo@apache.org> Signed-off-by: Michael Stack <stack@apache.org>
This commit is contained in:
parent
82c44b49f5
commit
5ef5e64010
|
@ -139,15 +139,6 @@ public final class FanOutOneBlockAsyncDFSOutputHelper {
|
||||||
|
|
||||||
private static final LeaseManager LEASE_MANAGER;
|
private static final LeaseManager LEASE_MANAGER;
|
||||||
|
|
||||||
// This is used to terminate a recoverFileLease call when FileSystem is already closed.
|
|
||||||
// isClientRunning is not public so we need to use reflection.
|
|
||||||
private interface DFSClientAdaptor {
|
|
||||||
|
|
||||||
boolean isClientRunning(DFSClient client);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final DFSClientAdaptor DFS_CLIENT_ADAPTOR;
|
|
||||||
|
|
||||||
// helper class for creating files.
|
// helper class for creating files.
|
||||||
private interface FileCreator {
|
private interface FileCreator {
|
||||||
default HdfsFileStatus create(ClientProtocol instance, String src, FsPermission masked,
|
default HdfsFileStatus create(ClientProtocol instance, String src, FsPermission masked,
|
||||||
|
@ -173,22 +164,6 @@ public final class FanOutOneBlockAsyncDFSOutputHelper {
|
||||||
|
|
||||||
private static final FileCreator FILE_CREATOR;
|
private static final FileCreator FILE_CREATOR;
|
||||||
|
|
||||||
private static DFSClientAdaptor createDFSClientAdaptor() throws NoSuchMethodException {
|
|
||||||
Method isClientRunningMethod = DFSClient.class.getDeclaredMethod("isClientRunning");
|
|
||||||
isClientRunningMethod.setAccessible(true);
|
|
||||||
return new DFSClientAdaptor() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isClientRunning(DFSClient client) {
|
|
||||||
try {
|
|
||||||
return (Boolean) isClientRunningMethod.invoke(client);
|
|
||||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private static LeaseManager createLeaseManager() throws NoSuchMethodException {
|
private static LeaseManager createLeaseManager() throws NoSuchMethodException {
|
||||||
Method beginFileLeaseMethod =
|
Method beginFileLeaseMethod =
|
||||||
DFSClient.class.getDeclaredMethod("beginFileLease", long.class, DFSOutputStream.class);
|
DFSClient.class.getDeclaredMethod("beginFileLease", long.class, DFSOutputStream.class);
|
||||||
|
@ -241,18 +216,6 @@ public final class FanOutOneBlockAsyncDFSOutputHelper {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static FileCreator createFileCreator2() throws NoSuchMethodException {
|
|
||||||
Method createMethod = ClientProtocol.class.getMethod("create", String.class, FsPermission.class,
|
|
||||||
String.class, EnumSetWritable.class, boolean.class, short.class, long.class,
|
|
||||||
CryptoProtocolVersion[].class);
|
|
||||||
|
|
||||||
return (instance, src, masked, clientName, flag, createParent, replication, blockSize,
|
|
||||||
supportedVersions) -> {
|
|
||||||
return (HdfsFileStatus) createMethod.invoke(instance, src, masked, clientName, flag,
|
|
||||||
createParent, replication, blockSize, supportedVersions);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private static FileCreator createFileCreator() throws NoSuchMethodException {
|
private static FileCreator createFileCreator() throws NoSuchMethodException {
|
||||||
try {
|
try {
|
||||||
return createFileCreator3_3();
|
return createFileCreator3_3();
|
||||||
|
@ -260,12 +223,7 @@ public final class FanOutOneBlockAsyncDFSOutputHelper {
|
||||||
LOG.debug("ClientProtocol::create wrong number of arguments, should be hadoop 3.2 or below");
|
LOG.debug("ClientProtocol::create wrong number of arguments, should be hadoop 3.2 or below");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
return createFileCreator3();
|
return createFileCreator3();
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
LOG.debug("ClientProtocol::create wrong number of arguments, should be hadoop 2.x");
|
|
||||||
}
|
|
||||||
return createFileCreator2();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cancel the processing if DFSClient is already closed.
|
// cancel the processing if DFSClient is already closed.
|
||||||
|
@ -279,14 +237,13 @@ public final class FanOutOneBlockAsyncDFSOutputHelper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean progress() {
|
public boolean progress() {
|
||||||
return DFS_CLIENT_ADAPTOR.isClientRunning(client);
|
return client.isClientRunning();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
LEASE_MANAGER = createLeaseManager();
|
LEASE_MANAGER = createLeaseManager();
|
||||||
DFS_CLIENT_ADAPTOR = createDFSClientAdaptor();
|
|
||||||
FILE_CREATOR = createFileCreator();
|
FILE_CREATOR = createFileCreator();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String msg = "Couldn't properly initialize access to HDFS internals. Please " +
|
String msg = "Couldn't properly initialize access to HDFS internals. Please " +
|
||||||
|
|
Loading…
Reference in New Issue