Package org.apache.hadoop.hbase.regionserver

Examples of org.apache.hadoop.hbase.regionserver.InternalScanner


   * @param listener
   * @throws IOException
   */
  public void scanMetaRegion(final HRegion m, final ScannerListener listener)
  throws IOException {
    InternalScanner metaScanner = m.getScanner(HConstants.COL_REGIONINFO_ARRAY,
      HConstants.EMPTY_START_ROW, HConstants.LATEST_TIMESTAMP, null);
    try {
      HStoreKey key = new HStoreKey();
      SortedMap<byte[], Cell> results =
        new TreeMap<byte[], Cell>(Bytes.BYTES_COMPARATOR);
      while (metaScanner.next(key, results)) {
        HRegionInfo info = Writables.getHRegionInfoOrNull(
            results.get(HConstants.COL_REGIONINFO).getValue());
        if (info == null) {
          LOG.warn("regioninfo null for row " + key.getRow() + " in table " +
            Bytes.toString(m.getTableDesc().getName()));
          continue;
        }
        if (!listener.processRow(info)) {
          break;
        }
        results.clear();
      }
    } finally {
      metaScanner.close();
    }
  }
View Full Code Here


      // Scan root region to find all the meta regions
     
      root = new HRegion(rootTableDir, hlog, fs, conf,
          HRegionInfo.ROOT_REGIONINFO, null, null);

      InternalScanner rootScanner =
        root.getScanner(COL_REGIONINFO_ARRAY, HConstants.EMPTY_START_ROW,
        HConstants.LATEST_TIMESTAMP, null);
     
      try {
        HStoreKey key = new HStoreKey();
        TreeMap<byte [], Cell> results =
          new TreeMap<byte [], Cell>(Bytes.BYTES_COMPARATOR);
        while(rootScanner.next(key, results)) {
          key.setHRegionInfo(HRegionInfo.ROOT_REGIONINFO);
          for(Cell c: results.values()) {
            HRegionInfo info = Writables.getHRegionInfoOrNull(c.getValue());
            if (info != null) {
              metaRegions.add(info);
            }
          }
        }
      } finally {
        rootScanner.close();
        try {
          root.close();
         
        } catch(IOException e) {
          LOG.error(e);
View Full Code Here

  @Override
  public <T, S> S getSum(ColumnInterpreter<T, S> ci, Scan scan, byte[] qualifier) throws IOException {
     long sum = 0l;
    S sumVal = null;
    T temp;
    InternalScanner scanner = ((RegionCoprocessorEnvironment) getEnvironment())
        .getRegion().getScanner(scan);
    byte[] colFamily = scan.getFamilies()[0];
    List<KeyValue> results = new ArrayList<KeyValue>();
    try {
      boolean hasMoreRows = false;
      do {
        hasMoreRows = scanner.next(results);
        log.info("results size is " + results.size());
        for (KeyValue kv : results) {
          if(!Bytes.equals(kv.getQualifier(), qualifier)) {
            continue;
          }
          temp = ci.getValue(colFamily, qualifier, kv);
          log.info("WaspAggregateImplementation log : qualifier="
              + Bytes.toString(qualifier) + " value is :" + Bytes.toStringBinary(kv.getValue()) + " sum is :" + sumVal
          + " temp is :" + temp + " row is :" + Bytes.toStringBinary(kv.getRow()));
          if (temp != null)
            sumVal = ci.add(sumVal, ci.castToReturnType(temp));
        }
        results.clear();
      } while (hasMoreRows);
    } finally {
      scanner.close();
    }
    log.debug("Sum from this region is "
        + ((RegionCoprocessorEnvironment) getEnvironment()).getRegion()
            .getRegionNameAsString() + ": " + sum);
    return sumVal;
View Full Code Here

    List<KeyValue> results = new ArrayList<KeyValue>();
    byte[] colFamily = scan.getFamilies()[0];
    byte[] qualifier = scan.getFamilyMap().get(colFamily).pollFirst();
    if (scan.getFilter() == null && qualifier == null)
      scan.setFilter(new FirstKeyOnlyFilter());
    InternalScanner scanner = ((RegionCoprocessorEnvironment) getEnvironment())
        .getRegion().getScanner(scan);
    try {
      boolean hasMoreRows = false;
      int j = 0;
      do {
        j++;
        hasMoreRows = scanner.next(results);
        log.info("results size is " + results.size());
        int i = 1;
        for (KeyValue result : results) {
          log.info("j = " + j + "; i = " + i + "; column = " + Bytes.toString(result.getQualifier()) + "; value = "
              + Bytes.toStringBinary(result.getValue()) );

        }
        if (results.size() > 0) {
          counter++;
        }
        results.clear();
      } while (hasMoreRows);
    } finally {
      scanner.close();
    }
    log.info("Row counter from this region is "
        + ((RegionCoprocessorEnvironment) getEnvironment()).getRegion()
            .getRegionNameAsString() + ": " + counter);
    return counter;
View Full Code Here

   * has no actual methods of querying itself, and relies on StoreScanner.
   */
  public static List<Cell> getFromStoreFile(HStore store,
                                                Get get) throws IOException {
    Scan scan = new Scan(get);
    InternalScanner scanner = (InternalScanner) store.getScanner(scan,
        scan.getFamilyMap().get(store.getFamily().getName()),
        // originally MultiVersionConsistencyControl.resetThreadReadPoint() was called to set
        // readpoint 0.
        0);

    List<Cell> result = new ArrayList<Cell>();
    scanner.next(result);
    if (!result.isEmpty()) {
      // verify that we are on the row we want:
      Cell kv = result.get(0);
      if (!CellUtil.matchingRow(kv, get.getRow())) {
        result.clear();
      }
    }
    scanner.close();
    return result;
  }
View Full Code Here

      scan.addColumn(family, qualifier);
    } else {
      scan.addFamily(family);
    }
    int sumResult = 0;
    InternalScanner scanner = null;
    try {
      scanner = this.env.getRegion().getScanner(scan);
      List<Cell> curVals = new ArrayList<Cell>();
      boolean hasMore = false;
      do {
        curVals.clear();
        hasMore = scanner.next(curVals);
        for (Cell kv : curVals) {
          if (CellUtil.matchingQualifier(kv, qualifier)) {
            sumResult += Bytes.toInt(kv.getValueArray(), kv.getValueOffset());
          }
        }
      } while (hasMore);
    } catch (IOException e) {
      ResponseConverter.setControllerException(controller, e);
      // Set result to -1 to indicate error.
      sumResult = -1;
      LOG.info("Setting sum result to -1 to indicate error", e);
    } finally {
      if (scanner != null) {
        try {
          scanner.close();
        } catch (IOException e) {
          ResponseConverter.setControllerException(controller, e);
          sumResult = -1;
          LOG.info("Setting sum result to -1 to indicate error", e);
        }
View Full Code Here

    long lastFlush;

    @Override
    public InternalScanner preCompact(ObserverContext<RegionCoprocessorEnvironment> e,
        Store store, final InternalScanner scanner, final ScanType scanType) {
      return new InternalScanner() {
        @Override
        public boolean next(List<Cell> results) throws IOException {
          return next(results, -1);
        }
View Full Code Here

   */
  public static List<KeyValue> getFromStoreFile(Store store,
                                                Get get) throws IOException {
    MultiVersionConsistencyControl.resetThreadReadPoint();
    Scan scan = new Scan(get);
    InternalScanner scanner = (InternalScanner) store.getScanner(scan,
        scan.getFamilyMap().get(store.getFamily().getName()));

    List<KeyValue> result = new ArrayList<KeyValue>();
    scanner.next(result);
    if (!result.isEmpty()) {
      // verify that we are on the row we want:
      KeyValue kv = result.get(0);
      if (!Bytes.equals(kv.getRow(), get.getRow())) {
        result.clear();
      }
    }
    scanner.close();
    return result;
  }
View Full Code Here

    // aggregate at each region
    Scan scan = new Scan();
    scan.addColumn(family, qualifier);
    int sumResult = 0;

    InternalScanner scanner = ((RegionCoprocessorEnvironment)getEnvironment())
        .getRegion().getScanner(scan);
    try {
      List<KeyValue> curVals = new ArrayList<KeyValue>();
      boolean done = false;
      do {
        curVals.clear();
        done = scanner.next(curVals);
        KeyValue kv = curVals.get(0);
        sumResult += Bytes.toInt(kv.getBuffer(), kv.getValueOffset());
      } while (done);
    } finally {
      scanner.close();
    }
    return sumResult;
  }
View Full Code Here

    long lastFlush;

    @Override
    public InternalScanner preCompact(ObserverContext<RegionCoprocessorEnvironment> e,
        Store store, final InternalScanner scanner) {
      return new InternalScanner() {
        @Override
        public boolean next(List<KeyValue> results) throws IOException {
          return next(results, -1);
        }
       
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.regionserver.InternalScanner

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.