Search in sources :

Example 11 with RegionSpecifier

use of org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier in project hbase by apache.

the class RequestConverter method buildFlushRegionRequest.

/**
  * Create a protocol buffer FlushRegionRequest for a given region name
  *
  * @param regionName the name of the region to get info
  * @return a protocol buffer FlushRegionRequest
  */
public static FlushRegionRequest buildFlushRegionRequest(final byte[] regionName, boolean writeFlushWALMarker) {
    FlushRegionRequest.Builder builder = FlushRegionRequest.newBuilder();
    RegionSpecifier region = buildRegionSpecifier(RegionSpecifierType.REGION_NAME, regionName);
    builder.setRegion(region);
    builder.setWriteFlushWalMarker(writeFlushWALMarker);
    return builder.build();
}
Also used : FlushRegionRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.FlushRegionRequest) RegionSpecifier(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier)

Example 12 with RegionSpecifier

use of org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier in project hbase by apache.

the class RequestConverter method buildBulkLoadHFileRequest.

/**
   * Create a protocol buffer bulk load request
   *
   * @param familyPaths
   * @param regionName
   * @param assignSeqNum
   * @param userToken
   * @param bulkToken
   * @param copyFiles
   * @return a bulk load request
   */
public static BulkLoadHFileRequest buildBulkLoadHFileRequest(final List<Pair<byte[], String>> familyPaths, final byte[] regionName, boolean assignSeqNum, final Token<?> userToken, final String bulkToken, boolean copyFiles) {
    RegionSpecifier region = RequestConverter.buildRegionSpecifier(RegionSpecifierType.REGION_NAME, regionName);
    ClientProtos.DelegationToken protoDT = null;
    if (userToken != null) {
        protoDT = ClientProtos.DelegationToken.newBuilder().setIdentifier(UnsafeByteOperations.unsafeWrap(userToken.getIdentifier())).setPassword(UnsafeByteOperations.unsafeWrap(userToken.getPassword())).setKind(userToken.getKind().toString()).setService(userToken.getService().toString()).build();
    }
    List<ClientProtos.BulkLoadHFileRequest.FamilyPath> protoFamilyPaths = new ArrayList<>(familyPaths.size());
    if (!familyPaths.isEmpty()) {
        ClientProtos.BulkLoadHFileRequest.FamilyPath.Builder pathBuilder = ClientProtos.BulkLoadHFileRequest.FamilyPath.newBuilder();
        for (Pair<byte[], String> el : familyPaths) {
            protoFamilyPaths.add(pathBuilder.setFamily(UnsafeByteOperations.unsafeWrap(el.getFirst())).setPath(el.getSecond()).build());
        }
        pathBuilder.clear();
    }
    BulkLoadHFileRequest.Builder request = ClientProtos.BulkLoadHFileRequest.newBuilder().setRegion(region).setAssignSeqNum(assignSeqNum).addAllFamilyPath(protoFamilyPaths);
    if (userToken != null) {
        request.setFsToken(protoDT);
    }
    if (bulkToken != null) {
        request.setBulkToken(bulkToken);
    }
    request.setCopyFile(copyFiles);
    return request.build();
}
Also used : BulkLoadHFileRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.BulkLoadHFileRequest) ArrayList(java.util.ArrayList) ClientProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos) RegionSpecifier(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier)

Example 13 with RegionSpecifier

use of org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier in project hbase by apache.

the class AnnotationReadingPriorityFunction method getBasePriority.

/**
   * Get the priority for a given request from the header and the param
   * This doesn't consider which user is sending the request at all.
   * This doesn't consider annotations
   */
