-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HDFS-15621. Datanode DirectoryScanner uses excessive memory #2849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -227,27 +227,27 @@ interface BlockIterator extends Closeable { | |
| */ | ||
| public static class ScanInfo implements Comparable<ScanInfo> { | ||
| private final long blockId; | ||
|
|
||
| /** | ||
| * The block file path, relative to the volume's base directory. | ||
| * If there was no block file found, this may be null. If 'vol' | ||
| * is null, then this is the full path of the block file. | ||
| * The full path to the folder containing the block / meta files. | ||
| */ | ||
| private final String blockSuffix; | ||
|
|
||
| private final File basePath; | ||
| /** | ||
| * The suffix of the meta file path relative to the block file. | ||
| * If blockSuffix is null, then this will be the entire path relative | ||
| * to the volume base directory, or an absolute path if vol is also | ||
| * null. | ||
| * The block file name, with no path | ||
| */ | ||
| private final String metaSuffix; | ||
| private final String blockFile; | ||
| /** | ||
| * Holds the meta file name, with no path, only if blockFile is null. | ||
| * If blockFile is not null, the meta file will be named identically to | ||
| * the blockFile, but with a suffix like "_1234.meta". If the blockFile | ||
| * is present, we store only the meta file suffix. | ||
| */ | ||
| private final String metaFile; | ||
|
|
||
| private final FsVolumeSpi volume; | ||
|
|
||
| private final FileRegion fileRegion; | ||
| /** | ||
| * Get the file's length in async block scan | ||
| * Get the file's length in async block scan. | ||
| */ | ||
| private final long blockLength; | ||
|
|
||
|
|
@@ -257,35 +257,19 @@ public static class ScanInfo implements Comparable<ScanInfo> { | |
| private final static String QUOTED_FILE_SEPARATOR = | ||
| Matcher.quoteReplacement(File.separator); | ||
|
|
||
| /** | ||
| * Get the most condensed version of the path. | ||
| * | ||
| * For example, the condensed version of /foo//bar is /foo/bar | ||
| * Unlike {@link File#getCanonicalPath()}, this will never perform I/O | ||
| * on the filesystem. | ||
| * | ||
| * @param path the path to condense | ||
| * @return the condensed path | ||
| */ | ||
| private static String getCondensedPath(String path) { | ||
| return CONDENSED_PATH_REGEX.matcher(path). | ||
| replaceAll(QUOTED_FILE_SEPARATOR); | ||
| } | ||
|
|
||
| /** | ||
| * Get a path suffix. | ||
| * | ||
| * @param f The file to get the suffix for. | ||
| * @param f The string to get the suffix for. | ||
| * @param prefix The prefix we're stripping off. | ||
| * | ||
| * @return A suffix such that prefix + suffix = path to f | ||
| * @return A suffix such that prefix + suffix = f | ||
| */ | ||
| private static String getSuffix(File f, String prefix) { | ||
| String fullPath = getCondensedPath(f.getAbsolutePath()); | ||
| if (fullPath.startsWith(prefix)) { | ||
| return fullPath.substring(prefix.length()); | ||
| private static String getSuffix(String f, String prefix) { | ||
| if (f.startsWith(prefix)) { | ||
| return f.substring(prefix.length()); | ||
| } | ||
| throw new RuntimeException(prefix + " is not a prefix of " + fullPath); | ||
| throw new RuntimeException(prefix + " is not a prefix of " + f); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -297,23 +281,18 @@ private static String getSuffix(File f, String prefix) { | |
| * @param metaFile the path to the block meta-data file | ||
|
||
| * @param vol the volume that contains the block | ||
| */ | ||
| public ScanInfo(long blockId, File blockFile, File metaFile, | ||
| FsVolumeSpi vol) { | ||
| public ScanInfo(long blockId, File basePath, String blockFile, | ||
| String metaFile, FsVolumeSpi vol) { | ||
| this.blockId = blockId; | ||
| String condensedVolPath = | ||
| (vol == null || vol.getBaseURI() == null) ? null : | ||
| getCondensedPath(new File(vol.getBaseURI()).getAbsolutePath()); | ||
| this.blockSuffix = blockFile == null ? null : | ||
| getSuffix(blockFile, condensedVolPath); | ||
| this.blockLength = (blockFile != null) ? blockFile.length() : 0; | ||
| if (metaFile == null) { | ||
| this.metaSuffix = null; | ||
| } else if (blockFile == null) { | ||
| this.metaSuffix = getSuffix(metaFile, condensedVolPath); | ||
| this.basePath = basePath; | ||
| this.blockFile = blockFile; | ||
| if (blockFile != null && metaFile != null) { | ||
| this.metaFile = getSuffix(metaFile, blockFile); | ||
| } else { | ||
| this.metaSuffix = getSuffix(metaFile, | ||
| condensedVolPath + blockSuffix); | ||
| this.metaFile = metaFile; | ||
| } | ||
| this.blockLength = (blockFile != null) ? | ||
| new File(basePath, blockFile).length() : 0; | ||
| this.volume = vol; | ||
| this.fileRegion = null; | ||
| } | ||
|
|
@@ -333,8 +312,9 @@ public ScanInfo(long blockId, FsVolumeSpi vol, FileRegion fileRegion, | |
| this.blockLength = length; | ||
| this.volume = vol; | ||
| this.fileRegion = fileRegion; | ||
| this.blockSuffix = null; | ||
| this.metaSuffix = null; | ||
| this.basePath = null; | ||
| this.blockFile = null; | ||
| this.metaFile = null; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -343,8 +323,8 @@ public ScanInfo(long blockId, FsVolumeSpi vol, FileRegion fileRegion, | |
| * @return the block data file | ||
| */ | ||
| public File getBlockFile() { | ||
| return (blockSuffix == null) ? null : | ||
| new File(new File(volume.getBaseURI()).getAbsolutePath(), blockSuffix); | ||
| return (blockFile == null) ? null : | ||
| new File(basePath.getAbsolutePath(), blockFile); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -363,15 +343,10 @@ public long getBlockLength() { | |
| * @return the block meta data file | ||
| */ | ||
| public File getMetaFile() { | ||
| if (metaSuffix == null) { | ||
| if (metaFile == null) { | ||
| return null; | ||
| } | ||
| String fileSuffix = metaSuffix; | ||
| if (blockSuffix != null) { | ||
| fileSuffix = blockSuffix + metaSuffix; | ||
| } | ||
| return new File(new File(volume.getBaseURI()).getAbsolutePath(), | ||
| fileSuffix); | ||
| return new File(basePath.getAbsolutePath(), fullMetaFile()); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -414,14 +389,24 @@ public int hashCode() { | |
| } | ||
|
|
||
| public long getGenStamp() { | ||
| return metaSuffix != null ? Block.getGenerationStamp( | ||
| getMetaFile().getName()) : | ||
| HdfsConstants.GRANDFATHER_GENERATION_STAMP; | ||
| return metaFile != null ? Block.getGenerationStamp(fullMetaFile()) | ||
| : HdfsConstants.GRANDFATHER_GENERATION_STAMP; | ||
| } | ||
|
|
||
| public FileRegion getFileRegion() { | ||
| return fileRegion; | ||
| } | ||
|
|
||
| private String fullMetaFile() { | ||
| if (metaFile == null) { | ||
| return null; | ||
| } | ||
| if (blockFile == null) { | ||
| return metaFile; | ||
| } else { | ||
| return blockFile + metaFile; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.