Search in sources :

Example 1 with Procedure

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

the class MasterRpcServices method getProcedureResult.

@Override
public GetProcedureResultResponse getProcedureResult(RpcController controller, GetProcedureResultRequest request) throws ServiceException {
    LOG.debug("Checking to see if procedure is done procId=" + request.getProcId());
    try {
        master.checkInitialized();
        GetProcedureResultResponse.Builder builder = GetProcedureResultResponse.newBuilder();
        Pair<ProcedureInfo, Procedure> v = master.getMasterProcedureExecutor().getResultOrProcedure(request.getProcId());
        if (v.getFirst() != null) {
            ProcedureInfo result = v.getFirst();
            builder.setState(GetProcedureResultResponse.State.FINISHED);
            builder.setStartTime(result.getStartTime());
            builder.setLastUpdate(result.getLastUpdate());
            if (result.isFailed()) {
                builder.setException(ForeignExceptionUtil.toProtoForeignException(result.getException()));
            }
            if (result.hasResultData()) {
                builder.setResult(UnsafeByteOperations.unsafeWrap(result.getResult()));
            }
            master.getMasterProcedureExecutor().removeResult(request.getProcId());
        } else {
            Procedure proc = v.getSecond();
            if (proc == null) {
                builder.setState(GetProcedureResultResponse.State.NOT_FOUND);
            } else {
                builder.setState(GetProcedureResultResponse.State.RUNNING);
                builder.setStartTime(proc.getStartTime());
                builder.setLastUpdate(proc.getLastUpdate());
            }
        }
        return builder.build();
    } catch (IOException e) {
        throw new ServiceException(e);
    }
}
Also used : GetProcedureResultResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetProcedureResultResponse) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) ProcedureInfo(org.apache.hadoop.hbase.ProcedureInfo) LockProcedure(org.apache.hadoop.hbase.master.locking.LockProcedure) Procedure(org.apache.hadoop.hbase.procedure2.Procedure) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException)

Example 2 with Procedure

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

the class WALProcedureStore method insert.

@Override
public void insert(final Procedure proc, final Procedure[] subprocs) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("Insert " + proc + ", subproc=" + Arrays.toString(subprocs));
    }
    ByteSlot slot = acquireSlot();
    try {
        // Serialize the insert
        long[] subProcIds = null;
        if (subprocs != null) {
            ProcedureWALFormat.writeInsert(slot, proc, subprocs);
            subProcIds = new long[subprocs.length];
            for (int i = 0; i < subprocs.length; ++i) {
                subProcIds[i] = subprocs[i].getProcId();
            }
        } else {
            assert !proc.hasParent();
            ProcedureWALFormat.writeInsert(slot, proc);
        }
        // Push the transaction data and wait until it is persisted
        pushData(PushType.INSERT, slot, proc.getProcId(), subProcIds);
    } catch (IOException e) {
        // We are not able to serialize the procedure.
        // this is a code error, and we are not able to go on.
        LOG.fatal("Unable to serialize one of the procedure: proc=" + proc + ", subprocs=" + Arrays.toString(subprocs), e);
        throw new RuntimeException(e);
    } finally {
        releaseSlot(slot);
    }
}
Also used : IOException(java.io.IOException) ByteSlot(org.apache.hadoop.hbase.procedure2.util.ByteSlot)

Example 3 with Procedure

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

the class WALProcedureStore method update.

@Override
public void update(final Procedure proc) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("Update " + proc);
    }
    ByteSlot slot = acquireSlot();
    try {
        // Serialize the update
        ProcedureWALFormat.writeUpdate(slot, proc);
        // Push the transaction data and wait until it is persisted
        pushData(PushType.UPDATE, slot, proc.getProcId(), null);
    } catch (IOException e) {
        // We are not able to serialize the procedure.
        // this is a code error, and we are not able to go on.
        LOG.fatal("Unable to serialize the procedure: " + proc, e);
        throw new RuntimeException(e);
    } finally {
        releaseSlot(slot);
    }
}
Also used : IOException(java.io.IOException) ByteSlot(org.apache.hadoop.hbase.procedure2.util.ByteSlot)

Example 4 with Procedure

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

the class MasterProcedureScheduler method doPoll.

private <T extends Comparable<T>> Procedure doPoll(final FairQueue<T> fairq) {
    final Queue<T> rq = fairq.poll();
    if (rq == null || !rq.isAvailable()) {
        return null;
    }
    final Procedure pollResult = rq.peek();
    final boolean xlockReq = rq.requireExclusiveLock(pollResult);
    if (xlockReq && rq.getLockStatus().isLocked() && !rq.getLockStatus().hasLockAccess(pollResult)) {
        // someone is already holding the lock (e.g. shared lock). avoid a yield
        removeFromRunQueue(fairq, rq);
        return null;
    }
    rq.poll();
    if (rq.isEmpty() || xlockReq) {
        removeFromRunQueue(fairq, rq);
    } else if (rq.getLockStatus().hasParentLock(pollResult)) {
        // if the rq is in the fairq because of runnable child
        // check if the next procedure is still a child.
        // if not, remove the rq from the fairq and go back to the xlock state
        Procedure nextProc = rq.peek();
        if (nextProc != null && !Procedure.haveSameParent(nextProc, pollResult)) {
            removeFromRunQueue(fairq, rq);
        }
    }
    return pollResult;
}
Also used : Procedure(org.apache.hadoop.hbase.procedure2.Procedure)

Example 5 with Procedure

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

the class MasterProcedureScheduler method waitTableQueueSharedLock.

private TableQueue waitTableQueueSharedLock(final Procedure procedure, final TableName table) {
    schedLock();
    try {
        final LockAndQueue namespaceLock = locking.getNamespaceLock(table.getNamespaceAsString());
        final LockAndQueue tableLock = locking.getTableLock(table);
        if (!namespaceLock.trySharedLock()) {
            waitProcedure(namespaceLock, procedure);
            return null;
        }
        if (!tableLock.trySharedLock()) {
            namespaceLock.releaseSharedLock();
            waitProcedure(tableLock, procedure);
            return null;
        }
        return getTableQueue(table);
    } finally {
        schedUnlock();
    }
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue)

Aggregations

Procedure (org.apache.hadoop.hbase.procedure2.Procedure)29 TestProcedure (org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.TestProcedure)26 Test (org.junit.Test)26 TableName (org.apache.hadoop.hbase.TableName)16 IOException (java.io.IOException)10 LockAndQueue (org.apache.hadoop.hbase.procedure2.LockAndQueue)10 ProcedureInfo (org.apache.hadoop.hbase.ProcedureInfo)6 SequentialProcedure (org.apache.hadoop.hbase.procedure2.SequentialProcedure)5 ByteSlot (org.apache.hadoop.hbase.procedure2.util.ByteSlot)5 FileStatus (org.apache.hadoop.fs.FileStatus)4 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)4 LockProcedure (org.apache.hadoop.hbase.master.locking.LockProcedure)4 LoadCounter (org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.LoadCounter)4 ProcedureStore (org.apache.hadoop.hbase.procedure2.store.ProcedureStore)4 ProcedureIterator (org.apache.hadoop.hbase.procedure2.store.ProcedureStore.ProcedureIterator)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 MasterProcedureEnv (org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv)2 After (org.junit.After)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1