Index: src/main/java/org/apache/hadoop/hbase/master/MasterFileSystem.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/master/MasterFileSystem.java (revision 1099363) +++ src/main/java/org/apache/hadoop/hbase/master/MasterFileSystem.java (working copy) @@ -129,17 +129,14 @@ * @return false if file system is not available */ public boolean checkFileSystem() { - if (this.fsOk) { - try { - FSUtils.checkFileSystemAvailable(this.fs); - } catch (IOException e) { - master.abort("Shutting down HBase cluster: file system not available", e); - this.fsOk = false; - } + this.fsOk = FSUtils.checkFileSystemWritable(this.fs, conf); + if (!this.fsOk) { + IOException io = new IOException("File system is not available"); + master.abort("Shutting down HBase cluster: file system not available", io); } return this.fsOk; } - + /** * @return HBase root dir. * @throws IOException Index: src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogSplitter.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogSplitter.java (revision 1099363) +++ src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogSplitter.java (working copy) @@ -53,6 +53,7 @@ import org.apache.hadoop.hbase.regionserver.wal.HLog.Writer; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.ClassSize; +import org.apache.hadoop.hbase.util.FSUtils; import org.apache.hadoop.io.MultipleIOException; import com.google.common.base.Preconditions; @@ -171,7 +172,10 @@ Preconditions.checkState(!hasSplit, "An HLogSplitter instance may only be used once"); hasSplit = true; - + + // If FS is in safe mode wait till out of it. + FSUtils.waitOnSafeMode(conf, conf.getInt(HConstants.THREAD_WAKE_FREQUENCY, + 10 * 1000)); long startTime = System.currentTimeMillis(); List splits = null; if (!fs.exists(srcDir)) { Index: src/main/java/org/apache/hadoop/hbase/util/FSUtils.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/util/FSUtils.java (revision 1099363) +++ src/main/java/org/apache/hadoop/hbase/util/FSUtils.java (working copy) @@ -138,6 +138,50 @@ } /** + * Checks to see if the specified file system is writable + * + * @param fs filesystem object + * @param conf + * @return true if dfs is writable + */ + public static boolean checkFileSystemWritable(final FileSystem fs, + final Configuration conf) { + + boolean isDfsWritable = false; + if (fs instanceof DistributedFileSystem) { + DistributedFileSystem dfs = (DistributedFileSystem) fs; + try { + //if dfs exists path "/" and dfs isn't on safemode, + //set isDfsWritable to true. + if (dfs.exists(new Path("/")) && !checkDfsSafeMode(conf)) { + isDfsWritable = true; + } + } catch (IOException e) { + } + } + return isDfsWritable; + } + + /** + * Check whether dfs is on safemode. + * @param conf + * @return true if dfs is on safemode. + * @throws IOException + */ + public static boolean checkDfsSafeMode(final Configuration conf) + throws IOException { + boolean isOnSafeMode = false; + FileSystem fs = FileSystem.get(conf); + + if (fs instanceof DistributedFileSystem) { + DistributedFileSystem dfs = (DistributedFileSystem)fs; + // Check whether dfs is on safemode. + isOnSafeMode = dfs.setSafeMode(FSConstants.SafeModeAction.SAFEMODE_GET); + } + return isOnSafeMode; + } + + /** * Verifies current version of file system * * @param fs filesystem object