Package org.hbase.async

Examples of org.hbase.async.Scanner$GetNextRowsRequest


  private static final class scan implements Cmd {
    @SuppressWarnings("fallthrough")
    public void execute(final HBaseClient client, String[] args) {
      ensureArguments(args, 3, 8);
      final Scanner scanner = client.newScanner(args[2]);
      switch (args.length) {
        case 8: scanner.setKeyRegexp(args[7]);
        case 7: scanner.setStopKey(args[6]);
        case 6: scanner.setQualifier(args[5]);
        case 5: scanner.setFamily(args[4]);
        case 4: scanner.setStartKey(args[3]);
      }
      args = null;
      LOG.info("Start scanner=" + scanner);
      try {
        ArrayList<ArrayList<KeyValue>> rows;
        while ((rows = scanner.nextRows().joinUninterruptibly()) != null) {
          LOG.info("scanned results=" + rows + " from " + scanner);
        }
      } catch (Exception e) {
        LOG.error("Scan failed", e);
      }
View Full Code Here


  private static final class mscan implements Cmd {
    @SuppressWarnings("fallthrough")
    public void execute(final HBaseClient client, String[] args) {
      ensureArguments(args, 3, 7);
      final Scanner scanner = client.newScanner(args[2]);
      switch (args.length) {
        case 7: scanner.setKeyRegexp(args[6]);
        case 6: scanner.setStopKey(args[5]);
        case 5:
          final String columns = args[4];
          final ArrayList<byte[]> families = new ArrayList<byte[]>();
          final ArrayList<byte[][]> qualifiers = new ArrayList<byte[][]>();
          for (String spec : columns.split("/")) {
            final String[] family = spec.split(":");
            families.add(family[0].getBytes());
            if (family.length == 1) {
              qualifiers.add(null);
            } else {
              final String[] quals = family[1].split(",");
              final byte[][] qb = new byte[quals.length][];
              for (int i = 0; i < qb.length; i++) {
                qb[i] = quals[i].getBytes();
              }
              qualifiers.add(qb);
            }
          }
          scanner.setFamilies(families.toArray(new byte[families.size()][]),
                              qualifiers.toArray(new byte[qualifiers.size()][][]));
        case 4: scanner.setStartKey(args[3]);
      }
      LOG.info("Start scanner=" + scanner);
      try {
        ArrayList<ArrayList<KeyValue>> rows;
        while ((rows = scanner.nextRows().joinUninterruptibly()) != null) {
          LOG.info("scanned results=" + rows + " from " + scanner);
        }
      } catch (Exception e) {
        LOG.error("Scan failed", e);
      }
View Full Code Here

   */
  private Deferred<TreeMap<byte[], Span>> findSpans() throws HBaseException {
    final short metric_width = tsdb.metrics.width();
    final TreeMap<byte[], Span> spans = // The key is a row key from HBase.
      new TreeMap<byte[], Span>(new SpanCmp(metric_width));
    final Scanner scanner = getScanner();
    final Deferred<TreeMap<byte[], Span>> results =
      new Deferred<TreeMap<byte[], Span>>();
   
    /**
    * Scanner callback executed recursively each time we get a set of data
    * from storage. This is responsible for determining what columns are
    * returned and issuing requests to load leaf objects.
    * When the scanner returns a null set of rows, the method initiates the
    * final callback.
    */
    final class ScannerCB implements Callback<Object,
      ArrayList<ArrayList<KeyValue>>> {
     
      int nrows = 0;
      int hbase_time = 0; // milliseconds.
      long starttime = System.nanoTime();
     
      /**
      * Starts the scanner and is called recursively to fetch the next set of
      * rows from the scanner.
      * @return The map of spans if loaded successfully, null if no data was
      * found
      */
       public Object scan() {
         starttime = System.nanoTime();
         return scanner.nextRows().addCallback(this);
       }
 
      /**
      * Loops through each row of the scanner results and parses out data
      * points and optional meta data
      * @return null if no rows were found, otherwise the TreeMap with spans
      */
       @Override
       public Object call(final ArrayList<ArrayList<KeyValue>> rows)
         throws Exception {
         hbase_time += (System.nanoTime() - starttime) / 1000000;
         try {
           if (rows == null) {
             hbase_time += (System.nanoTime() - starttime) / 1000000;
             scanlatency.add(hbase_time);
             LOG.info(TsdbQuery.this + " matched " + nrows + " rows in " +
                 spans.size() + " spans in " + hbase_time + "ms");
             if (nrows < 1) {
               results.callback(null);
             } else {
               results.callback(spans);
             }
             scanner.close();
             return null;
           }
          
           for (final ArrayList<KeyValue> row : rows) {
             final byte[] key = row.get(0).key();
             if (Bytes.memcmp(metric, key, 0, metric_width) != 0) {
               scanner.close();
               throw new IllegalDataException(
                   "HBase returned a row that doesn't match"
                   + " our scanner (" + scanner + ")! " + row + " does not start"
                   + " with " + Arrays.toString(metric));
             }
             Span datapoints = spans.get(key);
             if (datapoints == null) {
               datapoints = new Span(tsdb);
               spans.put(key, datapoints);
             }
             final KeyValue compacted =
               tsdb.compact(row, datapoints.getAnnotations());
             if (compacted != null) { // Can be null if we ignored all KVs.
               datapoints.addRow(compacted);
               nrows++;
             }
           }
          
           return scan();
         } catch (Exception e) {
           scanner.close();
           results.callback(e);
           return null;
         }
       }
     }
View Full Code Here

    } else {
      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 (tsuids != null && !tsuids.isEmpty()) {
      createAndSetTSUIDFilter(scanner);
    } else if (tags.size() > 0 || group_bys != null) {
      createAndSetFilter(scanner);
    }
    scanner.setFamily(TSDB.FAMILY);
    return scanner;
  }
View Full Code Here

   */
  public static Deferred<Branch> fetchBranch(final TSDB tsdb,
      final byte[] branch_id, final boolean load_leaf_uids) {
   
    final Deferred<Branch> result = new Deferred<Branch>();
    final Scanner scanner = setupBranchScanner(tsdb, branch_id);
   
    // This is the branch that will be loaded with data from the scanner and
    // returned at the end of the process.
    final Branch branch = new Branch();
   
    // A list of deferreds to wait on for child leaf processing
    final ArrayList<Deferred<Object>> leaf_group =
      new ArrayList<Deferred<Object>>();
   
    /**
     * Exception handler to catch leaves with an invalid UID name due to a
     * possible deletion. This will allow the scanner to keep loading valid
     * leaves and ignore problems. The fsck tool can be used to clean up
     * orphaned leaves. If we catch something other than an NSU, it will
     * re-throw the exception
     */
    final class LeafErrBack implements Callback<Object, Exception> {

      final byte[] qualifier;
     
      public LeafErrBack(final byte[] qualifier) {
        this.qualifier = qualifier;
      }
     
      @Override
      public Object call(final Exception e) throws Exception {
        Throwable ex = e;
        while (ex.getClass().equals(DeferredGroupException.class)) {
          ex = ex.getCause();
        }
        if (ex.getClass().equals(NoSuchUniqueId.class)) {
          LOG.debug("Invalid UID for leaf: " + idToString(qualifier) +
              " in branch: " + idToString(branch_id), ex);
        } else {
          throw (Exception)ex;
        }
        return null;
      }
     
    }
   
    /**
     * Called after a leaf has been loaded successfully and adds the leaf
     * to the branch's leaf set. Also lazily initializes the leaf set if it
     * hasn't been.
     */
    final class LeafCB implements Callback<Object, Leaf> {

      @Override
      public Object call(final Leaf leaf) throws Exception {
        if (leaf != null) {
          if (branch.leaves == null) {
            branch.leaves = new HashMap<Integer, Leaf>();
          }
          branch.leaves.put(leaf.hashCode(), leaf);
        }
        return null;
      }
     
    }
   
    /**
     * Scanner callback executed recursively each time we get a set of data
     * from storage. This is responsible for determining what columns are
     * returned and issuing requests to load leaf objects.
     * When the scanner returns a null set of rows, the method initiates the
     * final callback.
     */
    final class FetchBranchCB implements Callback<Object,
      ArrayList<ArrayList<KeyValue>>> {
 
      /**
       * Starts the scanner and is called recursively to fetch the next set of
       * rows from the scanner.
       * @return The branch if loaded successfully, null if the branch was not
       * found.
       */
      public Object fetchBranch() {
        return scanner.nextRows().addCallback(this);
      }
     
      /**
       * Loops through each row of the scanner results and parses out branch
       * definitions and child leaves.
View Full Code Here

   */
  private static Scanner setupBranchScanner(final TSDB tsdb,
      final byte[] branch_id) {
    final byte[] start = branch_id;
    final byte[] end = Arrays.copyOf(branch_id, branch_id.length);
    final Scanner scanner = tsdb.getClient().newScanner(tsdb.treeTable());
    scanner.setStartKey(start);
   
    // increment the tree ID so we scan the whole tree
    byte[] tree_id = new byte[INT_WIDTH];
    for (int i = 0; i < Tree.TREE_ID_WIDTH(); i++) {
      tree_id[i + (INT_WIDTH - Tree.TREE_ID_WIDTH())] = end[i];
    }
    int id = Bytes.getInt(tree_id) + 1;
    tree_id = Bytes.fromInt(id);
    for (int i = 0; i < Tree.TREE_ID_WIDTH(); i++) {
      end[i] = tree_id[i + (INT_WIDTH - Tree.TREE_ID_WIDTH())];
    }
    scanner.setStopKey(end);
    scanner.setFamily(Tree.TREE_FAMILY());

    // TODO - use the column filter to fetch only branches and leaves, ignore
    // collisions, no matches and other meta
   
    // set the regex filter
    // we want one branch below the current ID so we want something like:
    // {0, 1, 1, 2, 3, 4 }  where { 0, 1 } is the tree ID, { 1, 2, 3, 4 } is the
    // branch
    // "^\\Q\000\001\001\002\003\004\\E(?:.{4})$"
   
    final StringBuilder buf = new StringBuilder((start.length * 6) + 20);
    buf.append("(?s)"  // Ensure we use the DOTALL flag.
        + "^\\Q");
    for (final byte b : start) {
      buf.append((char) (b & 0xFF));
    }
    buf.append("\\E(?:.{").append(INT_WIDTH).append("})?$");
   
    scanner.setKeyRegexp(buf.toString(), CHARSET);
    return scanner;
  }
View Full Code Here

   */
  private static int grep(final HBaseClient client,
                          final byte[] table,
                          final boolean ignorecase,
                          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 = args[1];
    }
    if (ignorecase) {
      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);
        }
      }
    } catch (HBaseException e) {
View Full Code Here

    final byte[] METRICS_META = "metric_meta".getBytes(CHARSET);
    final byte[] TAGK_META = "tagk_meta".getBytes(CHARSET);
    final byte[] TAGV_META = "tagv_meta".getBytes(CHARSET);
    final long start_time = System.nanoTime();
    final HashMap<String, Uids> name2uids = new HashMap<String, Uids>();
    final Scanner scanner = client.newScanner(table);
    scanner.setMaxNumRows(1024);
    int kvcount = 0;
    try {
      ArrayList<ArrayList<KeyValue>> rows;
      while ((rows = scanner.nextRows().joinUninterruptibly()) != null) {
        for (final ArrayList<KeyValue> row : rows) {
          for (final KeyValue kv : row) {
            kvcount++;
           
            // TODO - validate meta data in the future, for now skip it
View Full Code Here

    short metric_width = TSDB.metrics_width();
    final byte[] start_row =
      Arrays.copyOfRange(Bytes.fromLong(start_id), 8 - metric_width, 8);
    final byte[] end_row =
      Arrays.copyOfRange(Bytes.fromLong(end_id), 8 - metric_width, 8);
    final Scanner scanner = tsdb.getClient().newScanner(table);
    scanner.setStartKey(start_row);
    scanner.setStopKey(end_row);
    scanner.setFamily(NAME_FAMILY);
    return scanner;
  }
View Full Code Here

    } 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_results <= 4096 ? max_results : 4096);
    return scanner;
  }
View Full Code Here

TOP

Related Classes of org.hbase.async.Scanner$GetNextRowsRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.