hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dhr...@apache.org
Subject svn commit: r651165 - in /hadoop/core/trunk: ./ src/java/org/apache/hadoop/dfs/ src/test/org/apache/hadoop/dfs/
Date Thu, 24 Apr 2008 06:13:57 GMT
Author: dhruba
Date: Wed Apr 23 23:13:50 2008
New Revision: 651165

URL: http://svn.apache.org/viewvc?rev=651165&view=rev
Log:
HADOOP-3270. Constant DatanodeCommands are stored in static final
immutable variables for better code clarity.
(Tsz Wo (Nicholas), SZE via dhruba)


Modified:
    hadoop/core/trunk/CHANGES.txt
    hadoop/core/trunk/src/java/org/apache/hadoop/dfs/BlockCommand.java
    hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java
    hadoop/core/trunk/src/java/org/apache/hadoop/dfs/NameNode.java
    hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestDistributedUpgrade.java

Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=651165&r1=651164&r2=651165&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Wed Apr 23 23:13:50 2008
@@ -77,6 +77,10 @@
     HADOOP-3300. Fix locking of explicit locks in NetworkTopology.
     (tomwhite via omalley)
 
+    HADOOP-3270. Constant DatanodeCommands are stored in static final
+    immutable variables for better code clarity.  
+    (Tsz Wo (Nicholas), SZE via dhruba)
+
 Release 0.17.0 - Unreleased
 
   INCOMPATIBLE CHANGES

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/dfs/BlockCommand.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/dfs/BlockCommand.java?rev=651165&r1=651164&r2=651165&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/dfs/BlockCommand.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/dfs/BlockCommand.java Wed Apr 23 23:13:50
2008
@@ -20,14 +20,51 @@
 import java.io.*;
 import org.apache.hadoop.io.*;
 
-class DatanodeCommand implements Writable {
-  protected int action;
+abstract class DatanodeCommand implements Writable {
+  static class Register extends DatanodeCommand {
+    private Register() {super(DatanodeProtocol.DNA_REGISTER);}
+    public void readFields(DataInput in) {}
+    public void write(DataOutput out) {}
+  }
+
+  static class BlockReport extends DatanodeCommand {
+    private BlockReport() {super(DatanodeProtocol.DNA_BLOCKREPORT);}
+    public void readFields(DataInput in) {}
+    public void write(DataOutput out) {}
+  }
+
+  static class Finalize extends DatanodeCommand {
+    private Finalize() {super(DatanodeProtocol.DNA_FINALIZE);}
+    public void readFields(DataInput in) {}
+    public void write(DataOutput out) {}
+  }
+
+  static {                                      // register a ctor
+    WritableFactories.setFactory(Register.class,
+        new WritableFactory() {
+          public Writable newInstance() {return new Register();}
+        });
+    WritableFactories.setFactory(BlockReport.class,
+        new WritableFactory() {
+          public Writable newInstance() {return new BlockReport();}
+        });
+    WritableFactories.setFactory(Finalize.class,
+        new WritableFactory() {
+          public Writable newInstance() {return new Finalize();}
+        });
+  }
+
+  static final DatanodeCommand REGISTER = new Register();
+  static final DatanodeCommand BLOCKREPORT = new BlockReport();
+  static final DatanodeCommand FINALIZE = new Finalize();
+
+  private int action;
   
   public DatanodeCommand() {
     this(DatanodeProtocol.DNA_UNKNOWN);
   }
   
-  public DatanodeCommand(int action) {
+  DatanodeCommand(int action) {
     this.action = action;
   }
 
@@ -38,14 +75,6 @@
   ///////////////////////////////////////////
   // Writable
   ///////////////////////////////////////////
-  static {                                      // register a ctor
-    WritableFactories.setFactory
-      (BlockCommand.class,
-       new WritableFactory() {
-         public Writable newInstance() { return new DatanodeCommand(); }
-       });
-  }
-
   public void write(DataOutput out) throws IOException {
     out.writeInt(this.action);
   }
@@ -74,27 +103,29 @@
    * @param blocks    blocks to be transferred 
    * @param targets   nodes to transfer
    */
-  public BlockCommand(Block blocks[], DatanodeInfo targets[][]) {
+  BlockCommand(Block blocks[], DatanodeInfo targets[][]) {
     super( DatanodeProtocol.DNA_TRANSFER);
     this.blocks = blocks;
     this.targets = targets;
   }
 
+  private static final DatanodeInfo[][] EMPTY_TARGET = {};
+
   /**
    * Create BlockCommand for the given action
    * @param blocks blocks related to the action
    */
-  public BlockCommand(int action, Block blocks[]) {
+  BlockCommand(int action, Block blocks[]) {
     super(action);
     this.blocks = blocks;
-    this.targets = new DatanodeInfo[0][];
+    this.targets = EMPTY_TARGET;
   }
 
-  public Block[] getBlocks() {
+  Block[] getBlocks() {
     return blocks;
   }
 
-  public DatanodeInfo[][] getTargets() {
+  DatanodeInfo[][] getTargets() {
     return targets;
   }
 

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java?rev=651165&r1=651164&r2=651165&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java Wed Apr 23 23:13:50
2008
@@ -2184,7 +2184,7 @@
         try {
           nodeinfo = getDatanode(nodeReg);
         } catch(UnregisteredDatanodeException e) {
-          return new DatanodeCommand(DatanodeProtocol.DNA_REGISTER);
+          return DatanodeCommand.REGISTER;
         }
           
         // Check if this datanode should actually be shutdown instead. 
@@ -2194,7 +2194,7 @@
         }
 
         if (nodeinfo == null || !nodeinfo.isAlive) {
-          return new DatanodeCommand(DatanodeProtocol.DNA_REGISTER);
+          return DatanodeCommand.REGISTER;
         }
 
         updateStats(nodeinfo, false);
@@ -2220,7 +2220,7 @@
       // have any work for that as well
       assert(cmd == null);
       if (isResolved(nodeReg)) {
-        return new DatanodeCommand(DatanodeProtocol.DNA_BLOCKREPORT);
+        return DatanodeCommand.BLOCKREPORT;
       }
     }
     //check distributed upgrade

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/dfs/NameNode.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/dfs/NameNode.java?rev=651165&r1=651164&r2=651165&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/dfs/NameNode.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/dfs/NameNode.java Wed Apr 23 23:13:50 2008
@@ -559,7 +559,7 @@
     if (blocksToDelete != null && blocksToDelete.length > 0)
       return new BlockCommand(DatanodeProtocol.DNA_INVALIDATE, blocksToDelete);
     if (getFSImage().isUpgradeFinalized())
-      return new DatanodeCommand(DatanodeProtocol.DNA_FINALIZE);
+      return DatanodeCommand.FINALIZE;
     return null;
   }
 

Modified: hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestDistributedUpgrade.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestDistributedUpgrade.java?rev=651165&r1=651164&r2=651165&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestDistributedUpgrade.java (original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestDistributedUpgrade.java Wed Apr 23
23:13:50 2008
@@ -174,7 +174,7 @@
 
   synchronized public UpgradeCommand processUpgradeCommand(
                                   UpgradeCommand command) throws IOException {
-    switch(command.action) {
+    switch(command.getAction()) {
       case UpgradeCommand.UC_ACTION_REPORT_STATUS:
         this.status += command.getCurrentStatus()/8;  // 4 reports needed
         break;



Mime
View raw message