You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by kr...@apache.org on 2019/02/27 19:07:40 UTC

[lucene-solr] branch master updated: SOLR-7321: Remove reflection in FSHDFSUtils.java (Mike Drob, Kevin Risden)

This is an automated email from the ASF dual-hosted git repository.

krisden pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/master by this push:
     new 15f3c3b  SOLR-7321: Remove reflection in FSHDFSUtils.java (Mike Drob, Kevin Risden)
15f3c3b is described below

commit 15f3c3b0e6cbf0866da23f96547a4ed7215994d7
Author: Kevin Risden <kr...@apache.org>
AuthorDate: Tue Feb 26 15:04:26 2019 -0500

    SOLR-7321: Remove reflection in FSHDFSUtils.java (Mike Drob, Kevin Risden)
    
    Signed-off-by: Kevin Risden <kr...@apache.org>
---
 solr/CHANGES.txt                                   |  2 ++
 .../src/java/org/apache/solr/util/FSHDFSUtils.java | 37 ++--------------------
 2 files changed, 5 insertions(+), 34 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index ca510ca..1d15666 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -111,6 +111,8 @@ Other Changes
 
 * SOLR-9762: Remove the workaround implemented for HADOOP-13346 (Kevin Risden)
 
+* SOLR-7321: Remove reflection in FSHDFSUtils.java (Mike Drob, Kevin Risden)
+
 ==================  8.0.0 ==================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
diff --git a/solr/core/src/java/org/apache/solr/util/FSHDFSUtils.java b/solr/core/src/java/org/apache/solr/util/FSHDFSUtils.java
index 2ed995c..8f784d4 100644
--- a/solr/core/src/java/org/apache/solr/util/FSHDFSUtils.java
+++ b/solr/core/src/java/org/apache/solr/util/FSHDFSUtils.java
@@ -20,7 +20,6 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InterruptedIOException;
 import java.lang.invoke.MethodHandles;
-import java.lang.reflect.Method;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
 
@@ -31,11 +30,9 @@ import org.apache.hadoop.hdfs.DistributedFileSystem;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 /**
  * Borrowed from Apache HBase to recover an HDFS lease.
  */
-
 public class FSHDFSUtils {
   private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
   
@@ -96,17 +93,7 @@ public class FSHDFSUtils {
     // default value for DFS_CLIENT_SOCKET_TIMEOUT_KEY.
     long subsequentPause = TimeUnit.NANOSECONDS.convert(conf.getInt("solr.hdfs.lease.recovery.dfs.timeout", 61 * 1000), TimeUnit.MILLISECONDS);
     
-    Method isFileClosedMeth = null;
-    // whether we need to look for isFileClosed method
-    
-    try {
-      isFileClosedMeth = dfs.getClass().getMethod("isFileClosed",
-          new Class[] {Path.class});
-    } catch (NoSuchMethodException nsme) {
-      log.debug("isFileClosed not available");
-    }
-    
-    if (isFileClosedMeth != null && isFileClosed(dfs, isFileClosedMeth, p)) {
+    if (dfs.isFileClosed(p)) {
       return true;
     }
     
@@ -121,13 +108,12 @@ public class FSHDFSUtils {
         if (nbAttempt == 0) {
           Thread.sleep(firstPause);
         } else {
-          // Cycle here until subsequentPause elapses.  While spinning, check isFileClosed if
-          // available (should be in hadoop 2.0.5... not in hadoop 1 though.
+          // Cycle here until subsequentPause elapses.  While spinning, check isFileClosed
           long localStartWaiting = System.nanoTime();
           while ((System.nanoTime() - localStartWaiting) < subsequentPause && !callerInfo.isCallerClosed()) {
             Thread.sleep(conf.getInt("solr.hdfs.lease.recovery.pause", 1000));
 
-            if (isFileClosedMeth != null && isFileClosed(dfs, isFileClosedMeth, p)) {
+            if (dfs.isFileClosed(p)) {
               recovered = true;
               break;
             }
@@ -187,21 +173,4 @@ public class FSHDFSUtils {
     return "attempt=" + nbAttempt + " on file=" + p + " after " +
       TimeUnit.MILLISECONDS.convert(System.nanoTime() - startWaiting, TimeUnit.NANOSECONDS) + "ms";
   }
-
-  /**
-   * Call HDFS-4525 isFileClosed if it is available.
-   * 
-   * @return True if file is closed.
-   */
-  private static boolean isFileClosed(final DistributedFileSystem dfs, final Method m, final Path p) {
-    try {
-      return (Boolean) m.invoke(dfs, p);
-    } catch (SecurityException e) {
-      log.warn("No access", e);
-    } catch (Exception e) {
-      log.warn("Failed invocation for " + p.toString(), e);
-    }
-    return false;
-  }
-
 }