use of org.apache.accumulo.server.master.state.TabletLocationState in project accumulo by apache.
the class CleanUp method isReady.
@Override
public long isReady(long tid, Master master) throws Exception {
if (!master.hasCycled(creationTime)) {
return 50;
}
boolean done = true;
Range tableRange = new KeyExtent(tableId, null, null).toMetadataRange();
Scanner scanner = master.getConnector().createScanner(MetadataTable.NAME, Authorizations.EMPTY);
MetaDataTableScanner.configureScanner(scanner, master);
scanner.setRange(tableRange);
for (Entry<Key, Value> entry : scanner) {
TabletLocationState locationState = MetaDataTableScanner.createTabletLocationState(entry.getKey(), entry.getValue());
TabletState state = locationState.getState(master.onlineTabletServers());
if (state.equals(TabletState.ASSIGNED) || state.equals(TabletState.HOSTED)) {
log.debug("Still waiting for table to be deleted: " + tableId + " locationState: " + locationState);
done = false;
break;
}
}
if (!done)
return 50;
return 0;
}
use of org.apache.accumulo.server.master.state.TabletLocationState in project accumulo by apache.
the class FindOfflineTablets method findOffline.
static int findOffline(ClientContext context, String tableName) throws AccumuloException, TableNotFoundException {
final AtomicBoolean scanning = new AtomicBoolean(false);
LiveTServerSet tservers = new LiveTServerSet(context, new Listener() {
@Override
public void update(LiveTServerSet current, Set<TServerInstance> deleted, Set<TServerInstance> added) {
if (!deleted.isEmpty() && scanning.get())
log.warn("Tablet servers deleted while scanning: {}", deleted);
if (!added.isEmpty() && scanning.get())
log.warn("Tablet servers added while scanning: {}", added);
}
});
tservers.startListeningForTabletServerChanges();
scanning.set(true);
Iterator<TabletLocationState> zooScanner;
try {
zooScanner = new ZooTabletStateStore().iterator();
} catch (DistributedStoreException e) {
throw new AccumuloException(e);
}
int offline = 0;
System.out.println("Scanning zookeeper");
if ((offline = checkTablets(zooScanner, tservers)) > 0)
return offline;
if (RootTable.NAME.equals(tableName))
return 0;
System.out.println("Scanning " + RootTable.NAME);
Iterator<TabletLocationState> rootScanner = new MetaDataTableScanner(context, MetadataSchema.TabletsSection.getRange(), RootTable.NAME);
if ((offline = checkTablets(rootScanner, tservers)) > 0)
return offline;
if (MetadataTable.NAME.equals(tableName))
return 0;
System.out.println("Scanning " + MetadataTable.NAME);
Range range = MetadataSchema.TabletsSection.getRange();
if (tableName != null) {
Table.ID tableId = Tables.getTableId(context.getInstance(), tableName);
range = new KeyExtent(tableId, null, null).toMetadataRange();
}
try (MetaDataTableScanner metaScanner = new MetaDataTableScanner(context, range, MetadataTable.NAME)) {
return checkTablets(metaScanner, tservers);
}
}
use of org.apache.accumulo.server.master.state.TabletLocationState in project accumulo by apache.
the class MasterRepairsDualAssignmentIT method test.
@Test
public void test() throws Exception {
// make some tablets, spread 'em around
Connector c = getConnector();
ClientContext context = new ClientContext(c.getInstance(), new Credentials("root", new PasswordToken(ROOT_PASSWORD)), getClientConfig());
String table = this.getUniqueNames(1)[0];
c.securityOperations().grantTablePermission("root", MetadataTable.NAME, TablePermission.WRITE);
c.securityOperations().grantTablePermission("root", RootTable.NAME, TablePermission.WRITE);
c.tableOperations().create(table);
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));
}
c.tableOperations().addSplits(table, partitions);
// scan the metadata table and get the two table location states
Set<TServerInstance> states = new HashSet<>();
Set<TabletLocationState> oldLocations = new HashSet<>();
MetaDataStateStore store = new MetaDataStateStore(context, null);
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<>();
// 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(ReplicationTable.ID, 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
BatchWriter bw = c.createBatchWriter(MetadataTable.NAME, new BatchWriterConfig());
Mutation assignment = new Mutation(moved.extent.getMetadataEntry());
moved.current.putLocation(assignment);
bw.addMutation(assignment);
bw.close();
// wait for the master to fix the problem
waitForCleanStore(store);
// now jam up the metadata table
bw = c.createBatchWriter(MetadataTable.NAME, new BatchWriterConfig());
assignment = new Mutation(new KeyExtent(MetadataTable.ID, null, null).getMetadataEntry());
moved.current.putLocation(assignment);
bw.addMutation(assignment);
bw.close();
waitForCleanStore(new RootTabletStateStore(context, null));
}
use of org.apache.accumulo.server.master.state.TabletLocationState in project accumulo by apache.
the class GarbageCollectWriteAheadLogs method removeEntriesInUse.
private Map<UUID, TServerInstance> removeEntriesInUse(Map<TServerInstance, Set<UUID>> candidates, Set<TServerInstance> liveServers, Map<UUID, Pair<WalState, Path>> logsState) throws IOException, KeeperException, InterruptedException {
Map<UUID, TServerInstance> result = new HashMap<>();
for (Entry<TServerInstance, Set<UUID>> entry : candidates.entrySet()) {
for (UUID id : entry.getValue()) {
result.put(id, entry.getKey());
}
}
// remove any entries if there's a log reference (recovery hasn't finished)
Iterator<TabletLocationState> states = store.iterator();
while (states.hasNext()) {
TabletLocationState state = states.next();
// Easiest to just ignore all the WALs for the dead server.
if (state.getState(liveServers) == TabletState.ASSIGNED_TO_DEAD_SERVER) {
Set<UUID> idsToIgnore = candidates.remove(state.current);
if (idsToIgnore != null) {
for (UUID id : idsToIgnore) {
result.remove(id);
}
}
}
// that made the WALs.
for (Collection<String> wals : state.walogs) {
for (String wal : wals) {
UUID walUUID = path2uuid(new Path(wal));
TServerInstance dead = result.get(walUUID);
// There's a reference to a log file, so skip that server's logs
Set<UUID> idsToIgnore = candidates.remove(dead);
if (idsToIgnore != null) {
for (UUID id : idsToIgnore) {
result.remove(id);
}
}
}
}
}
// Remove OPEN and CLOSED logs for live servers: they are still in use
for (TServerInstance liveServer : liveServers) {
Set<UUID> idsForServer = candidates.get(liveServer);
// Server may not have any logs yet
if (idsForServer != null) {
for (UUID id : idsForServer) {
Pair<WalState, Path> stateFile = logsState.get(id);
if (stateFile.getFirst() != WalState.UNREFERENCED) {
result.remove(id);
}
}
}
}
return result;
}
use of org.apache.accumulo.server.master.state.TabletLocationState in project accumulo by apache.
the class FindOfflineTablets method checkTablets.
private static int checkTablets(Iterator<TabletLocationState> scanner, LiveTServerSet tservers) {
int offline = 0;
while (scanner.hasNext() && !System.out.checkError()) {
TabletLocationState locationState = scanner.next();
TabletState state = locationState.getState(tservers.getCurrentServers());
if (state != null && state != TabletState.HOSTED && TableManager.getInstance().getTableState(locationState.extent.getTableId()) != TableState.OFFLINE) {
System.out.println(locationState + " is " + state + " #walogs:" + locationState.walogs.size());
offline++;
}
}
return offline;
}
Aggregations