/** * Illustrates bad internal heap state reported in Bugzilla PR #235818. */ public void testAddRemove() { resetEmpty(); PriorityBuffer heap = (PriorityBuffer) collection; heap.add(new Integer(0)); heap.add(new Integer(2)); heap.add(new Integer(4)); heap.add(new Integer(3)); heap.add(new Integer(8)); heap.add(new Integer(10)); heap.add(new Integer(12)); heap.add(new Integer(3)); confirmed.addAll(heap); // System.out.println(heap); Object obj = new Integer(10); heap.remove(obj); confirmed.remove(obj); // System.out.println(heap); verify(); }
h.add(new Integer(randGenerator.nextInt(heapSize)));
@VisibleForTesting synchronized boolean seek(WritableComparable<?> key) throws IOException { PriorityBuffer reheap = new PriorityBuffer(heap.size()); boolean result = false; for (Object obj : heap) { Index index = (Index) obj; try { WritableComparable<?> found = index.reader.getClosest(key, index.value, true); if (found != null && found.equals(key)) { result = true; } } catch (EOFException ex) { // thrown if key is beyond all data in the map } index.cached = false; reheap.add(index); } heap = reheap; return result; }
@VisibleForTesting synchronized boolean next(WritableComparable<?> key, Writable val) throws IOException { Index elt = (Index) heap.remove(); try { elt.cache(); if (elt.cached) { copy(elt.key, key); copy(elt.value, val); elt.cached = false; } else { return false; } } finally { heap.add(elt); } return true; }
public RecoveryLogReader(VolumeManager fs, Path directory, LogFileKey start, LogFileKey end) throws IOException { boolean foundFinish = false; for (FileStatus child : fs.listStatus(directory)) { if (child.getPath().getName().startsWith("_")) continue; if (SortedLogState.isFinished(child.getPath().getName())) { foundFinish = true; continue; } FileSystem ns = fs.getVolumeByPath(child.getPath()).getFileSystem(); heap.add(new Index(new Reader(ns.makeQualified(child.getPath()), ns.getConf()))); } if (!foundFinish) throw new IOException( "Sort \"" + SortedLogState.FINISHED.getMarker() + "\" flag not found in " + directory); iter = new SortCheckIterator(new RangeIterator(start, end)); }
public MultiReader(FileSystem fs, Configuration conf, String directory) throws IOException { boolean foundFinish = false; for (FileStatus child : fs.listStatus(new Path(directory))) { if (child.getPath().getName().startsWith("_")) continue; if (child.getPath().getName().equals("finished")) { foundFinish = true; continue; } heap.add(new Index(new Reader(fs, child.getPath().toString(), conf))); } if (!foundFinish) throw new IOException("Sort \"finished\" flag not found in " + directory); }
@VisibleForTesting synchronized boolean seek(WritableComparable<?> key) throws IOException { PriorityBuffer reheap = new PriorityBuffer(heap.size()); boolean result = false; for (Object obj : heap) { Index index = (Index) obj; try { WritableComparable<?> found = index.reader.getClosest(key, index.value, true); if (found != null && found.equals(key)) { result = true; } } catch (EOFException ex) { // thrown if key is beyond all data in the map } index.cached = false; reheap.add(index); } heap = reheap; return result; }
public synchronized boolean seek(WritableComparable key) throws IOException { PriorityBuffer reheap = new PriorityBuffer(heap.size()); boolean result = false; for (Object obj : heap) { Index index = (Index) obj; try { WritableComparable found = index.reader.getClosest(key, index.value, true); if (found != null && found.equals(key)) { result = true; } } catch (EOFException ex) { // thrown if key is beyond all data in the map } index.cached = false; reheap.add(index); } heap = reheap; return result; }
@VisibleForTesting synchronized boolean next(WritableComparable<?> key, Writable val) throws IOException { Index elt = (Index) heap.remove(); try { elt.cache(); if (elt.cached) { copy(elt.key, key); copy(elt.value, val); elt.cached = false; } else { return false; } } finally { heap.add(elt); } return true; }
public synchronized boolean next(WritableComparable key, Writable val) throws IOException { Index elt = (Index) heap.remove(); try { elt.cache(); if (elt.cached) { copy(elt.key, key); copy(elt.value, val); elt.cached = false; } else { return false; } } finally { heap.add(elt); } return true; }
public RecoveryLogReader(VolumeManager fs, Path directory, LogFileKey start, LogFileKey end) throws IOException { boolean foundFinish = false; for (FileStatus child : fs.listStatus(directory)) { if (child.getPath().getName().startsWith("_")) continue; if (SortedLogState.isFinished(child.getPath().getName())) { foundFinish = true; continue; } FileSystem ns = fs.getVolumeByPath(child.getPath()).getFileSystem(); heap.add(new Index(new Reader(ns.makeQualified(child.getPath()), ns.getConf()))); } if (!foundFinish) throw new IOException( "Sort \"" + SortedLogState.FINISHED.getMarker() + "\" flag not found in " + directory); iter = new SortCheckIterator(new RangeIterator(start, end)); }