hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dhr...@apache.org
Subject svn commit: r561573 - in /lucene/hadoop/trunk: ./ conf/ src/java/org/apache/hadoop/dfs/ src/java/org/apache/hadoop/fs/ src/test/org/apache/hadoop/dfs/ src/webapps/dfs/
Date Tue, 31 Jul 2007 22:11:21 GMT
Author: dhruba
Date: Tue Jul 31 15:11:19 2007
New Revision: 561573

URL: http://svn.apache.org/viewvc?view=rev&rev=561573
Log:
HADOOP-1463.  HDFS report correct usage statistics for disk space
used by HDFS.  (Hairong Kuang via dhruba)


Added:
    lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/Command.java   (with props)
    lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/DU.java   (with props)
Modified:
    lucene/hadoop/trunk/CHANGES.txt
    lucene/hadoop/trunk/conf/hadoop-default.xml
    lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSAdmin.java
    lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSClient.java
    lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DataNode.java
    lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DatanodeDescriptor.java
    lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DatanodeInfo.java
    lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DatanodeProtocol.java
    lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DistributedFileSystem.java
    lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSDataset.java
    lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java
    lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/NameNode.java
    lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/DF.java
    lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FsShell.java
    lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestReplicationPolicy.java
    lucene/hadoop/trunk/src/webapps/dfs/dfshealth.jsp

Modified: lucene/hadoop/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?view=diff&rev=561573&r1=561572&r2=561573
==============================================================================
--- lucene/hadoop/trunk/CHANGES.txt (original)
+++ lucene/hadoop/trunk/CHANGES.txt Tue Jul 31 15:11:19 2007
@@ -6,6 +6,9 @@
   1. HADOOP-1636.  Allow configuration of the number of jobs kept in memory
      by the JobTracker. (Michael Bieniosek via omalley)
 
+  2. HADOOP-1463.  HDFS report correct usage statistics for disk space
+     used by HDFS.  (Hairong Kuang via dhruba)
+
 
 Branch 0.14 (unreleased changes)
 

Modified: lucene/hadoop/trunk/conf/hadoop-default.xml
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/conf/hadoop-default.xml?view=diff&rev=561573&r1=561572&r2=561573
==============================================================================
--- lucene/hadoop/trunk/conf/hadoop-default.xml (original)
+++ lucene/hadoop/trunk/conf/hadoop-default.xml Tue Jul 31 15:11:19 2007
@@ -258,7 +258,7 @@
 <property>
   <name>dfs.datanode.du.reserved</name>
   <value>0</value>
-  <description>Reserved space in bytes. Always leave this much space free for non dfs
use
+  <description>Reserved space in bytes per volume. Always leave this much space free
for non dfs use.
   </description>
 </property>
 
@@ -328,7 +328,7 @@
 
 <property>
   <name>dfs.df.interval</name>
-  <value>3000</value>
+  <value>60000</value>
   <description>Disk usage statistics refresh interval in msec.</description>
 </property>
 

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSAdmin.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSAdmin.java?view=diff&rev=561573&r1=561572&r2=561573
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSAdmin.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSAdmin.java Tue Jul 31 15:11:19 2007
@@ -23,6 +23,7 @@
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.ipc.RemoteException;
 import org.apache.hadoop.ipc.RPC;
