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);
}
}
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);
}
Aggregations