scanner.setFamily(columnFamilyBytes); scanner.setStartKey(startkey.getBytes(UTF8_CHARSET)); scanner.setQualifiers(getQualifierList(fields)); try { int numResults = 0; while ((rows = scanner.nextRows().join(joinTimeout)) != null) { for (final ArrayList<KeyValue> row : rows) { final HashMap<String, ByteIterator> rowResult = scanner.close().join(joinTimeout); return Status.OK; } catch (InterruptedException e) {
private ArrayList<ArrayList<KeyValue>> _getSingleRow(final String start, final String end, final FilterList filterList, final String tableName) { final Scanner scanner = _client.newScanner(tableName); scanner.setStartKey(start); scanner.setStopKey(end); scanner.setMaxNumRows(1); scanner.setFilter(filterList); _logger.debug("Using table: " + tableName); _logger.debug("Scan startRow: " + start); _logger.debug("Scan stopRow: " + end); Deferred<ArrayList<ArrayList<KeyValue>>> deferred = scanner.nextRows(); deferred.addCallback(new Callback<ArrayList<ArrayList<KeyValue>>, ArrayList<ArrayList<KeyValue>>>() { @Override public ArrayList<ArrayList<KeyValue>> call(ArrayList<ArrayList<KeyValue>> rows) throws Exception { scanner.close(); return rows; } }); try { ArrayList<ArrayList<KeyValue>> result = deferred.join(SCAN_TIMEOUT_MS); return result; } catch (InterruptedException e) { throw new SystemException("Interrupted while waiting to obtain results for query", e); } catch (TimeoutException e) { _logger.warn("Timed out while waiting to obtain results."); } catch (Exception e) { throw new SystemException("Exception occurred in getting results for query", e); } return null; }
this.logger.debug("Fetching HBase Scanner"); this.scanner = this.client.newScanner(this.river.getTable()); this.scanner.setServerBlockCache(false); if (this.river.getFamily() != null) { this.scanner.setFamily(this.river.getFamily()); this.scanner.setQualifier(qualifier.trim().getBytes(this.river.getCharset())); this.logger.debug("Starting to fetch rows"); while ((rows = this.scanner.nextRows(this.river.getBatchSize()).addErrback(this.cbLogger).joinUninterruptibly()) != null) { if (this.stopThread) { this.logger.info("Stopping HBase import in the midle of it"); if (this.scanner != null) { try { this.scanner.close().addErrback(this.cbLogger); } catch (Exception e) { this.logger.error("An Exception has been caught while closing the HBase Scanner", e, (Object[]) null);
/** * Creates a scanner that scans the right range of rows for suggestions. */ private Scanner getSuggestScanner(final String search) { final byte[] start_row; final byte[] end_row; if (search.isEmpty()) { start_row = START_ROW; end_row = END_ROW; } else { start_row = toBytes(search); end_row = Arrays.copyOf(start_row, start_row.length); end_row[start_row.length - 1]++; } final Scanner scanner = client.newScanner(table); scanner.setStartKey(start_row); scanner.setStopKey(end_row); scanner.setFamily(ID_FAMILY); scanner.setQualifier(kind); scanner.setMaxNumRows(MAX_SUGGESTIONS); return scanner; }
final String[] args) { final Scanner scanner = client.newScanner(table); scanner.setMaxNumRows(1024); String regexp; scanner.setFamily(ID_FAMILY); if (args.length == 3) { scanner.setQualifier(toBytes(args[1])); regexp = args[2]; } else { regexp = "(?i)" + regexp; scanner.setKeyRegexp(regexp, CHARSET); boolean found = false; try { ArrayList<ArrayList<KeyValue>> rows; while ((rows = scanner.nextRows().joinUninterruptibly()) != null) { for (final ArrayList<KeyValue> row : rows) { found |= printResult(row, ID_FAMILY, true);
final byte[] family) { final Scanner scanner = newScanner(table); scanner.setReversed(true); scanner.setMaxNumRows(1); scanner.setStartKey(row); scanner.setFamily(family); scanner.setRegionName(region); HBaseRpc open_request = scanner.getOpenRequestForReverseScan(row); open_request.region = region; open_request.getDeferred().addCallbackDeferring(scanner.opened_scanner)
static List<Deferred<Boolean>> doList(HBaseClient client) throws Throwable { final Scanner scanner = client.newScanner(TABLE_NAME); scanner.setFamily(INFO_FAM); scanner.setQualifier(PASSWORD_COL); ArrayList<ArrayList<KeyValue>> rows = null; ArrayList<Deferred<Boolean>> workers = new ArrayList<Deferred<Boolean>>(); while ((rows = scanner.nextRows(1).joinUninterruptibly()) != null) { LOG.info("received a page of users."); for (ArrayList<KeyValue> row : rows) { KeyValue kv = row.get(0); byte[] expected = kv.value(); String userId = new String(kv.key()); PutRequest put = new PutRequest( TABLE_NAME, kv.key(), kv.family(), kv.qualifier(), mkNewPassword(expected)); Deferred<Boolean> d = client.compareAndSet(put, expected) .addCallback(new InterpretResponse(userId)) .addCallbacks(new ResultToMessage(), new FailureToMessage()) .addCallback(new SendMessage()); workers.add(d); } } return workers; }
/** * Scans the next batch of rows * * @return next batch of rows that were scanned. * * @see org.hbase.async.Scanner#nextRows() */ public Deferred<ArrayList<ArrayList<KeyValue>>> nextRows() { return scanner.nextRows(); }
meta_scanner.setStartKey(meta_start); meta_scanner.setStopKey(meta_stop); return meta_scanner.nextRows().addCallback(new MetaScanner());
/** * Scans a number of rows. Calling this method is equivalent to: * <pre> * this.{@link #setMaxNumRows setMaxNumRows}(nrows); * this.{@link #nextRows() nextRows}(); * </pre> * @param nrows The maximum number of rows to retrieve. * @return A deferred list of rows. * @see #setMaxNumRows * @see #nextRows() */ public Deferred<ArrayList<ArrayList<KeyValue>>> nextRows(final int nrows) { setMaxNumRows(nrows); return nextRows(); }
/** * Creates the {@link org.hbase.async.Scanner} to use for this query. */ Scanner getScanner() throws HBaseException { final short metric_width = tsdb.metrics.width(); final byte[] start_row = new byte[metric_width + Const.TIMESTAMP_BYTES]; final byte[] end_row = new byte[metric_width + Const.TIMESTAMP_BYTES]; // We search at least one row before and one row after the start & end // time we've been given as it's quite likely that the exact timestamp // we're looking for is in the middle of a row. Plus, a number of things // rely on having a few extra data points before & after the exact start // & end dates in order to do proper rate calculation or downsampling near // the "edges" of the graph. Bytes.setInt(start_row, (int) getScanStartTime(), metric_width); Bytes.setInt(end_row, (end_time == UNSET ? -1 // Will scan until the end (0xFFF...). : (int) getScanEndTime()), metric_width ); System.arraycopy(metric, 0, start_row, 0, metric_width); System.arraycopy(metric, 0, end_row, 0, metric_width); final Scanner scanner = tsdb.client.newScanner(tsdb.table); scanner.setStartKey(start_row); scanner.setStopKey(end_row); if (tags.size() > 0 || group_bys != null) { createAndSetFilter(scanner); } scanner.setFamily(TSDB.FAMILY); return scanner; }
ArrayList<ArrayList<KeyValue>> rows; while ((short) suggestions.size() < MAX_SUGGESTIONS && (rows = scanner.nextRows().joinUninterruptibly()) != null) { for (final ArrayList<KeyValue> row : rows) { if (row.size() != 1) { throw new RuntimeException("Should never be here", e); } finally { scanner.close();
public Object call(final Object error) { final RegionInfo old_region = region; // Save before invalidate(). invalidate(); // If there was an error, don't assume we're still OK. if (error instanceof NotServingRegionException) { return nextRows(); // XXX dangerous endless retry } else if (error instanceof UnknownScannerException) { error); return nextRows(); // XXX dangerous endless retry
@Override public ArrayList<ArrayList<KeyValue>> call(ArrayList<ArrayList<KeyValue>> rows) throws Exception { scanner.close(); return rows; } });
/** * Set the family to scan. * * @param family the family to scan. * * @return this {@link RowScanner} to facilitate method chaining. * * @see org.hbase.async.Scanner#setFamily(byte[]) */ public RowScanner setFamily(final byte[] family) { scanner.setFamily(family); return this; }
/** * Package-private access point for {@link Scanner}s to scan more rows. * @param scanner The scanner to use. * @return A deferred row. */ Deferred<Object> scanNextRows(final Scanner scanner) { final RegionInfo region = scanner.currentRegion(); final RegionClient client = clientFor(region); if (client == null) { // Oops, we no longer know anything about this client or region. Our // cache was probably invalidated while the client was scanning. This // means that we lost the connection to that RegionServer, so we have to // re-open this scanner if we wanna keep scanning. scanner.invalidate(); // Invalidate the scanner so that ... @SuppressWarnings("unchecked") final Deferred<Object> d = (Deferred) scanner.nextRows(); return d; // ... this will re-open it ______.^ } num_scans.increment(); final HBaseRpc next_request = scanner.getNextRowsRequest(); final Deferred<Object> d = next_request.getDeferred(); client.sendRpc(next_request); return d; }
/** * Set the first key in the range to scan. * * @param key the first key to scan from (inclusive). * * @return this {@link RowScanner} to facilitate method chaining. * * @see org.hbase.async.Scanner#setStartKey(byte[]) */ public RowScanner setStartKey(final byte[] key) { scanner.setStartKey(key); return this; }
/** * Set the qualifier to select from cells * * @param qualifier the family to select from cells. * * @return this {@link RowScanner} to facilitate method chaining. * * @see org.hbase.async.Scanner#setQualifier(byte[]) */ public RowScanner setQualifier(final byte[] qualifier) { scanner.setQualifier(qualifier); return this; }
return Deferred.fromResult(null); // The server already closed the scanner for us. return close() // Auto-close the scanner. .addCallback(new Callback<ArrayList<ArrayList<KeyValue>>, Object>() { public ArrayList<ArrayList<KeyValue>> call(final Object arg) { return continueScanOnNextRegion();
/** * Set the end key in the range to scan. * * @param key the end key to scan until (exclusive) * * @return this {@link RowScanner} to facilitate method chaining. * * @see org.hbase.async.Scanner#setStopKey(byte[]) */ public RowScanner setStopKey(final byte[] key) { scanner.setStopKey(key); return this; }