protected int getBasePriority(RequestHeader header, Message param) {
    if (param == null) {
        return HConstants.NORMAL_QOS;
    }
    // Trust the client-set priorities if set
    if (header.hasPriority()) {
        return header.getPriority();
    }
    String cls = param.getClass().getName();
    Class<? extends Message> rpcArgClass = argumentToClassMap.get(cls);
    RegionSpecifier regionSpecifier = null;
    //check whether the request has reference to meta region or now.
    try {
        // Check if the param has a region specifier; the pb methods are hasRegion and getRegion if
        // hasRegion returns true.  Not all listed methods have region specifier each time.  For
        // example, the ScanRequest has it on setup but thereafter relies on the scannerid rather than
        // send the region over every time.
        Method hasRegion = methodMap.get("hasRegion").get(rpcArgClass);
        if (hasRegion != null && (Boolean) hasRegion.invoke(param, (Object[]) null)) {
            Method getRegion = methodMap.get("getRegion").get(rpcArgClass);
            regionSpecifier = (RegionSpecifier) getRegion.invoke(param, (Object[]) null);
            Region region = rpcServices.getRegion(regionSpecifier);
            if (region.getRegionInfo().isSystemTable()) {
                if (LOG.isTraceEnabled()) {
                    LOG.trace("High priority because region=" + region.getRegionInfo().getRegionNameAsString());
                }
                return HConstants.SYSTEMTABLE_QOS;
            }
        }
    } catch (Exception ex) {
        // server and have it throw the exception if still an issue.  Just mark it normal priority.
        if (LOG.isTraceEnabled())
            LOG.trace("Marking normal priority after getting exception=" + ex);
        return HConstants.NORMAL_QOS;
    }
    if (param instanceof ScanRequest) {
        // scanner methods...
        ScanRequest request = (ScanRequest) param;
        if (!request.hasScannerId()) {
            return HConstants.NORMAL_QOS;
        }
        RegionScanner scanner = rpcServices.getScanner(request.getScannerId());
        if (scanner != null && scanner.getRegionInfo().isSystemTable()) {
            if (LOG.isTraceEnabled()) {
                // Scanner requests are small in size so TextFormat version should not overwhelm log.
                LOG.trace("High priority scanner request " + TextFormat.shortDebugString(request));
            }
            return HConstants.SYSTEMTABLE_QOS;
        }
    }
    return HConstants.NORMAL_QOS;
}
Also used : ScanRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanRequest) Method(java.lang.reflect.Method) RegionSpecifier(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier)

Example 14 with RegionSpecifier

use of org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier in project hbase by apache.

the class RSRpcServices method multi.

/**
   * Execute multiple actions on a table: get, mutate, and/or execCoprocessor
   *
   * @param rpcc the RPC controller
   * @param request the multi request
   * @throws ServiceException
   */
@Override
public MultiResponse multi(final RpcController rpcc, final MultiRequest request) throws ServiceException {
    try {
        checkOpen();
    } catch (IOException ie) {
        throw new ServiceException(ie);
    }
    // rpc controller is how we bring in data via the back door;  it is unprotobuf'ed data.
    // It is also the conduit via which we pass back data.
    HBaseRpcController controller = (HBaseRpcController) rpcc;
    CellScanner cellScanner = controller != null ? controller.cellScanner() : null;
    if (controller != null) {
        controller.setCellScanner(null);
    }
    long nonceGroup = request.hasNonceGroup() ? request.getNonceGroup() : HConstants.NO_NONCE;
    // this will contain all the cells that we need to return. It's created later, if needed.
    List<CellScannable> cellsToReturn = null;
    MultiResponse.Builder responseBuilder = MultiResponse.newBuilder();
    RegionActionResult.Builder regionActionResultBuilder = RegionActionResult.newBuilder();
    Boolean processed = null;
    RegionScannersCloseCallBack closeCallBack = null;
    RpcCallContext context = RpcServer.getCurrentCall();
    this.rpcMultiRequestCount.increment();
    Map<RegionSpecifier, ClientProtos.RegionLoadStats> regionStats = new HashMap<>(request.getRegionActionCount());
    for (RegionAction regionAction : request.getRegionActionList()) {
        this.requestCount.add(regionAction.getActionCount());
        OperationQuota quota;
        Region region;
        regionActionResultBuilder.clear();
        RegionSpecifier regionSpecifier = regionAction.getRegion();
        try {
            region = getRegion(regionSpecifier);
            quota = getQuotaManager().checkQuota(region, regionAction.getActionList());
        } catch (IOException e) {
            rpcServer.getMetrics().exception(e);
            regionActionResultBuilder.setException(ResponseConverter.buildException(e));
            responseBuilder.addRegionActionResult(regionActionResultBuilder.build());
            // corresponding to these Mutations.
            if (cellScanner != null) {
                skipCellsForMutations(regionAction.getActionList(), cellScanner);
            }
            // For this region it's a failure.
            continue;
        }
        if (regionAction.hasAtomic() && regionAction.getAtomic()) {
            // Need to return an item per Action along w/ Action index.  TODO.
            try {
                if (request.hasCondition()) {
                    Condition condition = request.getCondition();
                    byte[] row = condition.getRow().toByteArray();
                    byte[] family = condition.getFamily().toByteArray();
                    byte[] qualifier = condition.getQualifier().toByteArray();
                    CompareOp compareOp = CompareOp.valueOf(condition.getCompareType().name());
                    ByteArrayComparable comparator = ProtobufUtil.toComparator(condition.getComparator());
                    processed = checkAndRowMutate(region, regionAction.getActionList(), cellScanner, row, family, qualifier, compareOp, comparator, regionActionResultBuilder);
                } else {
                    mutateRows(region, regionAction.getActionList(), cellScanner, regionActionResultBuilder);
                    processed = Boolean.TRUE;
                }
            } catch (IOException e) {
                rpcServer.getMetrics().exception(e);
                // As it's atomic, we may expect it's a global failure.
                regionActionResultBuilder.setException(ResponseConverter.buildException(e));
            }
        } else {
            // doNonAtomicRegionMutation manages the exception internally
            if (context != null && closeCallBack == null) {
                // An RpcCallBack that creates a list of scanners that needs to perform callBack
                // operation on completion of multiGets.
                // Set this only once
                closeCallBack = new RegionScannersCloseCallBack();
                context.setCallBack(closeCallBack);
            }
            cellsToReturn = doNonAtomicRegionMutation(region, quota, regionAction, cellScanner, regionActionResultBuilder, cellsToReturn, nonceGroup, closeCallBack, context);
        }
        responseBuilder.addRegionActionResult(regionActionResultBuilder.build());
        quota.close();
        ClientProtos.RegionLoadStats regionLoadStats = ((HRegion) region).getLoadStatistics();
        if (regionLoadStats != null) {
            regionStats.put(regionSpecifier, regionLoadStats);
        }
    }
    // Load the controller with the Cells to return.
    if (cellsToReturn != null && !cellsToReturn.isEmpty() && controller != null) {
        controller.setCellScanner(CellUtil.createCellScanner(cellsToReturn));
    }
    if (processed != null) {
        responseBuilder.setProcessed(processed);
    }
    MultiRegionLoadStats.Builder builder = MultiRegionLoadStats.newBuilder();
    for (Entry<RegionSpecifier, ClientProtos.RegionLoadStats> stat : regionStats.entrySet()) {
        builder.addRegion(stat.getKey());
        builder.addStat(stat.getValue());
    }
    responseBuilder.setRegionStatistics(builder);
    return responseBuilder.build();
}
Also used : CellScannable(org.apache.hadoop.hbase.CellScannable) MultiResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MultiResponse) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) RegionAction(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionAction) CellScanner(org.apache.hadoop.hbase.CellScanner) RegionSpecifier(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier) ByteArrayComparable(org.apache.hadoop.hbase.filter.ByteArrayComparable) MultiRegionLoadStats(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MultiRegionLoadStats) RpcCallContext(org.apache.hadoop.hbase.ipc.RpcCallContext) Condition(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.Condition) OperationQuota(org.apache.hadoop.hbase.quotas.OperationQuota) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) RegionActionResult(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionActionResult) HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) MultiRegionLoadStats(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MultiRegionLoadStats) CompareOp(org.apache.hadoop.hbase.filter.CompareFilter.CompareOp) ClientProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos)

