@Override public Cell peek() { if (this.current == null) { return null; } return this.current.peek(); }
@Override public Cell peek() { return delegate.peek(); }
@Override public int compare(KeyValueScanner left, KeyValueScanner right) { int comparison = compare(left.peek(), right.peek()); if (comparison != 0) { return comparison; } else { // Since both the keys are exactly the same, we break the tie in favor of higher ordered // scanner since it'll have newer data. Since higher value should come first, we reverse // sort here. return Long.compare(right.getScannerOrder(), left.getScannerOrder()); } } /**
/** * Constructor. * @param scanners * @param comparator * @throws IOException */ KeyValueHeap(List<? extends KeyValueScanner> scanners, KVScannerComparator comparator) throws IOException { this.comparator = comparator; this.scannersForDelayedClose = new ArrayList<>(scanners.size()); if (!scanners.isEmpty()) { this.heap = new PriorityQueue<>(scanners.size(), this.comparator); for (KeyValueScanner scanner : scanners) { if (scanner.peek() != null) { this.heap.add(scanner); } else { this.scannersForDelayedClose.add(scanner); } } this.current = pollRealKV(); } }
@Override public Cell next() throws IOException { if(this.current == null) { return null; } Cell kvReturn = this.current.next(); Cell kvNext = this.current.peek(); if (kvNext == null) { this.scannersForDelayedClose.add(this.current); this.current = null; this.current = pollRealKV(); } else { KeyValueScanner topScanner = this.heap.peek(); // no need to add current back to the heap if it is the only scanner left if (topScanner != null && this.comparator.compare(kvNext, topScanner.peek()) >= 0) { this.heap.add(this.current); this.current = null; this.current = pollRealKV(); } } return kvReturn; }
@Override public boolean seekToPreviousRow(Cell seekKey) throws IOException { if (current == null) { return false; } heap.add(current); current = null; KeyValueScanner scanner; while ((scanner = heap.poll()) != null) { Cell topKey = scanner.peek(); if (comparator.getComparator().compareRows(topKey, seekKey) < 0) { // Row of Top KeyValue is before Seek row. heap.add(scanner); current = pollRealKV(); return current != null; } if (!scanner.seekToPreviousRow(seekKey)) { this.scannersForDelayedClose.add(scanner); } else { heap.add(scanner); } } // Heap is returning empty, scanner is done return false; }
@Override public boolean backwardSeek(Cell seekKey) throws IOException { if (current == null) { return false; } heap.add(current); current = null; KeyValueScanner scanner; while ((scanner = heap.poll()) != null) { Cell topKey = scanner.peek(); if ((CellUtil.matchingRows(seekKey, topKey) && comparator .getComparator().compare(seekKey, topKey) <= 0) || comparator.getComparator().compareRows(seekKey, topKey) > 0) { heap.add(scanner); current = pollRealKV(); return current != null; } if (!scanner.backwardSeek(seekKey)) { this.scannersForDelayedClose.add(scanner); } else { heap.add(scanner); } } return false; }
@Override public Cell next() throws IOException { if (this.current == null) { return null; } Cell kvReturn = this.current.next(); Cell kvNext = this.current.peek(); if (kvNext == null || this.comparator.kvComparator.compareRows(kvNext, kvReturn) > 0) { if (this.current.seekToPreviousRow(kvReturn)) { this.heap.add(this.current); } else { this.scannersForDelayedClose.add(this.current); } this.current = null; this.current = pollRealKV(); } else { KeyValueScanner topScanner = this.heap.peek(); if (topScanner != null && this.comparator.compare(this.current, topScanner) > 0) { this.heap.add(this.current); this.current = null; this.current = pollRealKV(); } } return kvReturn; }
try { while (scanner != null) { Cell topKey = scanner.peek(); if (comparator.getComparator().compare(seekKey, topKey) <= 0) {
for (KeyValueScanner kvs : currentFileScanners) { assert kvs.isFileScanner(); if (kvs.peek() == null) { continue;
Cell pee = this.current.peek();
Cell c = scanner.peek(); if (c != null) { totalScannersSoughtBytes += PrivateCellUtil.estimatedSerializedSizeOf(c);
@Override public KeyValue peek() { return delegate.peek(); }
Cell res = scan.peek(); assertEquals(kvs[0], res); res = scan.peek(); assertEquals(kvs[2], res); assertEquals(kvs[0], scan.peek()); assertEquals(kvs[0], scan.next()); assertEquals(kvs[1], scan.peek()); assertEquals(kvs[1], scan.next()); assertEquals(kvs[2], scan.peek()); assertEquals(kvs[2], scan.next()); assertEquals(null, scan.peek()); assertEquals(null, scan.next());
assertEquals(makeKV(ROWSIZE - 1, 0), scanner.peek()); assertEquals(seekKey, scanner.peek()); assertTrue(scanner.backwardSeek(KeyValueUtil.createLastOnRow(ROWS[seekRowNum]))); KeyValue expectedKey = makeKV(seekRowNum - 1, 0); assertEquals(expectedKey, scanner.peek()); assertEquals(null, scanner.peek()); .createFirstOnRow(ROWS[seekRowNum]))); expectedKey = makeKV(seekRowNum - 1, 0); assertEquals(expectedKey, scanner.peek()); assertEquals(null, scanner.peek());
protected void assertScannerResults(KeyValueScanner scanner, KeyValue[] expected) throws IOException { scanner.seek(KeyValueUtil.createFirstOnRow(new byte[]{})); List<Cell> returned = Lists.newArrayList(); while (true) { Cell next = scanner.next(); if (next == null) break; returned.add(next); } assertTrue( "Got:\n" + Joiner.on("\n").join(returned) + "\nExpected:\n" + Joiner.on("\n").join(expected), Iterables.elementsEqual(Arrays.asList(expected), returned)); assertNull(scanner.peek()); }
res = false; for (KeyValueScanner scanner : scanners) { res |= (expectedKey.equals(scanner.peek())); res = false; for (KeyValueScanner scanner : scanners) { res |= (expectedKey.equals(scanner.peek())); res |= (expectedKey.equals(scanner.peek())); res = false; for (KeyValueScanner scanner : scanners) { res |= (expectedKey.equals(scanner.peek()));
public Result getCurrentRowState() { KeyValueScanner scanner = this.memstore.getScanner(); List<KeyValue> kvs = new ArrayList<KeyValue>(); while (scanner.peek() != null) { try { kvs.add(scanner.next()); } catch (IOException e) { // this should never happen - something has gone terribly arwy if it has throw new RuntimeException("Local MemStore threw IOException!"); } } return new Result(kvs); }