Search in sources :

Example 16 with Procedure

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

the class MasterProcedureScheduler method wakeRegions.

/**
   * Wake the procedures waiting for the specified regions
   * @param procedure the procedure that was holding the regions
   * @param regionInfo the list of regions the procedure was holding
   */
public void wakeRegions(final Procedure procedure, final TableName table, final HRegionInfo... regionInfo) {
    Arrays.sort(regionInfo);
    schedLock();
    try {
        int numProcs = 0;
        final Procedure[] nextProcs = new Procedure[regionInfo.length];
        for (int i = 0; i < regionInfo.length; ++i) {
            assert regionInfo[i].getTable().equals(table);
            assert i == 0 || regionInfo[i] != regionInfo[i - 1] : "duplicate region: " + regionInfo[i];
            LockAndQueue regionLock = locking.getRegionLock(regionInfo[i].getEncodedName());
            if (regionLock.releaseExclusiveLock(procedure)) {
                if (!regionLock.isEmpty()) {
                    // release one procedure at the time since regions has an xlock
                    nextProcs[numProcs++] = regionLock.removeFirst();
                } else {
                    locking.removeRegionLock(regionInfo[i].getEncodedName());
                }
            }
        }
        // awake procedures if any
        for (int i = numProcs - 1; i >= 0; --i) {
            wakeProcedure(nextProcs[i]);
        }
        wakePollIfNeeded(numProcs);
        if (!procedure.hasParent()) {
            // release the table shared-lock.
            // (if we have a parent, it is holding an xlock so we didn't take the shared-lock)
            wakeTableSharedLock(procedure, table);
        }
    } finally {
        schedUnlock();
    }
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue) Procedure(org.apache.hadoop.hbase.procedure2.Procedure)

Example 17 with Procedure

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

the class MasterProcedureScheduler method waitNamespaceExclusiveLock.

// ============================================================================
//  Namespace Locking Helpers
// ============================================================================
/**
   * Suspend the procedure if the specified namespace is already locked.
   * @see #wakeNamespaceExclusiveLock(Procedure,String)
   * @param procedure the procedure trying to acquire the lock
   * @param namespace Namespace to lock
   * @return true if the procedure has to wait for the namespace to be available
   */
public boolean waitNamespaceExclusiveLock(final Procedure procedure, final String namespace) {
    schedLock();
    try {
        final LockAndQueue systemNamespaceTableLock = locking.getTableLock(TableName.NAMESPACE_TABLE_NAME);
        if (!systemNamespaceTableLock.trySharedLock()) {
            waitProcedure(systemNamespaceTableLock, procedure);
            return true;
        }
        final LockAndQueue namespaceLock = locking.getNamespaceLock(namespace);
        if (!namespaceLock.tryExclusiveLock(procedure)) {
            systemNamespaceTableLock.releaseSharedLock();
            waitProcedure(namespaceLock, procedure);
            return true;
        }
        return false;
    } finally {
        schedUnlock();
    }
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue)

Example 18 with Procedure

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

the class MasterProcedureScheduler method wakeServerExclusiveLock.

/**
   * Wake the procedures waiting for the specified server
   * @see #waitServerExclusiveLock(Procedure,ServerName)
   * @param procedure the procedure releasing the lock
   * @param serverName the server that has the exclusive lock
   */
public void wakeServerExclusiveLock(final Procedure procedure, final ServerName serverName) {
    schedLock();
    try {
        final LockAndQueue lock = locking.getServerLock(serverName);
        lock.releaseExclusiveLock(procedure);
        addToRunQueue(serverRunQueue, getServerQueue(serverName));
        int waitingCount = wakeWaitingProcedures(lock);
        wakePollIfNeeded(waitingCount);
    } finally {
        schedUnlock();
    }
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue)

Example 19 with Procedure

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

the class TestProcedureUtil method testConvert.

