Search in sources :

Example 26 with Procedure

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

the class TestAccessController method testListProcedures.

@Test
public void testListProcedures() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    final ProcedureExecutor<MasterProcedureEnv> procExec = TEST_UTIL.getHBaseCluster().getMaster().getMasterProcedureExecutor();
    Procedure proc = new TestTableDDLProcedure(procExec.getEnvironment(), tableName);
    proc.setOwner(USER_OWNER);
    final long procId = procExec.submitProcedure(proc);
    final List<ProcedureInfo> procInfoList = procExec.listProcedures();
    AccessTestAction listProceduresAction = new AccessTestAction() {

        @Override
        public Object run() throws Exception {
            List<ProcedureInfo> procInfoListClone = new ArrayList<>(procInfoList.size());
            for (ProcedureInfo pi : procInfoList) {
                procInfoListClone.add(pi.clone());
            }
            ACCESS_CONTROLLER.postListProcedures(ObserverContext.createAndPrepare(CP_ENV, null), procInfoListClone);
            return null;
        }
    };
    verifyAllowed(listProceduresAction, SUPERUSER, USER_ADMIN, USER_GROUP_ADMIN);
    verifyAllowed(listProceduresAction, USER_OWNER);
    verifyIfNull(listProceduresAction, USER_RW, USER_RO, USER_NONE, USER_GROUP_READ, USER_GROUP_WRITE);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ProcedureInfo(org.apache.hadoop.hbase.ProcedureInfo) ArrayList(java.util.ArrayList) LockProcedure(org.apache.hadoop.hbase.master.locking.LockProcedure) Procedure(org.apache.hadoop.hbase.procedure2.Procedure) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) Test(org.junit.Test)

Example 27 with Procedure

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

the class ProcedureExecutor method load.

private void load(final boolean abortOnCorruption) throws IOException {
    Preconditions.checkArgument(completed.isEmpty(), "completed not empty");
    Preconditions.checkArgument(rollbackStack.isEmpty(), "rollback state not empty");
    Preconditions.checkArgument(procedures.isEmpty(), "procedure map not empty");
    Preconditions.checkArgument(scheduler.size() == 0, "run queue not empty");
    store.load(new ProcedureStore.ProcedureLoader() {

        @Override
        public void setMaxProcId(long maxProcId) {
            assert lastProcId.get() < 0 : "expected only one call to setMaxProcId()";
            LOG.debug("Load maxProcId=" + maxProcId);
            lastProcId.set(maxProcId);
        }

        @Override
        public void load(ProcedureIterator procIter) throws IOException {
            loadProcedures(procIter, abortOnCorruption);
        }

        @Override
        public void handleCorrupted(ProcedureIterator procIter) throws IOException {
            int corruptedCount = 0;
            while (procIter.hasNext()) {
                ProcedureInfo proc = procIter.nextAsProcedureInfo();
                LOG.error("Corrupt " + proc);
                corruptedCount++;
            }
            if (abortOnCorruption && corruptedCount > 0) {
                throw new IOException("found " + corruptedCount + " corrupted procedure(s) on replay");
            }
        }
    });
}
Also used : ProcedureInfo(org.apache.hadoop.hbase.ProcedureInfo) ProcedureStore(org.apache.hadoop.hbase.procedure2.store.ProcedureStore) ProcedureIterator(org.apache.hadoop.hbase.procedure2.store.ProcedureStore.ProcedureIterator) IllegalArgumentIOException(org.apache.hadoop.hbase.exceptions.IllegalArgumentIOException) IOException(java.io.IOException)

Example 28 with Procedure

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

the class ProcedureWALFormatReader method finish.

public void finish() throws IOException {
    // notify the loader about the max proc ID
    loader.setMaxProcId(maxProcId);
    // fetch the procedure ready to run.
    ProcedureIterator procIter = procedureMap.fetchReady();
    if (procIter != null)
        loader.load(procIter);
    // remaining procedures have missing link or dependencies
    // consider them as corrupted, manual fix is probably required.
    procIter = procedureMap.fetchAll();
    if (procIter != null)
        loader.handleCorrupted(procIter);
}
Also used : ProcedureIterator(org.apache.hadoop.hbase.procedure2.store.ProcedureStore.ProcedureIterator)

Example 29 with Procedure

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

the class WALProcedureStore method delete.

@Override
public void delete(final Procedure proc, final long[] subProcIds) {
    assert proc != null : "expected a non-null procedure";
    assert subProcIds != null && subProcIds.length > 0 : "expected subProcIds";
    if (LOG.isTraceEnabled()) {
        LOG.trace("Update " + proc + " and Delete " + Arrays.toString(subProcIds));
    }
    ByteSlot slot = acquireSlot();
    try {
        // Serialize the delete
        ProcedureWALFormat.writeDelete(slot, proc, subProcIds);
        // Push the transaction data and wait until it is persisted
        pushData(PushType.DELETE, 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 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 30 with Procedure

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

the class WALProcedureStore method delete.

@Override
public void delete(final long procId) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("Delete " + procId);
    }
    ByteSlot slot = acquireSlot();
    try {
        // Serialize the delete
        ProcedureWALFormat.writeDelete(slot, procId);
        // Push the transaction data and wait until it is persisted
        pushData(PushType.DELETE, slot, procId, 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: " + procId, e);
        throw new RuntimeException(e);
    } finally {
        releaseSlot(slot);
    }
}
Also used : IOException(java.io.IOException) ByteSlot(org.apache.hadoop.hbase.procedure2.util.ByteSlot)

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