HDFS-5781. Use an array to record the mapping between FSEditLogOpCode and the corresponding byte value. Contributed by Jing Zhao.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1561788 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0be0174669
commit
4b61ff2283
|
@ -504,6 +504,9 @@ Release 2.4.0 - UNRELEASED
|
||||||
HDFS-5788. listLocatedStatus response can be very large. (Nathan Roberts
|
HDFS-5788. listLocatedStatus response can be very large. (Nathan Roberts
|
||||||
via kihwal)
|
via kihwal)
|
||||||
|
|
||||||
|
HDFS-5781. Use an array to record the mapping between FSEditLogOpCode and
|
||||||
|
the corresponding byte value. (jing9)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
HDFS-5239. Allow FSNamesystem lock fairness to be configurable (daryn)
|
HDFS-5239. Allow FSNamesystem lock fairness to be configurable (daryn)
|
||||||
|
|
|
@ -68,7 +68,7 @@ public enum FSEditLogOpCodes {
|
||||||
OP_REMOVE_CACHE_POOL ((byte) 38),
|
OP_REMOVE_CACHE_POOL ((byte) 38),
|
||||||
OP_MODIFY_CACHE_DIRECTIVE ((byte) 39),
|
OP_MODIFY_CACHE_DIRECTIVE ((byte) 39),
|
||||||
|
|
||||||
// Note that fromByte(..) depends on OP_INVALID being at the last position.
|
// Note that the current range of the valid OP code is 0~127
|
||||||
OP_INVALID ((byte) -1);
|
OP_INVALID ((byte) -1);
|
||||||
|
|
||||||
private final byte opCode;
|
private final byte opCode;
|
||||||
|
@ -91,7 +91,22 @@ public enum FSEditLogOpCodes {
|
||||||
return opCode;
|
return opCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final FSEditLogOpCodes[] VALUES = FSEditLogOpCodes.values();
|
private static FSEditLogOpCodes[] VALUES;
|
||||||
|
|
||||||
|
static {
|
||||||
|
byte max = 0;
|
||||||
|
for (FSEditLogOpCodes code : FSEditLogOpCodes.values()) {
|
||||||
|
if (code.getOpCode() > max) {
|
||||||
|
max = code.getOpCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
VALUES = new FSEditLogOpCodes[max + 1];
|
||||||
|
for (FSEditLogOpCodes code : FSEditLogOpCodes.values()) {
|
||||||
|
if (code.getOpCode() >= 0) {
|
||||||
|
VALUES[code.getOpCode()] = code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts byte to FSEditLogOpCodes enum value
|
* Converts byte to FSEditLogOpCodes enum value
|
||||||
|
@ -100,12 +115,9 @@ public enum FSEditLogOpCodes {
|
||||||
* @return enum with byte value of opCode
|
* @return enum with byte value of opCode
|
||||||
*/
|
*/
|
||||||
public static FSEditLogOpCodes fromByte(byte opCode) {
|
public static FSEditLogOpCodes fromByte(byte opCode) {
|
||||||
if (opCode == -1) {
|
if (opCode >= 0 && opCode < VALUES.length) {
|
||||||
return OP_INVALID;
|
|
||||||
}
|
|
||||||
if (opCode >= 0 && opCode < OP_INVALID.ordinal()) {
|
|
||||||
return VALUES[opCode];
|
return VALUES[opCode];
|
||||||
}
|
}
|
||||||
return null;
|
return opCode == -1 ? OP_INVALID : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue