use of org.apache.accumulo.core.client.impl.ClientContext in project accumulo by apache.
the class DetectDeadTabletServersIT method getStats.
private MasterMonitorInfo getStats(Connector c) throws Exception {
Credentials creds = new Credentials("root", new PasswordToken(ROOT_PASSWORD));
ClientContext context = new ClientContext(c.getInstance(), creds, getClientConfig());
Client client = null;
while (true) {
try {
client = MasterClient.getConnectionWithRetry(context);
log.info("Fetching master stats");
return client.getMasterStats(Tracer.traceInfo(), context.rpcCreds());
} catch (ThriftNotActiveServiceException e) {
// Let it loop, fetching a new location
sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
} finally {
if (client != null) {
MasterClient.close(client);
}
}
}
}
use of org.apache.accumulo.core.client.impl.ClientContext in project accumulo by apache.
the class MetadataMaxFilesIT method test.
@Test
public void test() throws Exception {
Connector c = getConnector();
SortedSet<Text> splits = new TreeSet<>();
for (int i = 0; i < 1000; i++) {
splits.add(new Text(String.format("%03d", i)));
}
c.tableOperations().setProperty(MetadataTable.NAME, Property.TABLE_SPLIT_THRESHOLD.getKey(), "10000");
// propagation time
sleepUninterruptibly(5, TimeUnit.SECONDS);
for (int i = 0; i < 5; i++) {
String tableName = "table" + i;
log.info("Creating {}", tableName);
c.tableOperations().create(tableName);
log.info("adding splits");
c.tableOperations().addSplits(tableName, splits);
log.info("flushing");
c.tableOperations().flush(MetadataTable.NAME, null, null, true);
c.tableOperations().flush(RootTable.NAME, null, null, true);
}
log.info("shutting down");
assertEquals(0, cluster.exec(Admin.class, "stopAll").waitFor());
cluster.stop();
log.info("starting up");
cluster.start();
Credentials creds = new Credentials("root", new PasswordToken(ROOT_PASSWORD));
while (true) {
MasterMonitorInfo stats = null;
Client client = null;
try {
ClientContext context = new ClientContext(c.getInstance(), creds, getClientConfig());
client = MasterClient.getConnectionWithRetry(context);
log.info("Fetching stats");
stats = client.getMasterStats(Tracer.traceInfo(), context.rpcCreds());
} catch (ThriftNotActiveServiceException e) {
// Let it loop, fetching a new location
sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
continue;
} finally {
if (client != null)
MasterClient.close(client);
}
int tablets = 0;
for (TabletServerStatus tserver : stats.tServerInfo) {
for (Entry<String, TableInfo> entry : tserver.tableMap.entrySet()) {
if (entry.getKey().startsWith("!") || entry.getKey().startsWith("+"))
continue;
tablets += entry.getValue().onlineTablets;
}
}
log.info("Online tablets " + tablets);
if (tablets == 5005)
break;
sleepUninterruptibly(1, TimeUnit.SECONDS);
}
}
use of org.apache.accumulo.core.client.impl.ClientContext in project accumulo by apache.
the class SuspendedTabletsIT method suspensionTestBody.
/**
* Main test body for suspension tests.
*
* @param serverStopper
* callback which shuts down some tablet servers.
*/
private void suspensionTestBody(TServerKiller serverStopper) throws Exception {
Credentials creds = new Credentials("root", new PasswordToken(ROOT_PASSWORD));
Instance instance = new ZooKeeperInstance(getCluster().getClientConfig());
ClientContext ctx = new ClientContext(instance, creds, getCluster().getClientConfig());
String tableName = getUniqueNames(1)[0];
Connector conn = ctx.getConnector();
// Create a table with a bunch of splits
log.info("Creating table " + tableName);
conn.tableOperations().create(tableName);
SortedSet<Text> splitPoints = new TreeSet<>();
for (int i = 1; i < TABLETS; ++i) {
splitPoints.add(new Text("" + i));
}
conn.tableOperations().addSplits(tableName, splitPoints);
// Wait for all of the tablets to hosted ...
log.info("Waiting on hosting and balance");
TabletLocations ds;
for (ds = TabletLocations.retrieve(ctx, tableName); ds.hostedCount != TABLETS; ds = TabletLocations.retrieve(ctx, tableName)) {
Thread.sleep(1000);
}
// ... and balanced.
conn.instanceOperations().waitForBalance();
do {
// Give at least another 5 seconds for migrations to finish up
Thread.sleep(5000);
ds = TabletLocations.retrieve(ctx, tableName);
} while (ds.hostedCount != TABLETS);
// Pray all of our tservers have at least 1 tablet.
Assert.assertEquals(TSERVERS, ds.hosted.keySet().size());
// Kill two tablet servers hosting our tablets. This should put tablets into suspended state, and thus halt balancing.
TabletLocations beforeDeathState = ds;
log.info("Eliminating tablet servers");
serverStopper.eliminateTabletServers(ctx, beforeDeathState, 2);
// Eventually some tablets will be suspended.
log.info("Waiting on suspended tablets");
ds = TabletLocations.retrieve(ctx, tableName);
// Until we can scan the metadata table, the master probably can't either, so won't have been able to suspend the tablets.
// So we note the time that we were first able to successfully scan the metadata table.
long killTime = System.nanoTime();
while (ds.suspended.keySet().size() != 2) {
Thread.sleep(1000);
ds = TabletLocations.retrieve(ctx, tableName);
}
SetMultimap<HostAndPort, KeyExtent> deadTabletsByServer = ds.suspended;
// "belong" to the dead tablet servers, and should be in exactly the same place as before any tserver death.
for (HostAndPort server : deadTabletsByServer.keySet()) {
Assert.assertEquals(deadTabletsByServer.get(server), beforeDeathState.hosted.get(server));
}
Assert.assertEquals(TABLETS, ds.hostedCount + ds.suspendedCount);
// Restart the first tablet server, making sure it ends up on the same port
HostAndPort restartedServer = deadTabletsByServer.keySet().iterator().next();
log.info("Restarting " + restartedServer);
getCluster().getClusterControl().start(ServerType.TABLET_SERVER, null, ImmutableMap.of(Property.TSERV_CLIENTPORT.getKey(), "" + restartedServer.getPort(), Property.TSERV_PORTSEARCH.getKey(), "false"), 1);
// Eventually, the suspended tablets should be reassigned to the newly alive tserver.
log.info("Awaiting tablet unsuspension for tablets belonging to " + restartedServer);
for (ds = TabletLocations.retrieve(ctx, tableName); ds.suspended.containsKey(restartedServer) || ds.assignedCount != 0; ds = TabletLocations.retrieve(ctx, tableName)) {
Thread.sleep(1000);
}
Assert.assertEquals(deadTabletsByServer.get(restartedServer), ds.hosted.get(restartedServer));
// Finally, after much longer, remaining suspended tablets should be reassigned.
log.info("Awaiting tablet reassignment for remaining tablets");
for (ds = TabletLocations.retrieve(ctx, tableName); ds.hostedCount != TABLETS; ds = TabletLocations.retrieve(ctx, tableName)) {
Thread.sleep(1000);
}
long recoverTime = System.nanoTime();
Assert.assertTrue(recoverTime - killTime >= NANOSECONDS.convert(SUSPEND_DURATION, MILLISECONDS));
}
use of org.apache.accumulo.core.client.impl.ClientContext in project accumulo by apache.
the class MasterAssignmentIT method getTabletLocationState.
private TabletLocationState getTabletLocationState(Connector c, String tableId) throws FileNotFoundException, ConfigurationException {
Credentials creds = new Credentials(getAdminPrincipal(), getAdminToken());
ClientContext context = new ClientContext(c.getInstance(), creds, getCluster().getClientConfig());
try (MetaDataTableScanner s = new MetaDataTableScanner(context, new Range(KeyExtent.getMetadataEntry(Table.ID.of(tableId), null)))) {
TabletLocationState tlState = s.next();
return tlState;
}
}
use of org.apache.accumulo.core.client.impl.ClientContext in project accumulo by apache.
the class SimpleBalancerFairnessIT method simpleBalancerFairness.
@Test
public void simpleBalancerFairness() throws Exception {
Connector c = getConnector();
c.tableOperations().create("test_ingest");
c.tableOperations().setProperty("test_ingest", Property.TABLE_SPLIT_THRESHOLD.getKey(), "10K");
c.tableOperations().create("unused");
TreeSet<Text> splits = TestIngest.getSplitPoints(0, 10000000, 500);
log.info("Creating {} splits", splits.size());
c.tableOperations().addSplits("unused", splits);
List<String> tservers = c.instanceOperations().getTabletServers();
TestIngest.Opts opts = new TestIngest.Opts();
opts.rows = 50000;
opts.setPrincipal("root");
TestIngest.ingest(c, opts, new BatchWriterOpts());
c.tableOperations().flush("test_ingest", null, null, false);
sleepUninterruptibly(45, TimeUnit.SECONDS);
Credentials creds = new Credentials("root", new PasswordToken(ROOT_PASSWORD));
ClientContext context = new ClientContext(c.getInstance(), creds, getClientConfig());
MasterMonitorInfo stats = null;
int unassignedTablets = 1;
for (int i = 0; unassignedTablets > 0 && i < 10; i++) {
MasterClientService.Iface client = null;
while (true) {
try {
client = MasterClient.getConnectionWithRetry(context);
stats = client.getMasterStats(Tracer.traceInfo(), creds.toThrift(c.getInstance()));
break;
} catch (ThriftNotActiveServiceException e) {
// Let it loop, fetching a new location
sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
} finally {
if (client != null)
MasterClient.close(client);
}
}
unassignedTablets = stats.getUnassignedTablets();
if (unassignedTablets > 0) {
log.info("Found {} unassigned tablets, sleeping 3 seconds for tablet assignment", unassignedTablets);
Thread.sleep(3000);
}
}
assertEquals("Unassigned tablets were not assigned within 30 seconds", 0, unassignedTablets);
// Compute online tablets per tserver
List<Integer> counts = new ArrayList<>();
for (TabletServerStatus server : stats.tServerInfo) {
int count = 0;
for (TableInfo table : server.tableMap.values()) {
count += table.onlineTablets;
}
counts.add(count);
}
assertTrue("Expected to have at least two TabletServers", counts.size() > 1);
for (int i = 1; i < counts.size(); i++) {
int diff = Math.abs(counts.get(0) - counts.get(i));
assertTrue("Expected difference in tablets to be less than or equal to " + counts.size() + " but was " + diff + ". Counts " + counts, diff <= tservers.size());
}
}
Aggregations