Search in sources :

Example 1 with DoNotRetryIOException

use of org.apache.hadoop.hbase.DoNotRetryIOException in project hbase by apache.

the class TestClientNoCluster method testConnectionClosedOnRegionLocate.

@Test
public void testConnectionClosedOnRegionLocate() throws IOException {
    Configuration testConf = new Configuration(this.conf);
    testConf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2);
    // Go against meta else we will try to find first region for the table on construction which
    // means we'll have to do a bunch more mocking. Tests that go against meta only should be
    // good for a bit of testing.
    Connection connection = ConnectionFactory.createConnection(testConf);
    Table table = connection.getTable(TableName.META_TABLE_NAME);
    connection.close();
    try {
        Get get = new Get(Bytes.toBytes("dummyRow"));
        table.get(get);
        fail("Should have thrown DoNotRetryException but no exception thrown");
    } catch (Exception e) {
        if (!(e instanceof DoNotRetryIOException)) {
            String errMsg = "Should have thrown DoNotRetryException but actually " + e.getClass().getSimpleName();
            LOG.error(errMsg, e);
            fail(errMsg);
        }
    } finally {
        table.close();
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) ByteString(org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString) NotImplementedException(org.apache.commons.lang.NotImplementedException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) ResultOrException(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ResultOrException) RegionTooBusyException(org.apache.hadoop.hbase.RegionTooBusyException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) RegionServerStoppedException(org.apache.hadoop.hbase.regionserver.RegionServerStoppedException) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) Test(org.junit.Test)

Example 2 with DoNotRetryIOException

use of org.apache.hadoop.hbase.DoNotRetryIOException in project hbase by apache.

the class ColumnAggregationEndpointWithErrors method sum.

@Override
public void sum(RpcController controller, ColumnAggregationWithErrorsSumRequest request, RpcCallback<ColumnAggregationWithErrorsSumResponse> done) {
    // aggregate at each region
    Scan scan = new Scan();
    // Family is required in pb. Qualifier is not.
    byte[] family = request.getFamily().toByteArray();
    byte[] qualifier = request.hasQualifier() ? request.getQualifier().toByteArray() : null;
    if (request.hasQualifier()) {
        scan.addColumn(family, qualifier);
    } else {
        scan.addFamily(family);
    }
    int sumResult = 0;
    InternalScanner scanner = null;
    try {
        Region region = this.env.getRegion();
        // throw an exception for requests to the last region in the table, to test error handling
        if (Bytes.equals(region.getRegionInfo().getEndKey(), HConstants.EMPTY_END_ROW)) {
            throw new DoNotRetryIOException("An expected exception");
        }
        scanner = region.getScanner(scan);
        List<Cell> curVals = new ArrayList<>();
        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) {
        CoprocessorRpcUtils.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) {
                CoprocessorRpcUtils.setControllerException(controller, e);
                sumResult = -1;
                LOG.info("Setting sum result to -1 to indicate error", e);
            }
        }
    }
    done.run(ColumnAggregationWithErrorsSumResponse.newBuilder().setSum(sumResult).build());
}
Also used : InternalScanner(org.apache.hadoop.hbase.regionserver.InternalScanner) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) ArrayList(java.util.ArrayList) Region(org.apache.hadoop.hbase.regionserver.Region) Scan(org.apache.hadoop.hbase.client.Scan) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) Cell(org.apache.hadoop.hbase.Cell)

Example 3 with DoNotRetryIOException

use of org.apache.hadoop.hbase.DoNotRetryIOException in project hbase by apache.

the class RSGroupInfoManagerImpl method moveTables.

@Override
public synchronized void moveTables(Set<TableName> tableNames, String groupName) throws IOException {
    if (groupName != null && !rsGroupMap.containsKey(groupName)) {
        throw new DoNotRetryIOException("Group " + groupName + " does not exist or is a special group");
    }
    Map<String, RSGroupInfo> newGroupMap = Maps.newHashMap(rsGroupMap);
    for (TableName tableName : tableNames) {
        if (tableMap.containsKey(tableName)) {
            RSGroupInfo src = new RSGroupInfo(newGroupMap.get(tableMap.get(tableName)));
            src.removeTable(tableName);
            newGroupMap.put(src.getName(), src);
        }
        if (groupName != null) {
            RSGroupInfo dst = new RSGroupInfo(newGroupMap.get(groupName));
            dst.addTable(tableName);
            newGroupMap.put(dst.getName(), dst);
        }
    }
    flushConfig(newGroupMap);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException)

Example 4 with DoNotRetryIOException

use of org.apache.hadoop.hbase.DoNotRetryIOException in project hbase by apache.

the class RSGroupInfoManagerImpl method multiMutate.

