@Test public void testKillUniquePath() throws Exception { final LocalDataSegmentKiller killer = new LocalDataSegmentKiller(new LocalDataSegmentPusherConfig()); final String uuid = UUID.randomUUID().toString().substring(0, 5); final File dataSourceDir = temporaryFolder.newFolder("dataSource"); final File intervalDir = new File(dataSourceDir, "interval"); final File versionDir = new File(intervalDir, "1"); final File partitionDir = new File(versionDir, "0"); final File uuidDir = new File(partitionDir, uuid); makePartitionDirWithIndex(uuidDir); killer.kill(getSegmentWithPath(new File(uuidDir, "index.zip").toString())); Assert.assertFalse(uuidDir.exists()); Assert.assertFalse(partitionDir.exists()); Assert.assertFalse(versionDir.exists()); Assert.assertFalse(intervalDir.exists()); Assert.assertFalse(dataSourceDir.exists()); }
@Override public void kill(DataSegment segment) throws SegmentLoadingException { final File path = getPath(segment); log.info("killing segment[%s] mapped to path[%s]", segment.getId(), path); try { if (path.getName().endsWith(".zip")) { // path format -- > .../dataSource/interval/version/partitionNum/xxx.zip // or .../dataSource/interval/version/partitionNum/UUID/xxx.zip File parentDir = path.getParentFile(); FileUtils.deleteDirectory(parentDir); // possibly recursively delete empty parent directories up to 'dataSource' parentDir = parentDir.getParentFile(); int maxDepth = 4; // if for some reason there's no datasSource directory, stop recursing somewhere reasonable while (parentDir != null && --maxDepth >= 0) { if (!parentDir.delete() || segment.getDataSource().equals(parentDir.getName())) { break; } parentDir = parentDir.getParentFile(); } } else { throw new SegmentLoadingException("Unknown file type[%s]", path); } } catch (IOException e) { throw new SegmentLoadingException(e, "Unable to kill segment"); } }
emitter, dataSegmentPusher, new LocalDataSegmentKiller(new LocalDataSegmentPusherConfig()), new DataSegmentMover()
@Test public void testKill() throws Exception LocalDataSegmentKiller killer = new LocalDataSegmentKiller(new LocalDataSegmentPusherConfig()); killer.kill(getSegmentWithPath(new File(partition011Dir, "index.zip").toString())); Assert.assertTrue(partition012Dir.exists()); killer.kill(getSegmentWithPath(new File(partition111Dir, "index.zip").toString())); Assert.assertTrue(partition012Dir.exists()); killer.kill(getSegmentWithPath(new File(partition021Dir, "index.zip").toString())); killer.kill(getSegmentWithPath(new File(partition012Dir, "index.zip").toString()));
@Override public void kill(DataSegment segment) throws SegmentLoadingException { final File path = getPath(segment); log.info("killing segment[%s] mapped to path[%s]", segment.getIdentifier(), path); try { if (path.getName().endsWith(".zip")) { // path format -- > .../dataSource/interval/version/partitionNum/xxx.zip // or .../dataSource/interval/version/partitionNum/UUID/xxx.zip File parentDir = path.getParentFile(); FileUtils.deleteDirectory(parentDir); // possibly recursively delete empty parent directories up to 'dataSource' parentDir = parentDir.getParentFile(); int maxDepth = 4; // if for some reason there's no datasSource directory, stop recursing somewhere reasonable while (parentDir != null && --maxDepth >= 0) { if (!parentDir.delete() || segment.getDataSource().equals(parentDir.getName())) { break; } parentDir = parentDir.getParentFile(); } } else { throw new SegmentLoadingException("Unknown file type[%s]", path); } } catch (IOException e) { throw new SegmentLoadingException(e, "Unable to kill segment"); } }