Browse Source

HDFS-1648. Only DataStorage must be locked using in_use.lock and no locks must be associated with BlockPoolStorage. Contributed by Tanping Wang.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hdfs/branches/HDFS-1052@1074728 13f79535-47bb-0310-9956-ffa450edef68
Suresh Srinivas 14 years ago
parent
commit
3840a02d59

+ 3 - 0
CHANGES.txt

@@ -41,6 +41,9 @@ Trunk (unreleased changes)
 
     HDFS-1639. Add block pool management to FSDataset. (suresh)
 
+    HDFS-1648. Only DataStorage must be locked using in_use.lock and no 
+    locks must be associated with BlockPoolStorage. (tanping via suresh)
+
   IMPROVEMENTS
 
     HDFS-1510. Added test-patch.properties required by test-patch.sh (nigel)

+ 21 - 4
src/java/org/apache/hadoop/hdfs/server/common/Storage.java

@@ -198,19 +198,32 @@ public abstract class Storage extends StorageInfo {
    */
   @InterfaceAudience.Private
   public class StorageDirectory {
-    File              root; // root directory
-    FileLock          lock; // storage lock
-    StorageDirType dirType; // storage dir type
+    final File root;              // root directory
+    final boolean useLock;        // flag to enable storage lock
+    final StorageDirType dirType; // storage dir type
+    FileLock lock;                // storage lock
     
     public StorageDirectory(File dir) {
       // default dirType is null
-      this(dir, null);
+      this(dir, null, true);
     }
     
     public StorageDirectory(File dir, StorageDirType dirType) {
+      this(dir, dirType, true);
+    }
+    
+    /**
+     * Constructor
+     * @param dir directory corresponding to the storage
+     * @param dirType storage directory type
+     * @param useLock true - enables locking on the storage directory and false
+     *          disables locking
+     */
+    public StorageDirectory(File dir, StorageDirType dirType, boolean useLock) {
       this.root = dir;
       this.lock = null;
       this.dirType = dirType;
+      this.useLock = useLock;
     }
     
     /**
@@ -616,6 +629,10 @@ public abstract class Storage extends StorageInfo {
      * @throws IOException if locking fails
      */
     public void lock() throws IOException {
+      if (!useLock) {
+        LOG.info("Locking is disabled");
+        return;
+      }
       this.lock = tryLock();
       if (lock == null) {
         String msg = "Cannot lock storage " + this.root 

+ 1 - 1
src/java/org/apache/hadoop/hdfs/server/datanode/BlockPoolStorage.java

@@ -94,7 +94,7 @@ public class BlockPoolStorage extends Storage {
         dataDirs.size());
     for (Iterator<File> it = dataDirs.iterator(); it.hasNext();) {
       File dataDir = it.next();
-      StorageDirectory sd = new StorageDirectory(dataDir);
+      StorageDirectory sd = new StorageDirectory(dataDir, null, false);
       StorageState curState;
       try {
         curState = sd.analyzeStorage(startOpt);

+ 0 - 7
src/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java

@@ -911,13 +911,6 @@ public class DataNode extends Configured
         register();
       } catch (IOException ioe) {
         LOG.error(bpRegistration + ": Setup failed", ioe);
-        try {
-          // TODO:FEDERATION needs to unlock only this specific storage...
-          // and remove it....
-          storage.unlockAll(); 
-        } catch (Exception e) { 
-          LOG.warn("failed to unlock storage for dn: " + bpRegistration, e);
-        }
         // TODO:FEDERATION should be local only
         //shutdown();
         return;