private void multiMutate(List<Mutation> mutations) throws IOException {
    CoprocessorRpcChannel channel = rsGroupTable.coprocessorService(ROW_KEY);
    MultiRowMutationProtos.MutateRowsRequest.Builder mmrBuilder = MultiRowMutationProtos.MutateRowsRequest.newBuilder();
    for (Mutation mutation : mutations) {
        if (mutation instanceof Put) {
            mmrBuilder.addMutationRequest(org.apache.hadoop.hbase.protobuf.ProtobufUtil.toMutation(org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto.MutationType.PUT, mutation));
        } else if (mutation instanceof Delete) {
            mmrBuilder.addMutationRequest(org.apache.hadoop.hbase.protobuf.ProtobufUtil.toMutation(org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto.MutationType.DELETE, mutation));
        } else {
            throw new DoNotRetryIOException("multiMutate doesn't support " + mutation.getClass().getName());
        }
    }
    MultiRowMutationProtos.MultiRowMutationService.BlockingInterface service = MultiRowMutationProtos.MultiRowMutationService.newBlockingStub(channel);
    try {
        service.mutateRows(null, mmrBuilder.build());
    } catch (ServiceException ex) {
        ProtobufUtil.toIOException(ex);
    }
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) ServiceException(com.google.protobuf.ServiceException) CoprocessorRpcChannel(org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) Mutation(org.apache.hadoop.hbase.client.Mutation) Put(org.apache.hadoop.hbase.client.Put)

Example 5 with DoNotRetryIOException

use of org.apache.hadoop.hbase.DoNotRetryIOException in project hbase by apache.

the class MasterRpcServices method requestLock.

@Override
public LockResponse requestLock(RpcController controller, final LockRequest request) throws ServiceException {
    try {
        if (request.getDescription().isEmpty()) {
            throw new IllegalArgumentException("Empty description");
        }
        NonceProcedureRunnable npr;
        LockProcedure.LockType type = LockProcedure.LockType.valueOf(request.getLockType().name());
        if (request.getRegionInfoCount() > 0) {
            final HRegionInfo[] regionInfos = new HRegionInfo[request.getRegionInfoCount()];
            for (int i = 0; i < request.getRegionInfoCount(); ++i) {
                regionInfos[i] = HRegionInfo.convert(request.getRegionInfo(i));
            }
            npr = new NonceProcedureRunnable(master, request.getNonceGroup(), request.getNonce()) {

                @Override
                protected void run() throws IOException {
                    setProcId(master.getLockManager().remoteLocks().requestRegionsLock(regionInfos, request.getDescription(), getNonceKey()));
                }

                @Override
                protected String getDescription() {
                    return "RequestLock";
                }
            };
        } else if (request.hasTableName()) {
            final TableName tableName = ProtobufUtil.toTableName(request.getTableName());
            npr = new NonceProcedureRunnable(master, request.getNonceGroup(), request.getNonce()) {

                @Override
                protected void run() throws IOException {
                    setProcId(master.getLockManager().remoteLocks().requestTableLock(tableName, type, request.getDescription(), getNonceKey()));
                }

                @Override
                protected String getDescription() {
                    return "RequestLock";
                }
            };
        } else if (request.hasNamespace()) {
            npr = new NonceProcedureRunnable(master, request.getNonceGroup(), request.getNonce()) {

                @Override
                protected void run() throws IOException {
                    setProcId(master.getLockManager().remoteLocks().requestNamespaceLock(request.getNamespace(), type, request.getDescription(), getNonceKey()));
                }

                @Override
                protected String getDescription() {
                    return "RequestLock";
                }
            };
        } else {
            throw new IllegalArgumentException("one of table/namespace/region should be specified");
        }
        long procId = MasterProcedureUtil.submitProcedure(npr);
        return LockResponse.newBuilder().setProcId(procId).build();
    } catch (IllegalArgumentException e) {
        LOG.warn("Exception when queuing lock", e);
        throw new ServiceException(new DoNotRetryIOException(e));
    } catch (IOException e) {
        LOG.warn("Exception when queuing lock", e);
        throw new ServiceException(e);
    }
}
Also used : DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) LockProcedure(org.apache.hadoop.hbase.master.locking.LockProcedure) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) NonceProcedureRunnable(org.apache.hadoop.hbase.master.procedure.MasterProcedureUtil.NonceProcedureRunnable)

Aggregations

DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)77 IOException (java.io.IOException)28 Cell (org.apache.hadoop.hbase.Cell)18 ArrayList (java.util.ArrayList)12 ServiceException (org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException)12 MutationType (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto.MutationType)12 TableName (org.apache.hadoop.hbase.TableName)11 InterruptedIOException (java.io.InterruptedIOException)10 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)10 Delete (org.apache.hadoop.hbase.client.Delete)10 Put (org.apache.hadoop.hbase.client.Put)10 Test (org.junit.Test)10 AccessDeniedException (org.apache.hadoop.hbase.security.AccessDeniedException)9 User (org.apache.hadoop.hbase.security.User)8 Mutation (org.apache.hadoop.hbase.client.Mutation)7 ByteString (org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString)7 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)6 NameBytesPair (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.NameBytesPair)6 ByteBufferCell (org.apache.hadoop.hbase.ByteBufferCell)5 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)5