Search in sources :

Example 21 with TableName

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

the class MasterRpcServices method getTableState.

@Override
public GetTableStateResponse getTableState(RpcController controller, GetTableStateRequest request) throws ServiceException {
    try {
        master.checkServiceStarted();
        TableName tableName = ProtobufUtil.toTableName(request.getTableName());
        TableState.State state = master.getTableStateManager().getTableState(tableName);
        GetTableStateResponse.Builder builder = GetTableStateResponse.newBuilder();
        builder.setTableState(new TableState(tableName, state).convert());
        return builder.build();
    } catch (IOException e) {
        throw new ServiceException(e);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) GetTableStateResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetTableStateResponse) TableState(org.apache.hadoop.hbase.client.TableState)

Example 22 with TableName

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

the class MasterRpcServices method compactRegion.

/**
   * Compact a region on the master.
   *
   * @param controller the RPC controller
   * @param request the request
   * @throws ServiceException
   */
@Override
@QosPriority(priority = HConstants.ADMIN_QOS)
public CompactRegionResponse compactRegion(final RpcController controller, final CompactRegionRequest request) throws ServiceException {
    try {
        master.checkInitialized();
        byte[] regionName = request.getRegion().getValue().toByteArray();
        TableName tableName = HRegionInfo.getTable(regionName);
        // if the region is a mob region, do the mob file compaction.
        if (MobUtils.isMobRegionName(tableName, regionName)) {
            return compactMob(request, tableName);
        } else {
            return super.compactRegion(controller, request);
        }
    } catch (IOException ie) {
        throw new ServiceException(ie);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) QosPriority(org.apache.hadoop.hbase.ipc.QosPriority)

Example 23 with TableName

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

the class MasterRpcServices method getTableNames.

/**
   * Get list of userspace table names
   * @param controller Unused (set to null).
   * @param req GetTableNamesRequest
   * @return GetTableNamesResponse
   * @throws ServiceException
   */
@Override
public GetTableNamesResponse getTableNames(RpcController controller, GetTableNamesRequest req) throws ServiceException {
    try {
        master.checkServiceStarted();
        final String regex = req.hasRegex() ? req.getRegex() : null;
        final String namespace = req.hasNamespace() ? req.getNamespace() : null;
        List<TableName> tableNames = master.listTableNames(namespace, regex, req.getIncludeSysTables());
        GetTableNamesResponse.Builder builder = GetTableNamesResponse.newBuilder();
        if (tableNames != null && tableNames.size() > 0) {
            // Add the table names to the response
            for (TableName table : tableNames) {
                builder.addTableNames(ProtobufUtil.toProtoTableName(table));
            }
        }
        return builder.build();
    } catch (IOException e) {
        throw new ServiceException(e);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) GetTableNamesResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetTableNamesResponse) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException)

Example 24 with TableName

use of org.apache.hadoop.hbase.TableName 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)

Example 25 with TableName

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

the class MasterRpcServices method getTableDescriptors.

/**
   * Get list of TableDescriptors for requested tables.
   * @param c Unused (set to null).
   * @param req GetTableDescriptorsRequest that contains:
   * - tableNames: requested tables, or if empty, all are requested
   * @return GetTableDescriptorsResponse
   * @throws ServiceException
   */
@Override
public GetTableDescriptorsResponse getTableDescriptors(RpcController c, GetTableDescriptorsRequest req) throws ServiceException {
    try {
        master.checkInitialized();
        final String regex = req.hasRegex() ? req.getRegex() : null;
        final String namespace = req.hasNamespace() ? req.getNamespace() : null;
        List<TableName> tableNameList = null;
        if (req.getTableNamesCount() > 0) {
            tableNameList = new ArrayList<TableName>(req.getTableNamesCount());
            for (HBaseProtos.TableName tableNamePB : req.getTableNamesList()) {
                tableNameList.add(ProtobufUtil.toTableName(tableNamePB));
            }
        }
        List<HTableDescriptor> descriptors = master.listTableDescriptors(namespace, regex, tableNameList, req.getIncludeSysTables());
        GetTableDescriptorsResponse.Builder builder = GetTableDescriptorsResponse.newBuilder();
        if (descriptors != null && descriptors.size() > 0) {
            // Add the table descriptors to the response
            for (HTableDescriptor htd : descriptors) {
                builder.addTableSchema(ProtobufUtil.convertToTableSchema(htd));
            }
        }
        return builder.build();
    } catch (IOException ioe) {
        throw new ServiceException(ioe);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) GetTableDescriptorsResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetTableDescriptorsResponse) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Aggregations

TableName (org.apache.hadoop.hbase.TableName)1029 Test (org.junit.Test)694 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)257 Table (org.apache.hadoop.hbase.client.Table)227 IOException (java.io.IOException)225 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)215 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)203 Result (org.apache.hadoop.hbase.client.Result)124 ArrayList (java.util.ArrayList)118 Put (org.apache.hadoop.hbase.client.Put)118 Path (org.apache.hadoop.fs.Path)113 Connection (org.apache.hadoop.hbase.client.Connection)103 Scan (org.apache.hadoop.hbase.client.Scan)97 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)88 ServerName (org.apache.hadoop.hbase.ServerName)85 Admin (org.apache.hadoop.hbase.client.Admin)85 Cell (org.apache.hadoop.hbase.Cell)77 HashMap (java.util.HashMap)75 Delete (org.apache.hadoop.hbase.client.Delete)65 InterruptedIOException (java.io.InterruptedIOException)63