+import org.apache.hadoop.dfs.DistributedFileSystem.DiskStatus;
 import org.apache.hadoop.dfs.FSConstants.UpgradeAction;
 
 /**
@@ -44,8 +45,10 @@
   public void report() throws IOException {
     if (fs instanceof DistributedFileSystem) {
       DistributedFileSystem dfs = (DistributedFileSystem) fs;
-      long raw = dfs.getRawCapacity();
-      long rawUsed = dfs.getRawUsed();
+      DiskStatus ds = dfs.getDiskStatus();
+      long raw = ds.getCapacity();
+      long rawUsed = ds.getDfsUsed();
+      long remaining = ds.getRemaining();
       long used = dfs.getUsed();
       boolean mode = dfs.setSafeMode(FSConstants.SafeModeAction.SAFEMODE_GET);
       UpgradeStatusReport status = 
@@ -59,6 +62,8 @@
       }
       System.out.println("Total raw bytes: " + raw
                          + " (" + byteDesc(raw) + ")");
+      System.out.println("Remaining raw bytes: " + remaining
+          + " (" + byteDesc(remaining) + ")");
       System.out.println("Used raw bytes: " + rawUsed
                          + " (" + byteDesc(rawUsed) + ")");
       System.out.println("% used: "

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSClient.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSClient.java?view=diff&rev=561573&r1=561572&r2=561573
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSClient.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSClient.java Tue Jul 31 15:11:19
2007
@@ -24,6 +24,7 @@
 import org.apache.hadoop.fs.*;
 import org.apache.hadoop.ipc.*;
 import org.apache.hadoop.conf.*;
+import org.apache.hadoop.dfs.DistributedFileSystem.DiskStatus;
 import org.apache.hadoop.util.*;
 
 import org.apache.commons.logging.*;
@@ -430,6 +431,10 @@
     return namenode.getFileInfo(src.toString());
   }
 
+  public DiskStatus getDiskStatus() throws IOException {
+    long rawNums[] = namenode.getStats();
+    return new DiskStatus(rawNums[0], rawNums[1], rawNums[2]);
+  }
   /**
    */
   public long totalRawCapacity() throws IOException {

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DataNode.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DataNode.java?view=diff&rev=561573&r1=561572&r2=561573
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DataNode.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DataNode.java Tue Jul 31 15:11:19 2007
@@ -130,7 +130,6 @@
   private static Thread dataNodeThread = null;
   String machineName;
   int defaultBytesPerChecksum = 512;
-
   private static class DataNodeMetrics implements Updater {
     private final MetricsRecord metricsRecord;
     private int bytesWritten = 0;
@@ -490,9 +489,10 @@
           // -- Total capacity
           // -- Bytes remaining
           //
-          DatanodeCommand cmd = namenode.sendHeartbeat(dnRegistration, 
-                                                       data.getCapacity(), 
-                                                       data.getRemaining(), 
+          DatanodeCommand cmd = namenode.sendHeartbeat(dnRegistration,
+                                                       data.getCapacity(),
+                                                       data.getDfsUsed(),
+                                                       data.getRemaining(),
                                                        xmitsInProgress,
                                                        xceiverCount.getValue());
           //LOG.info("Just sent heartbeat, with name " + localName);

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DatanodeDescriptor.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DatanodeDescriptor.java?view=diff&rev=561573&r1=561572&r2=561573
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DatanodeDescriptor.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DatanodeDescriptor.java Tue Jul 31
15:11:19 2007
@@ -59,7 +59,7 @@
    * @param nodeID id of the data node
    */
   public DatanodeDescriptor(DatanodeID nodeID) {
-    this(nodeID, 0L, 0L, 0);
+    this(nodeID, 0L, 0L, 0L, 0);
   }
 
   /** DatanodeDescriptor constructor
@@ -81,22 +81,24 @@
   public DatanodeDescriptor(DatanodeID nodeID, 
                             String networkLocation,
                             String hostName) {
-    this(nodeID, networkLocation, hostName, 0L, 0L, 0);
+    this(nodeID, networkLocation, hostName, 0L, 0L, 0L, 0);
   }
   
   /** DatanodeDescriptor constructor
    * 
    * @param nodeID id of the data node
    * @param capacity capacity of the data node
+   * @param dfsUsed space used by the data node
    * @param remaining remaing capacity of the data node
    * @param xceiverCount # of data transfers at the data node
    */
   public DatanodeDescriptor(DatanodeID nodeID, 
-                            long capacity, 
+                            long capacity,
+                            long dfsUsed,
                             long remaining,
                             int xceiverCount) {
     super(nodeID);
-    updateHeartbeat(capacity, remaining, xceiverCount);
+    updateHeartbeat(capacity, dfsUsed, remaining, xceiverCount);
     initWorkLists();
   }
 
@@ -104,18 +106,20 @@
    * 
    * @param nodeID id of the data node
    * @param networkLocation location of the data node in network
-   * @param capacity capacity of the data node
+   * @param capacity capacity of the data node, including space used by non-dfs
+   * @param dfsUsed the used space by dfs datanode
    * @param remaining remaing capacity of the data node
    * @param xceiverCount # of data transfers at the data node
    */
   public DatanodeDescriptor(DatanodeID nodeID,
                             String networkLocation,
                             String hostName,
-                            long capacity, 
+                            long capacity,
+                            long dfsUsed,
                             long remaining,
                             int xceiverCount) {
     super(nodeID, networkLocation, hostName);
-    updateHeartbeat(capacity, remaining, xceiverCount);
+    updateHeartbeat(capacity, dfsUsed, remaining, xceiverCount);
     initWorkLists();
   }
 
@@ -151,8 +155,10 @@
   
   /**
    */
-  void updateHeartbeat(long capacity, long remaining, int xceiverCount) {
+  void updateHeartbeat(long capacity, long dfsUsed, long remaining,
+      int xceiverCount) {
     this.capacity = capacity;
+    this.dfsUsed = dfsUsed;
     this.remaining = remaining;
     this.lastUpdate = System.currentTimeMillis();
     this.xceiverCount = xceiverCount;

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DatanodeInfo.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DatanodeInfo.java?view=diff&rev=561573&r1=561572&r2=561573
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DatanodeInfo.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DatanodeInfo.java Tue Jul 31 15:11:19
2007
@@ -40,6 +40,7 @@
  */
 public class DatanodeInfo extends DatanodeID implements Node {
   protected long capacity;
+  protected long dfsUsed;
   protected long remaining;
   protected long lastUpdate;
   protected int xceiverCount;
@@ -63,6 +64,7 @@
   DatanodeInfo(DatanodeInfo from) {
     super(from);
     this.capacity = from.getCapacity();
+    this.dfsUsed = from.getDfsUsed();
     this.remaining = from.getRemaining();
     this.lastUpdate = from.getLastUpdate();
     this.xceiverCount = from.getXceiverCount();
@@ -74,6 +76,7 @@
   DatanodeInfo(DatanodeID nodeID) {
     super(nodeID);
     this.capacity = 0L;
+    this.dfsUsed = 0L;
     this.remaining = 0L;
     this.lastUpdate = 0L;
     this.xceiverCount = 0;
@@ -88,6 +91,9 @@
   
   /** The raw capacity. */
   public long getCapacity() { return capacity; }
+  
+  /** The used space by the data node. */
+  public long getDfsUsed() { return dfsUsed; }
 
   /** The raw free space. */
   public long getRemaining() { return remaining; }
@@ -144,7 +150,7 @@
     StringBuffer buffer = new StringBuffer();
     long c = getCapacity();
     long r = getRemaining();
-    long u = c - r;
+    long u = getDfsUsed();
     buffer.append("Name: "+name+"\n");
     if (!NetworkTopology.DEFAULT_RACK.equals(location)) {
       buffer.append("Rack: "+location+"\n");
@@ -157,6 +163,7 @@
       buffer.append("State          : In Service\n");
     }
     buffer.append("Total raw bytes: "+c+" ("+FsShell.byteDesc(c)+")"+"\n");
+    buffer.append("Remaining raw bytes: " +r+ "("+FsShell.byteDesc(r)+")"+"\n");
     buffer.append("Used raw bytes: "+u+" ("+FsShell.byteDesc(u)+")"+"\n");
     buffer.append("% used: "+FsShell.limitDecimal(((1.0*u)/c)*100, 2)+"%"+"\n");
     buffer.append("Last contact: "+new Date(lastUpdate)+"\n");
@@ -168,7 +175,7 @@
     StringBuffer buffer = new StringBuffer();
     long c = getCapacity();
     long r = getRemaining();
-    long u = c - r;
+    long u = getDfsUsed();
     buffer.append(name);
     if (!NetworkTopology.DEFAULT_RACK.equals(location)) {
       buffer.append(" "+location);
@@ -183,6 +190,7 @@
     buffer.append(" " + c + "(" + FsShell.byteDesc(c)+")");
     buffer.append(" " + u + "(" + FsShell.byteDesc(u)+")");
     buffer.append(" " + FsShell.limitDecimal(((1.0*u)/c)*100, 2)+"%");
+    buffer.append(" " + r + "(" + FsShell.byteDesc(r)+")");
     buffer.append(" " + new Date(lastUpdate));
     return buffer.toString();
   }
@@ -281,6 +289,7 @@
   public void write(DataOutput out) throws IOException {
     super.write(out);
     out.writeLong(capacity);
+    out.writeLong(dfsUsed);
     out.writeLong(remaining);
     out.writeLong(lastUpdate);
     out.writeInt(xceiverCount);
@@ -298,6 +307,7 @@
   public void readFields(DataInput in) throws IOException {
     super.readFields(in);
     this.capacity = in.readLong();
+    this.dfsUsed = in.readLong();
     this.remaining = in.readLong();
     this.lastUpdate = in.readLong();
     this.xceiverCount = in.readInt();

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DatanodeProtocol.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DatanodeProtocol.java?view=diff&rev=561573&r1=561572&r2=561573
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DatanodeProtocol.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DatanodeProtocol.java Tue Jul 31 15:11:19
2007
@@ -31,9 +31,9 @@
  **********************************************************************/
 interface DatanodeProtocol extends VersionedProtocol {
   /*
-   * 8: blockCrcUpgradeGetBlockLocations() added;
+   * 9: heartbeat sends also the data node used space;
    */
-  public static final long versionID = 8L;
+  public static final long versionID = 9L;
   
   // error code
   final static int NOTIFY = 0;
@@ -72,7 +72,8 @@
    * or to copy them to other DataNodes, etc.
    */
   public DatanodeCommand sendHeartbeat(DatanodeRegistration registration,
-                                       long capacity, long remaining,
+                                       long capacity,
+                                       long dfsUsed, long remaining,
                                        int xmitsInProgress,
                                        int xceiverCount) throws IOException;
 

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DistributedFileSystem.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DistributedFileSystem.java?view=diff&rev=561573&r1=561572&r2=561573
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DistributedFileSystem.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DistributedFileSystem.java Tue Jul
31 15:11:19 2007
@@ -210,6 +210,35 @@
   DFSClient getClient() {
     return dfs;
   }        
+  
+  public static class DiskStatus {
+    private long capacity;
+    private long dfsUsed;
+    private long remaining;
+    public DiskStatus(long capacity, long dfsUsed, long remaining) {
+      this.capacity = capacity;
+      this.dfsUsed = dfsUsed;
+      this.remaining = remaining;
+    }
+    
+    public long getCapacity() {
+      return capacity;
+    }
+    public long getDfsUsed() {
+      return dfsUsed;
+    }
+    public long getRemaining() {
+      return remaining;
+    }
+  }
+  
+
+  /** Return the disk usage of the filesystem, including total capacity,
+   * used space, and remaining space */
+  public DiskStatus getDiskStatus() throws IOException {
+    return dfs.getDiskStatus();
+  }
+  
   /** Return the total raw capacity of the filesystem, disregarding
    * replication .*/
   public long getRawCapacity() throws IOException{

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSDataset.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSDataset.java?view=diff&rev=561573&r1=561572&r2=561573
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSDataset.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSDataset.java Tue Jul 31 15:11:19
2007
@@ -265,8 +265,10 @@
     private FSDir dataDir;
     private File tmpDir;
     private DF usage;
+    private DU dfsUsage;
     private long reserved;
     private double usableDiskPct = USABLE_DISK_PCT_DEFAULT;
+
     
     FSVolume(File currentDir, Configuration conf) throws IOException {
       this.reserved = conf.getLong("dfs.datanode.du.reserved", 0);
@@ -286,17 +288,29 @@
         }
       }
       this.usage = new DF(parent, conf);
+      this.dfsUsage = new DU(parent, conf);
     }
-      
+
+    void decDfsUsed(long value) {
+      dfsUsage.decDfsUsed(value);
+    }
+    
+    long getDfsUsed() throws IOException {
+      return dfsUsage.getUsed();
+    }
+    
     long getCapacity() throws IOException {
       return usage.getCapacity();
     }
       
     long getAvailable() throws IOException {
-      long capacity = usage.getCapacity();
-      long freespace = Math.round(usage.getAvailableSkipRefresh() -
-                                  capacity * (1 - usableDiskPct) - reserved); 
-      return (freespace > 0) ? freespace : 0;
+      long remaining = getCapacity()-getDfsUsed()-reserved;
+      long available = usage.getAvailable();
+      if (remaining>available) {
+        remaining = available;
+      }
+      remaining = (long)(remaining * usableDiskPct); 
+      return (remaining > 0) ? remaining : 0;
     }
       
     String getMount() throws IOException {
@@ -324,7 +338,10 @@
     }
       
     File addBlock(Block b, File f) throws IOException {
-      return dataDir.addBlock(b, f);
+      File blockFile = dataDir.addBlock(b, f);
+      File metaFile = getMetaFile( blockFile );
+      dfsUsage.incDfsUsed(b.getNumBytes()+metaFile.length());
+      return blockFile;
     }
       
     void checkDirs() throws DiskErrorException {
@@ -373,6 +390,14 @@
       }
     }
       
+    long getDfsUsed() throws IOException {
+      long dfsUsed = 0L;
+      for (int idx = 0; idx < volumes.length; idx++) {
+        dfsUsed += volumes[idx].getDfsUsed();
+      }
+      return dfsUsed;
+    }
+
     synchronized long getCapacity() throws IOException {
       long capacity = 0L;
       for (int idx = 0; idx < volumes.length; idx++) {
@@ -460,6 +485,13 @@
   }
 
   /**
+   * Return the total space used by dfs datanode
+   */
+  public long getDfsUsed() throws IOException {
+    return volumes.getDfsUsed();
+  }
+  
+  /**
    * Return total capacity, used and unused
    */
   public long getCapacity() throws IOException {
@@ -628,9 +660,10 @@
     boolean error = false;
     for (int i = 0; i < invalidBlks.length; i++) {
       File f = null;
+      FSVolume v;
       synchronized (this) {
         f = getFile(invalidBlks[i]);
-        FSVolume v = volumeMap.get(invalidBlks[i]);
+        v = volumeMap.get(invalidBlks[i]);
         if (f == null) {
           DataNode.LOG.warn("Unexpected error trying to delete block "
                             + invalidBlks[i] + 
@@ -660,12 +693,14 @@
         volumeMap.remove(invalidBlks[i]);
       }
       File metaFile = getMetaFile( f );
+      long blockSize = f.length()+metaFile.length();
       if ( !f.delete() || ( !metaFile.delete() && metaFile.exists() ) ) {
         DataNode.LOG.warn("Unexpected error trying to delete block "
                           + invalidBlks[i] + " at file " + f);
         error = true;
         continue;
       }
+      v.decDfsUsed(blockSize);
       DataNode.LOG.info("Deleting block " + invalidBlks[i] + " file " + f);
       if (f.exists()) {
         //

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java?view=diff&rev=561573&r1=561572&r2=561573
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java Tue Jul 31 15:11:19
2007
@@ -113,7 +113,7 @@
   //
   // Stats on overall usage
   //
-  long totalCapacity = 0, totalRemaining = 0;
+  long totalCapacity = 0L, totalUsed=0L, totalRemaining = 0L;
 
   // total number of connections per live datanode
   int totalLoad = 0;
@@ -1687,7 +1687,7 @@
         if( !heartbeats.contains(nodeS)) {
           heartbeats.add(nodeS);
           //update its timestamp
-          nodeS.updateHeartbeat(0L, 0L, 0);
+          nodeS.updateHeartbeat(0L, 0L, 0L, 0);
           nodeS.isAlive = true;
         }
       }
@@ -1771,7 +1771,8 @@
    * @throws IOException
    */
   public boolean gotHeartbeat(DatanodeID nodeID,
-                              long capacity, 
+                              long capacity,
+                              long dfsUsed,
                               long remaining,
                               int xceiverCount,
                               int xmitsInProgress,
@@ -1800,7 +1801,7 @@
           return true;
         } else {
           updateStats(nodeinfo, false);
-          nodeinfo.updateHeartbeat(capacity, remaining, xceiverCount);
+          nodeinfo.updateHeartbeat(capacity, dfsUsed, remaining, xceiverCount);
           updateStats(nodeinfo, true);
           //
           // Extract pending replication work or block invalidation
@@ -1825,10 +1826,12 @@
     assert(Thread.holdsLock(heartbeats));
     if (isAdded) {
       totalCapacity += node.getCapacity();
+      totalUsed += node.getDfsUsed();
       totalRemaining += node.getRemaining();
       totalLoad += node.getXceiverCount();
     } else {
       totalCapacity -= node.getCapacity();
+      totalUsed -= node.getDfsUsed();
       totalRemaining -= node.getRemaining();
       totalLoad -= node.getXceiverCount();
     }
@@ -2505,15 +2508,22 @@
   }
 
   /**
-   * Total raw bytes.
+   * Total raw bytes including non-dfs used space.
    */
   public long totalCapacity() {
-
     synchronized (heartbeats) {
       return totalCapacity;
     }
   }
 
+  /**
+   * Total used space by data nodes
+   */
+  public long totalDfsUsed() {
+    synchronized(heartbeats){
+      return totalUsed;
+    }
+  }
   /**
    * Total non-used raw bytes.
    */

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/NameNode.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/NameNode.java?view=diff&rev=561573&r1=561572&r2=561573
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/NameNode.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/NameNode.java Tue Jul 31 15:11:19 2007
@@ -491,10 +491,10 @@
   /**
    */
   public long[] getStats() throws IOException {
-    long results[] = new long[2];
-    long totalCapacity = namesystem.totalCapacity();
-    results[0] = totalCapacity;
-    results[1] = totalCapacity - namesystem.totalRemaining();
+    long results[] = new long[3];
+    results[0] = namesystem.totalCapacity();
+    results[1] = namesystem.totalDfsUsed();
+    results[2] = namesystem.totalRemaining();
     return results;
   }
 
@@ -596,7 +596,8 @@
    * This will be either a transfer or a delete operation.
    */
   public DatanodeCommand sendHeartbeat(DatanodeRegistration nodeReg,
-                                       long capacity, 
+                                       long capacity,
+                                       long dfsUsed,
                                        long remaining,
                                        int xmitsInProgress,
                                        int xceiverCount) throws IOException {
@@ -606,7 +607,7 @@
     deleteList[0] = null; 
 
     verifyRequest(nodeReg);
-    if (namesystem.gotHeartbeat(nodeReg, capacity, remaining, 
+    if (namesystem.gotHeartbeat(nodeReg, capacity, dfsUsed, remaining, 
                                 xceiverCount, 
                                 xmitsInProgress,
                                 xferResults,

Added: lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/Command.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/Command.java?view=auto&rev=561573
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/Command.java (added)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/Command.java Tue Jul 31 15:11:19 2007
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.fs;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.BufferedReader;
+
+/** A base class for running a unix command like du or df*/
+abstract public class Command {
+  /** Run a command */
+  protected void run() throws IOException { 
+    Process process;
+    process = Runtime.getRuntime().exec(getExecString());
+
+    try {
+      if (process.waitFor() != 0) {
+        throw new IOException
+          (new BufferedReader(new InputStreamReader(process.getErrorStream()))
+           .readLine());
+      }
+      parseExecResult(new BufferedReader(
+          new InputStreamReader(process.getInputStream())));
+    } catch (InterruptedException e) {
+      throw new IOException(e.toString());
+    } finally {
+      process.destroy();
+    }
+  }
+
+  /** return an array comtaining the command name & its parameters */ 
+  protected abstract String[] getExecString();
+  
+  /** Parse the execution result */
+  protected abstract void parseExecResult(BufferedReader lines)
+  throws IOException;
+  }

Propchange: lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/Command.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/Command.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision HeadURL

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/DF.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/DF.java?view=diff&rev=561573&r1=561572&r2=561573
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/DF.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/DF.java Tue Jul 31 15:11:19 2007
@@ -28,7 +28,7 @@
 
 /** Filesystem disk space usage statistics.  Uses the unix 'df' program.
  * Tested on Linux, FreeBSD, Cygwin. */
-public class DF {
+public class DF extends Command {
   public static final long DF_INTERVAL_DEFAULT = 3 * 1000; // default DF refresh interval

   
   private String  dirPath;
@@ -56,22 +56,7 @@
   private void doDF() throws IOException { 
     if (lastDF + dfInterval > System.currentTimeMillis())
       return;
-    Process process;
-    process = Runtime.getRuntime().exec(getExecString());
-
-    try {
-      if (process.waitFor() != 0) {
-        throw new IOException
-          (new BufferedReader(new InputStreamReader(process.getErrorStream()))
-           .readLine());
-      }
-      parseExecResult(
-                      new BufferedReader(new InputStreamReader(process.getInputStream())));
-    } catch (InterruptedException e) {
-      throw new IOException(e.toString());
-    } finally {
-      process.destroy();
-    }
+    super.run();
   }
 
   /// ACCESSORS
@@ -110,22 +95,6 @@
     return mount;
   }
   
-  public long getCapacitySkipRefresh() { 
-    return capacity; 
-  }
-  
-  public long getUsedSkipRefresh() { 
-    return used;
-  }
-  
-  public long getAvailableSkipRefresh() { 
-    return available;
-  }
-  
-  public int getPercentUsedSkipRefresh() {
-    return percentUsed;
-  }
-  
   public String toString() {
     return
       "df -k " + mount +"\n" +
@@ -137,11 +106,11 @@
       mount;
   }
 
-  private String[] getExecString() {
+  protected String[] getExecString() {
     return new String[] {"df","-k", dirPath};
   }
   
-  private void parseExecResult(BufferedReader lines) throws IOException {
+  protected void parseExecResult(BufferedReader lines) throws IOException {
     lines.readLine();                         // skip headings
   
     String line = lines.readLine();

Added: lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/DU.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/DU.java?view=auto&rev=561573
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/DU.java (added)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/DU.java Tue Jul 31 15:11:19 2007
@@ -0,0 +1,96 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.fs;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.BufferedReader;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.dfs.FSConstants;
+
+/** Filesystem disk space usage statistics.  Uses the unix 'du' program*/
+public class DU extends Command {
+  private String  dirPath;
+  private long    duInterval; // DU refresh interval in msec
+  private long    lastDU;   // last time doDU() was performed
+
+  private long used;
+  
+  public DU(File path, long interval) throws IOException {
+    this.dirPath = path.getCanonicalPath();
+    this.duInterval = interval;
+    run();
+  }
+  
+  public DU(File path, Configuration conf) throws IOException {
+    this(path, conf.getLong("dfs.blockreport.intervalMsec",
+        FSConstants.BLOCKREPORT_INTERVAL));
+  }
+  
+  synchronized public void decDfsUsed(long value) {
+    used -= value;
+  }
+
+  synchronized public void incDfsUsed(long value) {
+    used += value;
+  }
+  
+  synchronized public long getUsed() throws IOException { 
+    if (lastDU + duInterval > System.currentTimeMillis()) {
+      run();
+    }
+    return used;
+  }
+
+  public String getDirPath() {
+    return dirPath;
+  }
+  
+  
+  public String toString() {
+    return
+      "du -s " + dirPath +"\n" +
+      used + "\t" + dirPath;
+  }
+
+  protected String[] getExecString() {
+    return new String[] {"du","-s", dirPath};
+  }
+  
+  protected void parseExecResult(BufferedReader lines) throws IOException {
+    String line = lines.readLine();
+    if (line == null) {
+      throw new IOException( "Expecting a line not the end of stream" );
+    }
+    String[] tokens = line.split("\t");
+    if(tokens.length == 0) {
+      throw new IOException("Illegal du output");
+    }
+    this.used = Long.parseLong(tokens[0])*1024;
+    this.lastDU = System.currentTimeMillis();
+  }
+
+  public static void main(String[] args) throws Exception {
+    String path = ".";
+    if (args.length > 0)
+      path = args[0];
+
+    System.out.println(new DU(new File(path), new Configuration()).toString());
+  }
+}

Propchange: lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/DU.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/DU.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision HeadURL

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FsShell.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FsShell.java?view=diff&rev=561573&r1=561572&r2=561573
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FsShell.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FsShell.java Tue Jul 31 15:11:19 2007
@@ -19,10 +19,10 @@
 
 import java.io.*;
 import java.util.*;
+import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
 
 import org.apache.hadoop.conf.*;
-import org.apache.hadoop.dfs.ChecksumDistributedFileSystem;
 import org.apache.hadoop.ipc.*;
 import org.apache.hadoop.util.ToolBase;
 
@@ -38,6 +38,8 @@
   {
     modifFmt.setTimeZone(TimeZone.getTimeZone("UTC"));
   }
+  private static final DecimalFormat decimalFormat = 
+    new DecimalFormat("#*0.0#*");
 
   /**
    */
@@ -798,11 +800,11 @@
     String ending = "";
     if (len < 1024 * 1024) {
       val = (1.0 * len) / 1024;
-      ending = " k";
+      ending = " KB";
     } else if (len < 1024 * 1024 * 1024) {
       val = (1.0 * len) / (1024 * 1024);
       ending = " MB";
-    } else if (len < 128L * 1024 * 1024 * 1024) {
+    } else if (len < 1024L * 1024 * 1024 * 1024) {
       val = (1.0 * len) / (1024 * 1024 * 1024);
       ending = " GB";
     } else if (len < 1024L * 1024 * 1024 * 1024 * 1024) {
@@ -816,7 +818,7 @@
   }
 
   public static String limitDecimal(double d, int placesAfterDecimal) {
-    String strVal = Double.toString(d);
+    String strVal = decimalFormat.format(d);
     int decpt = strVal.indexOf(".");
     if (decpt >= 0) {
       strVal = strVal.substring(0, Math.min(strVal.length(), decpt + 1 + placesAfterDecimal));

Modified: lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestReplicationPolicy.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestReplicationPolicy.java?view=diff&rev=561573&r1=561572&r2=561573
==============================================================================
--- lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestReplicationPolicy.java (original)
+++ lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestReplicationPolicy.java Tue Jul
31 15:11:19 2007
@@ -65,8 +65,8 @@
     }
     for(int i=0; i<NUM_OF_DATANODES; i++) {
       dataNodes[i].updateHeartbeat(
-                                   2*FSConstants.MIN_BLOCKS_FOR_WRITE*BLOCK_SIZE, 
-                                   2*FSConstants.MIN_BLOCKS_FOR_WRITE*BLOCK_SIZE, 0);
+          2*FSConstants.MIN_BLOCKS_FOR_WRITE*BLOCK_SIZE, 0L,
+          2*FSConstants.MIN_BLOCKS_FOR_WRITE*BLOCK_SIZE, 0);
     }
   }
   
@@ -80,8 +80,8 @@
    */
   public void testChooseTarget1() throws Exception {
     dataNodes[0].updateHeartbeat(
-                                 2*FSConstants.MIN_BLOCKS_FOR_WRITE*BLOCK_SIZE, 
-                                 FSConstants.MIN_BLOCKS_FOR_WRITE*BLOCK_SIZE, 4); // overloaded
+        2*FSConstants.MIN_BLOCKS_FOR_WRITE*BLOCK_SIZE, 0L, 
+        FSConstants.MIN_BLOCKS_FOR_WRITE*BLOCK_SIZE, 4); // overloaded
 
     DatanodeDescriptor[] targets;
     targets = replicator.chooseTarget(
@@ -115,8 +115,8 @@
     assertFalse(cluster.isOnSameRack(targets[0], targets[3]));
 
     dataNodes[0].updateHeartbeat(
-                                 2*FSConstants.MIN_BLOCKS_FOR_WRITE*BLOCK_SIZE, 
-                                 FSConstants.MIN_BLOCKS_FOR_WRITE*BLOCK_SIZE, 0); 
+        2*FSConstants.MIN_BLOCKS_FOR_WRITE*BLOCK_SIZE, 0L,
+        FSConstants.MIN_BLOCKS_FOR_WRITE*BLOCK_SIZE, 0); 
   }
 
   /**
@@ -186,8 +186,8 @@
   public void testChooseTarget3() throws Exception {
     // make data node 0 to be not qualified to choose
     dataNodes[0].updateHeartbeat(
-                                 2*FSConstants.MIN_BLOCKS_FOR_WRITE*BLOCK_SIZE, 
-                                 (FSConstants.MIN_BLOCKS_FOR_WRITE-1)*BLOCK_SIZE, 0); //
no space
+        2*FSConstants.MIN_BLOCKS_FOR_WRITE*BLOCK_SIZE, 0L,
+        (FSConstants.MIN_BLOCKS_FOR_WRITE-1)*BLOCK_SIZE, 0); // no space
         
     DatanodeDescriptor[] targets;
     targets = replicator.chooseTarget(
@@ -224,8 +224,8 @@
     assertFalse(cluster.isOnSameRack(targets[1], targets[3]));
 
     dataNodes[0].updateHeartbeat(
-                                 2*FSConstants.MIN_BLOCKS_FOR_WRITE*BLOCK_SIZE, 
-                                 FSConstants.MIN_BLOCKS_FOR_WRITE*BLOCK_SIZE, 0); 
+        2*FSConstants.MIN_BLOCKS_FOR_WRITE*BLOCK_SIZE, 0L,
+        FSConstants.MIN_BLOCKS_FOR_WRITE*BLOCK_SIZE, 0); 
   }
   
   /**
@@ -240,8 +240,8 @@
     // make data node 0 & 1 to be not qualified to choose: not enough disk space
     for(int i=0; i<2; i++) {
       dataNodes[i].updateHeartbeat(
-                                   2*FSConstants.MIN_BLOCKS_FOR_WRITE*BLOCK_SIZE, 
-                                   (FSConstants.MIN_BLOCKS_FOR_WRITE-1)*BLOCK_SIZE, 0);
+          2*FSConstants.MIN_BLOCKS_FOR_WRITE*BLOCK_SIZE, 0L,
+          (FSConstants.MIN_BLOCKS_FOR_WRITE-1)*BLOCK_SIZE, 0);
     }
       
     DatanodeDescriptor[] targets;
@@ -272,8 +272,8 @@
     
     for(int i=0; i<2; i++) {
       dataNodes[i].updateHeartbeat(
-                                   2*FSConstants.MIN_BLOCKS_FOR_WRITE*BLOCK_SIZE, 
-                                   FSConstants.MIN_BLOCKS_FOR_WRITE*BLOCK_SIZE, 0);
+          2*FSConstants.MIN_BLOCKS_FOR_WRITE*BLOCK_SIZE, 0L,
+          FSConstants.MIN_BLOCKS_FOR_WRITE*BLOCK_SIZE, 0);
     }
   }
   /**

Modified: lucene/hadoop/trunk/src/webapps/dfs/dfshealth.jsp
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/webapps/dfs/dfshealth.jsp?view=diff&rev=561573&r1=561572&r2=561573
==============================================================================
--- lucene/hadoop/trunk/src/webapps/dfs/dfshealth.jsp (original)
+++ lucene/hadoop/trunk/src/webapps/dfs/dfshealth.jsp Tue Jul 31 15:11:19 2007
@@ -83,8 +83,7 @@
         return;
     
     long c = d.getCapacity();
-    long r = d.getRemaining();
-    long u = c - r;
+    long u = d.getDfsUsed();
     
     String percentUsed;
     if (c > 0) 
@@ -105,7 +104,9 @@
 	      "<td class=\"size\">" +
               FsShell.limitDecimal(c*1.0/diskBytes, 2) +
 	      "<td class=\"pcused\">" + percentUsed +
-              "<td class=\"blocks\">" + d.numBlocks() + "\n");
+	      "<td class=\"size\">" +
+              FsShell.limitDecimal(d.getRemaining()*1.0/diskBytes, 2) +
+          "<td class=\"blocks\">" + d.numBlocks() + "\n");
   }
 
   public void generateDFSHealthReport(JspWriter out,
@@ -147,11 +148,12 @@
     out.print( "<div id=\"dfstable\"> <table>\n" +
 	       rowTxt() + colTxt() + "Capacity" + colTxt() + ":" + colTxt() +
 	       FsShell.byteDesc( fsn.totalCapacity() ) +
-	       rowTxt() + colTxt() + "Remaining" + colTxt() + ":" + colTxt() +
+	       rowTxt() + colTxt() + "DFS Remaining" + colTxt() + ":" + colTxt() +
 	       FsShell.byteDesc( fsn.totalRemaining() ) +
-	       rowTxt() + colTxt() + "Used" + colTxt() + ":" + colTxt() +
-	       FsShell.limitDecimal((fsn.totalCapacity() -
-				      fsn.totalRemaining())*100.0/
+	       rowTxt() + colTxt() + "DFS Used" + colTxt() + ":" + colTxt() +
+	       FsShell.byteDesc( fsn.totalDfsUsed() ) +
+	       rowTxt() + colTxt() + "DFS Used%" + colTxt() + ":" + colTxt() +
+	       FsShell.limitDecimal((fsn.totalDfsUsed())*100.0/
 				     (fsn.totalCapacity() + 1e-10), 2) + " %" +
 	       rowTxt() + colTxt() +
                "<a href=\"#LiveNodes\">Live Nodes</a> " +
@@ -181,13 +183,15 @@
             }
 
 	    out.print( "<tr class=\"headerRow\"> <th " +
-                       NodeHeaderStr("name") + "> Node <th " +
+                       ("name") + "> Node <th " +
                        NodeHeaderStr("lastcontact") + "> Last Contact <th " +
                        NodeHeaderStr("adminstate") + "> Admin State <th " +
                        NodeHeaderStr("size") + "> Size (" + diskByteStr +
                        ") <th " + NodeHeaderStr("pcused") +
-                       "> Used (%) <th " + NodeHeaderStr("blocks") +
-                       "> Blocks\n" );
+                       "> Used (%) <th " + 
+                       NodeHeaderStr("remaining") + "> Remaining (" + 
+                       diskByteStr + ") <th " +
+                       NodeHeaderStr("blocks") + "> Blocks\n" );
             
 	    for ( int i=0; i < live.size(); i++ ) {
 		generateNodeData( out, live.get(i), port_suffix, true );



Mime
View raw message