Example 15 with RegionSpecifier

use of org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier in project hbase by apache.

the class RSRpcServices method getRegionLoad.

@Override
@QosPriority(priority = HConstants.ADMIN_QOS)
public GetRegionLoadResponse getRegionLoad(RpcController controller, GetRegionLoadRequest request) throws ServiceException {
    List<Region> regions;
    if (request.hasTableName()) {
        TableName tableName = ProtobufUtil.toTableName(request.getTableName());
        regions = regionServer.getOnlineRegions(tableName);
    } else {
        regions = regionServer.getOnlineRegions();
    }
    List<RegionLoad> rLoads = new ArrayList<>(regions.size());
    RegionLoad.Builder regionLoadBuilder = ClusterStatusProtos.RegionLoad.newBuilder();
    RegionSpecifier.Builder regionSpecifier = RegionSpecifier.newBuilder();
    try {
        for (Region region : regions) {
            rLoads.add(regionServer.createRegionLoad(region, regionLoadBuilder, regionSpecifier));
        }
    } catch (IOException e) {
        throw new ServiceException(e);
    }
    GetRegionLoadResponse.Builder builder = GetRegionLoadResponse.newBuilder();
    builder.addAllRegionLoads(rLoads);
    return builder.build();
}
Also used : ArrayList(java.util.ArrayList) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) RegionSpecifier(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier) TableName(org.apache.hadoop.hbase.TableName) RegionLoad(org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos.RegionLoad) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) GetRegionLoadResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionLoadResponse) QosPriority(org.apache.hadoop.hbase.ipc.QosPriority)

Aggregations

RegionSpecifier (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier)27 MutateRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutateRequest)7 IOException (java.io.IOException)4 Condition (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.Condition)3 InterruptedIOException (java.io.InterruptedIOException)2 ArrayList (java.util.ArrayList)2 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)2 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)2 ServiceException (org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException)2 CloseRegionRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.CloseRegionRequest)2 ClientProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos)2 GetRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.GetRequest)2 ScanRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanRequest)2 RegionLoad (org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos.RegionLoad)2 Test (org.junit.Test)2 RatioGauge (com.codahale.metrics.RatioGauge)1 MemoryUsage (java.lang.management.MemoryUsage)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1