From 9ce1cf4d68367bc4adccf7fd86da51114a7fa685 Mon Sep 17 00:00:00 2001 From: Wei-Chiu Chuang Date: Thu, 1 Jul 2021 11:24:34 +0800 Subject: [PATCH] HBASE-26057 Remove reflections used to access Hadoop 2 API in FanOutOneBlockAsyncDFSOutputHelper Change-Id: I67af0e17f4c3ce879b51f4c49d1404c15e2aa735 --- .../FanOutOneBlockAsyncDFSOutputHelper.java | 47 +------------------ 1 file changed, 2 insertions(+), 45 deletions(-) diff --git a/hbase-asyncfs/src/main/java/org/apache/hadoop/hbase/io/asyncfs/FanOutOneBlockAsyncDFSOutputHelper.java b/hbase-asyncfs/src/main/java/org/apache/hadoop/hbase/io/asyncfs/FanOutOneBlockAsyncDFSOutputHelper.java index 6bed33fa3dc7..f4a0005d7f8e 100644 --- a/hbase-asyncfs/src/main/java/org/apache/hadoop/hbase/io/asyncfs/FanOutOneBlockAsyncDFSOutputHelper.java +++ b/hbase-asyncfs/src/main/java/org/apache/hadoop/hbase/io/asyncfs/FanOutOneBlockAsyncDFSOutputHelper.java @@ -139,15 +139,6 @@ private interface LeaseManager { 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. private interface FileCreator { default HdfsFileStatus create(ClientProtocol instance, String src, FsPermission masked, @@ -173,22 +164,6 @@ Object createObject(ClientProtocol instance, String src, FsPermission masked, St 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 { Method beginFileLeaseMethod = DFSClient.class.getDeclaredMethod("beginFileLease", long.class, DFSOutputStream.class); @@ -241,18 +216,6 @@ private static FileCreator createFileCreator3() throws NoSuchMethodException { }; } - 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 { try { return createFileCreator3_3(); @@ -260,12 +223,7 @@ private static FileCreator createFileCreator() throws NoSuchMethodException { LOG.debug("ClientProtocol::create wrong number of arguments, should be hadoop 3.2 or below"); } - try { - return createFileCreator3(); - } catch (NoSuchMethodException e) { - LOG.debug("ClientProtocol::create wrong number of arguments, should be hadoop 2.x"); - } - return createFileCreator2(); + return createFileCreator3(); } // cancel the processing if DFSClient is already closed. @@ -279,14 +237,13 @@ public CancelOnClose(DFSClient client) { @Override public boolean progress() { - return DFS_CLIENT_ADAPTOR.isClientRunning(client); + return client.isClientRunning(); } } static { try { LEASE_MANAGER = createLeaseManager(); - DFS_CLIENT_ADAPTOR = createDFSClientAdaptor(); FILE_CREATOR = createFileCreator(); } catch (Exception e) { String msg = "Couldn't properly initialize access to HDFS internals. Please " +