Search in sources :

Example 21 with Procedure

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

the class TestWALProcedureStore method trackersLoadedForAllOldLogs.

/**
   * Tests that tracker for all old logs are loaded back after procedure store is restarted.
   */
@Test
public void trackersLoadedForAllOldLogs() throws Exception {
    for (int i = 0; i <= 20; ++i) {
        procStore.insert(new TestProcedure(i), null);
        if (i > 0 && (i % 5) == 0) {
            LoadCounter loader = new LoadCounter();
            storeRestart(loader);
        }
    }
    assertEquals(5, procStore.getActiveLogs().size());
    for (int i = 0; i < procStore.getActiveLogs().size() - 1; ++i) {
        ProcedureStoreTracker tracker = procStore.getActiveLogs().get(i).getTracker();
        assertTrue(tracker != null && !tracker.isEmpty());
    }
}
Also used : TestProcedure(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.TestProcedure) LoadCounter(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.LoadCounter) ProcedureStoreTracker(org.apache.hadoop.hbase.procedure2.store.ProcedureStoreTracker) Test(org.junit.Test)

Example 22 with Procedure

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

the class TestWALProcedureStore method testLoadChildren.

@Test
public void testLoadChildren() throws Exception {
    TestProcedure a = new TestProcedure(1, 0);
    TestProcedure b = new TestProcedure(2, 1);
    TestProcedure c = new TestProcedure(3, 1);
    // INIT
    procStore.insert(a, null);
    // Run A first step
    a.addStackId(0);
    procStore.update(a);
    // Run A second step
    a.addStackId(1);
    procStore.insert(a, new Procedure[] { b, c });
    // Run B first step
    b.addStackId(2);
    procStore.update(b);
    // Run C first and last step
    c.addStackId(3);
    procStore.update(c);
    // Run B second setp
    b.addStackId(4);
    procStore.update(b);
    // back to A
    a.addStackId(5);
    a.setFinishedState();
    procStore.delete(a, new long[] { b.getProcId(), c.getProcId() });
    restartAndAssert(3, 0, 1, 0);
}
Also used : TestProcedure(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.TestProcedure) Test(org.junit.Test)

Example 23 with Procedure

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

the class MasterProcedureScheduler method markTableAsDeleted.

/**
   * Tries to remove the queue and the table-lock of the specified table.
   * If there are new operations pending (e.g. a new create),
   * the remove will not be performed.
   * @param table the name of the table that should be marked as deleted
   * @param procedure the procedure that is removing the table
   * @return true if deletion succeeded, false otherwise meaning that there are
   *     other new operations pending for that table (e.g. a new create).
   */
@VisibleForTesting
protected boolean markTableAsDeleted(final TableName table, final Procedure procedure) {
    schedLock();
    try {
        final TableQueue queue = getTableQueue(table);
        final LockAndQueue tableLock = locking.getTableLock(table);
        if (queue == null)
            return true;
        if (queue.isEmpty() && tableLock.tryExclusiveLock(procedure)) {
            // remove the table from the run-queue and the map
            if (AvlIterableList.isLinked(queue)) {
                tableRunQueue.remove(queue);
            }
            removeTableQueue(table);
        } else {
            // TODO: If there are no create, we can drop all the other ops
            return false;
        }
    } finally {
        schedUnlock();
    }
    return true;
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 24 with Procedure

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

the class MasterProcedureScheduler method wakeTableSharedLock.

/**
   * Wake the procedures waiting for the specified table
   * @param procedure the procedure releasing the lock
   * @param table the name of the table that has the shared lock
   */
public void wakeTableSharedLock(final Procedure procedure, final TableName table) {
    schedLock();
    try {
        final LockAndQueue namespaceLock = locking.getNamespaceLock(table.getNamespaceAsString());
        final LockAndQueue tableLock = locking.getTableLock(table);
        int waitingCount = 0;
        if (tableLock.releaseSharedLock()) {
            addToRunQueue(tableRunQueue, getTableQueue(table));
            waitingCount += wakeWaitingProcedures(tableLock);
        }
        if (namespaceLock.releaseSharedLock()) {
            waitingCount += wakeWaitingProcedures(namespaceLock);
        }
        wakePollIfNeeded(waitingCount);
    } finally {
        schedUnlock();
    }
}
Also used : LockAndQueue(org.apache.hadoop.hbase.procedure2.LockAndQueue)

Example 25 with Procedure

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

the class MasterProcedureScheduler method wakeNamespaceExclusiveLock.

/**
   * Wake the procedures waiting for the specified namespace
   * @see #waitNamespaceExclusiveLock(Procedure,String)
   * @param procedure the procedure releasing the lock
   * @param namespace the namespace that has the exclusive lock
   */
public void wakeNamespaceExclusiveLock(final Procedure procedure, final String namespace) {
    schedLock();
    try {
        final LockAndQueue namespaceLock = locking.getNamespaceLock(namespace);
        final LockAndQueue systemNamespaceTableLock = locking.getTableLock(TableName.NAMESPACE_TABLE_NAME);
        namespaceLock.releaseExclusiveLock(procedure);
        int waitingCount = 0;
        if (systemNamespaceTableLock.releaseSharedLock()) {
            addToRunQueue(tableRunQueue, getTableQueue(TableName.NAMESPACE_TABLE_NAME));
            waitingCount += wakeWaitingProcedures(systemNamespaceTableLock);
        }
        waitingCount += wakeWaitingProcedures(namespaceLock);
        wakePollIfNeeded(waitingCount);
    } 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