Search in sources :

Example 1 with LockType

use of org.apache.hadoop.hbase.procedure2.LockType 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;
        LockType type = LockType.valueOf(request.getLockType().name());
        if (request.getRegionInfoCount() > 0) {
            final RegionInfo[] regionInfos = new RegionInfo[request.getRegionInfoCount()];
            for (int i = 0; i < request.getRegionInfoCount(); ++i) {
                regionInfos[i] = ProtobufUtil.toRegionInfo(request.getRegionInfo(i));
            }
            npr = new NonceProcedureRunnable(server, request.getNonceGroup(), request.getNonce()) {

                @Override
                protected void run() throws IOException {
                    setProcId(server.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(server, request.getNonceGroup(), request.getNonce()) {

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

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

                @Override
                protected void run() throws IOException {
                    setProcId(server.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) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) LockType(org.apache.hadoop.hbase.procedure2.LockType) TableName(org.apache.hadoop.hbase.TableName) ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) NonceProcedureRunnable(org.apache.hadoop.hbase.master.procedure.MasterProcedureUtil.NonceProcedureRunnable)

Example 2 with LockType

use of org.apache.hadoop.hbase.procedure2.LockType in project hbase by apache.

the class SchemaLocking method createLockedResource.

private LockedResource createLockedResource(LockedResourceType resourceType, String resourceName, LockAndQueue queue) {
    LockType lockType;
    Procedure<?> exclusiveLockOwnerProcedure;
    int sharedLockCount;
    if (queue.hasExclusiveLock()) {
        lockType = LockType.EXCLUSIVE;
        exclusiveLockOwnerProcedure = queue.getExclusiveLockOwnerProcedure();
        sharedLockCount = 0;
    } else {
        lockType = LockType.SHARED;
        exclusiveLockOwnerProcedure = null;
        sharedLockCount = queue.getSharedLockCount();
    }
    List<Procedure<?>> waitingProcedures = new ArrayList<>();
    queue.filterWaitingQueue(p -> p instanceof LockProcedure).forEachOrdered(waitingProcedures::add);
    return new LockedResource(resourceType, resourceName, lockType, exclusiveLockOwnerProcedure, sharedLockCount, waitingProcedures);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) LockedResourceType(org.apache.hadoop.hbase.procedure2.LockedResourceType) ImmutableMap(org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue) Function(java.util.function.Function) LockProcedure(org.apache.hadoop.hbase.master.locking.LockProcedure) Procedure(org.apache.hadoop.hbase.procedure2.Procedure) LockType(org.apache.hadoop.hbase.procedure2.LockType) ArrayList(java.util.ArrayList) LockedResource(org.apache.hadoop.hbase.procedure2.LockedResource) List(java.util.List) InterfaceAudience(org.apache.yetus.audience.InterfaceAudience) Map(java.util.Map) ServerName(org.apache.hadoop.hbase.ServerName) LockProcedure(org.apache.hadoop.hbase.master.locking.LockProcedure) LockedResource(org.apache.hadoop.hbase.procedure2.LockedResource) ArrayList(java.util.ArrayList) LockProcedure(org.apache.hadoop.hbase.master.locking.LockProcedure) Procedure(org.apache.hadoop.hbase.procedure2.Procedure) LockType(org.apache.hadoop.hbase.procedure2.LockType)

Aggregations

TableName (org.apache.hadoop.hbase.TableName)2 LockType (org.apache.hadoop.hbase.procedure2.LockType)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Function (java.util.function.Function)1 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)1 ServerName (org.apache.hadoop.hbase.ServerName)1 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)1 LockProcedure (org.apache.hadoop.hbase.master.locking.LockProcedure)1 NonceProcedureRunnable (org.apache.hadoop.hbase.master.procedure.MasterProcedureUtil.NonceProcedureRunnable)1 LockAndQueue (org.apache.hadoop.hbase.procedure2.LockAndQueue)1 LockedResource (org.apache.hadoop.hbase.procedure2.LockedResource)1 LockedResourceType (org.apache.hadoop.hbase.procedure2.LockedResourceType)1 Procedure (org.apache.hadoop.hbase.procedure2.Procedure)1 ImmutableMap (org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap)1 ByteString (org.apache.hbase.thirdparty.com.google.protobuf.ByteString)1 ServiceException (org.apache.hbase.thirdparty.com.google.protobuf.ServiceException)1