if (nextKV == null || comparator.compare(curKV, nextKV) < 0) {
while (scanner != null) { Cell topKey = scanner.peek(); if (comparator.getComparator().compare(seekKey, topKey) <= 0) {
while ((scanner = heap.poll()) != null) { Cell topKey = scanner.peek(); if (comparator.getComparator().compare(seekKey, topKey) <= 0) {
if (nextKV == null || comparator.compare(curKV, nextKV) < 0) {
if (nextKV == null || comparator.compare(curKV, nextKV) < 0) {
while ((scanner = heap.poll()) != null) { KeyValue topKey = scanner.peek(); if (comparator.getComparator().compare(seekKey, topKey) <= 0) {
@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.current.close(); } 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; }
@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.matchingRow(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)) { scanner.close(); } else { heap.add(scanner); } } return false; }
@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.getRowArray(), topKey.getRowOffset(), topKey.getRowLength(), seekKey.getRowArray(), seekKey.getRowOffset(), seekKey.getRowLength()) < 0) { // Row of Top KeyValue is before Seek row. heap.add(scanner); current = pollRealKV(); return current != null; } if (!scanner.seekToPreviousRow(seekKey)) { scanner.close(); } else { heap.add(scanner); } } // Heap is returning empty, scanner is done return false; }
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.current.close(); 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; }
/** * Constructor. This KeyValueHeap will handle closing of passed in * KeyValueScanners. * @param scanners * @param comparator */ public KeyValueHeap(List<? extends KeyValueScanner> scanners, KVComparator comparator) throws IOException { this.comparator = new KVScannerComparator(comparator); if (!scanners.isEmpty()) { this.heap = new PriorityQueue<KeyValueScanner>(scanners.size(), this.comparator); for (KeyValueScanner scanner : scanners) { if (scanner.peek() != null) { this.heap.add(scanner); } else { scanner.close(); } } this.current = pollRealKV(); } }
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 the key which came latest. long leftSequenceID = left.getSequenceID(); long rightSequenceID = right.getSequenceID(); if (leftSequenceID > rightSequenceID) { return -1; } else if (leftSequenceID < rightSequenceID) { return 1; } else { return 0; } } } /**
public KeyValue next() throws IOException { if(this.current == null) { return null; } KeyValue kvReturn = this.current.next(); KeyValue kvNext = this.current.peek(); if (kvNext == null) { this.current.close(); this.current = pollRealKV(); } else { KeyValueScanner topScanner = this.heap.peek(); if (topScanner == null || this.comparator.compare(kvNext, topScanner.peek()) >= 0) { this.heap.add(this.current); this.current = pollRealKV(); } } return kvReturn; }
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 the key which came latest. long leftSequenceID = left.getSequenceID(); long rightSequenceID = right.getSequenceID(); if (leftSequenceID > rightSequenceID) { return -1; } else if (leftSequenceID < rightSequenceID) { return 1; } else { return 0; } } } /**
/** * Constructor. This KeyValueHeap will handle closing of passed in * KeyValueScanners. * @param scanners * @param comparator */ public KeyValueHeap(List<? extends KeyValueScanner> scanners, KVComparator comparator) throws IOException { this(scanners, new KVScannerComparator(comparator)); }
@Override public int compare(KeyValueScanner left, KeyValueScanner right) { int rowComparison = compareRows(left.peek(), right.peek()); if (rowComparison != 0) { return -rowComparison; } return super.compare(left, right); }
@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; }
@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.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; }