예제 #1
0
 /**
  * Finds all the {@link Span}s that match this query. This is what actually scans the HBase table
  * and loads the data into {@link Span}s.
  *
  * @return A map from HBase row key to the {@link Span} for that row key. Since a {@link Span}
  *     actually contains multiple HBase rows, the row key stored in the map has its timestamp
  *     zero'ed out.
  * @throws HBaseException if there was a problem communicating with HBase to perform the search.
  * @throws IllegalArgumentException if bad data was retreived from HBase.
  */
 private 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));
   int nrows = 0;
   int hbase_time = 0; // milliseconds.
   long starttime = System.nanoTime();
   final Scanner scanner = getScanner();
   try {
     ArrayList<ArrayList<KeyValue>> rows;
     while ((rows = scanner.nextRows().joinUninterruptibly()) != null) {
       hbase_time += (System.nanoTime() - starttime) / 1000000;
       for (final ArrayList<KeyValue> row : rows) {
         final byte[] key = row.get(0).key();
         if (Bytes.memcmp(metric, key, 0, metric_width) != 0) {
           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);
         }
         datapoints.addRow(tsdb.compact(row));
         nrows++;
         starttime = System.nanoTime();
       }
     }
   } catch (RuntimeException e) {
     throw e;
   } catch (Exception e) {
     throw new RuntimeException("Should never be here", e);
   } finally {
     hbase_time += (System.nanoTime() - starttime) / 1000000;
     scanlatency.add(hbase_time);
   }
   LOG.info(this + " matched " + nrows + " rows in " + spans.size() + " spans");
   if (nrows == 0) {
     return null;
   }
   return spans;
 }
예제 #2
0
파일: HttpQuery.java 프로젝트: gitbrid/tsdb
 /** Method to call after writing the HTTP response to the wire. */
 private void done() {
   final int processing_time = processingTimeMillis();
   httplatency.add(processing_time);
   logInfo("HTTP " + getUri() + " done in " + processing_time + "ms");
   deferred.callback(null);
 }