use of org.apache.accumulo.core.metadata.TServerInstance in project accumulo by apache.
the class TabletMetadataIT method getLiveTServersTest.
@Test
public void getLiveTServersTest() throws Exception {
try (AccumuloClient c = Accumulo.newClient().from(getClientProperties()).build()) {
while (c.instanceOperations().getTabletServers().size() != NUM_TSERVERS) {
log.info("Waiting for tservers to start up...");
sleepUninterruptibly(5, TimeUnit.SECONDS);
}
Set<TServerInstance> servers = TabletMetadata.getLiveTServers((ClientContext) c);
assertEquals(NUM_TSERVERS, servers.size());
// kill a tserver and see if its gone from the list
getCluster().killProcess(TABLET_SERVER, getCluster().getProcesses().get(TABLET_SERVER).iterator().next());
while (c.instanceOperations().getTabletServers().size() == NUM_TSERVERS) {
log.info("Waiting for a tserver to die...");
sleepUninterruptibly(5, TimeUnit.SECONDS);
}
servers = TabletMetadata.getLiveTServers((ClientContext) c);
assertEquals(NUM_TSERVERS - 1, servers.size());
}
}
use of org.apache.accumulo.core.metadata.TServerInstance in project accumulo by apache.
the class ReplicationIT method getLogs.
private Multimap<String, TableId> getLogs(AccumuloClient client, ServerContext context) throws Exception {
// Map of server to tableId
Multimap<TServerInstance, TableId> serverToTableID = HashMultimap.create();
try (Scanner scanner = client.createScanner(MetadataTable.NAME, Authorizations.EMPTY)) {
scanner.setRange(TabletsSection.getRange());
scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
for (Entry<Key, Value> entry : scanner) {
var tServer = new TServerInstance(entry.getValue(), entry.getKey().getColumnQualifier());
TableId tableId = KeyExtent.fromMetaRow(entry.getKey().getRow()).tableId();
serverToTableID.put(tServer, tableId);
}
// Map of logs to tableId
Multimap<String, TableId> logs = HashMultimap.create();
WalStateManager wals = new WalStateManager(context);
for (Entry<TServerInstance, List<UUID>> entry : wals.getAllMarkers().entrySet()) {
for (UUID id : entry.getValue()) {
Pair<WalState, Path> state = wals.state(entry.getKey(), id);
for (TableId tableId : serverToTableID.get(entry.getKey())) {
logs.put(state.getSecond().toString(), tableId);
}
}
}
return logs;
}
}
use of org.apache.accumulo.core.metadata.TServerInstance in project accumulo by apache.
the class SuspendedTabletsIT method shutdownAndResumeTserver.
@Test
public void shutdownAndResumeTserver() throws Exception {
// Run the test body. When we get to the point where we need tservers to go away, stop them via
// a clean shutdown.
suspensionTestBody((ctx, locs, count) -> {
Set<TServerInstance> tserverSet = new HashSet<>();
Set<TServerInstance> metadataServerSet = new HashSet<>();
TabletLocator tl = TabletLocator.getLocator(ctx, MetadataTable.ID);
for (TabletLocationState tls : locs.locationStates.values()) {
if (tls.current != null) {
// add to set of all servers
tserverSet.add(tls.current);
// get server that the current tablets metadata is on
TabletLocator.TabletLocation tab = tl.locateTablet(ctx, tls.extent.toMetaRow(), false, false);
// add it to the set of servers with metadata
metadataServerSet.add(new TServerInstance(tab.tablet_location, Long.valueOf(tab.tablet_session, 16)));
}
}
// remove servers with metadata on them from the list of servers to be shutdown
assertEquals("Expecting a single tServer in metadataServerSet", 1, metadataServerSet.size());
tserverSet.removeAll(metadataServerSet);
assertEquals("Expecting " + (TSERVERS - 1) + " tServers in shutdown-list", TSERVERS - 1, tserverSet.size());
List<TServerInstance> tserversList = new ArrayList<>(tserverSet);
Collections.shuffle(tserversList, random);
for (int i1 = 0; i1 < count; ++i1) {
final String tserverName = tserversList.get(i1).getHostPortSession();
ManagerClient.executeVoid(ctx, client -> {
log.info("Sending shutdown command to {} via ManagerClientService", tserverName);
client.shutdownTabletServer(null, ctx.rpcCreds(), tserverName, false);
});
}
log.info("Waiting for tserver process{} to die", count == 1 ? "" : "es");
for (int i2 = 0; i2 < 10; ++i2) {
List<ProcessReference> deadProcs = new ArrayList<>();
for (ProcessReference pr1 : getCluster().getProcesses().get(ServerType.TABLET_SERVER)) {
Process p = pr1.getProcess();
if (!p.isAlive()) {
deadProcs.add(pr1);
}
}
for (ProcessReference pr2 : deadProcs) {
log.info("Process {} is dead, informing cluster control about this", pr2.getProcess());
getCluster().getClusterControl().killProcess(ServerType.TABLET_SERVER, pr2);
--count;
}
if (count == 0) {
return;
} else {
Thread.sleep(SECONDS.toMillis(2));
}
}
throw new IllegalStateException("Tablet servers didn't die!");
});
}
use of org.apache.accumulo.core.metadata.TServerInstance in project accumulo by apache.
the class NullTserver method main.
public static void main(String[] args) throws Exception {
Opts opts = new Opts();
opts.parseArgs(NullTserver.class.getName(), args);
// modify metadata
int zkTimeOut = (int) DefaultConfiguration.getInstance().getTimeInMillis(Property.INSTANCE_ZK_TIMEOUT);
var siteConfig = SiteConfiguration.auto();
ServerContext context = ServerContext.override(siteConfig, opts.iname, opts.keepers, zkTimeOut);
TransactionWatcher watcher = new TransactionWatcher(context);
ThriftClientHandler tch = new ThriftClientHandler(context, watcher);
Processor<Iface> processor = new Processor<>(tch);
TServerUtils.startTServer(context.getConfiguration(), ThriftServerType.CUSTOM_HS_HA, processor, "NullTServer", "null tserver", 2, ThreadPools.DEFAULT_TIMEOUT_MILLISECS, 1000, 10 * 1024 * 1024, null, null, -1, HostAndPort.fromParts("0.0.0.0", opts.port));
HostAndPort addr = HostAndPort.fromParts(InetAddress.getLocalHost().getHostName(), opts.port);
TableId tableId = context.getTableId(opts.tableName);
// read the locations for the table
Range tableRange = new KeyExtent(tableId, null, null).toMetaRange();
List<Assignment> assignments = new ArrayList<>();
try (var s = new MetaDataTableScanner(context, tableRange, MetadataTable.NAME)) {
long randomSessionID = opts.port;
TServerInstance instance = new TServerInstance(addr, randomSessionID);
while (s.hasNext()) {
TabletLocationState next = s.next();
assignments.add(new Assignment(next.extent, instance));
}
}
// point them to this server
TabletStateStore store = TabletStateStore.getStoreForLevel(DataLevel.USER, context);
store.setLocations(assignments);
while (true) {
sleepUninterruptibly(10, TimeUnit.SECONDS);
}
}
use of org.apache.accumulo.core.metadata.TServerInstance in project accumulo by apache.
the class ManagerRepairsDualAssignmentIT method test.
@Test
public void test() throws Exception {
// make some tablets, spread 'em around
try (AccumuloClient c = Accumulo.newClient().from(getClientProperties()).build()) {
ClientContext context = (ClientContext) c;
ServerContext serverContext = cluster.getServerContext();
String table = this.getUniqueNames(1)[0];
c.securityOperations().grantTablePermission("root", MetadataTable.NAME, TablePermission.WRITE);
c.securityOperations().grantTablePermission("root", RootTable.NAME, TablePermission.WRITE);
SortedSet<Text> partitions = new TreeSet<>();
for (String part : "a b c d e f g h i j k l m n o p q r s t u v w x y z".split(" ")) {
partitions.add(new Text(part));
}
NewTableConfiguration ntc = new NewTableConfiguration().withSplits(partitions);
c.tableOperations().create(table, ntc);
// scan the metadata table and get the two table location states
Set<TServerInstance> states = new HashSet<>();
Set<TabletLocationState> oldLocations = new HashSet<>();
TabletStateStore store = TabletStateStore.getStoreForLevel(DataLevel.USER, context);
while (states.size() < 2) {
UtilWaitThread.sleep(250);
oldLocations.clear();
for (TabletLocationState tls : store) {
if (tls.current != null) {
states.add(tls.current);
oldLocations.add(tls);
}
}
}
assertEquals(2, states.size());
// Kill a tablet server... we don't care which one... wait for everything to be reassigned
cluster.killProcess(ServerType.TABLET_SERVER, cluster.getProcesses().get(ServerType.TABLET_SERVER).iterator().next());
Set<TServerInstance> replStates = new HashSet<>();
@SuppressWarnings("deprecation") TableId repTable = org.apache.accumulo.core.replication.ReplicationTable.ID;
// Find out which tablet server remains
while (true) {
UtilWaitThread.sleep(1000);
states.clear();
replStates.clear();
boolean allAssigned = true;
for (TabletLocationState tls : store) {
if (tls != null && tls.current != null) {
states.add(tls.current);
} else if (tls != null && tls.extent.equals(new KeyExtent(repTable, null, null))) {
replStates.add(tls.current);
} else {
allAssigned = false;
}
}
System.out.println(states + " size " + states.size() + " allAssigned " + allAssigned);
if (states.size() != 2 && allAssigned)
break;
}
assertEquals(1, replStates.size());
assertEquals(1, states.size());
// pick an assigned tablet and assign it to the old tablet
TabletLocationState moved = null;
for (TabletLocationState old : oldLocations) {
if (!states.contains(old.current)) {
moved = old;
}
}
assertNotEquals(null, moved);
// throw a mutation in as if we were the dying tablet
TabletMutator tabletMutator = serverContext.getAmple().mutateTablet(moved.extent);
tabletMutator.putLocation(moved.current, LocationType.CURRENT);
tabletMutator.mutate();
// wait for the manager to fix the problem
waitForCleanStore(store);
// now jam up the metadata table
tabletMutator = serverContext.getAmple().mutateTablet(new KeyExtent(MetadataTable.ID, null, null));
tabletMutator.putLocation(moved.current, LocationType.CURRENT);
tabletMutator.mutate();
waitForCleanStore(TabletStateStore.getStoreForLevel(DataLevel.METADATA, context));
}
}
Aggregations