use of org.apache.accumulo.core.client.Connector in project accumulo by apache.
the class VolumeIT method testRemoveVolumes.
@Test
public void testRemoveVolumes() throws Exception {
String[] tableNames = getUniqueNames(2);
verifyVolumesUsed(tableNames[0], false, v1, v2);
Assert.assertEquals(0, cluster.exec(Admin.class, "stopAll").waitFor());
cluster.stop();
Configuration conf = new Configuration(false);
conf.addResource(new Path(cluster.getConfig().getConfDir().toURI().toString(), "accumulo-site.xml"));
conf.set(Property.INSTANCE_VOLUMES.getKey(), v2.toString());
BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(new File(cluster.getConfig().getConfDir(), "accumulo-site.xml")));
conf.writeXml(fos);
fos.close();
// start cluster and verify that volume was decommisioned
cluster.start();
Connector conn = cluster.getConnector("root", new PasswordToken(ROOT_PASSWORD));
conn.tableOperations().compact(tableNames[0], null, null, true, true);
verifyVolumesUsed(tableNames[0], true, v2);
// check that root tablet is not on volume 1
ZooReader zreader = new ZooReader(cluster.getZooKeepers(), 30000);
String zpath = ZooUtil.getRoot(new ZooKeeperInstance(cluster.getClientConfig())) + RootTable.ZROOT_TABLET_PATH;
String rootTabletDir = new String(zreader.getData(zpath, false, null), UTF_8);
Assert.assertTrue(rootTabletDir.startsWith(v2.toString()));
conn.tableOperations().clone(tableNames[0], tableNames[1], true, new HashMap<>(), new HashSet<>());
conn.tableOperations().flush(MetadataTable.NAME, null, null, true);
conn.tableOperations().flush(RootTable.NAME, null, null, true);
verifyVolumesUsed(tableNames[0], true, v2);
verifyVolumesUsed(tableNames[1], true, v2);
}
use of org.apache.accumulo.core.client.Connector in project accumulo by apache.
the class WaitForBalanceIT method isBalanced.
private boolean isBalanced() throws Exception {
final Map<String, Integer> counts = new HashMap<>();
int offline = 0;
final Connector c = getConnector();
for (String tableName : new String[] { MetadataTable.NAME, RootTable.NAME }) {
try (Scanner s = c.createScanner(tableName, Authorizations.EMPTY)) {
s.setRange(MetadataSchema.TabletsSection.getRange());
s.fetchColumnFamily(MetadataSchema.TabletsSection.CurrentLocationColumnFamily.NAME);
MetadataSchema.TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.fetch(s);
String location = null;
for (Entry<Key, Value> entry : s) {
Key key = entry.getKey();
if (key.getColumnFamily().equals(MetadataSchema.TabletsSection.CurrentLocationColumnFamily.NAME)) {
location = key.getColumnQualifier().toString();
} else if (MetadataSchema.TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.hasColumns(key)) {
if (location == null) {
offline++;
} else {
Integer count = counts.get(location);
if (count == null)
count = 0;
count = count + 1;
counts.put(location, count);
}
location = null;
}
}
}
}
// the replication table is expected to be offline for this test, so ignore it
if (offline > 1) {
System.out.println("Offline tablets " + offline);
return false;
}
int average = 0;
for (Integer i : counts.values()) {
average += i;
}
average /= counts.size();
System.out.println(counts);
int tablesCount = c.tableOperations().list().size();
for (Entry<String, Integer> hostCount : counts.entrySet()) {
if (Math.abs(average - hostCount.getValue()) > tablesCount) {
System.out.println("Average " + average + " count " + hostCount.getKey() + ": " + hostCount.getValue());
return false;
}
}
return true;
}
use of org.apache.accumulo.core.client.Connector in project accumulo by apache.
the class TracerRecoversAfterOfflineTableIT method test.
@Test
public void test() throws Exception {
Process tracer = null;
Connector conn = getConnector();
if (!conn.tableOperations().exists("trace")) {
MiniAccumuloClusterImpl mac = cluster;
tracer = mac.exec(TraceServer.class);
while (!conn.tableOperations().exists("trace")) {
sleepUninterruptibly(1, TimeUnit.SECONDS);
}
sleepUninterruptibly(5, TimeUnit.SECONDS);
}
log.info("Taking table offline");
conn.tableOperations().offline("trace", true);
String tableName = getUniqueNames(1)[0];
conn.tableOperations().create(tableName);
log.info("Start a distributed trace span");
DistributedTrace.enable("localhost", "testTrace", getClientConfig());
Span root = Trace.on("traceTest");
BatchWriter bw = conn.createBatchWriter(tableName, null);
Mutation m = new Mutation("m");
m.put("a", "b", "c");
bw.addMutation(m);
bw.close();
root.stop();
log.info("Bringing trace table back online");
conn.tableOperations().online("trace", true);
log.info("Trace table is online, should be able to find trace");
try (Scanner scanner = conn.createScanner("trace", Authorizations.EMPTY)) {
scanner.setRange(new Range(new Text(Long.toHexString(root.traceId()))));
while (true) {
final StringBuilder finalBuffer = new StringBuilder();
int traceCount = TraceDump.printTrace(scanner, new Printer() {
@Override
public void print(final String line) {
try {
finalBuffer.append(line).append("\n");
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
});
String traceOutput = finalBuffer.toString();
log.info("Trace output:{}", traceOutput);
if (traceCount > 0) {
int lastPos = 0;
for (String part : "traceTest,close,binMutations".split(",")) {
log.info("Looking in trace output for '{}'", part);
int pos = traceOutput.indexOf(part);
assertTrue("Did not find '" + part + "' in output", pos > 0);
assertTrue("'" + part + "' occurred earlier than the previous element unexpectedly", pos > lastPos);
lastPos = pos;
}
break;
} else {
log.info("Ignoring trace output as traceCount not greater than zero: {}", traceCount);
Thread.sleep(1000);
}
}
if (tracer != null) {
tracer.destroy();
}
}
}
use of org.apache.accumulo.core.client.Connector in project accumulo by apache.
the class UserCompactionStrategyIT method testConcurrent.
@Test
public void testConcurrent() throws Exception {
// two compactions without iterators or strategy should be able to run concurrently
Connector c = getConnector();
String tableName = getUniqueNames(1)[0];
c.tableOperations().create(tableName);
// write random data because its very unlikely it will compress
writeRandomValue(c, tableName, 1 << 16);
writeRandomValue(c, tableName, 1 << 16);
c.tableOperations().compact(tableName, new CompactionConfig().setWait(false));
c.tableOperations().compact(tableName, new CompactionConfig().setWait(true));
Assert.assertEquals(1, FunctionalTestUtils.countRFiles(c, tableName));
writeRandomValue(c, tableName, 1 << 16);
IteratorSetting iterConfig = new IteratorSetting(30, SlowIterator.class);
SlowIterator.setSleepTime(iterConfig, 1000);
long t1 = System.currentTimeMillis();
c.tableOperations().compact(tableName, new CompactionConfig().setWait(false).setIterators(Arrays.asList(iterConfig)));
try {
// this compaction should fail because previous one set iterators
c.tableOperations().compact(tableName, new CompactionConfig().setWait(true));
if (System.currentTimeMillis() - t1 < 2000)
Assert.fail("Expected compaction to fail because another concurrent compaction set iterators");
} catch (AccumuloException e) {
}
}
use of org.apache.accumulo.core.client.Connector in project accumulo by apache.
the class UserCompactionStrategyIT method testPerTableClasspath.
@Test
public void testPerTableClasspath() throws Exception {
// Can't assume that a test-resource will be on the server's classpath
Assume.assumeTrue(ClusterType.MINI == getClusterType());
// test per-table classpath + user specified compaction strategy
final Connector c = getConnector();
final String tableName = getUniqueNames(1)[0];
File target = new File(System.getProperty("user.dir"), "target");
Assert.assertTrue(target.mkdirs() || target.isDirectory());
File destFile = installJar(target, "/TestCompactionStrat.jar");
c.tableOperations().create(tableName);
c.instanceOperations().setProperty(Property.VFS_CONTEXT_CLASSPATH_PROPERTY.getKey() + "context1", destFile.toString());
c.tableOperations().setProperty(tableName, Property.TABLE_CLASSPATH.getKey(), "context1");
c.tableOperations().addSplits(tableName, new TreeSet<>(Arrays.asList(new Text("efg"))));
writeFlush(c, tableName, "a");
writeFlush(c, tableName, "b");
writeFlush(c, tableName, "h");
writeFlush(c, tableName, "i");
Assert.assertEquals(4, FunctionalTestUtils.countRFiles(c, tableName));
// EfgCompactionStrat will only compact a tablet w/ end row of 'efg'. No other tablets are compacted.
CompactionStrategyConfig csConfig = new CompactionStrategyConfig("org.apache.accumulo.test.EfgCompactionStrat");
c.tableOperations().compact(tableName, new CompactionConfig().setWait(true).setCompactionStrategy(csConfig));
Assert.assertEquals(3, FunctionalTestUtils.countRFiles(c, tableName));
c.tableOperations().compact(tableName, new CompactionConfig().setWait(true));
Assert.assertEquals(2, FunctionalTestUtils.countRFiles(c, tableName));
}
Aggregations