use of org.apache.accumulo.proxy.thrift.ActiveCompaction in project accumulo by apache.
the class SimpleProxyBase method attachIteratorWithCompactions.
@Test
public void attachIteratorWithCompactions() throws Exception {
if (client.tableExists(creds, "slow")) {
client.deleteTable(creds, "slow");
}
// create a table that's very slow, so we can look for compactions
client.createTable(creds, "slow", true, TimeType.MILLIS);
IteratorSetting setting = new IteratorSetting(100, "slow", SlowIterator.class.getName(), Collections.singletonMap("sleepTime", "250"));
client.attachIterator(creds, "slow", setting, EnumSet.allOf(IteratorScope.class));
// Should take 10 seconds to read every record
for (int i = 0; i < 40; i++) {
client.updateAndFlush(creds, "slow", mutation("row" + i, "cf", "cq", "value"));
}
Map<String, String> map = client.tableIdMap(creds);
// start a compaction
Thread t = new Thread() {
@Override
public void run() {
TestProxyClient proxyClient2 = null;
try {
if (isKerberosEnabled()) {
UserGroupInformation.loginUserFromKeytab(clientPrincipal, clientKeytab.getAbsolutePath());
proxyClient2 = new TestProxyClient(hostname, proxyPort, factory, proxyPrimary, UserGroupInformation.getCurrentUser());
} else {
proxyClient2 = new TestProxyClient(hostname, proxyPort, factory);
}
Client client2 = proxyClient2.proxy();
client2.compactTable(creds, "slow", null, null, null, true, true, null);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (null != proxyClient2) {
proxyClient2.close();
}
}
}
};
t.start();
final String desiredTableId = map.get("slow");
// Make sure we can find the slow table
assertNotNull(desiredTableId);
// try to catch it in the act
List<ActiveCompaction> compactions = new ArrayList<>();
for (int i = 0; i < 100 && compactions.isEmpty(); i++) {
// Iterate over the tservers
for (String tserver : client.getTabletServers(creds)) {
// And get the compactions on each
List<ActiveCompaction> compactionsOnServer = client.getActiveCompactions(creds, tserver);
for (ActiveCompaction compact : compactionsOnServer) {
// case we want to prune out those that aren't for our slow table
if (desiredTableId.equals(compact.getExtent().tableId)) {
compactions.add(compact);
}
}
// If we found a compaction for the table we wanted, so we can stop looking
if (!compactions.isEmpty())
break;
}
sleepUninterruptibly(10, TimeUnit.MILLISECONDS);
}
t.join();
// verify the compaction information
assertFalse(compactions.isEmpty());
for (ActiveCompaction c : compactions) {
if (desiredTableId.equals(c.getExtent().tableId)) {
assertTrue(c.inputFiles.isEmpty());
assertEquals(CompactionType.MINOR, c.getType());
assertEquals(CompactionReason.USER, c.getReason());
assertEquals("", c.localityGroup);
assertTrue(c.outputFile.contains("default_tablet"));
return;
}
}
fail("Expection to find running compaction for table 'slow' but did not find one");
}
Aggregations