Search in sources :

Example 1 with NonceProcedureRunnable

use of org.apache.hadoop.hbase.master.procedure.MasterProcedureUtil.NonceProcedureRunnable 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

IOException (java.io.IOException)1 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)1 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)1 TableName (org.apache.hadoop.hbase.TableName)1 LockProcedure (org.apache.hadoop.hbase.master.locking.LockProcedure)1 NonceProcedureRunnable (org.apache.hadoop.hbase.master.procedure.MasterProcedureUtil.NonceProcedureRunnable)1 ServiceException (org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException)1