mirror of https://github.com/apache/lucene.git
SOLR-7321: Remove reflection in FSHDFSUtils.java (Mike Drob, Kevin Risden)
Signed-off-by: Kevin Risden <krisden@apache.org>
This commit is contained in:
parent
00c02290d5
commit
15f3c3b0e6
|
@ -111,6 +111,8 @@ Other Changes
|
||||||
|
|
||||||
* SOLR-9762: Remove the workaround implemented for HADOOP-13346 (Kevin Risden)
|
* 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 ==================
|
================== 8.0.0 ==================
|
||||||
|
|
||||||
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
|
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
|
||||||
|
|
|
@ -20,7 +20,6 @@ import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InterruptedIOException;
|
import java.io.InterruptedIOException;
|
||||||
import java.lang.invoke.MethodHandles;
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
|
@ -31,11 +30,9 @@ import org.apache.hadoop.hdfs.DistributedFileSystem;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Borrowed from Apache HBase to recover an HDFS lease.
|
* Borrowed from Apache HBase to recover an HDFS lease.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class FSHDFSUtils {
|
public class FSHDFSUtils {
|
||||||
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
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.
|
// 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);
|
long subsequentPause = TimeUnit.NANOSECONDS.convert(conf.getInt("solr.hdfs.lease.recovery.dfs.timeout", 61 * 1000), TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
Method isFileClosedMeth = null;
|
if (dfs.isFileClosed(p)) {
|
||||||
// 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)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,13 +108,12 @@ public class FSHDFSUtils {
|
||||||
if (nbAttempt == 0) {
|
if (nbAttempt == 0) {
|
||||||
Thread.sleep(firstPause);
|
Thread.sleep(firstPause);
|
||||||
} else {
|
} else {
|
||||||
// Cycle here until subsequentPause elapses. While spinning, check isFileClosed if
|
// Cycle here until subsequentPause elapses. While spinning, check isFileClosed
|
||||||
// available (should be in hadoop 2.0.5... not in hadoop 1 though.
|
|
||||||
long localStartWaiting = System.nanoTime();
|
long localStartWaiting = System.nanoTime();
|
||||||
while ((System.nanoTime() - localStartWaiting) < subsequentPause && !callerInfo.isCallerClosed()) {
|
while ((System.nanoTime() - localStartWaiting) < subsequentPause && !callerInfo.isCallerClosed()) {
|
||||||
Thread.sleep(conf.getInt("solr.hdfs.lease.recovery.pause", 1000));
|
Thread.sleep(conf.getInt("solr.hdfs.lease.recovery.pause", 1000));
|
||||||
|
|
||||||
if (isFileClosedMeth != null && isFileClosed(dfs, isFileClosedMeth, p)) {
|
if (dfs.isFileClosed(p)) {
|
||||||
recovered = true;
|
recovered = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -187,21 +173,4 @@ public class FSHDFSUtils {
|
||||||
return "attempt=" + nbAttempt + " on file=" + p + " after " +
|
return "attempt=" + nbAttempt + " on file=" + p + " after " +
|
||||||
TimeUnit.MILLISECONDS.convert(System.nanoTime() - startWaiting, TimeUnit.NANOSECONDS) + "ms";
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue