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);
}
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);
}
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;
}
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);
}
}
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;
}
Aggregations