You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by en...@apache.org on 2013/07/16 00:25:27 UTC

svn commit: r1503501 - in /hbase/trunk/hbase-server/src: main/java/org/apache/hadoop/hbase/util/FSUtils.java test/java/org/apache/hadoop/hbase/io/TestFileLink.java

Author: enis
Date: Mon Jul 15 22:25:27 2013
New Revision: 1503501

URL: http://svn.apache.org/r1503501
Log:
HBASE-8838 [WINDOWS] FileLink assumptions are broken under NTFS

Modified:
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestFileLink.java

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java?rev=1503501&r1=1503500&r2=1503501&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java Mon Jul 15 22:25:27 2013
@@ -87,6 +87,9 @@ public abstract class FSUtils {
   /** Full access permissions (starting point for a umask) */
   private static final String FULL_RWX_PERMISSIONS = "777";
 
+  /** Set to true on Windows platforms */
+  public static final boolean WINDOWS = System.getProperty("os.name").startsWith("Windows");
+
   protected FSUtils() {
     super();
   }
@@ -95,7 +98,7 @@ public abstract class FSUtils {
    * Compare of path component. Does not consider schema; i.e. if schemas different but <code>path
    * <code> starts with <code>rootPath<code>, then the function returns true
    * @param rootPath
-   * @param path 
+   * @param path
    * @return True if <code>path</code> starts with <code>rootPath</code>
    */
   public static boolean isStartingWithPath(final Path rootPath, final String path) {
@@ -404,7 +407,7 @@ public abstract class FSUtils {
   /**
    * We use reflection because {@link DistributedFileSystem#setSafeMode(
    * FSConstants.SafeModeAction action, boolean isChecked)} is not in hadoop 1.1
-   * 
+   *
    * @param dfs
    * @return whether we're in safe mode
    * @throws IOException
@@ -418,14 +421,14 @@ public abstract class FSUtils {
         org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction.SAFEMODE_GET, true);
     } catch (Exception e) {
       if (e instanceof IOException) throw (IOException) e;
-      
+
       // Check whether dfs is on safemode.
       inSafeMode = dfs.setSafeMode(
-        org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction.SAFEMODE_GET);      
+        org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction.SAFEMODE_GET);
     }
-    return inSafeMode;    
+    return inSafeMode;
   }
-  
+
   /**
    * Check whether dfs is in safemode.
    * @param conf
@@ -458,7 +461,7 @@ public abstract class FSUtils {
     Path versionFile = new Path(rootdir, HConstants.VERSION_FILE_NAME);
     FileStatus[] status = null;
     try {
-      // hadoop 2.0 throws FNFE if directory does not exist.  
+      // hadoop 2.0 throws FNFE if directory does not exist.
       // hadoop 1.0 returns null if directory does not exist.
       status = fs.listStatus(versionFile);
     } catch (FileNotFoundException fnfe) {
@@ -1446,7 +1449,7 @@ public abstract class FSUtils {
    * @return Map keyed by StoreFile name with a value of the full Path.
    * @throws IOException When scanning the directory fails.
    */
-  public static Map<String, Path> getTableStoreFilePathMap(Map<String, Path> map, 
+  public static Map<String, Path> getTableStoreFilePathMap(Map<String, Path> map,
     final FileSystem fs, final Path hbaseRootDir, byte[] tablename)
   throws IOException {
     if (map == null) {
@@ -1456,7 +1459,7 @@ public abstract class FSUtils {
     // only include the directory paths to tables
     Path tableDir = new Path(hbaseRootDir, Bytes.toString(tablename));
     // Inside a table, there are compaction.dir directories to skip.  Otherwise, all else
-    // should be regions. 
+    // should be regions.
     PathFilter df = new BlackListDirFilter(fs, HConstants.HBASE_NON_TABLE_DIRS);
     FileStatus[] regionDirs = fs.listStatus(tableDir);
     for (FileStatus regionDir : regionDirs) {
@@ -1480,7 +1483,7 @@ public abstract class FSUtils {
     return map;
   }
 
-  
+
   /**
    * Runs through the HBase rootdir and creates a reverse lookup map for
    * table StoreFile names to the full Path.
@@ -1501,7 +1504,7 @@ public abstract class FSUtils {
 
     // if this method looks similar to 'getTableFragmentation' that is because
     // it was borrowed from it.
-    
+
     // only include the directory paths to tables
     PathFilter df = new BlackListDirFilter(fs, HConstants.HBASE_NON_TABLE_DIRS);
     FileStatus [] tableDirs = fs.listStatus(hbaseRootDir, df);

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestFileLink.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestFileLink.java?rev=1503501&r1=1503500&r2=1503501&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestFileLink.java (original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestFileLink.java Mon Jul 15 22:25:27 2013
@@ -22,26 +22,22 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-import org.junit.Test;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import junit.framework.TestCase;
-import org.junit.experimental.categories.Category;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.fs.FileSystem;
-import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.FSDataInputStream;
 import org.apache.hadoop.fs.FSDataOutputStream;
-import org.apache.hadoop.hdfs.MiniDFSCluster;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.hbase.HBaseTestingUtility;
 import org.apache.hadoop.hbase.MediumTests;
-import org.apache.hadoop.hbase.io.FileLink;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
+import org.apache.hadoop.hbase.util.FSUtils;
+import org.apache.hadoop.hdfs.MiniDFSCluster;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
 
 /**
  * Test that FileLink switches between alternate locations
@@ -108,12 +104,21 @@ public class TestFileLink {
       dataVerify(data, n, (byte)2);
       size += n;
 
+      if (FSUtils.WINDOWS) {
+        in.close();
+      }
+
       // Move origin to archive
       assertFalse(fs.exists(archivedPath));
       fs.rename(originalPath, archivedPath);
       assertFalse(fs.exists(originalPath));
       assertTrue(fs.exists(archivedPath));
 
+      if (FSUtils.WINDOWS) {
+        in = link.open(fs); // re-read from beginning
+        in.read(data);
+      }
+
       // Try to read to the end
       while ((n = in.read(data)) > 0) {
         dataVerify(data, n, (byte)2);