HDFS-12171. Reduce IIP object allocations for inode lookup. Contributed by Daryn Sharp.
This commit is contained in:
parent
6d983cca52
commit
a68b5b31cf
@ -209,9 +209,8 @@ private EncryptionZoneInt getEncryptionZoneForPath(INodesInPath iip) {
|
|||||||
if (!hasCreatedEncryptionZone()) {
|
if (!hasCreatedEncryptionZone()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
List<INode> inodes = iip.getReadOnlyINodes();
|
for (int i = iip.length() - 1; i >= 0; i--) {
|
||||||
for (int i = inodes.size() - 1; i >= 0; i--) {
|
final INode inode = iip.getINode(i);
|
||||||
final INode inode = inodes.get(i);
|
|
||||||
if (inode != null) {
|
if (inode != null) {
|
||||||
final EncryptionZoneInt ezi = encryptionZones.get(inode.getId());
|
final EncryptionZoneInt ezi = encryptionZones.get(inode.getId());
|
||||||
if (ezi != null) {
|
if (ezi != null) {
|
||||||
|
@ -355,9 +355,8 @@ private static ErasureCodingPolicy getErasureCodingPolicyForPath(
|
|||||||
Preconditions.checkNotNull(iip, "INodes cannot be null");
|
Preconditions.checkNotNull(iip, "INodes cannot be null");
|
||||||
fsd.readLock();
|
fsd.readLock();
|
||||||
try {
|
try {
|
||||||
List<INode> inodes = iip.getReadOnlyINodes();
|
for (int i = iip.length() - 1; i >= 0; i--) {
|
||||||
for (int i = inodes.size() - 1; i >= 0; i--) {
|
final INode inode = iip.getINode(i);
|
||||||
final INode inode = inodes.get(i);
|
|
||||||
if (inode == null) {
|
if (inode == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,6 @@
|
|||||||
package org.apache.hadoop.hdfs.server.namenode;
|
package org.apache.hadoop.hdfs.server.namenode;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
@ -336,17 +333,9 @@ public int getPathSnapshotId() {
|
|||||||
* otherwise, i < 0, return the (length + i)-th inode.
|
* otherwise, i < 0, return the (length + i)-th inode.
|
||||||
*/
|
*/
|
||||||
public INode getINode(int i) {
|
public INode getINode(int i) {
|
||||||
if (inodes == null || inodes.length == 0) {
|
return inodes[(i < 0) ? inodes.length + i : i];
|
||||||
throw new NoSuchElementException("inodes is null or empty");
|
|
||||||
}
|
|
||||||
int index = i >= 0 ? i : inodes.length + i;
|
|
||||||
if (index < inodes.length && index >= 0) {
|
|
||||||
return inodes[index];
|
|
||||||
} else {
|
|
||||||
throw new NoSuchElementException("inodes.length == " + inodes.length);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return the last inode. */
|
/** @return the last inode. */
|
||||||
public INode getLastINode() {
|
public INode getLastINode() {
|
||||||
return getINode(-1);
|
return getINode(-1);
|
||||||
@ -384,10 +373,6 @@ public int length() {
|
|||||||
return inodes.length;
|
return inodes.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<INode> getReadOnlyINodes() {
|
|
||||||
return Collections.unmodifiableList(Arrays.asList(inodes));
|
|
||||||
}
|
|
||||||
|
|
||||||
public INode[] getINodesArray() {
|
public INode[] getINodesArray() {
|
||||||
INode[] retArr = new INode[inodes.length];
|
INode[] retArr = new INode[inodes.length];
|
||||||
System.arraycopy(inodes, 0, retArr, 0, inodes.length);
|
System.arraycopy(inodes, 0, retArr, 0, inodes.length);
|
||||||
|
@ -310,9 +310,8 @@ public void testSnapshotPathINodesAfterDeletion() throws Exception {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int getNumNonNull(INodesInPath iip) {
|
private int getNumNonNull(INodesInPath iip) {
|
||||||
List<INode> inodes = iip.getReadOnlyINodes();
|
for (int i = iip.length() - 1; i >= 0; i--) {
|
||||||
for (int i = inodes.size() - 1; i >= 0; i--) {
|
if (iip.getINode(i) != null) {
|
||||||
if (inodes.get(i) != null) {
|
|
||||||
return i+1;
|
return i+1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user