Search in sources :

Example 6 with InstanceId

use of org.apache.accumulo.core.data.InstanceId in project accumulo by apache.

the class CompactionDriverTest method testCancelId.

@Test
public void testCancelId() throws Exception {
    final InstanceId instance = InstanceId.of(UUID.randomUUID());
    final long compactId = 123;
    final long cancelId = 124;
    final NamespaceId namespaceId = NamespaceId.of("13");
    final TableId tableId = TableId.of("42");
    final byte[] startRow = new byte[0];
    final byte[] endRow = new byte[0];
    Manager manager = EasyMock.createNiceMock(Manager.class);
    ServerContext ctx = EasyMock.createNiceMock(ServerContext.class);
    ZooReaderWriter zrw = EasyMock.createNiceMock(ZooReaderWriter.class);
    EasyMock.expect(manager.getInstanceID()).andReturn(instance).anyTimes();
    EasyMock.expect(manager.getContext()).andReturn(ctx);
    EasyMock.expect(ctx.getZooReaderWriter()).andReturn(zrw);
    final String zCancelID = CompactionDriver.createCompactionCancellationPath(instance, tableId);
    EasyMock.expect(zrw.getData(zCancelID)).andReturn(Long.toString(cancelId).getBytes());
    EasyMock.replay(manager, ctx, zrw);
    final CompactionDriver driver = new CompactionDriver(compactId, namespaceId, tableId, startRow, endRow);
    final long tableIdLong = Long.parseLong(tableId.toString());
    var e = assertThrows(AcceptableThriftTableOperationException.class, () -> driver.isReady(tableIdLong, manager));
    assertTrue(e.getTableId().equals(tableId.toString()));
    assertTrue(e.getOp().equals(TableOperation.COMPACT));
    assertTrue(e.getType().equals(TableOperationExceptionType.OTHER));
    assertTrue(e.getDescription().equals(TableOperationsImpl.COMPACTION_CANCELED_MSG));
    EasyMock.verify(manager, ctx, zrw);
}
Also used : TableId(org.apache.accumulo.core.data.TableId) ServerContext(org.apache.accumulo.server.ServerContext) InstanceId(org.apache.accumulo.core.data.InstanceId) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) NamespaceId(org.apache.accumulo.core.data.NamespaceId) Manager(org.apache.accumulo.manager.Manager) Test(org.junit.Test)

Example 7 with InstanceId

use of org.apache.accumulo.core.data.InstanceId in project accumulo by apache.

the class AdminTest method testZooKeeperTserverPath.

@Test
public void testZooKeeperTserverPath() {
    ClientContext context = EasyMock.createMock(ClientContext.class);
    InstanceId instanceId = InstanceId.of(UUID.randomUUID());
    EasyMock.expect(context.getZooKeeperRoot()).andReturn(Constants.ZROOT + "/" + instanceId);
    EasyMock.replay(context);
    assertEquals(Constants.ZROOT + "/" + instanceId + Constants.ZTSERVERS, Admin.getTServersZkPath(context));
    EasyMock.verify(context);
}
Also used : InstanceId(org.apache.accumulo.core.data.InstanceId) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) Test(org.junit.Test)

Example 8 with InstanceId

use of org.apache.accumulo.core.data.InstanceId in project accumulo by apache.

the class FateConcurrencyIT method lookupFateInZookeeper.

/**
 * Checks fates in zookeeper looking for transaction associated with a compaction as a double
 * check that the test will be valid because the running compaction does have a fate transaction
 * lock.
 * <p>
 * This method throws can throw either IllegalStateException (failed) or a Zookeeper exception.
 * Throwing the Zookeeper exception allows for retries if desired to handle transient zookeeper
 * issues.
 *
 * @param tableName
 *          a table name
 * @return true if corresponding fate transaction found, false otherwise
 * @throws KeeperException
 *           if a zookeeper error occurred - allows for retries.
 */
private boolean lookupFateInZookeeper(final String tableName) throws KeeperException {
    AdminUtil<String> admin = new AdminUtil<>(false);
    try {
        TableId tableId = context.getTableId(tableName);
        log.trace("tid: {}", tableId);
        InstanceId instanceId = context.getInstanceID();
        ZooReaderWriter zk = new ZooReaderWriter(context.getZooKeepers(), context.getZooKeepersSessionTimeOut(), secret);
        ZooStore<String> zs = new ZooStore<>(ZooUtil.getRoot(instanceId) + Constants.ZFATE, zk);
        AdminUtil.FateStatus fateStatus = admin.getStatus(zs, zk, ZooUtil.getRoot(instanceId) + Constants.ZTABLE_LOCKS + "/" + tableId, null, null);
        log.trace("current fates: {}", fateStatus.getTransactions().size());
        for (AdminUtil.TransactionStatus tx : fateStatus.getTransactions()) {
            if (isCompaction(tx))
                return true;
        }
    } catch (TableNotFoundException | InterruptedException ex) {
        throw new IllegalStateException(ex);
    }
    // did not find appropriate fate transaction for compaction.
    return Boolean.FALSE;
}
Also used : TableId(org.apache.accumulo.core.data.TableId) InstanceId(org.apache.accumulo.core.data.InstanceId) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) ZooStore(org.apache.accumulo.fate.ZooStore) AdminUtil(org.apache.accumulo.fate.AdminUtil) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException)

Example 9 with InstanceId

use of org.apache.accumulo.core.data.InstanceId 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 10 with InstanceId

use of org.apache.accumulo.core.data.InstanceId in project accumulo by apache.

the class InstanceOperationsImpl method lookupInstanceName.

/**
 * Given a zooCache and instanceId, look up the instance name.
 */
public static String lookupInstanceName(ZooCache zooCache, InstanceId instanceId) {
    checkArgument(zooCache != null, "zooCache is null");
    checkArgument(instanceId != null, "instanceId is null");
    for (String name : zooCache.getChildren(Constants.ZROOT + Constants.ZINSTANCES)) {
        var bytes = zooCache.get(Constants.ZROOT + Constants.ZINSTANCES + "/" + name);
        InstanceId iid = InstanceId.of(new String(bytes, UTF_8));
        if (iid.equals(instanceId)) {
            return name;
        }
    }
    return null;
}
Also used : InstanceId(org.apache.accumulo.core.data.InstanceId)

Aggregations

InstanceId (org.apache.accumulo.core.data.InstanceId)23 Test (org.junit.Test)8 IOException (java.io.IOException)6 ZooReaderWriter (org.apache.accumulo.fate.zookeeper.ZooReaderWriter)6 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)5 TableId (org.apache.accumulo.core.data.TableId)5 ServerContext (org.apache.accumulo.server.ServerContext)5 Path (org.apache.hadoop.fs.Path)5 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)4 KeeperException (org.apache.zookeeper.KeeperException)4 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)3 Socket (java.net.Socket)3 SiteConfiguration (org.apache.accumulo.core.conf.SiteConfiguration)3 ZooReader (org.apache.accumulo.fate.zookeeper.ZooReader)3 Initialize (org.apache.accumulo.server.init.Initialize)3 Configuration (org.apache.hadoop.conf.Configuration)3 AccumuloException (org.apache.accumulo.core.client.AccumuloException)2 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)2 NamespaceId (org.apache.accumulo.core.data.NamespaceId)2 AdminUtil (org.apache.accumulo.fate.AdminUtil)2