LocalCacheDirectoryManager { public synchronized void incrementFileCountForPath(String relPath) { relPath = relPath == null ? "" : relPath.trim(); Directory subDir = knownDirectories.get(relPath); if (subDir == null) { int dirnum = Directory.getDirectoryNumber(relPath); totalSubDirectories = Math.max(dirnum, totalSubDirectories); subDir = new Directory(dirnum); nonFullDirectories.add(subDir); knownDirectories.put(subDir.getRelativePath(), subDir); } if (subDir.incrementAndGetCount() >= perDirectoryFileLimit) { nonFullDirectories.remove(subDir); } } LocalCacheDirectoryManager(Configuration conf); synchronized String getRelativePathForLocalization(); synchronized void decrementFileCountForPath(String relPath); synchronized void incrementFileCountForPath(String relPath); static Path getCacheDirectoryRoot(Path path); static final int DIRECTORIES_PER_LEVEL; }
@Test public void testIncrementFileCountForPath() { YarnConfiguration conf = new YarnConfiguration(); conf.setInt(YarnConfiguration.NM_LOCAL_CACHE_MAX_FILES_PER_DIRECTORY, LocalCacheDirectoryManager.DIRECTORIES_PER_LEVEL + 2); LocalCacheDirectoryManager mgr = new LocalCacheDirectoryManager(conf); final String rootPath = ""; mgr.incrementFileCountForPath(rootPath); Assert.assertEquals(rootPath, mgr.getRelativePathForLocalization()); Assert.assertFalse("root dir should be full", rootPath.equals(mgr.getRelativePathForLocalization())); mgr.getRelativePathForLocalization(); mgr.decrementFileCountForPath(rootPath); mgr.decrementFileCountForPath(rootPath); Assert.assertEquals(rootPath, mgr.getRelativePathForLocalization()); Assert.assertEquals(rootPath, mgr.getRelativePathForLocalization()); String otherDir = mgr.getRelativePathForLocalization(); Assert.assertFalse("root dir should be full", otherDir.equals(rootPath)); final String deepDir0 = "d/e/e/p/0"; final String deepDir1 = "d/e/e/p/1"; final String deepDir2 = "d/e/e/p/2"; final String deepDir3 = "d/e/e/p/3"; mgr.incrementFileCountForPath(deepDir0); Assert.assertEquals(otherDir, mgr.getRelativePathForLocalization()); Assert.assertEquals(deepDir0, mgr.getRelativePathForLocalization()); Assert.assertEquals("total dir count incorrect after increment", deepDir1, mgr.getRelativePathForLocalization()); mgr.incrementFileCountForPath(deepDir2); mgr.incrementFileCountForPath(deepDir1); mgr.incrementFileCountForPath(deepDir2); Assert.assertEquals(deepDir3, mgr.getRelativePathForLocalization()); }