Package org.apache.hadoop.hbase.regionserver

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


        }
      }
      if (LOG.isTraceEnabled()) {
        LOG.trace("Scanning for cells with " + get);
      }
      RegionScanner scanner = getRegion(e).getScanner(new Scan(get));
      List<Cell> cells = Lists.newArrayList();
      try {
        boolean more = false;
        do {
          cells.clear();
          more = scanner.next(cells);
          for (Cell cell: cells) {
            if (LOG.isTraceEnabled()) {
              LOG.trace("Found cell " + cell);
            }
            for (Action action: cellCheckActions) {
              // Are there permissions for this user for the cell?
              if (!authManager.authorize(user, getTableName(e), cell, false, action)) {
                AuthResult authResult = AuthResult.deny(request, "Insufficient permissions",
                  user, action, getTableName(e), CellUtil.cloneFamily(cell),
                  CellUtil.cloneQualifier(cell));
                logResult(authResult);
                throw new AccessDeniedException("Insufficient permissions " +
                  authResult.toContextString());
              }
            }
            cellsChecked++;
          }
        } while (more);
      } catch (AccessDeniedException ex) {
        throw ex;
      } catch (IOException ex) {
        LOG.error("Exception while getting cells to calculate covering permission", ex);
      } finally {
        scanner.close();
      }
    }

    // If there were no cells to check, throw the ADE
    if (cellsChecked < 1) {
View Full Code Here


    long totalRowsDeleted = 0L;
    long totalVersionsDeleted = 0L;
    BulkDeleteResponse response = new BulkDeleteResponse();
    HRegion region = ((RegionCoprocessorEnvironment) getEnvironment()).getRegion();
    boolean hasMore = true;
    RegionScanner scanner = null;
    if (scan.getFilter() == null && deleteType == DeleteType.ROW) {
      // What we need is just the rowkeys. So only 1st KV from any row is enough.
      // Only when it is a row delete, we can apply this filter
      // In other types we rely on the scan to know which all columns to be deleted.
      scan.setFilter(new FirstKeyOnlyFilter());
    }
    // When the delete is based on some conditions so that Filters are available in the scan,
    // we assume that the scan is perfect having necessary column(s) only.
    try {
      scanner = region.getScanner(scan);
      while (hasMore) {
        List<List<KeyValue>> deleteRows = new ArrayList<List<KeyValue>>(rowBatchSize);
        for (int i = 0; i < rowBatchSize; i++) {
          List<KeyValue> results = new ArrayList<KeyValue>();
          hasMore = scanner.next(results);
          if (results.size() > 0) {
            deleteRows.add(results);
          }
          if (!hasMore) {
            // There are no more rows.
            break;
          }
        }
        if (deleteRows.size() > 0) {
          Pair<Mutation, Integer>[] deleteWithLockArr = new Pair[deleteRows.size()];
          int i = 0;
          for (List<KeyValue> deleteRow : deleteRows) {
            Delete delete = createDeleteMutation(deleteRow, deleteType, timestamp);
            deleteWithLockArr[i++] = new Pair<Mutation, Integer>(delete, null);
          }
          OperationStatus[] opStatus = region.batchMutate(deleteWithLockArr);
          for (i = 0; i < opStatus.length; i++) {
            if (opStatus[i].getOperationStatusCode() != OperationStatusCode.SUCCESS) {
              break;
            }
            totalRowsDeleted++;
            if (deleteType == DeleteType.VERSION) {
              byte[] versionsDeleted = deleteWithLockArr[i].getFirst().getAttribute(
                  NO_OF_VERSIONS_TO_DELETE);
              if (versionsDeleted != null) {
                totalVersionsDeleted += Bytes.toInt(versionsDeleted);
              }
            }
          }
        }
      }
    } catch (IOException ioe) {
      LOG.error(ioe);
      response.setIoException(ioe);
    } finally {
      if (scanner != null) {
        try {
          scanner.close();
        } catch (IOException ioe) {
          LOG.error(ioe);
        }
      }
    }
View Full Code Here

    Coprocessor c = region.getCoprocessorHost().
      findCoprocessor(CoprocessorImpl.class.getName());

    // HBASE-4197
    Scan s = new Scan();
    RegionScanner scanner = regions[0].getCoprocessorHost().postScannerOpen(s, regions[0].getScanner(s));
    assertTrue(scanner instanceof CustomScanner);
    // this would throw an exception before HBASE-4197
    scanner.next(new ArrayList<KeyValue>());

    assertTrue("Coprocessor not started", ((CoprocessorImpl)c).wasStarted());
    assertTrue("Coprocessor not stopped", ((CoprocessorImpl)c).wasStopped());
    assertTrue(((CoprocessorImpl)c).wasOpened());
    assertTrue(((CoprocessorImpl)c).wasClosed());
View Full Code Here

        Scan scan = IndexManagementUtil.newLocalStateScan(maintainers);
        ScanRanges scanRanges = ScanRanges.create(SchemaUtil.VAR_BINARY_SCHEMA, Collections.singletonList(keys), ScanUtil.SINGLE_COLUMN_SLOT_SPAN);
        scanRanges.setScanStartStopRow(scan);
        scan.setFilter(scanRanges.getSkipScanFilter());
        HRegion region = this.env.getRegion();
        RegionScanner scanner = region.getScanner(scan);
        // Run through the scanner using internal nextRaw method
        MultiVersionConsistencyControl.setThreadReadPoint(scanner.getMvccReadPoint());
        region.startRegionOperation();
        try {
            boolean hasMore;
            do {
                List<KeyValue> results = Lists.newArrayList();
                // Results are potentially returned even when the return value of s.next is false
                // since this is an indication of whether or not there are more values after the
                // ones returned
                hasMore = scanner.nextRaw(results, null);
            } while (hasMore);
        } finally {
            try {
                scanner.close();
            } finally {
                region.closeRegionOperation();
            }
        }
    }
