hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sj...@apache.org
Subject [46/50] hadoop git commit: HADOOP-13368. DFSOpsCountStatistics$OpType#fromSymbol and s3a.Statistic#fromSymbol should be O(1) operation. Contributed by Mingliang Liu.
Date Sat, 16 Jul 2016 03:22:07 GMT
HADOOP-13368. DFSOpsCountStatistics$OpType#fromSymbol and s3a.Statistic#fromSymbol should be
O(1) operation. Contributed by Mingliang Liu.


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

Branch: refs/heads/YARN-5355
Commit: c2f9cd584cd7852b4745396494cc0c423eb645c1
Parents: 4421620
Author: Jitendra Pandey <jitendra@apache.org>
Authored: Fri Jul 15 14:28:53 2016 -0700
Committer: Jitendra Pandey <jitendra@apache.org>
Committed: Fri Jul 15 14:28:53 2016 -0700

----------------------------------------------------------------------
 .../hadoop/hdfs/DFSOpsCountStatistics.java      | 18 ++++++++++--------
 .../hadoop/hdfs/TestDFSOpsCountStatistics.java  |  2 ++
 .../org/apache/hadoop/fs/s3a/Statistic.java     | 20 ++++++++++++--------
 3 files changed, 24 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/c2f9cd58/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSOpsCountStatistics.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSOpsCountStatistics.java
b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSOpsCountStatistics.java
index 83d880a..d631dd4 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSOpsCountStatistics.java
+++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSOpsCountStatistics.java
@@ -21,6 +21,7 @@ import org.apache.hadoop.fs.StorageStatistics;
 import org.apache.hadoop.hdfs.protocol.HdfsConstants;
 
 import java.util.EnumMap;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -88,6 +89,14 @@ public class DFSOpsCountStatistics extends StorageStatistics {
     TRUNCATE(CommonStatisticNames.OP_TRUNCATE),
     UNSET_STORAGE_POLICY("op_unset_storage_policy");
 
+    private static final Map<String, OpType> SYMBOL_MAP =
+        new HashMap<>(OpType.values().length);
+    static {
+      for (OpType opType : values()) {
+        SYMBOL_MAP.put(opType.getSymbol(), opType);
+      }
+    }
+
     private final String symbol;
 
     OpType(String symbol) {
@@ -99,14 +108,7 @@ public class DFSOpsCountStatistics extends StorageStatistics {
     }
 
     public static OpType fromSymbol(String symbol) {
-      if (symbol != null) {
-        for (OpType opType : values()) {
-          if (opType.getSymbol().equals(symbol)) {
-            return opType;
-          }
-        }
-      }
-      return null;
+      return SYMBOL_MAP.get(symbol);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/hadoop/blob/c2f9cd58/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/TestDFSOpsCountStatistics.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/TestDFSOpsCountStatistics.java
b/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/TestDFSOpsCountStatistics.java
index d63ef10..5ccee3e 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/TestDFSOpsCountStatistics.java
+++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/TestDFSOpsCountStatistics.java
@@ -111,12 +111,14 @@ public class TestDFSOpsCountStatistics {
 
   @Test
   public void testGetLong() {
+    assertNull(statistics.getLong(null));
     assertNull(statistics.getLong(NO_SUCH_OP));
     verifyStatistics();
   }
 
   @Test
   public void testIsTracked() {
+    assertFalse(statistics.isTracked(null));
     assertFalse(statistics.isTracked(NO_SUCH_OP));
 
     final Iterator<LongStatistic> iter = statistics.getLongStatistics();

http://git-wip-us.apache.org/repos/asf/hadoop/blob/c2f9cd58/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/Statistic.java
----------------------------------------------------------------------
diff --git a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/Statistic.java
b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/Statistic.java
index 3c205f3..36d163c 100644
--- a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/Statistic.java
+++ b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/Statistic.java
@@ -20,6 +20,9 @@ package org.apache.hadoop.fs.s3a;
 
 import org.apache.hadoop.fs.StorageStatistics.CommonStatisticNames;
 
+import java.util.HashMap;
+import java.util.Map;
+
 /**
  * Statistic which are collected in S3A.
  * These statistics are available at a low level in {@link S3AStorageStatistics}
@@ -105,6 +108,14 @@ public enum Statistic {
   STREAM_ABORT_BYTES_DISCARDED("stream_bytes_discarded_in_abort",
       "Count of bytes discarded by aborting the stream");
 
+  private static final Map<String, Statistic> SYMBOL_MAP =
+      new HashMap<>(Statistic.values().length);
+  static {
+    for (Statistic stat : values()) {
+      SYMBOL_MAP.put(stat.getSymbol(), stat);
+    }
+  }
+
   Statistic(String symbol, String description) {
     this.symbol = symbol;
     this.description = description;
@@ -123,14 +134,7 @@ public enum Statistic {
    * @return the value or null.
    */
   public static Statistic fromSymbol(String symbol) {
-    if (symbol != null) {
-      for (Statistic opType : values()) {
-        if (opType.getSymbol().equals(symbol)) {
-          return opType;
-        }
-      }
-    }
-    return null;
+    return SYMBOL_MAP.get(symbol);
   }
 
   public String getDescription() {


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


Mime
View raw message