You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by aa...@apache.org on 2016/05/08 22:50:49 UTC

hadoop git commit: HDFS-10337. OfflineEditsViewer stats option should print 0 instead of null for the count of operations. Contributed by Yiqun Lin.

Repository: hadoop
Updated Branches:
  refs/heads/trunk 2750fb900 -> 411fb4b2b


HDFS-10337. OfflineEditsViewer stats option should print 0 instead of null for the count of operations. Contributed by Yiqun Lin.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/411fb4b2
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/411fb4b2
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/411fb4b2

Branch: refs/heads/trunk
Commit: 411fb4b2b792ad71722f47b61a1c6745e61bd5e5
Parents: 2750fb9
Author: Akira Ajisaka <aa...@apache.org>
Authored: Sun May 8 15:49:13 2016 -0700
Committer: Akira Ajisaka <aa...@apache.org>
Committed: Sun May 8 15:49:13 2016 -0700

----------------------------------------------------------------------
 .../StatisticsEditsVisitor.java                 | 11 +++----
 .../TestOfflineEditsViewer.java                 | 30 ++++++++++++++++++++
 2 files changed, 36 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/411fb4b2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/StatisticsEditsVisitor.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/StatisticsEditsVisitor.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/StatisticsEditsVisitor.java
index c173e17..c84e2ed 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/StatisticsEditsVisitor.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/StatisticsEditsVisitor.java
@@ -107,16 +107,17 @@ public class StatisticsEditsVisitor implements OfflineEditsVisitor {
    * @return statistics in in string format, suitable for printing
    */
   public String getStatisticsString() {
-    StringBuffer sb = new StringBuffer();
+    StringBuilder sb = new StringBuilder();
     sb.append(String.format(
         "    %-30.30s      : %d%n",
         "VERSION", version));
     for(FSEditLogOpCodes opCode : FSEditLogOpCodes.values()) {
+      Long count = opCodeCount.get(opCode);
       sb.append(String.format(
-        "    %-30.30s (%3d): %d%n",
-        opCode.toString(),
-        opCode.getOpCode(),
-        opCodeCount.get(opCode)));
+          "    %-30.30s (%3d): %d%n",
+          opCode.toString(),
+          opCode.getOpCode(),
+          count == null ? Long.valueOf(0L) : count));
     }
     return sb.toString();
   }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/411fb4b2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/TestOfflineEditsViewer.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/TestOfflineEditsViewer.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/TestOfflineEditsViewer.java
index c5bc721..a21bc8f 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/TestOfflineEditsViewer.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/TestOfflineEditsViewer.java
@@ -28,6 +28,7 @@ import java.io.IOException;
 import java.io.PrintStream;
 import java.nio.ByteBuffer;
 import java.nio.channels.FileChannel;
+import java.util.Map;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.logging.Log;
@@ -308,4 +309,33 @@ public class TestOfflineEditsViewer {
       IOUtils.closeStream(out);
     }
   }
+
+  @Test
+  public void testStatisticsStrWithNullOpCodeCount() throws IOException {
+    String editFilename = nnHelper.generateEdits();
+    String outFilename = editFilename + ".stats";
+    FileOutputStream fout = new FileOutputStream(outFilename);
+    StatisticsEditsVisitor visitor = new StatisticsEditsVisitor(fout);
+    OfflineEditsViewer oev = new OfflineEditsViewer();
+
+    String statisticsStr = null;
+    if (oev.go(editFilename, outFilename, "stats", new Flags(), visitor) == 0) {
+      statisticsStr = visitor.getStatisticsString();
+    }
+    Assert.assertNotNull(statisticsStr);
+
+    String str;
+    Long count;
+    Map<FSEditLogOpCodes, Long> opCodeCount = visitor.getStatistics();
+    for (FSEditLogOpCodes opCode : FSEditLogOpCodes.values()) {
+      count = opCodeCount.get(opCode);
+      // Verify the str when the opCode's count is null
+      if (count == null) {
+        str =
+            String.format("    %-30.30s (%3d): %d%n", opCode.toString(),
+                opCode.getOpCode(), Long.valueOf(0L));
+        assertTrue(statisticsStr.contains(str));
+      }
+    }
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org