View Full Code Here

    RegionCoprocessorEnvironment env = Mockito.mock(RegionCoprocessorEnvironment.class);
    Mockito.when(env.getConfiguration()).thenReturn(conf);

    HRegion region = Mockito.mock(HRegion.class);
    Mockito.when(env.getRegion()).thenReturn(region);
    RegionScanner scanner = Mockito.mock(RegionScanner.class);
    Mockito.when(region.getScanner(Mockito.any(Scan.class))).thenReturn(scanner);
    final byte[] stored = Bytes.toBytes("stored-value");
    Mockito.when(scanner.next(Mockito.any(List.class))).thenAnswer(new Answer<Boolean>() {
      @Override
      public Boolean answer(InvocationOnMock invocation) throws Throwable {
        List<KeyValue> list = (List<KeyValue>) invocation.getArguments()[0];
        KeyValue kv = new KeyValue(row, fam, qual, ts, Type.Put, stored);
        kv.setMemstoreTS(0);
View Full Code Here

    // setup mocks
    RegionCoprocessorEnvironment env = Mockito.mock(RegionCoprocessorEnvironment.class);

    HRegion region = Mockito.mock(HRegion.class);
    Mockito.when(env.getRegion()).thenReturn(region);
    RegionScanner scanner = Mockito.mock(RegionScanner.class);
    Mockito.when(region.getScanner(Mockito.any(Scan.class))).thenReturn(scanner);
    final byte[] stored = Bytes.toBytes("stored-value");
    final KeyValue storedKv = new KeyValue(row, fam, qual, ts, Type.Put, stored);
    storedKv.setMemstoreTS(2);
    Mockito.when(scanner.next(Mockito.any(List.class))).thenAnswer(new Answer<Boolean>() {
      @Override
      public Boolean answer(InvocationOnMock invocation) throws Throwable {
        List<KeyValue> list = (List<KeyValue>) invocation.getArguments()[0];

        list.add(storedKv);
View Full Code Here

    // setup mocks
    RegionCoprocessorEnvironment env = Mockito.mock(RegionCoprocessorEnvironment.class);

    HRegion region = Mockito.mock(HRegion.class);
    Mockito.when(env.getRegion()).thenReturn(region);
    RegionScanner scanner = Mockito.mock(RegionScanner.class);
    Mockito.when(region.getScanner(Mockito.any(Scan.class))).thenReturn(scanner);
    final KeyValue storedKv =
        new KeyValue(row, fam, qual, ts, Type.Put, Bytes.toBytes("stored-value"));
    storedKv.setMemstoreTS(2);
    Mockito.when(scanner.next(Mockito.any(List.class))).thenAnswer(new Answer<Boolean>() {
      @Override
      public Boolean answer(InvocationOnMock invocation) throws Throwable {
        List<KeyValue> list = (List<KeyValue>) invocation.getArguments()[0];

        list.add(storedKv);
View Full Code Here

        byte[] limitBytes = scan.getAttribute(GROUP_BY_LIMIT);
        if (limitBytes != null) {
            limit = PDataType.INTEGER.getCodec().decodeInt(limitBytes, 0, SortOrder.getDefault());
        }

        RegionScanner innerScanner = s;
        if (p != null || j != null) {
            innerScanner =
                    new HashJoinRegionScanner(s, p, j, ScanUtil.getTenantId(scan),
                            c.getEnvironment());
        }
View Full Code Here

                } while (hasMore && groupByCache.size() < limit);
            } finally {
                region.closeRegionOperation();
            }

            RegionScanner regionScanner = groupByCache.getScanner(s);

            // Do not sort here, but sort back on the client instead
            // The reason is that if the scan ever extends beyond a region
            // (which can happen if we're basing our parallelization split
            // points on old metadata), we'll get incorrect query results.
View Full Code Here

    protected RegionScanner doPostScannerOpen(final ObserverContext<RegionCoprocessorEnvironment> c, final Scan scan, final RegionScanner s) throws Throwable {
        final TupleProjector p = TupleProjector.deserializeProjectorFromScan(scan);
        final HashJoinInfo j = HashJoinInfo.deserializeHashJoinFromScan(scan);
        final ImmutableBytesWritable tenantId = ScanUtil.getTenantId(scan);
       
        RegionScanner innerScanner = s;
        if (p != null || j != null) {
            innerScanner = new HashJoinRegionScanner(s, p, j, tenantId, c.getEnvironment());
        }
       
        final OrderedResultIterator iterator = deserializeFromScan(scan,innerScanner);
View Full Code Here

TOP

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

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.