HDFS-10772. Reduce byte/string conversions for get listing. Contributed by Daryn Sharp.

This commit is contained in:
Kihwal Lee 2016-08-24 15:21:08 -05:00
parent 3476156807
commit a1f3293762

View File

@ -24,6 +24,7 @@
import org.apache.hadoop.fs.DirectoryListingStartAfterNotFoundException; import org.apache.hadoop.fs.DirectoryListingStartAfterNotFoundException;
import org.apache.hadoop.fs.FileEncryptionInfo; import org.apache.hadoop.fs.FileEncryptionInfo;
import org.apache.hadoop.fs.InvalidPathException; import org.apache.hadoop.fs.InvalidPathException;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.permission.FsAction; import org.apache.hadoop.fs.permission.FsAction;
import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.fs.QuotaUsage; import org.apache.hadoop.fs.QuotaUsage;
@ -52,7 +53,6 @@
class FSDirStatAndListingOp { class FSDirStatAndListingOp {
static DirectoryListing getListingInt(FSDirectory fsd, final String srcArg, static DirectoryListing getListingInt(FSDirectory fsd, final String srcArg,
byte[] startAfter, boolean needLocation) throws IOException { byte[] startAfter, boolean needLocation) throws IOException {
final String startAfterString = DFSUtil.bytes2String(startAfter);
String src = null; String src = null;
final INodesInPath iip; final INodesInPath iip;
@ -65,18 +65,22 @@ static DirectoryListing getListingInt(FSDirectory fsd, final String srcArg,
iip = fsd.getINodesInPath(src, true); iip = fsd.getINodesInPath(src, true);
} }
// Get file name when startAfter is an INodePath // Get file name when startAfter is an INodePath. This is not the
// common case so avoid any unnecessary processing unless required.
if (startAfter.length > 0 && startAfter[0] == Path.SEPARATOR_CHAR) {
final String startAfterString = DFSUtil.bytes2String(startAfter);
if (FSDirectory.isReservedName(startAfterString)) { if (FSDirectory.isReservedName(startAfterString)) {
try { try {
String tmp = FSDirectory.resolvePath(startAfterString, fsd); byte[][] components = INode.getPathComponents(startAfterString);
byte[][] regularPath = INode.getPathComponents(tmp); components = FSDirectory.resolveComponents(components, fsd);
startAfter = regularPath[regularPath.length - 1]; startAfter = components[components.length - 1];
} catch (IOException e) { } catch (IOException e) {
// Possibly the inode is deleted // Possibly the inode is deleted
throw new DirectoryListingStartAfterNotFoundException( throw new DirectoryListingStartAfterNotFoundException(
"Can't find startAfter " + startAfterString); "Can't find startAfter " + startAfterString);
} }
} }
}
boolean isSuperUser = true; boolean isSuperUser = true;
if (fsd.isPermissionEnabled()) { if (fsd.isPermissionEnabled()) {