Search in sources :

Example 1 with SlowOps

use of org.apache.accumulo.test.util.SlowOps in project accumulo by apache.

the class FateConcurrencyIT method getFateStatus.

/**
 * Validate the the AdminUtil.getStatus works correctly after refactor and validate that
 * getTransactionStatus can be called without lock map(s). The test starts a long running fate
 * transaction (slow compaction) and the calls AdminUtil functions to get the FATE.
 */
@Test
public void getFateStatus() {
    SlowOps.setExpectedCompactions(client, 1);
    String tableName = getUniqueNames(1)[0];
    slowOps = new SlowOps(client, tableName, maxWaitMillis);
    TableId tableId;
    try {
        assertEquals("verify table online after created", TableState.ONLINE, getTableState(tableName));
        tableId = context.getTableId(tableName);
        log.trace("tid: {}", tableId);
    } catch (TableNotFoundException ex) {
        throw new IllegalStateException(String.format("Table %s does not exist, failing test", tableName));
    }
    slowOps.startCompactTask();
    AdminUtil.FateStatus withLocks = null;
    List<AdminUtil.TransactionStatus> noLocks = null;
    int maxRetries = 3;
    AdminUtil<String> admin = new AdminUtil<>(false);
    while (maxRetries > 0) {
        try {
            InstanceId instanceId = context.getInstanceID();
            ZooReaderWriter zk = new ZooReaderWriter(context.getZooKeepers(), context.getZooKeepersSessionTimeOut(), secret);
            ZooStore<String> zs = new ZooStore<>(ZooUtil.getRoot(instanceId) + Constants.ZFATE, zk);
            withLocks = admin.getStatus(zs, zk, ZooUtil.getRoot(instanceId) + Constants.ZTABLE_LOCKS + "/" + tableId, null, null);
            // call method that does not use locks.
            noLocks = admin.getTransactionStatus(zs, null, null);
            // no zk exception, no need to retry
            break;
        } catch (InterruptedException ex) {
            Thread.currentThread().interrupt();
            fail("Interrupt received - test failed");
            return;
        } catch (KeeperException ex) {
            maxRetries--;
            try {
                Thread.sleep(1000);
            } catch (InterruptedException intr_ex) {
                Thread.currentThread().interrupt();
                return;
            }
        }
    }
    assertNotNull(withLocks);
    assertNotNull(noLocks);
    // fast check - count number of transactions
    assertEquals(withLocks.getTransactions().size(), noLocks.size());
    int matchCount = 0;
    for (AdminUtil.TransactionStatus tx : withLocks.getTransactions()) {
        if (isCompaction(tx)) {
            log.trace("Fate id: {}, status: {}", tx.getTxid(), tx.getStatus());
            for (AdminUtil.TransactionStatus tx2 : noLocks) {
                if (tx2.getTxid().equals(tx.getTxid())) {
                    matchCount++;
                }
            }
        }
    }
    assertTrue("Number of fates matches should be > 0", matchCount > 0);
    try {
        // test complete, cancel compaction and move on.
        client.tableOperations().cancelCompaction(tableName);
        // block if compaction still running
        boolean cancelled = slowOps.blockWhileCompactionRunning();
        log.debug("Cancel completed successfully: {}", cancelled);
    } catch (TableNotFoundException | AccumuloSecurityException | AccumuloException ex) {
        log.debug("Could not cancel compaction due to exception", ex);
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) AccumuloException(org.apache.accumulo.core.client.AccumuloException) InstanceId(org.apache.accumulo.core.data.InstanceId) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) ZooStore(org.apache.accumulo.fate.ZooStore) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AdminUtil(org.apache.accumulo.fate.AdminUtil) SlowOps(org.apache.accumulo.test.util.SlowOps) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) KeeperException(org.apache.zookeeper.KeeperException) Test(org.junit.Test)

Example 2 with SlowOps

use of org.apache.accumulo.test.util.SlowOps in project accumulo by apache.

the class FateConcurrencyIT method changeTableStateTest.

/**
 * Validate that {@code TableOperations} online operation does not block when table is already
 * online and fate transaction lock is held by other operations. The test creates, populates a
 * table and then runs a compaction with a slow iterator so that operation takes long enough to
 * simulate the condition. After the online operation while compaction is running completes, the
 * test is complete and the compaction is canceled so that other tests can run.
 *
 * @throws Exception
 *           any exception is a test failure.
 */
@Test
public void changeTableStateTest() throws Exception {
    String tableName = getUniqueNames(1)[0];
    SlowOps.setExpectedCompactions(client, 1);
    slowOps = new SlowOps(client, tableName, maxWaitMillis);
    assertEquals("verify table online after created", TableState.ONLINE, getTableState(tableName));
    OnLineCallable onlineOp = new OnLineCallable(tableName);
    Future<OnlineOpTiming> task = pool.submit(onlineOp);
    OnlineOpTiming timing1 = task.get();
    log.trace("Online 1 in {} ms", NANOSECONDS.toMillis(timing1.runningTime()));
    assertEquals("verify table is still online", TableState.ONLINE, getTableState(tableName));
    // verify that offline then online functions as expected.
    client.tableOperations().offline(tableName, true);
    assertEquals("verify table is offline", TableState.OFFLINE, getTableState(tableName));
    onlineOp = new OnLineCallable(tableName);
    task = pool.submit(onlineOp);
    OnlineOpTiming timing2 = task.get();
    log.trace("Online 2 in {} ms", NANOSECONDS.toMillis(timing2.runningTime()));
    assertEquals("verify table is back online", TableState.ONLINE, getTableState(tableName));
    // launch a full table compaction with the slow iterator to ensure table lock is acquired and
    // held by the compaction
    slowOps.startCompactTask();
    // try to set online while fate transaction is in progress - before ACCUMULO-4574 this would
    // block
    onlineOp = new OnLineCallable(tableName);
    task = pool.submit(onlineOp);
    OnlineOpTiming timing3 = task.get();
    assertTrue("online should take less time than expected compaction time", timing3.runningTime() < MILLISECONDS.toNanos(NUM_ROWS * SLOW_SCAN_SLEEP_MS));
    assertEquals("verify table is still online", TableState.ONLINE, getTableState(tableName));
    assertTrue("Find FATE operation for table", findFate(tableName));
    // test complete, cancel compaction and move on.
    client.tableOperations().cancelCompaction(tableName);
    log.debug("Success: Timing results for online commands.");
    log.debug("Time for unblocked online {} ms", NANOSECONDS.toMillis(timing1.runningTime()));
    log.debug("Time for online when offline {} ms", NANOSECONDS.toMillis(timing2.runningTime()));
    log.debug("Time for blocked online {} ms", NANOSECONDS.toMillis(timing3.runningTime()));
    // block if compaction still running
    slowOps.blockWhileCompactionRunning();
}
Also used : SlowOps(org.apache.accumulo.test.util.SlowOps) Test(org.junit.Test)

Aggregations

SlowOps (org.apache.accumulo.test.util.SlowOps)2 Test (org.junit.Test)2 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 InstanceId (org.apache.accumulo.core.data.InstanceId)1 TableId (org.apache.accumulo.core.data.TableId)1 AdminUtil (org.apache.accumulo.fate.AdminUtil)1 ZooStore (org.apache.accumulo.fate.ZooStore)1 ZooReaderWriter (org.apache.accumulo.fate.zookeeper.ZooReaderWriter)1 KeeperException (org.apache.zookeeper.KeeperException)1