@Test
public void testConvert() throws Exception {
    // check Procedure to protobuf conversion
    final TestProcedure proc1 = new TestProcedure(10);
    final ProcedureProtos.Procedure proto1 = ProcedureUtil.convertToProtoProcedure(proc1);
    final TestProcedure proc2 = (TestProcedure) ProcedureUtil.convertToProcedure(proto1);
    final ProcedureProtos.Procedure proto2 = ProcedureUtil.convertToProtoProcedure(proc2);
    assertEquals(false, proto2.hasResult());
    assertEquals("Procedure protobuf does not match", proto1, proto2);
    // remove the state-data from the procedure protobuf to compare it to the gen ProcedureInfo
    final ProcedureProtos.Procedure pbproc = proto2.toBuilder().clearStateData().build();
    // check ProcedureInfo to protobuf conversion
    final ProcedureInfo protoInfo1 = ProcedureUtil.convertToProcedureInfo(proc1);
    final ProcedureProtos.Procedure proto3 = ProcedureUtil.convertToProtoProcedure(protoInfo1);
    final ProcedureInfo protoInfo2 = ProcedureUtil.convertToProcedureInfo(proto3);
    final ProcedureProtos.Procedure proto4 = ProcedureUtil.convertToProtoProcedure(protoInfo2);
    assertEquals("ProcedureInfo protobuf does not match", proto3, proto4);
    assertEquals("ProcedureInfo/Procedure protobuf does not match", pbproc, proto3);
    assertEquals("ProcedureInfo/Procedure protobuf does not match", pbproc, proto4);
}
Also used : TestProcedure(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.TestProcedure) ProcedureInfo(org.apache.hadoop.hbase.ProcedureInfo) ProcedureProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos) Test(org.junit.Test)

Example 20 with Procedure

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

the class TestWALProcedureStore method testWalReplayOrder_ABC_BAD.

@Test(timeout = 60000)
public void testWalReplayOrder_ABC_BAD() throws Exception {
    /*
     * | A B C | -> | B A D |
     */
    TestProcedure a = new TestProcedure(1, 0);
    TestProcedure b = new TestProcedure(2, 1);
    TestProcedure c = new TestProcedure(3, 2);
    TestProcedure d = new TestProcedure(4, 0);
    procStore.insert(a, null);
    a.addStackId(0);
    procStore.update(a);
    procStore.insert(a, new Procedure[] { b });
    b.addStackId(1);
    procStore.update(b);
    procStore.insert(b, new Procedure[] { c });
    b.addStackId(2);
    procStore.update(b);
    procStore.rollWriterForTesting();
    b.addStackId(3);
    procStore.update(b);
    a.addStackId(4);
    procStore.update(a);
    procStore.insert(d, null);
    d.addStackId(0);
    procStore.update(d);
    storeRestart(new ProcedureStore.ProcedureLoader() {

        @Override
        public void setMaxProcId(long maxProcId) {
            assertEquals(4, maxProcId);
        }

        @Override
        public void load(ProcedureIterator procIter) throws IOException {
            assertTrue(procIter.hasNext());
            assertEquals(4, procIter.nextAsProcedureInfo().getProcId());
            // TODO: This will be multiple call once we do fast-start
            //assertFalse(procIter.hasNext());
            assertTrue(procIter.hasNext());
            assertEquals(1, procIter.nextAsProcedureInfo().getProcId());
            assertTrue(procIter.hasNext());
            assertEquals(2, procIter.nextAsProcedureInfo().getProcId());
            assertTrue(procIter.hasNext());
            assertEquals(3, procIter.nextAsProcedureInfo().getProcId());
            assertFalse(procIter.hasNext());
        }

        @Override
        public void handleCorrupted(ProcedureIterator procIter) throws IOException {
            assertFalse(procIter.hasNext());
        }
    });
}
Also used : TestProcedure(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.TestProcedure) ProcedureStore(org.apache.hadoop.hbase.procedure2.store.ProcedureStore) ProcedureIterator(org.apache.hadoop.hbase.procedure2.store.ProcedureStore.ProcedureIterator) IOException(java.io.IOException) Test(org.junit.Test)

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