hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r530556 [4/12] - in /lucene/hadoop/trunk: ./ src/contrib/abacus/src/java/org/apache/hadoop/abacus/ src/contrib/hbase/src/java/org/apache/hadoop/hbase/ src/contrib/hbase/src/test/org/apache/hadoop/hbase/ src/contrib/streaming/src/java/org/ap...
Date Thu, 19 Apr 2007 21:34:53 GMT
Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java?view=diff&rev=530556&r1=530555&r2=530556
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java Thu Apr 19 14:34:41 2007
@@ -114,12 +114,12 @@
      * @return Iterator of children
      */
     Iterator<INode> getChildIterator() {
-      return ( children != null ) ?  children.values().iterator() : null;
+      return (children != null) ?  children.values().iterator() : null;
       // instead of null, we could return a static empty iterator.
     }
         
     void addChild(String name, INode node) {
-      if ( children == null ) {
+      if (children == null) {
         children = new TreeMap<String, INode>();
       }
       children.put(name, node);
@@ -129,8 +129,8 @@
      * This is the external interface
      */
     INode getNode(String target) {
-      if ( target == null || 
-           ! target.startsWith("/") || target.length() == 0) {
+      if (target == null || 
+          !target.startsWith("/") || target.length() == 0) {
         return null;
       } else if (parent == null && "/".equals(target)) {
         return this;
@@ -152,7 +152,7 @@
     /**
      */
     INode getNode(Vector<String> components, int index) {
-      if (! name.equals(components.elementAt(index))) {
+      if (!name.equals(components.elementAt(index))) {
         return null;
       }
       if (index == components.size()-1) {
@@ -168,8 +168,8 @@
       }
     }
         
-    INode getChild( String name) {
-      return (children == null) ? null : children.get( name );
+    INode getChild(String name) {
+      return (children == null) ? null : children.get(name);
     }
 
     /**
@@ -183,7 +183,7 @@
      * @author shv
      */
     INode addNode(String path, INode newNode) throws FileNotFoundException {
-      File target = new File( path );
+      File target = new File(path);
       // find parent
       Path parent = new Path(path).getParent();
       if (parent == null) { // add root
@@ -200,7 +200,7 @@
       }
       // check whether the parent already has a node with that name
       String name = newNode.name = target.getName();
-      if( parentNode.getChild( name ) != null ) {
+      if (parentNode.getChild(name) != null) {
         return null;
       }
       // insert into the parent children list
@@ -233,7 +233,7 @@
       }
       incrDeletedFileCount();
       for (Iterator<INode> it = getChildIterator(); it != null &&
-             it.hasNext(); ) {
+             it.hasNext();) {
         it.next().collectSubtreeBlocks(v);
       }
     }
@@ -243,7 +243,7 @@
     int numItemsInTree() {
       int total = 0;
       for (Iterator<INode> it = getChildIterator(); it != null && 
-             it.hasNext(); ) {
+             it.hasNext();) {
         total += it.next().numItemsInTree();
       }
       return total + 1;
@@ -276,7 +276,7 @@
     long computeContentsLength() {
       long total = computeFileLength();
       for (Iterator<INode> it = getChildIterator(); it != null && 
-             it.hasNext(); ) {
+             it.hasNext();) {
         total += it.next().computeContentsLength();
       }
       return total;
@@ -302,7 +302,7 @@
       }
 
       for (Iterator<INode> it = getChildIterator(); it != null && 
-             it.hasNext(); ) {
+             it.hasNext();) {
         v.add(it.next());
       }
     }
@@ -335,17 +335,17 @@
     directoryMetrics = MetricsUtil.createRecord(metricsContext, "FSDirectory");
   }
 
-  void loadFSImage( Collection<File> dataDirs,
-                    StartupOption startOpt ) throws IOException {
+  void loadFSImage(Collection<File> dataDirs,
+                   StartupOption startOpt) throws IOException {
     // format before starting up if requested
-    if( startOpt == StartupOption.FORMAT ) {
-      fsImage.setStorageDirectories( dataDirs );
+    if (startOpt == StartupOption.FORMAT) {
+      fsImage.setStorageDirectories(dataDirs);
       fsImage.format();
       startOpt = StartupOption.REGULAR;
     }
     try {
-      fsImage.recoverTransitionRead( dataDirs, startOpt );
-    } catch( IOException e ) {
+      fsImage.recoverTransitionRead(dataDirs, startOpt);
+    } catch(IOException e) {
       fsImage.close();
       throw e;
     }
@@ -371,7 +371,7 @@
    * Block until the object is ready to be used.
    */
   void waitForReady() {
-    if (! ready) {
+    if (!ready) {
       synchronized (this) {
         while (!ready) {
           try {
@@ -391,20 +391,20 @@
 
     // Always do an implicit mkdirs for parent directory tree
     String pathString = path.toString();
-    if( ! mkdirs(new Path(pathString).getParent().toString()) ) {
+    if (!mkdirs(new Path(pathString).getParent().toString())) {
       return false;
     }
-    INode newNode = new INode( new File(pathString).getName(), blocks, replication);
-    if( ! unprotectedAddFile(path, newNode) ) {
+    INode newNode = new INode(new File(pathString).getName(), blocks, replication);
+    if (!unprotectedAddFile(path, newNode)) {
       NameNode.stateChangeLog.info("DIR* FSDirectory.addFile: "
                                    +"failed to add "+path+" with "
-                                   +blocks.length+" blocks to the file system" );
+                                   +blocks.length+" blocks to the file system");
       return false;
     }
     // add create file record to log
-    fsImage.getEditLog().logCreateFile( newNode );
+    fsImage.getEditLog().logCreateFile(newNode);
     NameNode.stateChangeLog.debug("DIR* FSDirectory.addFile: "
-                                  +path+" with "+blocks.length+" blocks is added to the file system" );
+                                  +path+" with "+blocks.length+" blocks is added to the file system");
     return true;
   }
     
@@ -413,7 +413,7 @@
   boolean unprotectedAddFile(UTF8 path, INode newNode) {
     synchronized (rootDir) {
       try {
-        if( rootDir.addNode(path.toString(), newNode ) != null ) {
+        if (rootDir.addNode(path.toString(), newNode) != null) {
           int nrBlocks = (newNode.blocks == null) ? 0 : newNode.blocks.length;
           // Add file->block mapping
           for (int i = 0; i < nrBlocks; i++)
@@ -422,15 +422,15 @@
         } else {
           return false;
         }
-      } catch (FileNotFoundException e ) {
+      } catch (FileNotFoundException e) {
         return false;
       }
     }
   }
     
-  boolean unprotectedAddFile(UTF8 path, Block[] blocks, short replication ) {
-    return unprotectedAddFile( path,  
-                               new INode( path.toString(), blocks, replication ));
+  boolean unprotectedAddFile(UTF8 path, Block[] blocks, short replication) {
+    return unprotectedAddFile(path,  
+                              new INode(path.toString(), blocks, replication));
   }
 
   /**
@@ -438,9 +438,9 @@
    */
   public boolean renameTo(UTF8 src, UTF8 dst) {
     NameNode.stateChangeLog.debug("DIR* FSDirectory.renameTo: "
-                                  +src+" to "+dst );
+                                  +src+" to "+dst);
     waitForReady();
-    if( ! unprotectedRenameTo(src, dst) )
+    if (!unprotectedRenameTo(src, dst))
       return false;
     fsImage.getEditLog().logRename(src, dst);
     return true;
@@ -455,29 +455,29 @@
       INode renamedNode = rootDir.getNode(srcStr);
       if (renamedNode == null) {
         NameNode.stateChangeLog.warn("DIR* FSDirectory.unprotectedRenameTo: "
-                                     +"failed to rename "+src+" to "+dst+ " because source does not exist" );
+                                     +"failed to rename "+src+" to "+dst+ " because source does not exist");
         return false;
       }
       if (isDir(dst)) {
         dstStr += "/" + new File(srcStr).getName();
       }
-      if( rootDir.getNode(dstStr.toString()) != null ) {
+      if (rootDir.getNode(dstStr.toString()) != null) {
         NameNode.stateChangeLog.warn("DIR* FSDirectory.unprotectedRenameTo: "
-                                     +"failed to rename "+src+" to "+dstStr+ " because destination exists" );
+                                     +"failed to rename "+src+" to "+dstStr+ " because destination exists");
         return false;
       }
       renamedNode.removeNode();
             
       // the renamed node can be reused now
       try {
-        if( rootDir.addNode(dstStr, renamedNode ) != null ) {
+        if (rootDir.addNode(dstStr, renamedNode) != null) {
           NameNode.stateChangeLog.debug("DIR* FSDirectory.unprotectedRenameTo: "
-                                        +src+" is renamed to "+dst );
+                                        +src+" is renamed to "+dst);
           return true;
         }
-      } catch (FileNotFoundException e ) {
+      } catch (FileNotFoundException e) {
         NameNode.stateChangeLog.warn("DIR* FSDirectory.unprotectedRenameTo: "
-                                     +"failed to rename "+src+" to "+dst );
+                                     +"failed to rename "+src+" to "+dst);
         try {
           rootDir.addNode(srcStr, renamedNode); // put it back
         }catch(FileNotFoundException e2) {                
@@ -497,33 +497,33 @@
    * @return array of file blocks
    * @throws IOException
    */
-  Block[] setReplication( String src, 
-                          short replication,
-                          Vector<Integer> oldReplication
-                          ) throws IOException {
+  Block[] setReplication(String src, 
+                         short replication,
+                         Vector<Integer> oldReplication
+                         ) throws IOException {
     waitForReady();
-    Block[] fileBlocks = unprotectedSetReplication(src, replication, oldReplication );
-    if( fileBlocks != null )  // log replication change
-      fsImage.getEditLog().logSetReplication( src, replication );
+    Block[] fileBlocks = unprotectedSetReplication(src, replication, oldReplication);
+    if (fileBlocks != null)  // log replication change
+      fsImage.getEditLog().logSetReplication(src, replication);
     return fileBlocks;
   }
 
-  Block[] unprotectedSetReplication(  String src, 
-                                      short replication,
-                                      Vector<Integer> oldReplication
-                                      ) throws IOException {
-    if( oldReplication == null )
+  Block[] unprotectedSetReplication( String src, 
+                                     short replication,
+                                     Vector<Integer> oldReplication
+                                     ) throws IOException {
+    if (oldReplication == null)
       oldReplication = new Vector<Integer>();
     oldReplication.setSize(1);
-    oldReplication.set( 0, new Integer(-1) );
+    oldReplication.set(0, new Integer(-1));
     Block[] fileBlocks = null;
     synchronized(rootDir) {
       INode fileNode = rootDir.getNode(src);
       if (fileNode == null)
         return null;
-      if( fileNode.isDir() )
+      if (fileNode.isDir())
         return null;
-      oldReplication.set( 0, new Integer( fileNode.blockReplication ));
+      oldReplication.set(0, new Integer(fileNode.blockReplication));
       fileNode.blockReplication = replication;
       fileBlocks = fileNode.blocks;
     }
@@ -555,11 +555,11 @@
    */
   public Block[] delete(UTF8 src) {
     NameNode.stateChangeLog.debug("DIR* FSDirectory.delete: "
-                                  +src );
+                                  +src);
     waitForReady();
     Block[] blocks = unprotectedDelete(src); 
-    if( blocks != null )
-      fsImage.getEditLog().logDelete( src );
+    if (blocks != null)
+      fsImage.getEditLog().logDelete(src);
     return blocks;
   }
 
@@ -570,20 +570,20 @@
       INode targetNode = rootDir.getNode(src.toString());
       if (targetNode == null) {
         NameNode.stateChangeLog.warn("DIR* FSDirectory.unprotectedDelete: "
-                                     +"failed to remove "+src+" because it does not exist" );
+                                     +"failed to remove "+src+" because it does not exist");
         return null;
       } else {
         //
         // Remove the node from the namespace and GC all
         // the blocks underneath the node.
         //
-        if (! targetNode.removeNode()) {
+        if (!targetNode.removeNode()) {
           NameNode.stateChangeLog.warn("DIR* FSDirectory.unprotectedDelete: "
-                                       +"failed to remove "+src+" because it does not have a parent" );
+                                       +"failed to remove "+src+" because it does not have a parent");
           return null;
         } else {
           NameNode.stateChangeLog.debug("DIR* FSDirectory.unprotectedDelete: "
-                                        +src+" is removed" );
+                                        +src+" is removed");
           Vector<Block> v = new Vector<Block>();
           targetNode.collectSubtreeBlocks(v);
           for (Block b : v) {
@@ -675,7 +675,7 @@
     String srcs = normalizePath(src);
     synchronized (rootDir) {
       if (srcs.startsWith("/") && 
-          ! srcs.endsWith("/") && 
+          !srcs.endsWith("/") && 
           rootDir.getNode(srcs) == null) {
         return true;
       } else {
@@ -722,8 +722,8 @@
         INode inserted = unprotectedMkdir(cur);
         if (inserted != null) {
           NameNode.stateChangeLog.debug("DIR* FSDirectory.mkdirs: "
-                                        +"created directory "+cur );
-          fsImage.getEditLog().logMkDir( inserted );
+                                        +"created directory "+cur);
+          fsImage.getEditLog().logMkDir(inserted);
         } else { // otherwise cur exists, verify that it is a directory
           if (!isDir(new UTF8(cur))) {
             NameNode.stateChangeLog.debug("DIR* FSDirectory.mkdirs: "
@@ -731,7 +731,7 @@
             return false;
           } 
         }
-      } catch (FileNotFoundException e ) {
+      } catch (FileNotFoundException e) {
         NameNode.stateChangeLog.debug("DIR* FSDirectory.mkdirs: "
                                       +"failed to create directory "+src);
         return false;

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSEditLog.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSEditLog.java?view=diff&rev=530556&r1=530555&r2=530556
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSEditLog.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSEditLog.java Thu Apr 19 14:34:41 2007
@@ -52,8 +52,8 @@
   static class EditLogOutputStream extends DataOutputStream {
     private FileDescriptor fd;
 
-    EditLogOutputStream( File name ) throws IOException {
-      super( new FileOutputStream( name, true )); // open for append
+    EditLogOutputStream(File name) throws IOException {
+      super(new FileOutputStream(name, true)); // open for append
       this.fd = ((FileOutputStream)out).getFD();
     }
 
@@ -63,21 +63,21 @@
     }
 
     void create() throws IOException {
-      writeInt( FSConstants.LAYOUT_VERSION );
+      writeInt(FSConstants.LAYOUT_VERSION);
       flushAndSync();
     }
   }
 
-  FSEditLog( FSImage image ) {
+  FSEditLog(FSImage image) {
     fsimage = image;
   }
 
-  private File getEditFile( int idx ) {
-    return fsimage.getEditFile( idx );
+  private File getEditFile(int idx) {
+    return fsimage.getEditFile(idx);
   }
 
-  private File getEditNewFile( int idx ) {
-    return fsimage.getEditNewFile( idx );
+  private File getEditNewFile(int idx) {
+    return fsimage.getEditNewFile(idx);
   }
   
   private int getNumStorageDirs() {
@@ -96,23 +96,23 @@
    */
   void open() throws IOException {
     int size = getNumStorageDirs();
-    if( editStreams == null )
-      editStreams = new ArrayList<EditLogOutputStream>( size );
+    if (editStreams == null)
+      editStreams = new ArrayList<EditLogOutputStream>(size);
     for (int idx = 0; idx < size; idx++) {
-      File eFile = getEditFile( idx );
+      File eFile = getEditFile(idx);
       try {
-        EditLogOutputStream eStream = new EditLogOutputStream( eFile );
-        editStreams.add( eStream );
+        EditLogOutputStream eStream = new EditLogOutputStream(eFile);
+        editStreams.add(eStream);
       } catch (IOException e) {
-        FSNamesystem.LOG.warn( "Unable to open edit log file " + eFile );
+        FSNamesystem.LOG.warn("Unable to open edit log file " + eFile);
         processIOError(idx); 
         idx--; 
       }
     }
   }
 
-  void createEditLogFile( File name ) throws IOException {
-    EditLogOutputStream eStream = new EditLogOutputStream( name );
+  void createEditLogFile(File name) throws IOException {
+    EditLogOutputStream eStream = new EditLogOutputStream(name);
     eStream.create();
     eStream.flushAndSync();
     eStream.close();
@@ -123,9 +123,9 @@
    */
   void createNewIfMissing() throws IOException {
     for (int idx = 0; idx < getNumStorageDirs(); idx++) {
-      File newFile = getEditNewFile( idx );
-      if( ! newFile.exists() )
-        createEditLogFile( newFile );
+      File newFile = getEditNewFile(idx);
+      if (!newFile.exists())
+        createEditLogFile(newFile);
     }
   }
   
@@ -137,7 +137,7 @@
       return;
     }
     for (int idx = 0; idx < editStreams.size(); idx++) {
-      EditLogOutputStream eStream = editStreams.get( idx );
+      EditLogOutputStream eStream = editStreams.get(idx);
       try {
         eStream.flushAndSync();
         eStream.close();
@@ -162,7 +162,7 @@
     assert(index < getNumStorageDirs());
     assert(getNumStorageDirs() == editStreams.size());
 
-    editStreams.remove( index );
+    editStreams.remove(index);
     //
     // Invoke the ioerror routine of the fsimage
     //
@@ -174,7 +174,7 @@
    */
   boolean existsNew() throws IOException {
     for (int idx = 0; idx < getNumStorageDirs(); idx++) {
-      if (getEditNewFile( idx ).exists()) { 
+      if (getEditNewFile(idx).exists()) { 
         return true;
       }
     }
@@ -186,7 +186,7 @@
    * This is where we apply edits that we've been writing to disk all
    * along.
    */
-  int loadFSEdits( File edits ) throws IOException {
+  int loadFSEdits(File edits) throws IOException {
     FSNamesystem fsNamesys = FSNamesystem.getFSNamesystem();
     FSDirectory fsDir = fsNamesys.dir;
     int numEdits = 0;
@@ -197,7 +197,7 @@
                                                new BufferedInputStream(
                                                                        new FileInputStream(edits)));
       // Read log file version. Could be missing. 
-      in.mark( 4 );
+      in.mark(4);
       // If edits log is greater than 2G, available method will return negative
       // numbers, so we avoid having to call available
       boolean available = true;
@@ -208,16 +208,16 @@
       }
       if (available) {
         in.reset();
-        if( logVersion >= 0 )
+        if (logVersion >= 0)
           logVersion = 0;
         else
           logVersion = in.readInt();
-        if( logVersion < FSConstants.LAYOUT_VERSION ) // future version
+        if (logVersion < FSConstants.LAYOUT_VERSION) // future version
           throw new IOException(
                                 "Unexpected version of the file system log file: "
                                 + logVersion
                                 + ". Current version = " 
-                                + FSConstants.LAYOUT_VERSION + "." );
+                                + FSConstants.LAYOUT_VERSION + ".");
       }
       
       short replication = fsNamesys.getDefaultReplication();
@@ -236,20 +236,20 @@
             ArrayWritable aw = null;
             Writable writables[];
             // version 0 does not support per file replication
-            if( logVersion >= 0 )
+            if (logVersion >= 0)
               name.readFields(in);  // read name only
             else {  // other versions do
               // get name and replication
               aw = new ArrayWritable(UTF8.class);
               aw.readFields(in);
               writables = aw.get(); 
-              if( writables.length != 2 )
+              if (writables.length != 2)
                 throw new IOException("Incorrect data fortmat. " 
                                       + "Name & replication pair expected");
               name = (UTF8) writables[0];
               replication = Short.parseShort(
                                              ((UTF8)writables[1]).toString());
-              replication = adjustReplication( replication );
+              replication = adjustReplication(replication);
             }
             // get blocks
             aw = new ArrayWritable(Block.class);
@@ -258,7 +258,7 @@
             Block blocks[] = new Block[writables.length];
             System.arraycopy(writables, 0, blocks, 0, blocks.length);
             // add to the file tree
-            fsDir.unprotectedAddFile(name, blocks, replication );
+            fsDir.unprotectedAddFile(name, blocks, replication);
             break;
           }
           case OP_SET_REPLICATION: {
@@ -266,7 +266,7 @@
             UTF8 repl = new UTF8();
             src.readFields(in);
             repl.readFields(in);
-            replication = adjustReplication( fromLogReplication(repl) );
+            replication = adjustReplication(fromLogReplication(repl));
             fsDir.unprotectedSetReplication(src.toString(), 
                                             replication,
                                             null);
@@ -293,26 +293,26 @@
             break;
           }
           case OP_DATANODE_ADD: {
-            if( logVersion > -3 )
+            if (logVersion > -3)
               throw new IOException("Unexpected opcode " + opcode 
-                                    + " for version " + logVersion );
+                                    + " for version " + logVersion);
             FSImage.DatanodeImage nodeimage = new FSImage.DatanodeImage();
             nodeimage.readFields(in);
             DatanodeDescriptor node = nodeimage.getDatanodeDescriptor();
-            fsNamesys.unprotectedAddDatanode( node );
+            fsNamesys.unprotectedAddDatanode(node);
             break;
           }
           case OP_DATANODE_REMOVE: {
-            if( logVersion > -3 )
+            if (logVersion > -3)
               throw new IOException("Unexpected opcode " + opcode 
-                                    + " for version " + logVersion );
+                                    + " for version " + logVersion);
             DatanodeID nodeID = new DatanodeID();
             nodeID.readFields(in);
-            DatanodeDescriptor node = fsNamesys.getDatanode( nodeID );
-            if( node != null ) {
-              fsNamesys.unprotectedRemoveDatanode( node );
+            DatanodeDescriptor node = fsNamesys.getDatanode(nodeID);
+            if (node != null) {
+              fsNamesys.unprotectedRemoveDatanode(node);
               // physically remove node from datanodeMap
-              fsNamesys.wipeDatanode( nodeID );
+              fsNamesys.wipeDatanode(nodeID);
             }
             break;
           }
@@ -326,19 +326,19 @@
       }
     }
     
-    if( logVersion != FSConstants.LAYOUT_VERSION ) // other version
+    if (logVersion != FSConstants.LAYOUT_VERSION) // other version
       numEdits++; // save this image asap
     return numEdits;
   }
   
-  static short adjustReplication( short replication) {
+  static short adjustReplication(short replication) {
     FSNamesystem fsNamesys = FSNamesystem.getFSNamesystem();
     short minReplication = fsNamesys.getMinReplication();
-    if( replication<minReplication ) {
+    if (replication<minReplication) {
       replication = minReplication;
     }
     short maxReplication = fsNamesys.getMaxReplication();
-    if( replication>maxReplication ) {
+    if (replication>maxReplication) {
       replication = maxReplication;
     }
     return replication;
@@ -351,14 +351,14 @@
     assert this.getNumEditStreams() > 0 : "no editlog streams";
     for (int idx = 0; idx < editStreams.size(); idx++) {
       EditLogOutputStream eStream;
-      synchronized ( eStream = editStreams.get( idx ) ) {
+      synchronized (eStream = editStreams.get(idx)) {
         try {
           eStream.write(op);
           if (w1 != null) {
-            w1.write( eStream );
+            w1.write(eStream);
           }
           if (w2 != null) {
-            w2.write( eStream );
+            w2.write(eStream);
           }
           eStream.flushAndSync();
         } catch (IOException ie) {
@@ -377,43 +377,43 @@
   /** 
    * Add create file record to edit log
    */
-  void logCreateFile( FSDirectory.INode newNode ) {
+  void logCreateFile(FSDirectory.INode newNode) {
     UTF8 nameReplicationPair[] = new UTF8[] { 
-      new UTF8( newNode.computeName() ), 
-      FSEditLog.toLogReplication( newNode.getReplication() )};
+      new UTF8(newNode.computeName()), 
+      FSEditLog.toLogReplication(newNode.getReplication())};
     logEdit(OP_ADD,
-            new ArrayWritable( UTF8.class, nameReplicationPair ), 
-            new ArrayWritable( Block.class, newNode.getBlocks() ));
+            new ArrayWritable(UTF8.class, nameReplicationPair), 
+            new ArrayWritable(Block.class, newNode.getBlocks()));
   }
   
   /** 
    * Add create directory record to edit log
    */
-  void logMkDir( FSDirectory.INode newNode ) {
-    logEdit(OP_MKDIR, new UTF8( newNode.computeName() ), null );
+  void logMkDir(FSDirectory.INode newNode) {
+    logEdit(OP_MKDIR, new UTF8(newNode.computeName()), null);
   }
   
   /** 
    * Add rename record to edit log
    * TODO: use String parameters until just before writing to disk
    */
-  void logRename( UTF8 src, UTF8 dst ) {
+  void logRename(UTF8 src, UTF8 dst) {
     logEdit(OP_RENAME, src, dst);
   }
   
   /** 
    * Add set replication record to edit log
    */
-  void logSetReplication( String src, short replication ) {
+  void logSetReplication(String src, short replication) {
     logEdit(OP_SET_REPLICATION, 
             new UTF8(src), 
-            FSEditLog.toLogReplication( replication ));
+            FSEditLog.toLogReplication(replication));
   }
   
   /** 
    * Add delete file record to edit log
    */
-  void logDelete( UTF8 src ) {
+  void logDelete(UTF8 src) {
     logEdit(OP_DELETE, src, null);
   }
   
@@ -421,23 +421,23 @@
    * Creates a record in edit log corresponding to a new data node
    * registration event.
    */
-  void logAddDatanode( DatanodeDescriptor node ) {
-    logEdit( OP_DATANODE_ADD, new FSImage.DatanodeImage(node), null );
+  void logAddDatanode(DatanodeDescriptor node) {
+    logEdit(OP_DATANODE_ADD, new FSImage.DatanodeImage(node), null);
   }
   
   /** 
    * Creates a record in edit log corresponding to a data node
    * removal event.
    */
-  void logRemoveDatanode( DatanodeID nodeID ) {
-    logEdit( OP_DATANODE_REMOVE, new DatanodeID( nodeID ), null );
+  void logRemoveDatanode(DatanodeID nodeID) {
+    logEdit(OP_DATANODE_REMOVE, new DatanodeID(nodeID), null);
   }
   
-  static UTF8 toLogReplication( short replication ) {
-    return new UTF8( Short.toString(replication));
+  static UTF8 toLogReplication(short replication) {
+    return new UTF8(Short.toString(replication));
   }
   
-  static short fromLogReplication( UTF8 replication ) {
+  static short fromLogReplication(UTF8 replication) {
     return Short.parseShort(replication.toString());
   }
 
@@ -448,9 +448,9 @@
     assert(getNumStorageDirs() == editStreams.size());
     long size = 0;
     for (int idx = 0; idx < getNumStorageDirs(); idx++) {
-      synchronized (editStreams.get( idx )) {
-        assert(size == 0 || size == getEditFile( idx ).length());
-        size = getEditFile( idx ).length();
+      synchronized (editStreams.get(idx)) {
+        assert(size == 0 || size == getEditFile(idx).length());
+        size = getEditFile(idx).length();
       }
     }
     return size;
@@ -472,11 +472,11 @@
     //
     // Open edits.new
     //
-    for (int idx = 0; idx < getNumStorageDirs(); idx++ ) {
+    for (int idx = 0; idx < getNumStorageDirs(); idx++) {
       try {
-        EditLogOutputStream eStream = new EditLogOutputStream( getEditNewFile( idx ));
+        EditLogOutputStream eStream = new EditLogOutputStream(getEditNewFile(idx));
         eStream.create();
-        editStreams.add( eStream );
+        editStreams.add(eStream);
       } catch (IOException e) {
         processIOError(idx);
         idx--;
@@ -501,14 +501,14 @@
     //
     // Delete edits and rename edits.new to edits.
     //
-    for (int idx = 0; idx < getNumStorageDirs(); idx++ ) {
-      if (!getEditNewFile( idx ).renameTo(getEditFile( idx ))) {
+    for (int idx = 0; idx < getNumStorageDirs(); idx++) {
+      if (!getEditNewFile(idx).renameTo(getEditFile(idx))) {
         //
         // renameTo() fails on Windows if the destination
         // file exists.
         //
-        getEditFile( idx ).delete();
-        if (!getEditNewFile( idx ).renameTo(getEditFile( idx ))) {
+        getEditFile(idx).delete();
+        if (!getEditNewFile(idx).renameTo(getEditFile(idx))) {
           processIOError(idx); 
           idx--; 
         }
@@ -524,6 +524,6 @@
    * Return the name of the edit file
    */
   File getFsEditName() throws IOException {
-    return getEditFile( 0 );
+    return getEditFile(0);
   }
 }

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSImage.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSImage.java?view=diff&rev=530556&r1=530555&r2=530556
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSImage.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/FSImage.java Thu Apr 19 14:34:41 2007
@@ -59,7 +59,7 @@
     EDITS_NEW ("edits.new");
     
     private String fileName = null;
-    private NameNodeFile( String name ) {this.fileName = name;}
+    private NameNodeFile(String name) {this.fileName = name;}
     String getName() {return fileName;}
   }
   
@@ -70,53 +70,53 @@
   /**
    */
   FSImage() {
-    super( NodeType.NAME_NODE );
-    this.editLog = new FSEditLog( this );
+    super(NodeType.NAME_NODE);
+    this.editLog = new FSEditLog(this);
   }
 
   /**
    */
-  FSImage( Collection<File> fsDirs ) throws IOException {
+  FSImage(Collection<File> fsDirs) throws IOException {
     this();
-    setStorageDirectories( fsDirs );
+    setStorageDirectories(fsDirs);
   }
 
-  FSImage( StorageInfo storageInfo ) {
-    super( NodeType.NAME_NODE, storageInfo );
+  FSImage(StorageInfo storageInfo) {
+    super(NodeType.NAME_NODE, storageInfo);
   }
 
   /**
    * Represents an Image (image and edit file).
    */
-  FSImage( File imageDir ) throws IOException {
+  FSImage(File imageDir) throws IOException {
     this();
     ArrayList<File> dirs = new ArrayList<File>(1);
-    dirs.add( imageDir );
-    setStorageDirectories( dirs );
+    dirs.add(imageDir);
+    setStorageDirectories(dirs);
   }
   
-  void setStorageDirectories( Collection<File> fsDirs ) throws IOException {
-    this.storageDirs = new ArrayList<StorageDirectory>( fsDirs.size() );
-    for( Iterator<File> it = fsDirs.iterator(); it.hasNext(); )
-      this.addStorageDir( new StorageDirectory( it.next() ));
+  void setStorageDirectories(Collection<File> fsDirs) throws IOException {
+    this.storageDirs = new ArrayList<StorageDirectory>(fsDirs.size());
+    for(Iterator<File> it = fsDirs.iterator(); it.hasNext();)
+      this.addStorageDir(new StorageDirectory(it.next()));
   }
 
   /**
    */
-  File getImageFile( int imageDirIdx, NameNodeFile type ) {
-    return getImageFile( getStorageDir( imageDirIdx ), type );
+  File getImageFile(int imageDirIdx, NameNodeFile type) {
+    return getImageFile(getStorageDir(imageDirIdx), type);
   }
   
-  static File getImageFile( StorageDirectory sd, NameNodeFile type ) {
-    return new File( sd.getCurrentDir(), type.getName() );
+  static File getImageFile(StorageDirectory sd, NameNodeFile type) {
+    return new File(sd.getCurrentDir(), type.getName());
   }
   
-  File getEditFile( int idx ) {
-    return getImageFile( idx, NameNodeFile.EDITS );
+  File getEditFile(int idx) {
+    return getImageFile(idx, NameNodeFile.EDITS);
   }
   
-  File getEditNewFile( int idx ) {
-    return getImageFile( idx, NameNodeFile.EDITS_NEW );
+  File getEditNewFile(int idx) {
+    return getImageFile(idx, NameNodeFile.EDITS_NEW);
   }
   
   /**
@@ -129,42 +129,42 @@
    * @param startOpt startup option
    * @throws IOException
    */
-  void recoverTransitionRead( Collection<File> dataDirs,
-                              StartupOption startOpt
-                              ) throws IOException {
+  void recoverTransitionRead(Collection<File> dataDirs,
+                             StartupOption startOpt
+                             ) throws IOException {
     assert startOpt != StartupOption.FORMAT : 
       "NameNode formatting should be performed before reading the image";
     // 1. For each data directory calculate its state and 
     // check whether all is consistent before transitioning.
-    this.storageDirs = new ArrayList<StorageDirectory>( dataDirs.size() );
+    this.storageDirs = new ArrayList<StorageDirectory>(dataDirs.size());
     AbstractList<StorageState> dataDirStates = 
-      new ArrayList<StorageState>( dataDirs.size() );
+      new ArrayList<StorageState>(dataDirs.size());
     boolean isFormatted = false;
-    for( Iterator<File> it = dataDirs.iterator(); it.hasNext(); ) {
+    for(Iterator<File> it = dataDirs.iterator(); it.hasNext();) {
       File dataDir = it.next();
-      StorageDirectory sd = new StorageDirectory( dataDir );
+      StorageDirectory sd = new StorageDirectory(dataDir);
       StorageState curState;
       try {
-        curState = sd.analyzeStorage( startOpt );
+        curState = sd.analyzeStorage(startOpt);
         // sd is locked but not opened
-        switch( curState ) {
+        switch(curState) {
         case NON_EXISTENT:
           // name-node fails if any of the configured storage dirs are missing
-          throw new InconsistentFSStateException( sd.root,
-                                                  "storage directory does not exist or is not accessible." );
+          throw new InconsistentFSStateException(sd.root,
+                                                 "storage directory does not exist or is not accessible.");
         case NOT_FORMATTED:
           break;
         case CONVERT:
-          if( convertLayout( sd ) ) // need to reformat empty image
+          if (convertLayout(sd)) // need to reformat empty image
             curState = StorageState.NOT_FORMATTED;
           break;
         case NORMAL:
           break;
         default:  // recovery is possible
-          sd.doRecover( curState );      
+          sd.doRecover(curState);      
         }
-        if( curState != StorageState.NOT_FORMATTED 
-            && startOpt != StartupOption.ROLLBACK ) {
+        if (curState != StorageState.NOT_FORMATTED 
+            && startOpt != StartupOption.ROLLBACK) {
           sd.read(); // read and verify consistency with other directories
           isFormatted = true;
         }
@@ -173,34 +173,34 @@
         throw ioe;
       }
       // add to the storage list
-      addStorageDir( sd );
-      dataDirStates.add( curState );
+      addStorageDir(sd);
+      dataDirStates.add(curState);
     }
 
-    if( dataDirs.size() == 0 )  // none of the data dirs exist
-      throw new IOException( 
-                            "All specified directories are not accessible or do not exist." );
-    if( ! isFormatted && startOpt != StartupOption.ROLLBACK )
-      throw new IOException( "NameNode is not formatted." );
-    if( startOpt != StartupOption.UPGRADE
+    if (dataDirs.size() == 0)  // none of the data dirs exist
+      throw new IOException(
+                            "All specified directories are not accessible or do not exist.");
+    if (!isFormatted && startOpt != StartupOption.ROLLBACK)
+      throw new IOException("NameNode is not formatted.");
+    if (startOpt != StartupOption.UPGRADE
         && layoutVersion < LAST_PRE_UPGRADE_LAYOUT_VERSION
-        && layoutVersion != FSConstants.LAYOUT_VERSION )
-      throw new IOException( 
+        && layoutVersion != FSConstants.LAYOUT_VERSION)
+      throw new IOException(
                             "\nFile system image contains an old layout version " + layoutVersion
                             + ".\nAn upgrade to version " + FSConstants.LAYOUT_VERSION
-                            + " is required.\nPlease restart NameNode with -upgrade option." );
+                            + " is required.\nPlease restart NameNode with -upgrade option.");
 
     // 2. Format unformatted dirs.
     this.checkpointTime = 0L;
-    for( int idx = 0; idx < getNumStorageDirs(); idx++ ) {
-      StorageDirectory sd = getStorageDir( idx );
-      StorageState curState = dataDirStates.get( idx );
-      switch( curState ) {
+    for(int idx = 0; idx < getNumStorageDirs(); idx++) {
+      StorageDirectory sd = getStorageDir(idx);
+      StorageState curState = dataDirStates.get(idx);
+      switch(curState) {
       case NON_EXISTENT:
         assert false : StorageState.NON_EXISTENT + " state cannot be here";
       case NOT_FORMATTED:
-        LOG.info( "Storage directory " + sd.root + " is not formatted." );
-        LOG.info( "Formatting ..." );
+        LOG.info("Storage directory " + sd.root + " is not formatted.");
+        LOG.info("Formatting ...");
         sd.clearDirectory(); // create empty currrent dir
         break;
       default:
@@ -209,7 +209,7 @@
     }
 
     // 3. Do transitions
-    switch( startOpt ) {
+    switch(startOpt) {
     case UPGRADE:
       doUpgrade();
       break;
@@ -217,7 +217,7 @@
       doRollback();
       // and now load that image
     case REGULAR:
-      if( loadFSImage() )
+      if (loadFSImage())
         saveFSImage();
       else
         editLog.open();
@@ -229,12 +229,12 @@
   private void doUpgrade() throws IOException {
     // Upgrade is allowed only if there are 
     // no previous fs states in any of the directories
-    for( int idx = 0; idx < getNumStorageDirs(); idx++ ) {
-      StorageDirectory sd = getStorageDir( idx );
-      if( sd.getPreviousDir().exists() )
-        throw new InconsistentFSStateException( sd.root,
-                                                "previous fs state should not exist during upgrade. "
-                                                + "Finalize or rollback first." );
+    for(int idx = 0; idx < getNumStorageDirs(); idx++) {
+      StorageDirectory sd = getStorageDir(idx);
+      if (sd.getPreviousDir().exists())
+        throw new InconsistentFSStateException(sd.root,
+                                               "previous fs state should not exist during upgrade. "
+                                               + "Finalize or rollback first.");
     }
 
     // load the latest image
@@ -246,32 +246,32 @@
     int oldLV = this.getLayoutVersion();
     this.layoutVersion = FSConstants.LAYOUT_VERSION;
     this.checkpointTime = FSNamesystem.now();
-    for( int idx = 0; idx < getNumStorageDirs(); idx++ ) {
-      StorageDirectory sd = getStorageDir( idx );
-      LOG.info( "Upgrading image directory " + sd.root 
-                + ".\n   old LV = " + oldLV
-                + "; old CTime = " + oldCTime
-                + ".\n   new LV = " + this.getLayoutVersion()
-                + "; new CTime = " + this.getCTime() );
+    for(int idx = 0; idx < getNumStorageDirs(); idx++) {
+      StorageDirectory sd = getStorageDir(idx);
+      LOG.info("Upgrading image directory " + sd.root 
+               + ".\n   old LV = " + oldLV
+               + "; old CTime = " + oldCTime
+               + ".\n   new LV = " + this.getLayoutVersion()
+               + "; new CTime = " + this.getCTime());
       File curDir = sd.getCurrentDir();
       File prevDir = sd.getPreviousDir();
       File tmpDir = sd.getPreviousTmp();
       assert curDir.exists() : "Current directory must exist.";
-      assert ! prevDir.exists() : "prvious directory must not exist.";
-      assert ! tmpDir.exists() : "prvious.tmp directory must not exist.";
+      assert !prevDir.exists() : "prvious directory must not exist.";
+      assert !tmpDir.exists() : "prvious.tmp directory must not exist.";
       // rename current to tmp
-      rename( curDir, tmpDir );
+      rename(curDir, tmpDir);
       // save new image
-      if( ! curDir.mkdir() )
-        throw new IOException("Cannot create directory " + curDir );
-      saveFSImage( getImageFile( sd, NameNodeFile.IMAGE ));
-      editLog.createEditLogFile( getImageFile( sd, NameNodeFile.EDITS ));
+      if (!curDir.mkdir())
+        throw new IOException("Cannot create directory " + curDir);
+      saveFSImage(getImageFile(sd, NameNodeFile.IMAGE));
+      editLog.createEditLogFile(getImageFile(sd, NameNodeFile.EDITS));
       // write version and time files
       sd.write();
       // rename tmp to previous
-      rename( tmpDir, prevDir );
+      rename(tmpDir, prevDir);
       isUpgradeFinalized = false;
-      LOG.info( "Upgrade of " + sd.root + " is complete." );
+      LOG.info("Upgrade of " + sd.root + " is complete.");
     }
     editLog.open();
   }
@@ -283,91 +283,91 @@
     boolean canRollback = false;
     FSImage prevState = new FSImage();
     prevState.layoutVersion = FSConstants.LAYOUT_VERSION;
-    for( int idx = 0; idx < getNumStorageDirs(); idx++ ) {
-      StorageDirectory sd = getStorageDir( idx );
+    for(int idx = 0; idx < getNumStorageDirs(); idx++) {
+      StorageDirectory sd = getStorageDir(idx);
       File prevDir = sd.getPreviousDir();
-      if( ! prevDir.exists() ) {  // use current directory then
-        LOG.info( "Storage directory " + sd.root
-                  + " does not contain previous fs state." );
+      if (!prevDir.exists()) {  // use current directory then
+        LOG.info("Storage directory " + sd.root
+                 + " does not contain previous fs state.");
         sd.read(); // read and verify consistency with other directories
         continue;
       }
-      StorageDirectory sdPrev = prevState.new StorageDirectory( sd.root );
-      sdPrev.read( sdPrev.getPreviousVersionFile() );  // read and verify consistency of the prev dir
+      StorageDirectory sdPrev = prevState.new StorageDirectory(sd.root);
+      sdPrev.read(sdPrev.getPreviousVersionFile());  // read and verify consistency of the prev dir
       canRollback = true;
     }
-    if( ! canRollback )
-      throw new IOException( "Cannot rollback. " 
-                             + "None of the storage directories contain previous fs state." );
+    if (!canRollback)
+      throw new IOException("Cannot rollback. " 
+                            + "None of the storage directories contain previous fs state.");
 
     // Now that we know all directories are going to be consistent
     // Do rollback for each directory containing previous state
-    for( int idx = 0; idx < getNumStorageDirs(); idx++ ) {
-      StorageDirectory sd = getStorageDir( idx );
+    for(int idx = 0; idx < getNumStorageDirs(); idx++) {
+      StorageDirectory sd = getStorageDir(idx);
       File prevDir = sd.getPreviousDir();
-      if( ! prevDir.exists() )
+      if (!prevDir.exists())
         continue;
 
-      LOG.info( "Rolling back storage directory " + sd.root 
-                + ".\n   new LV = " + prevState.getLayoutVersion()
-                + "; new CTime = " + prevState.getCTime() );
+      LOG.info("Rolling back storage directory " + sd.root 
+               + ".\n   new LV = " + prevState.getLayoutVersion()
+               + "; new CTime = " + prevState.getCTime());
       File tmpDir = sd.getRemovedTmp();
-      assert ! tmpDir.exists() : "removed.tmp directory must not exist.";
+      assert !tmpDir.exists() : "removed.tmp directory must not exist.";
       // rename current to tmp
       File curDir = sd.getCurrentDir();
       assert curDir.exists() : "Current directory must exist.";
-      rename( curDir, tmpDir );
+      rename(curDir, tmpDir);
       // rename previous to current
-      rename( prevDir, curDir );
+      rename(prevDir, curDir);
 
       // delete tmp dir
-      deleteDir( tmpDir );
-      LOG.info( "Rollback of " + sd.root + " is complete." );
+      deleteDir(tmpDir);
+      LOG.info("Rollback of " + sd.root + " is complete.");
     }
     isUpgradeFinalized = true;
   }
 
-  private void doFinalize( StorageDirectory sd ) throws IOException {
+  private void doFinalize(StorageDirectory sd) throws IOException {
     File prevDir = sd.getPreviousDir();
-    if( ! prevDir.exists() )
+    if (!prevDir.exists())
       return; // already discarded
-    LOG.info( "Finalizing upgrade for storage directory " 
-              + sd.root 
-              + ".\n   cur LV = " + this.getLayoutVersion()
-              + "; cur CTime = " + this.getCTime() );
+    LOG.info("Finalizing upgrade for storage directory " 
+             + sd.root 
+             + ".\n   cur LV = " + this.getLayoutVersion()
+             + "; cur CTime = " + this.getCTime());
     assert sd.getCurrentDir().exists() : "Current directory must exist.";
     final File tmpDir = sd.getFinalizedTmp();
     // rename previous to tmp and remove
-    rename( prevDir, tmpDir );
-    deleteDir( tmpDir );
+    rename(prevDir, tmpDir);
+    deleteDir(tmpDir);
     isUpgradeFinalized = true;
-    LOG.info( "Finalize upgrade for " + sd.root + " is complete." );
+    LOG.info("Finalize upgrade for " + sd.root + " is complete.");
   }
 
   void finalizeUpgrade() throws IOException {
-    for( int idx = 0; idx < getNumStorageDirs(); idx++ )
-      doFinalize( getStorageDir( idx ));
+    for(int idx = 0; idx < getNumStorageDirs(); idx++)
+      doFinalize(getStorageDir(idx));
   }
 
   boolean isUpgradeFinalized() {
     return isUpgradeFinalized;
   }
 
-  protected void getFields( Properties props, 
-                            StorageDirectory sd 
-                            ) throws IOException {
-    super.getFields( props, sd );
-    if( layoutVersion == 0 )
+  protected void getFields(Properties props, 
+                           StorageDirectory sd 
+                           ) throws IOException {
+    super.getFields(props, sd);
+    if (layoutVersion == 0)
       throw new IOException("NameNode directory " 
-                            + sd.root + " is not formatted." );
-    this.checkpointTime = readCheckpointTime( sd );
+                            + sd.root + " is not formatted.");
+    this.checkpointTime = readCheckpointTime(sd);
   }
 
-  long readCheckpointTime( StorageDirectory sd ) throws IOException {
-    File timeFile = getImageFile( sd, NameNodeFile.TIME );
+  long readCheckpointTime(StorageDirectory sd) throws IOException {
+    File timeFile = getImageFile(sd, NameNodeFile.TIME);
     long timeStamp = 0L;
-    if( timeFile.exists() && timeFile.canRead() ) {
-      DataInputStream in = new DataInputStream( new FileInputStream(timeFile) );
+    if (timeFile.exists() && timeFile.canRead()) {
+      DataInputStream in = new DataInputStream(new FileInputStream(timeFile));
       try {
         timeStamp = in.readLong();
       } finally {
@@ -387,11 +387,11 @@
    * @param sd storage directory
    * @throws IOException
    */
-  protected void setFields( Properties props, 
-                            StorageDirectory sd 
-                            ) throws IOException {
-    super.setFields( props, sd );
-    writeCheckpointTime( sd );
+  protected void setFields(Properties props, 
+                           StorageDirectory sd 
+                           ) throws IOException {
+    super.setFields(props, sd);
+    writeCheckpointTime(sd);
   }
 
   /**
@@ -400,15 +400,15 @@
    * @param sd
    * @throws IOException
    */
-  void writeCheckpointTime( StorageDirectory sd ) throws IOException {
-    if( checkpointTime < 0L )
+  void writeCheckpointTime(StorageDirectory sd) throws IOException {
+    if (checkpointTime < 0L)
       return; // do not write negative time
-    File timeFile = getImageFile( sd, NameNodeFile.TIME );
+    File timeFile = getImageFile(sd, NameNodeFile.TIME);
     if (timeFile.exists()) { timeFile.delete(); }
     DataOutputStream out = new DataOutputStream(
                                                 new FileOutputStream(timeFile));
     try {
-      out.writeLong( checkpointTime );
+      out.writeLong(checkpointTime);
     } finally {
       out.close();
     }
@@ -422,41 +422,41 @@
    */
   void processIOError(int index) throws IOException {
     int nrDirs = getNumStorageDirs();
-    assert( index >= 0 && index < nrDirs );
-    if( nrDirs == 1 )
+    assert(index >= 0 && index < nrDirs);
+    if (nrDirs == 1)
       throw new IOException("Checkpoint directories inaccessible.");
-    storageDirs.remove( index );
+    storageDirs.remove(index);
   }
 
   FSEditLog getEditLog() {
     return editLog;
   }
 
-  boolean isConversionNeeded( StorageDirectory sd ) throws IOException {
-    File oldImageDir = new File( sd.root, "image" );
-    if( ! oldImageDir.exists() )
+  boolean isConversionNeeded(StorageDirectory sd) throws IOException {
+    File oldImageDir = new File(sd.root, "image");
+    if (!oldImageDir.exists())
       return false;
     // check consistency of the old storage
-    if( ! oldImageDir.isDirectory() )
-      throw new InconsistentFSStateException( sd.root,
-                                              oldImageDir + " is not a directory." );
-    if( ! oldImageDir.canWrite() )
-      throw new InconsistentFSStateException( sd.root,
-                                              oldImageDir + " is not writable." );
+    if (!oldImageDir.isDirectory())
+      throw new InconsistentFSStateException(sd.root,
+                                             oldImageDir + " is not a directory.");
+    if (!oldImageDir.canWrite())
+      throw new InconsistentFSStateException(sd.root,
+                                             oldImageDir + " is not writable.");
     return true;
   }
   
-  private boolean convertLayout( StorageDirectory sd ) throws IOException {
+  private boolean convertLayout(StorageDirectory sd) throws IOException {
     assert FSConstants.LAYOUT_VERSION < LAST_PRE_UPGRADE_LAYOUT_VERSION :
       "Bad current layout version: FSConstants.LAYOUT_VERSION should decrease";
-    File oldImageDir = new File( sd.root, "image" );
+    File oldImageDir = new File(sd.root, "image");
     assert oldImageDir.exists() : "Old image directory is missing";
-    File oldImage = new File( oldImageDir, "fsimage" );
+    File oldImage = new File(oldImageDir, "fsimage");
     
-    LOG.info( "Old layout version directory " + oldImageDir
-              + " is found. New layout version is "
-              + FSConstants.LAYOUT_VERSION );
-    LOG.info( "Trying to convert ..." );
+    LOG.info("Old layout version directory " + oldImageDir
+             + " is found. New layout version is "
+             + FSConstants.LAYOUT_VERSION);
+    LOG.info("Trying to convert ...");
 
     // we did not use locking for the pre upgrade layout, so we cannot prevent 
     // old name-nodes from running in the same directory as the new ones
@@ -464,35 +464,35 @@
     // check new storage
     File newImageDir = sd.getCurrentDir();
     File versionF = sd.getVersionFile();
-    if( versionF.exists() )
-      throw new IOException( "Version file already exists: " + versionF );
-    if( newImageDir.exists() ) // // somebody created current dir manually
-      deleteDir( newImageDir );
+    if (versionF.exists())
+      throw new IOException("Version file already exists: " + versionF);
+    if (newImageDir.exists()) // // somebody created current dir manually
+      deleteDir(newImageDir);
 
     // move old image files into new location
-    rename( oldImageDir, newImageDir );
-    File oldEdits1 = new File( sd.root, "edits" );
+    rename(oldImageDir, newImageDir);
+    File oldEdits1 = new File(sd.root, "edits");
     // move old edits into data
-    if( oldEdits1.exists() )
-      rename( oldEdits1, getImageFile( sd, NameNodeFile.EDITS ));
-    File oldEdits2 = new File( sd.root, "edits.new" );
-    if( oldEdits2.exists() )
-      rename( oldEdits2, getImageFile( sd, NameNodeFile.EDITS_NEW ));
+    if (oldEdits1.exists())
+      rename(oldEdits1, getImageFile(sd, NameNodeFile.EDITS));
+    File oldEdits2 = new File(sd.root, "edits.new");
+    if (oldEdits2.exists())
+      rename(oldEdits2, getImageFile(sd, NameNodeFile.EDITS_NEW));
 
     // Write new layout with 
     // setting layoutVersion = LAST_PRE_UPGRADE_LAYOUT_VERSION
     // means the actual version should be obtained from the image file
     this.layoutVersion = LAST_PRE_UPGRADE_LAYOUT_VERSION;
-    File newImageFile = getImageFile( sd, NameNodeFile.IMAGE );
+    File newImageFile = getImageFile(sd, NameNodeFile.IMAGE);
     boolean needReformat = false;
-    if( ! newImageFile.exists() ) {
+    if (!newImageFile.exists()) {
       // in pre upgrade versions image file was allowed not to exist
       // we treat it as non formatted then
-      LOG.info( "Old image file " + oldImage + " does not exist. " );
+      LOG.info("Old image file " + oldImage + " does not exist. ");
       needReformat = true;
     } else {
       sd.write();
-      LOG.info( "Conversion of " + oldImage + " is complete." );
+      LOG.info("Conversion of " + oldImage + " is complete.");
     }
     return needReformat;
   }
@@ -500,15 +500,15 @@
   //
   // Atomic move sequence, to recover from interrupted checkpoint
   //
-  void recoverInterruptedCheckpoint( StorageDirectory sd ) throws IOException {
-    File curFile = getImageFile( sd, NameNodeFile.IMAGE );
-    File ckptFile = getImageFile( sd, NameNodeFile.IMAGE_NEW );
+  void recoverInterruptedCheckpoint(StorageDirectory sd) throws IOException {
+    File curFile = getImageFile(sd, NameNodeFile.IMAGE);
+    File ckptFile = getImageFile(sd, NameNodeFile.IMAGE_NEW);
 
     //
     // If we were in the midst of a checkpoint
     //
     if (ckptFile.exists()) {
-      if (getImageFile( sd, NameNodeFile.EDITS_NEW ).exists()) {
+      if (getImageFile(sd, NameNodeFile.EDITS_NEW).exists()) {
         //
         // checkpointing migth have uploaded a new
         // merged image, but we discard it here because we are
@@ -552,23 +552,23 @@
     boolean needToSave = false;
     isUpgradeFinalized = true;
     for (int idx = 0; idx < getNumStorageDirs(); idx++) {
-      StorageDirectory sd = getStorageDir( idx );
-      recoverInterruptedCheckpoint( sd );
-      if( ! sd.getVersionFile().exists() ) {
+      StorageDirectory sd = getStorageDir(idx);
+      recoverInterruptedCheckpoint(sd);
+      if (!sd.getVersionFile().exists()) {
         needToSave |= true;
         continue; // some of them might have just been formatted
       }
-      assert getImageFile( sd, NameNodeFile.IMAGE ).exists() :
+      assert getImageFile(sd, NameNodeFile.IMAGE).exists() :
         "Image file must exist.";
-      checkpointTime = readCheckpointTime( sd );
-      if( latestCheckpointTime < checkpointTime ) {
+      checkpointTime = readCheckpointTime(sd);
+      if (latestCheckpointTime < checkpointTime) {
         latestCheckpointTime = checkpointTime;
         latestSD = sd;
       }
-      if( checkpointTime <= 0L )
+      if (checkpointTime <= 0L)
         needToSave |= true;
       // set finalized flag
-      isUpgradeFinalized &= ! sd.getPreviousDir().exists();
+      isUpgradeFinalized &= !sd.getPreviousDir().exists();
     }
     assert latestSD != null : "Latest storage directory was not determined.";
 
@@ -576,13 +576,13 @@
     // Load in bits
     //
     latestSD.read();
-    needToSave |= loadFSImage( getImageFile( latestSD, NameNodeFile.IMAGE ));
+    needToSave |= loadFSImage(getImageFile(latestSD, NameNodeFile.IMAGE));
 
     //
     // read in the editlog from the same directory from
     // which we read in the image
     //
-    needToSave |= ( loadFSEdits( latestSD ) > 0 );
+    needToSave |= (loadFSEdits(latestSD) > 0);
 
     return needToSave;
   }
@@ -592,7 +592,7 @@
    * filenames and blocks.  Return whether we should
    * "re-save" and consolidate the edit-logs
    */
-  boolean loadFSImage( File curFile ) throws IOException {
+  boolean loadFSImage(File curFile) throws IOException {
     assert this.getLayoutVersion() < 0 : "Negative layout version is expected.";
     assert curFile != null : "curFile is null";
 
@@ -613,13 +613,13 @@
       // read image version: first appeared in version -1
       imgVersion = in.readInt();
       // read namespaceID: first appeared in version -2
-      if( imgVersion <= -2 )
+      if (imgVersion <= -2)
         this.namespaceID = in.readInt();
       // read number of files
       int numFiles = 0;
       // version 0 does not store version #
       // starts directly with the number of files
-      if( imgVersion >= 0 ) {
+      if (imgVersion >= 0) {
         numFiles = imgVersion;
         imgVersion = 0;
       } else {
@@ -627,7 +627,7 @@
       }
       this.layoutVersion = imgVersion;
 
-      needToSave = ( imgVersion != FSConstants.LAYOUT_VERSION );
+      needToSave = (imgVersion != FSConstants.LAYOUT_VERSION);
 
       // read file info
       short replication = FSNamesystem.getFSNamesystem().getDefaultReplication();
@@ -635,9 +635,9 @@
         UTF8 name = new UTF8();
         name.readFields(in);
         // version 0 does not support per file replication
-        if( !(imgVersion >= 0) ) {
+        if (!(imgVersion >= 0)) {
           replication = in.readShort(); // other versions do
-          replication = FSEditLog.adjustReplication( replication );
+          replication = FSEditLog.adjustReplication(replication);
         }
         int numBlocks = in.readInt();
         Block blocks[] = null;
@@ -648,11 +648,11 @@
             blocks[j].readFields(in);
           }
         }
-        fsDir.unprotectedAddFile(name, blocks, replication );
+        fsDir.unprotectedAddFile(name, blocks, replication);
       }
       
       // load datanode info
-      this.loadDatanodes( imgVersion, in );
+      this.loadDatanodes(imgVersion, in);
     } finally {
       in.close();
     }
@@ -667,19 +667,19 @@
    * @return number of edits loaded
    * @throws IOException
    */
-  int loadFSEdits( StorageDirectory sd ) throws IOException {
+  int loadFSEdits(StorageDirectory sd) throws IOException {
     int numEdits = 0;
-    numEdits = editLog.loadFSEdits( getImageFile( sd, NameNodeFile.EDITS ));
-    File editsNew = getImageFile( sd, NameNodeFile.EDITS_NEW );
-    if( editsNew.exists() ) 
-      numEdits += editLog.loadFSEdits( editsNew );
+    numEdits = editLog.loadFSEdits(getImageFile(sd, NameNodeFile.EDITS));
+    File editsNew = getImageFile(sd, NameNodeFile.EDITS_NEW);
+    if (editsNew.exists()) 
+      numEdits += editLog.loadFSEdits(editsNew);
     return numEdits;
   }
 
   /**
    * Save the contents of the FS image to the file.
    */
-  void saveFSImage( File newFile  ) throws IOException {
+  void saveFSImage(File newFile ) throws IOException {
     FSDirectory fsDir = FSNamesystem.getFSNamesystem().dir;
     //
     // Write out data
@@ -691,8 +691,8 @@
       out.writeInt(FSConstants.LAYOUT_VERSION);
       out.writeInt(namespaceID);
       out.writeInt(fsDir.rootDir.numItemsInTree() - 1);
-      saveImage( "", fsDir.rootDir, out );
-      saveDatanodes( out );
+      saveImage("", fsDir.rootDir, out);
+      saveDatanodes(out);
     } finally {
       out.close();
     }
@@ -704,9 +704,9 @@
   void saveFSImage() throws IOException {
     editLog.createNewIfMissing();
     for (int idx = 0; idx < getNumStorageDirs(); idx++) {
-      StorageDirectory sd = getStorageDir( idx );
-      saveFSImage( getImageFile( sd, NameNodeFile.IMAGE_NEW ));
-      editLog.createEditLogFile( getImageFile( sd, NameNodeFile.EDITS ));
+      StorageDirectory sd = getStorageDir(idx);
+      saveFSImage(getImageFile(sd, NameNodeFile.IMAGE_NEW));
+      editLog.createEditLogFile(getImageFile(sd, NameNodeFile.EDITS));
     }
     rollFSImage();
   }
@@ -725,27 +725,27 @@
    */
   private int newNamespaceID() {
     Random r = new Random();
-    r.setSeed( FSNamesystem.now() );
+    r.setSeed(FSNamesystem.now());
     int newID = 0;
-    while( newID == 0)
-      newID = r.nextInt( 0x7FFFFFFF );  // use 31 bits only
+    while(newID == 0)
+      newID = r.nextInt(0x7FFFFFFF);  // use 31 bits only
     return newID;
   }
 
   /** Create new dfs name directory.  Caution: this destroys all files
    * in this filesystem. */
-  void format( StorageDirectory sd ) throws IOException {
+  void format(StorageDirectory sd) throws IOException {
     sd.clearDirectory(); // create currrent dir
     sd.lock();
     try {
-      saveFSImage( getImageFile( sd, NameNodeFile.IMAGE ));
-      editLog.createEditLogFile( getImageFile( sd, NameNodeFile.EDITS ));
+      saveFSImage(getImageFile(sd, NameNodeFile.IMAGE));
+      editLog.createEditLogFile(getImageFile(sd, NameNodeFile.EDITS));
       sd.write();
     } finally {
       sd.unlock();
     }
-    LOG.info( "Storage directory " + sd.root 
-              + " has been successfully formatted." );
+    LOG.info("Storage directory " + sd.root 
+             + " has been successfully formatted.");
   }
 
   public void format() throws IOException {
@@ -753,9 +753,9 @@
     this.namespaceID = newNamespaceID();
     this.cTime = 0L;
     this.checkpointTime = FSNamesystem.now();
-    for( int idx = 0; idx < getNumStorageDirs(); idx++ ) {
-      StorageDirectory sd = getStorageDir( idx );
-      format( sd );
+    for(int idx = 0; idx < getNumStorageDirs(); idx++) {
+      StorageDirectory sd = getStorageDir(idx);
+      format(sd);
     }
   }
 
@@ -764,24 +764,24 @@
    */
   private static void saveImage(String parentPrefix, 
                                 FSDirectory.INode root, 
-                                DataOutputStream out ) throws IOException {
+                                DataOutputStream out) throws IOException {
     String fullName = "";
-    if( root.getParent() != null) {
+    if (root.getParent() != null) {
       fullName = parentPrefix + "/" + root.getLocalName();
       new UTF8(fullName).write(out);
-      out.writeShort( root.getReplication() );
-      if( root.isDir() ) {
+      out.writeShort(root.getReplication());
+      if (root.isDir()) {
         out.writeInt(0);
       } else {
         int nrBlocks = root.getBlocks().length;
-        out.writeInt( nrBlocks );
+        out.writeInt(nrBlocks);
         for (int i = 0; i < nrBlocks; i++)
           root.getBlocks()[i].write(out);
       }
     }
     for(Iterator<INode> it = root.getChildIterator(); it != null &&
-          it.hasNext(); ) {
-      saveImage( fullName, it.next(), out );
+          it.hasNext();) {
+      saveImage(fullName, it.next(), out);
     }
   }
 
@@ -793,22 +793,22 @@
    * @param out output stream
    * @throws IOException
    */
-  void saveDatanodes( DataOutputStream out ) throws IOException {
+  void saveDatanodes(DataOutputStream out) throws IOException {
     Map datanodeMap = FSNamesystem.getFSNamesystem().datanodeMap;
     int size = datanodeMap.size();
-    out.writeInt( size );
-    for( Iterator it = datanodeMap.values().iterator(); it.hasNext(); ) {
+    out.writeInt(size);
+    for(Iterator it = datanodeMap.values().iterator(); it.hasNext();) {
       DatanodeImage nodeImage = new DatanodeImage((DatanodeDescriptor) it.next());
-      nodeImage.write( out );
+      nodeImage.write(out);
     }
   }
 
-  void loadDatanodes( int version, DataInputStream in ) throws IOException {
-    if( version > -3 ) // pre datanode image version
+  void loadDatanodes(int version, DataInputStream in) throws IOException {
+    if (version > -3) // pre datanode image version
       return;
     FSNamesystem fsNamesys = FSNamesystem.getFSNamesystem();
     int size = in.readInt();
-    for( int i = 0; i < size; i++ ) {
+    for(int i = 0; i < size; i++) {
       DatanodeImage nodeImage = new DatanodeImage();
       nodeImage.readFields(in);
       fsNamesys.unprotectedAddDatanode(nodeImage.getDatanodeDescriptor());
@@ -827,9 +827,9 @@
     if (!editLog.existsNew()) {
       throw new IOException("New Edits file does not exist");
     }
-    for( int idx = 0; idx < getNumStorageDirs(); idx++ ) {
-      StorageDirectory sd = getStorageDir( idx );
-      File ckpt = getImageFile( sd, NameNodeFile.IMAGE_NEW );
+    for(int idx = 0; idx < getNumStorageDirs(); idx++) {
+      StorageDirectory sd = getStorageDir(idx);
+      File ckpt = getImageFile(sd, NameNodeFile.IMAGE_NEW);
       if (!ckpt.exists()) {
         throw new IOException("Checkpoint file " + ckpt +
                               " does not exist");
@@ -840,10 +840,10 @@
     //
     // Renames new image
     //
-    for( int idx = 0; idx < getNumStorageDirs(); idx++ ) {
-      StorageDirectory sd = getStorageDir( idx );
-      File ckpt = getImageFile( sd, NameNodeFile.IMAGE_NEW );
-      File curFile = getImageFile( sd, NameNodeFile.IMAGE );
+    for(int idx = 0; idx < getNumStorageDirs(); idx++) {
+      StorageDirectory sd = getStorageDir(idx);
+      File ckpt = getImageFile(sd, NameNodeFile.IMAGE_NEW);
+      File curFile = getImageFile(sd, NameNodeFile.IMAGE);
       // renameTo fails on Windows if the destination file 
       // already exists.
       if (!ckpt.renameTo(curFile)) {
@@ -860,12 +860,12 @@
     //
     this.layoutVersion = FSConstants.LAYOUT_VERSION;
     this.checkpointTime = FSNamesystem.now();
-    for( int idx = 0; idx < getNumStorageDirs(); idx++ ) {
-      StorageDirectory sd = getStorageDir( idx );
+    for(int idx = 0; idx < getNumStorageDirs(); idx++) {
+      StorageDirectory sd = getStorageDir(idx);
       try {
         sd.write();
       } catch (IOException e) {
-        LOG.error( "Cannot write file " + sd.root, e );
+        LOG.error("Cannot write file " + sd.root, e);
         editLog.processIOError(idx);
         idx--;
       }
@@ -881,7 +881,7 @@
    * Return the name of the image file.
    */
   File getFsImageName() {
-    return getImageFile( 0, NameNodeFile.IMAGE );
+    return getImageFile(0, NameNodeFile.IMAGE);
   }
 
   /**
@@ -890,8 +890,8 @@
    */
   File[] getFsImageNameCheckpoint() {
     File[] list = new File[getNumStorageDirs()];
-    for( int i = 0; i < getNumStorageDirs(); i++ ) {
-      list[i] = getImageFile( getStorageDir( i ), NameNodeFile.IMAGE_NEW );
+    for(int i = 0; i < getNumStorageDirs(); i++) {
+      list[i] = getImageFile(getStorageDir(i), NameNodeFile.IMAGE_NEW);
     }
     return list;
   }



Mime
View raw message