hadoop-hdfs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From szets...@apache.org
Subject svn commit: r1526215 - in /hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs: ./ src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/ src/main/java/org/apache/hadoop/hdfs/server/namenode/
Date Wed, 25 Sep 2013 16:03:20 GMT
Author: szetszwo
Date: Wed Sep 25 16:03:20 2013
New Revision: 1526215

URL: http://svn.apache.org/r1526215
Log:
HDFS-5222. Move block schedule information from DatanodeDescriptor to DatanodeStorageInfo.

Modified:
    hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-2832.txt
    hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
    hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyDefault.java
    hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeDescriptor.java
    hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeStorageInfo.java
    hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

Modified: hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-2832.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-2832.txt?rev=1526215&r1=1526214&r2=1526215&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-2832.txt
(original)
+++ hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-2832.txt
Wed Sep 25 16:03:20 2013
@@ -30,3 +30,6 @@ IMPROVEMENTS:
     HDFS-5232. Protocol changes to transmit StorageUuid. (Arpit Agarwal)
 
     HDFS-5233. Use Datanode UUID to identify Datanodes. (Arpit Agarwal)
+
+    HDFS-5222. Move block schedule information from DatanodeDescriptor to
+    DatanodeStorageInfo.  (szetszwo)

Modified: hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java?rev=1526215&r1=1526214&r2=1526215&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
(original)
+++ hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
Wed Sep 25 16:03:20 2013
@@ -1328,10 +1328,7 @@ public class BlockManager {
           // Add block to the to be replicated list
           rw.srcNode.addBlockToBeReplicated(block, targets);
           scheduledWork++;
-
-          for (DatanodeStorageInfo storage : targets) {
-            storage.getDatanodeDescriptor().incBlocksScheduled();
-          }
+          DatanodeStorageInfo.incrementBlocksScheduled(targets);
 
           // Move the block-replication into a "pending" state.
           // The reason we use 'pending' is so we can retry
@@ -2621,10 +2618,10 @@ assert storedBlock.findDatanode(dn) < 0 
   @VisibleForTesting
   void addBlock(DatanodeDescriptor node, String storageID, Block block, String delHint)
       throws IOException {
-    // decrement number of blocks scheduled to this datanode.
+    // Decrement number of blocks scheduled to this storage.
     // for a retry request (of DatanodeProtocol#blockReceivedAndDeleted with 
     // RECEIVED_BLOCK), we currently also decrease the approximate number. 
-    node.decBlocksScheduled();
+    node.getStorageInfo(storageID).decrementBlocksScheduled();
 
     // get the deletion hint node
     DatanodeDescriptor delHintNode = null;

Modified: hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyDefault.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyDefault.java?rev=1526215&r1=1526214&r2=1526215&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyDefault.java
(original)
+++ hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyDefault.java
Wed Sep 25 16:03:20 2013
@@ -620,19 +620,12 @@ public class BlockPlacementPolicyDefault
     }
     
     final long requiredSize = blockSize * HdfsConstants.MIN_BLOCKS_FOR_WRITE;
-    if (requiredSize > storage.getRemaining()) {
+    final long scheduledSize = blockSize = storage.getBlocksScheduled();
+    if (requiredSize > storage.getRemaining() - scheduledSize) {
       logNodeIsNotChosen(storage, "the storage does not have enough space ");
       return false;
     }
-    //TODO: move getBlocksScheduled() to DatanodeStorageInfo. 
-    long remaining = node.getRemaining() - 
-                     (node.getBlocksScheduled() * blockSize); 
-    // check the remaining capacity of the target machine
-    if (requiredSize > remaining) {
-      logNodeIsNotChosen(storage, "the node does not have enough space ");
-      return false;
-    }
-      
+
     // check the communication traffic of the target machine
     if (considerLoad) {
       double avgLoad = 0;

Modified: hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeDescriptor.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeDescriptor.java?rev=1526215&r1=1526214&r2=1526215&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeDescriptor.java
(original)
+++ hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeDescriptor.java
Wed Sep 25 16:03:20 2013
@@ -125,15 +125,6 @@ public class DatanodeDescriptor extends 
   /** A set of blocks to be invalidated by this datanode */
   private LightWeightHashSet<Block> invalidateBlocks = new LightWeightHashSet<Block>();
 
-  /* Variables for maintaining number of blocks scheduled to be written to
-   * this datanode. This count is approximate and might be slightly bigger
-   * in case of errors (e.g. datanode does not report if an error occurs
-   * while writing the block).
-   */
-  private int currApproxBlocksScheduled = 0;
-  private int prevApproxBlocksScheduled = 0;
-  private long lastBlocksScheduledRollTime = 0;
-  private static final int BLOCKS_SCHEDULED_ROLL_INTERVAL = 600*1000; //10min
   private int volumeFailures = 0;
   
   /** 
@@ -313,9 +304,8 @@ public class DatanodeDescriptor extends 
     setLastUpdate(Time.now());    
     this.volumeFailures = volFailures;
     for(DatanodeStorageInfo storage : getStorageInfos()) {
-      storage.receivedHeartbeat();
+      storage.receivedHeartbeat(getLastUpdate());
     }
-    rollBlocksScheduled(getLastUpdate());
   }
 
   private static class BlockIterator implements Iterator<BlockInfo> {
@@ -437,38 +427,11 @@ public class DatanodeDescriptor extends 
    * to this datanode.
    */
   public int getBlocksScheduled() {
-    return currApproxBlocksScheduled + prevApproxBlocksScheduled;
-  }
-  
-  /**
-   * Increments counter for number of blocks scheduled. 
-   */
-  public void incBlocksScheduled() {
-    currApproxBlocksScheduled++;
-  }
-  
-  /**
-   * Decrements counter for number of blocks scheduled.
-   */
-  void decBlocksScheduled() {
-    if (prevApproxBlocksScheduled > 0) {
-      prevApproxBlocksScheduled--;
-    } else if (currApproxBlocksScheduled > 0) {
-      currApproxBlocksScheduled--;
-    } 
-    // its ok if both counters are zero.
-  }
-  
-  /**
-   * Adjusts curr and prev number of blocks scheduled every few minutes.
-   */
-  private void rollBlocksScheduled(long now) {
-    if ((now - lastBlocksScheduledRollTime) > 
-        BLOCKS_SCHEDULED_ROLL_INTERVAL) {
-      prevApproxBlocksScheduled = currApproxBlocksScheduled;
-      currApproxBlocksScheduled = 0;
-      lastBlocksScheduledRollTime = now;
+    int n = 0;
+    for(DatanodeStorageInfo storage : getStorageInfos()) {
+      n += storage.getBlocksScheduled();
     }
+    return n;
   }
   
   @Override

Modified: hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeStorageInfo.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeStorageInfo.java?rev=1526215&r1=1526214&r2=1526215&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeStorageInfo.java
(original)
+++ hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeStorageInfo.java
Wed Sep 25 16:03:20 2013
@@ -92,9 +92,11 @@ public class DatanodeStorageInfo {
   private final String storageID;
   private final StorageType storageType;
   private State state;
+
   private long capacity;
   private long dfsUsed;
   private long remaining;
+
   private volatile BlockInfo blockList = null;
   private int numBlocks = 0;
 
@@ -117,6 +119,16 @@ public class DatanodeStorageInfo {
    */
   private boolean blockContentsStale = true;
 
+  /* Variables for maintaining number of blocks scheduled to be written to
+   * this storage. This count is approximate and might be slightly bigger
+   * in case of errors (e.g. datanode does not report if an error occurs
+   * while writing the block).
+   */
+  private int currApproxBlocksScheduled = 0;
+  private int prevApproxBlocksScheduled = 0;
+  private long lastBlocksScheduledRollTime = 0;
+  private static final int BLOCKS_SCHEDULED_ROLL_INTERVAL = 600*1000; //10min
+
   public DatanodeStorageInfo(DatanodeDescriptor dn, DatanodeStorage s) {
     this.dn = dn;
     this.storageID = s.getStorageID();
@@ -132,27 +144,28 @@ public class DatanodeStorageInfo {
     this.blockReportCount = blockReportCount;
   }
 
-  public boolean areBlockContentsStale() {
+  boolean areBlockContentsStale() {
     return blockContentsStale;
   }
 
-  public void markStaleAfterFailover() {
+  void markStaleAfterFailover() {
     heartbeatedSinceFailover = false;
     blockContentsStale = true;
   }
 
-  public void receivedHeartbeat() {
+  void receivedHeartbeat(final long lastUpdate) {
     heartbeatedSinceFailover = true;
+    rollBlocksScheduled(lastUpdate);
   }
 
-  public void receivedBlockReport() {
+  void receivedBlockReport() {
     if (heartbeatedSinceFailover) {
       blockContentsStale = false;
     }
     blockReportCount++;
   }
 
-  public void setUtilization(long capacity, long dfsUsed, long remaining) {
+  void setUtilization(long capacity, long dfsUsed, long remaining) {
     this.capacity = capacity;
     this.dfsUsed = dfsUsed;
     this.remaining = remaining;
@@ -224,7 +237,46 @@ public class DatanodeStorageInfo {
   public DatanodeDescriptor getDatanodeDescriptor() {
     return dn;
   }
+
+  /**
+   * @return Approximate number of blocks currently scheduled to be written
+   *         to this storage.
+   */
+  int getBlocksScheduled() {
+    return currApproxBlocksScheduled + prevApproxBlocksScheduled;
+  }
+
+  /** Increment the number of blocks scheduled for each given storage */ 
+  public static void incrementBlocksScheduled(DatanodeStorageInfo... storages) {
+    for (DatanodeStorageInfo s : storages) {
+      s.incrementBlocksScheduled();
+    }
+  }
+
+  /** Increment the number of blocks scheduled. */
+  private void incrementBlocksScheduled() {
+    currApproxBlocksScheduled++;
+  }
   
+  /** Decrement the number of blocks scheduled. */
+  void decrementBlocksScheduled() {
+    if (prevApproxBlocksScheduled > 0) {
+      prevApproxBlocksScheduled--;
+    } else if (currApproxBlocksScheduled > 0) {
+      currApproxBlocksScheduled--;
+    } 
+    // its ok if both counters are zero.
+  }
+  
+  /** Adjusts curr and prev number of blocks scheduled every few minutes. */
+  private void rollBlocksScheduled(long now) {
+    if (now - lastBlocksScheduledRollTime > BLOCKS_SCHEDULED_ROLL_INTERVAL) {
+      prevApproxBlocksScheduled = currApproxBlocksScheduled;
+      currApproxBlocksScheduled = 0;
+      lastBlocksScheduledRollTime = now;
+    }
+  }
+
   @Override
   public boolean equals(Object obj) {
     if (this == obj) {

Modified: hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java?rev=1526215&r1=1526214&r2=1526215&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
(original)
+++ hadoop/common/branches/HDFS-2832/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
Wed Sep 25 16:03:20 2013
@@ -2868,9 +2868,7 @@ public class FSNamesystem implements Nam
     BlockInfo b = dir.addBlock(src, inodesInPath, newBlock, targets);
     NameNode.stateChangeLog.info("BLOCK* allocateBlock: " + src + ". "
         + getBlockPoolId() + " " + b);
-    for (DatanodeStorageInfo storage : targets) {
-      storage.getDatanodeDescriptor().incBlocksScheduled();
-    }
+    DatanodeStorageInfo.incrementBlocksScheduled(targets);
     return b;
   }
 



Mime
View raw message