Explorar o código

HDFS-9221. HdfsServerConstants#ReplicaState#getState should avoid calling values() since it creates a temporary array. (Staffan Friberg via yliu)
(cherry picked from commit 0ff1216100d16cfa862854a89cd1be8969b0bd7e)

Kihwal Lee %!s(int64=9) %!d(string=hai) anos
pai
achega
2c51bbda51

+ 3 - 0
hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

@@ -16,6 +16,9 @@ Release 2.7.2 - UNRELEASED
     HDFS-8099. Change "DFSInputStream has been closed already" message to
     HDFS-8099. Change "DFSInputStream has been closed already" message to
     debug log level (Charles Lamb via Colin P. McCabe)
     debug log level (Charles Lamb via Colin P. McCabe)
 
 
+    HDFS-9221. HdfsServerConstants#ReplicaState#getState should avoid calling
+    values() since it creates a temporary array. (Staffan Friberg via yliu)
+
   OPTIMIZATIONS
   OPTIMIZATIONS
 
 
     HDFS-8722. Optimize datanode writes for small writes and flushes (kihwal)
     HDFS-8722. Optimize datanode writes for small writes and flushes (kihwal)

+ 4 - 2
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/HdfsServerConstants.java

@@ -250,6 +250,8 @@ public final class HdfsServerConstants {
     /** Temporary replica: created for replication and relocation only. */
     /** Temporary replica: created for replication and relocation only. */
     TEMPORARY(4);
     TEMPORARY(4);
 
 
+    private static final ReplicaState[] cachedValues = ReplicaState.values();
+
     private final int value;
     private final int value;
 
 
     private ReplicaState(int v) {
     private ReplicaState(int v) {
@@ -261,12 +263,12 @@ public final class HdfsServerConstants {
     }
     }
 
 
     public static ReplicaState getState(int v) {
     public static ReplicaState getState(int v) {
-      return ReplicaState.values()[v];
+      return cachedValues[v];
     }
     }
 
 
     /** Read from in */
     /** Read from in */
     public static ReplicaState read(DataInput in) throws IOException {
     public static ReplicaState read(DataInput in) throws IOException {
-      return values()[in.readByte()];
+      return cachedValues[in.readByte()];
     }
     }
 
 
     /** Write to out */
     /** Write to out */