mirror of https://github.com/apache/lucene.git
SOLR-8130: Solr's hdfs safe mode detection does not catch all cases of being in safe mode.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1707974 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
905d3bb5b4
commit
75c7abbd99
|
@ -258,6 +258,9 @@ Bug Fixes
|
|||
home directory. Fixes the inability to use ICU analysis components with a
|
||||
"solr." prefix on the classname. (Shawn Heisey)
|
||||
|
||||
* SOLR-8130: Solr's hdfs safe mode detection does not catch all cases of being in safe mode.
|
||||
(Mark Miller, Mike Drob)
|
||||
|
||||
Optimizations
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -29,7 +29,8 @@ import org.apache.hadoop.fs.FileContext;
|
|||
import org.apache.hadoop.fs.FileStatus;
|
||||
import org.apache.hadoop.fs.FileSystem;
|
||||
import org.apache.hadoop.fs.Path;
|
||||
import org.apache.hadoop.ipc.RemoteException;
|
||||
import org.apache.hadoop.hdfs.DistributedFileSystem;
|
||||
import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction;
|
||||
import org.apache.lucene.store.BaseDirectory;
|
||||
import org.apache.lucene.store.IOContext;
|
||||
import org.apache.lucene.store.IndexInput;
|
||||
|
@ -63,37 +64,30 @@ public class HdfsDirectory extends BaseDirectory {
|
|||
fileSystem = FileSystem.get(hdfsDirPath.toUri(), configuration);
|
||||
fileContext = FileContext.getFileContext(hdfsDirPath.toUri(), configuration);
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
if (!fileSystem.exists(hdfsDirPath)) {
|
||||
boolean success = fileSystem.mkdirs(hdfsDirPath);
|
||||
if (!success) {
|
||||
throw new RuntimeException("Could not create directory: " + hdfsDirPath);
|
||||
}
|
||||
} else {
|
||||
fileSystem.mkdirs(hdfsDirPath); // check for safe mode
|
||||
if (fileSystem instanceof DistributedFileSystem) {
|
||||
// Make sure dfs is not in safe mode
|
||||
while (((DistributedFileSystem) fileSystem).setSafeMode(SafeModeAction.SAFEMODE_GET, true)) {
|
||||
LOG.warn("The NameNode is in SafeMode - Solr will wait 5 seconds and try again.");
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.interrupted();
|
||||
// continue
|
||||
}
|
||||
|
||||
break;
|
||||
} catch (RemoteException e) {
|
||||
if (e.getClassName().equals("org.apache.hadoop.hdfs.server.namenode.SafeModeException")) {
|
||||
LOG.warn("The NameNode is in SafeMode - Solr will wait 5 seconds and try again.");
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException e1) {
|
||||
Thread.interrupted();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
org.apache.solr.common.util.IOUtils.closeQuietly(fileSystem);
|
||||
throw new RuntimeException(
|
||||
"Problem creating directory: " + hdfsDirPath, e);
|
||||
} catch (Exception e) {
|
||||
org.apache.solr.common.util.IOUtils.closeQuietly(fileSystem);
|
||||
throw new RuntimeException(
|
||||
"Problem creating directory: " + hdfsDirPath, e);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (!fileSystem.exists(hdfsDirPath)) {
|
||||
boolean success = fileSystem.mkdirs(hdfsDirPath);
|
||||
if (!success) {
|
||||
throw new RuntimeException("Could not create directory: " + hdfsDirPath);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
org.apache.solr.common.util.IOUtils.closeQuietly(fileSystem);
|
||||
throw new RuntimeException("Problem creating directory: " + hdfsDirPath, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue