Sfoglia il codice sorgente

HDFS-10693. metaSave should print blocks, not LightWeightHashSet. Contributed by Yuanbo Liu.

(cherry picked from commit 4d3af47f2765f6f57936d316ef2a4150b787cc97)
Konstantin V Shvachko 8 anni fa
parent
commit
bfc261f2a0

+ 4 - 3
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/InvalidateBlocks.java

@@ -32,6 +32,7 @@ import org.apache.hadoop.hdfs.protocol.Block;
 import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
 import org.apache.hadoop.hdfs.server.namenode.NameNode;
 import org.apache.hadoop.hdfs.util.LightWeightHashSet;
+import org.apache.hadoop.util.StringUtils;
 import org.apache.hadoop.util.Time;
 import org.apache.hadoop.hdfs.DFSUtil;
 
@@ -140,7 +141,7 @@ class InvalidateBlocks {
   /** Print the contents to out. */
   synchronized void dump(final PrintWriter out) {
     final int size = node2blocks.values().size();
-    out.println("Metasave: Blocks " + numBlocks 
+    out.println("Metasave: Blocks " + numBlocks
         + " waiting deletion from " + size + " datanodes.");
     if (size == 0) {
       return;
@@ -150,7 +151,7 @@ class InvalidateBlocks {
       final LightWeightHashSet<Block> blocks = entry.getValue();
       if (blocks.size() > 0) {
         out.println(entry.getKey());
-        out.println(blocks);
+        out.println(StringUtils.join(",", blocks));
       }
     }
   }
@@ -196,7 +197,7 @@ class InvalidateBlocks {
     numBlocks -= toInvalidate.size();
     return toInvalidate;
   }
-  
+
   synchronized void clear() {
     node2blocks.clear();
     numBlocks = 0;

+ 3 - 1
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestMetaSave.java

@@ -163,7 +163,9 @@ public class TestMetaSave {
       assertTrue(line.equals("Metasave: Blocks 2 waiting deletion from 1 datanodes."));
      //skip 2 lines to reach HDFS-9033 scenario.
       line = reader.readLine();
+      // skip 1 line for Corrupt Blocks section.
       line = reader.readLine();
+      assertTrue(line.contains("blk"));
       line = reader.readLine();
       assertTrue(line.equals("Metasave: Number of datanodes: 2"));
       line = reader.readLine();
@@ -221,7 +223,7 @@ public class TestMetaSave {
 
   /**
    * Returns a File for the given name inside the log directory.
-   * 
+   *
    * @param name String file name
    * @return File for given name inside log directory
    */