private RowIterator getImpl(ScannerConfiguration config) { return new RowIteratorImpl(new SnapshotScanner(this.env, config, startTs, stats)); }
@Override public boolean hasNext() { if (next == null) { next = getNext(); } return next != null; }
@Override public Entry<Key, Value> next() { if (!hasNext()) { throw new NoSuchElementException(); } Entry<Key, Value> tmp = next; next = null; return tmp; }
public SnapshotScanner(Environment env, ScannerConfiguration config, long startTs, TxStats stats) { this.env = env; this.config = config; this.startTs = startTs; this.stats = stats; setUpIterator(); }
private BatchScanner setupBatchScanner(Collection<Bytes> rows, Set<Column> columns) { BatchScanner scanner; try { // TODO hardcoded number of threads! // one thread is probably good.. going for throughput scanner = env.getConnector().createBatchScanner(env.getTable(), env.getAuthorizations(), 1); } catch (TableNotFoundException e) { throw new RuntimeException(e); } scanner.clearColumns(); scanner.clearScanIterators(); List<Range> ranges = new ArrayList<>(rows.size()); for (Bytes row : rows) { ranges.add(Range.exact(ByteUtil.toText(row))); } scanner.setRanges(ranges); SnapshotScanner.setupScanner(scanner, columns, startTs); return scanner; }
public Entry<Key, Value> getNext() { mloop: while (true) { // its possible a next could exist then be rolled back if (!iterator.hasNext()) { return null; } Entry<Key, Value> entry = iterator.next(); long colType = entry.getKey().getTimestamp() & ColumnConstants.PREFIX_MASK; if (colType == ColumnConstants.LOCK_PREFIX) { resolveLock(entry); continue mloop; } else if (colType == ColumnConstants.DATA_PREFIX) { stats.incrementEntriesReturned(1); return entry; } else { throw new IllegalArgumentException("Unexpected column type " + colType); } } }
RowColumn end = SpanUtil.toRowColumn(locks.get(locks.size() - 1).getKey()).following(); resetScanner(new Span(start, true, end, false)); resetScanner(new Span(start, true, origEnd, isEndInclusive));
private void resetScanner(Span span) { try { config = (ScannerConfiguration) config.clone(); } catch (CloneNotSupportedException e) { throw new RuntimeException(e); } config.setSpan(span); setUpIterator(); }
private void setUpIterator() { Scanner scanner; try { scanner = env.getConnector().createScanner(env.getTable(), env.getAuthorizations()); } catch (TableNotFoundException e) { throw new RuntimeException(e); } scanner.clearColumns(); scanner.clearScanIterators(); scanner.setRange(SpanUtil.toRange(config.getSpan())); setupScanner(scanner, config.getColumns(), startTs); this.iterator = scanner.iterator(); }