HADOOP-13368. DFSOpsCountStatistics$OpType#fromSymbol and s3a.Statistic#fromSymbol should be O(1) operation. Contributed by Mingliang Liu.
This commit is contained in:
parent
04c8294b6f
commit
328866905c
@ -21,6 +21,7 @@
|
|||||||
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
|
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
|
||||||
|
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@ -88,6 +89,14 @@ public enum OpType {
|
|||||||
TRUNCATE(CommonStatisticNames.OP_TRUNCATE),
|
TRUNCATE(CommonStatisticNames.OP_TRUNCATE),
|
||||||
UNSET_STORAGE_POLICY("op_unset_storage_policy");
|
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;
|
private final String symbol;
|
||||||
|
|
||||||
OpType(String symbol) {
|
OpType(String symbol) {
|
||||||
@ -99,14 +108,7 @@ public String getSymbol() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static OpType fromSymbol(String symbol) {
|
public static OpType fromSymbol(String symbol) {
|
||||||
if (symbol != null) {
|
return SYMBOL_MAP.get(symbol);
|
||||||
for (OpType opType : values()) {
|
|
||||||
if (opType.getSymbol().equals(symbol)) {
|
|
||||||
return opType;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,12 +111,14 @@ public void testGetLongStatistics() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetLong() {
|
public void testGetLong() {
|
||||||
|
assertNull(statistics.getLong(null));
|
||||||
assertNull(statistics.getLong(NO_SUCH_OP));
|
assertNull(statistics.getLong(NO_SUCH_OP));
|
||||||
verifyStatistics();
|
verifyStatistics();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsTracked() {
|
public void testIsTracked() {
|
||||||
|
assertFalse(statistics.isTracked(null));
|
||||||
assertFalse(statistics.isTracked(NO_SUCH_OP));
|
assertFalse(statistics.isTracked(NO_SUCH_OP));
|
||||||
|
|
||||||
final Iterator<LongStatistic> iter = statistics.getLongStatistics();
|
final Iterator<LongStatistic> iter = statistics.getLongStatistics();
|
||||||
|
@ -20,6 +20,9 @@
|
|||||||
|
|
||||||
import org.apache.hadoop.fs.StorageStatistics.CommonStatisticNames;
|
import org.apache.hadoop.fs.StorageStatistics.CommonStatisticNames;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Statistic which are collected in S3A.
|
* Statistic which are collected in S3A.
|
||||||
* These statistics are available at a low level in {@link S3AStorageStatistics}
|
* 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",
|
STREAM_ABORT_BYTES_DISCARDED("stream_bytes_discarded_in_abort",
|
||||||
"Count of bytes discarded by aborting the stream");
|
"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) {
|
Statistic(String symbol, String description) {
|
||||||
this.symbol = symbol;
|
this.symbol = symbol;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
@ -123,14 +134,7 @@ public String getSymbol() {
|
|||||||
* @return the value or null.
|
* @return the value or null.
|
||||||
*/
|
*/
|
||||||
public static Statistic fromSymbol(String symbol) {
|
public static Statistic fromSymbol(String symbol) {
|
||||||
if (symbol != null) {
|
return SYMBOL_MAP.get(symbol);
|
||||||
for (Statistic opType : values()) {
|
|
||||||
if (opType.getSymbol().equals(symbol)) {
|
|
||||||
return opType;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user