@Test public void testMinimizeDeletes() { Volume vol1 = createMock(Volume.class); expect(vol1.isValidPath(anyObject())) .andAnswer(() -> getCurrentArguments()[0].toString().startsWith("hdfs: .anyTimes(); Volume vol2 = createMock(Volume.class); expect(vol2.isValidPath(anyObject())) .andAnswer(() -> getCurrentArguments()[0].toString().startsWith("hdfs: .anyTimes(); Collection<Volume> vols = Arrays.asList(vol1, vol2); VolumeManager volMgr2 = createMock(VolumeManager.class); expect(volMgr2.getVolumes()).andReturn(vols).anyTimes(); replay(vol1, vol2, volMgr2); TreeMap<String,String> confirmed = new TreeMap<>(); confirmed.put("5a/t-0001", "hdfs: confirmed.put("5a/t-0001/F0001.rf", "hdfs: confirmed.put("5a/t-0001/F0002.rf", "hdfs: confirmed.put("5a/t-0002/F0001.rf", "hdfs: confirmed.put("5b/t-0003", GcVolumeUtil.getDeleteTabletOnAllVolumesUri(TableId.of("5b"), "t-0003")); confirmed.put("5b/t-0003/F0001.rf", "hdfs: confirmed.put("5b/t-0003/F0002.rf", "hdfs: confirmed.put("5b/t-0003/F0003.rf", "hdfs: confirmed.put("5b/t-0004", GcVolumeUtil.getDeleteTabletOnAllVolumesUri(TableId.of("5b"), "t-0004")); confirmed.put("5b/t-0004/F0001.rf", "hdfs: List<String> processedDeletes = new ArrayList<>(); SimpleGarbageCollector.minimizeDeletes(confirmed, processedDeletes, volMgr2); TreeMap<String,String> expected = new TreeMap<>(); expected.put("5a/t-0001", "hdfs: expected.put("5a/t-0002/F0001.rf", "hdfs: expected.put("5b/t-0003", GcVolumeUtil.getDeleteTabletOnAllVolumesUri(TableId.of("5b"), "t-0003")); expected.put("5b/t-0003/F0003.rf", "hdfs: expected.put("5b/t-0004", GcVolumeUtil.getDeleteTabletOnAllVolumesUri(TableId.of("5b"), "t-0004")); assertEquals(expected, confirmed); assertEquals(Arrays.asList("hdfs: "hdfs: "hdfs: "hdfs: "hdfs: }
@VisibleForTesting static void minimizeDeletes(SortedMap<String,String> confirmedDeletes, List<String> processedDeletes, VolumeManager fs) { Set<Path> seenVolumes = new HashSet<>(); Collection<Volume> volumes = fs.getVolumes(); Iterator<Entry<String,String>> cdIter = confirmedDeletes.entrySet().iterator(); String lastDirRel = null; Path lastDirAbs = null; while (cdIter.hasNext()) { Entry<String,String> entry = cdIter.next(); String relPath = entry.getKey(); Path absPath = new Path(entry.getValue()); if (isDir(relPath)) { lastDirRel = relPath; lastDirAbs = absPath; } else if (lastDirRel != null) { if (relPath.startsWith(lastDirRel)) { Path vol = FileType.TABLE.getVolume(absPath); boolean sameVol = false; if (GcVolumeUtil.isAllVolumesUri(lastDirAbs)) { if (seenVolumes.contains(vol)) { sameVol = true; } else { for (Volume cvol : volumes) { if (cvol.isValidPath(vol)) { seenVolumes.add(vol); sameVol = true; } } } } else { sameVol = FileType.TABLE.getVolume(lastDirAbs).equals(vol); } if (sameVol) { log.info("Ignoring {} because {} exist", entry.getValue(), lastDirAbs); processedDeletes.add(entry.getValue()); cdIter.remove(); } } else { lastDirRel = null; lastDirAbs = null; } } } }
SimpleGarbageCollector extends AbstractServer implements Iface { @VisibleForTesting static void minimizeDeletes(SortedMap<String,String> confirmedDeletes, List<String> processedDeletes, VolumeManager fs) { Set<Path> seenVolumes = new HashSet<>(); Collection<Volume> volumes = fs.getVolumes(); Iterator<Entry<String,String>> cdIter = confirmedDeletes.entrySet().iterator(); String lastDirRel = null; Path lastDirAbs = null; while (cdIter.hasNext()) { Entry<String,String> entry = cdIter.next(); String relPath = entry.getKey(); Path absPath = new Path(entry.getValue()); if (isDir(relPath)) { lastDirRel = relPath; lastDirAbs = absPath; } else if (lastDirRel != null) { if (relPath.startsWith(lastDirRel)) { Path vol = FileType.TABLE.getVolume(absPath); boolean sameVol = false; if (GcVolumeUtil.isAllVolumesUri(lastDirAbs)) { if (seenVolumes.contains(vol)) { sameVol = true; } else { for (Volume cvol : volumes) { if (cvol.isValidPath(vol)) { seenVolumes.add(vol); sameVol = true; } } } } else { sameVol = FileType.TABLE.getVolume(lastDirAbs).equals(vol); } if (sameVol) { log.info("Ignoring {} because {} exist", entry.getValue(), lastDirAbs); processedDeletes.add(entry.getValue()); cdIter.remove(); } } else { lastDirRel = null; lastDirAbs = null; } } } } }
SimpleGarbageCollector extends AbstractServer implements Iface { @VisibleForTesting static void minimizeDeletes(SortedMap<String,String> confirmedDeletes, List<String> processedDeletes, VolumeManager fs) { Set<Path> seenVolumes = new HashSet<>(); Collection<Volume> volumes = fs.getVolumes(); Iterator<Entry<String,String>> cdIter = confirmedDeletes.entrySet().iterator(); String lastDirRel = null; Path lastDirAbs = null; while (cdIter.hasNext()) { Entry<String,String> entry = cdIter.next(); String relPath = entry.getKey(); Path absPath = new Path(entry.getValue()); if (isDir(relPath)) { lastDirRel = relPath; lastDirAbs = absPath; } else if (lastDirRel != null) { if (relPath.startsWith(lastDirRel)) { Path vol = FileType.TABLE.getVolume(absPath); boolean sameVol = false; if (GcVolumeUtil.isAllVolumesUri(lastDirAbs)) { if (seenVolumes.contains(vol)) { sameVol = true; } else { for (Volume cvol : volumes) { if (cvol.isValidPath(vol)) { seenVolumes.add(vol); sameVol = true; } } } } else { sameVol = FileType.TABLE.getVolume(lastDirAbs).equals(vol); } if (sameVol) { log.info("Ignoring {} because {} exist", entry.getValue(), lastDirAbs); processedDeletes.add(entry.getValue()); cdIter.remove(); } } else { lastDirRel = null; lastDirAbs = null; } } } } SimpleGarbageCollector(ServerOpts opts, String[] args); }
SimpleGarbageCollector extends AbstractServer implements Iface { @VisibleForTesting static void minimizeDeletes(SortedMap<String,String> confirmedDeletes, List<String> processedDeletes, VolumeManager fs) { Set<Path> seenVolumes = new HashSet<>(); Collection<Volume> volumes = fs.getVolumes(); Iterator<Entry<String,String>> cdIter = confirmedDeletes.entrySet().iterator(); String lastDirRel = null; Path lastDirAbs = null; while (cdIter.hasNext()) { Entry<String,String> entry = cdIter.next(); String relPath = entry.getKey(); Path absPath = new Path(entry.getValue()); if (isDir(relPath)) { lastDirRel = relPath; lastDirAbs = absPath; } else if (lastDirRel != null) { if (relPath.startsWith(lastDirRel)) { Path vol = FileType.TABLE.getVolume(absPath); boolean sameVol = false; if (GcVolumeUtil.isAllVolumesUri(lastDirAbs)) { if (seenVolumes.contains(vol)) { sameVol = true; } else { for (Volume cvol : volumes) { if (cvol.isValidPath(vol)) { seenVolumes.add(vol); sameVol = true; } } } } else { sameVol = FileType.TABLE.getVolume(lastDirAbs).equals(vol); } if (sameVol) { log.info("Ignoring {} because {} exist", entry.getValue(), lastDirAbs); processedDeletes.add(entry.getValue()); cdIter.remove(); } } else { lastDirRel = null; lastDirAbs = null; } } } } SimpleGarbageCollector(ServerOpts opts, String[] args); static void main(String[] args); @Override @SuppressFBWarnings(value = "DM_EXIT", justification = "main class can call System.exit") void run(); @Override GCStatus getStatus(TInfo info, TCredentials credentials); GcCycleMetrics getGcCycleMetrics(); }
SimpleGarbageCollector extends AbstractServer implements Iface { @VisibleForTesting static void minimizeDeletes(SortedMap<String,String> confirmedDeletes, List<String> processedDeletes, VolumeManager fs) { Set<Path> seenVolumes = new HashSet<>(); Collection<Volume> volumes = fs.getVolumes(); Iterator<Entry<String,String>> cdIter = confirmedDeletes.entrySet().iterator(); String lastDirRel = null; Path lastDirAbs = null; while (cdIter.hasNext()) { Entry<String,String> entry = cdIter.next(); String relPath = entry.getKey(); Path absPath = new Path(entry.getValue()); if (isDir(relPath)) { lastDirRel = relPath; lastDirAbs = absPath; } else if (lastDirRel != null) { if (relPath.startsWith(lastDirRel)) { Path vol = FileType.TABLE.getVolume(absPath); boolean sameVol = false; if (GcVolumeUtil.isAllVolumesUri(lastDirAbs)) { if (seenVolumes.contains(vol)) { sameVol = true; } else { for (Volume cvol : volumes) { if (cvol.isValidPath(vol)) { seenVolumes.add(vol); sameVol = true; } } } } else { sameVol = FileType.TABLE.getVolume(lastDirAbs).equals(vol); } if (sameVol) { log.info("Ignoring {} because {} exist", entry.getValue(), lastDirAbs); processedDeletes.add(entry.getValue()); cdIter.remove(); } } else { lastDirRel = null; lastDirAbs = null; } } } } SimpleGarbageCollector(ServerOpts opts, String[] args); static void main(String[] args); @Override @SuppressFBWarnings(value = "DM_EXIT", justification = "main class can call System.exit") void run(); @Override GCStatus getStatus(TInfo info, TCredentials credentials); GcCycleMetrics getGcCycleMetrics();  }