IndexRootDirectory { private void gcIndexDirs() throws IOException { Map<String, List<LocalIndexDir>> mapping = getIndexesPerPath(); long totalDeletedSize = 0; for (Map.Entry<String, List<LocalIndexDir>> e : mapping.entrySet()) { List<LocalIndexDir> dirs = e.getValue(); for (int i = 1; i < dirs.size(); i++) { LocalIndexDir dir = dirs.get(i); long dirSize = FileUtils.sizeOf(dir.dir); if (FileUtils.deleteQuietly(dir.dir)){ totalDeletedSize += dirSize; } else { log.warn("Not able to deleted unused local index directory [{}]. " + "Deletion would be retried later again.", dir); } } if (!dirs.isEmpty()) { totalDeletedSize += gcNRTIndexDirs(dirs.get(0)); } totalDeletedSize += deleteOldFormatDir(dirs.get(0).getJcrPath()); } if (totalDeletedSize > 0){ log.info("Reclaimed [{}] space by removing unused/old index directories", IOUtils.humanReadableByteCount(totalDeletedSize)); } } IndexRootDirectory(File indexRootDir);  IndexRootDirectory(File indexRootDir, boolean gcOnStart); long getSize(); File getIndexDir(IndexDefinition definition, String indexPath, String dirName); List<LocalIndexDir> getAllLocalIndexes(); List<LocalIndexDir> getLocalIndexes(String jcrPath); long gcEmptyDirs(File subDir); static final String INDEX_METADATA_FILE_NAME; }
@Test public void gcIndexDirs() throws Exception{ File fa0 = dir.getIndexDir(getDefn(), "/a", "default"); configureUniqueId(); File fa1 = dir.getIndexDir(getDefn(), "/a", "default"); configureUniqueId(); File fa2 = dir.getIndexDir(getDefn(), "/a", "default"); List<LocalIndexDir> dirs = dir.getLocalIndexes("/a"); assertEquals(2, dirs.size()); dir.gcEmptyDirs(fa2); assertEquals(2, dirs.size()); configureUniqueId(); File fa3 = dir.getIndexDir(getDefn(), "/a", "default"); assertEquals(3, dir.getLocalIndexes("/a").size()); dir.gcEmptyDirs(fa3); assertEquals(3, dir.getLocalIndexes("/a").size()); FileUtils.deleteQuietly(fa1); dir.gcEmptyDirs(fa1); assertEquals(2, dir.getLocalIndexes("/a").size()); assertFalse(fa0.exists()); FileUtils.deleteDirectory(fa2); FileUtils.deleteDirectory(fa3); dir.gcEmptyDirs(fa2); assertEquals(1, dir.getLocalIndexes("/a").size()); }