use of org.apache.accumulo.core.metadata.TabletLocationState in project accumulo by apache.
the class TabletMetadata method getTabletState.
public TabletState getTabletState(Set<TServerInstance> liveTServers) {
ensureFetched(ColumnType.LOCATION);
ensureFetched(ColumnType.LAST);
ensureFetched(ColumnType.SUSPEND);
try {
TServerInstance current = null;
TServerInstance future = null;
if (hasCurrent()) {
current = location;
} else {
future = location;
}
// only care about the state so don't need walogs and chopped params
var tls = new TabletLocationState(extent, future, current, last, suspend, null, false);
return tls.getState(liveTServers);
} catch (TabletLocationState.BadLocationStateException blse) {
throw new IllegalArgumentException("Error creating TabletLocationState", blse);
}
}
use of org.apache.accumulo.core.metadata.TabletLocationState in project accumulo by apache.
the class TabletStateChangeIterator method consume.
@Override
protected void consume() throws IOException {
while (getSource().hasTop()) {
Key k = getSource().getTopKey();
Value v = getSource().getTopValue();
if (onlineTables == null || current == null || managerState != ManagerState.NORMAL)
return;
TabletLocationState tls;
try {
tls = MetaDataTableScanner.createTabletLocationState(k, v);
if (tls == null)
return;
} catch (BadLocationStateException e) {
// maybe the manager can do something with a tablet with bad/inconsistent state
return;
}
// we always want data about merges
MergeInfo merge = merges.get(tls.extent.tableId());
if (merge != null) {
// could make this smarter by only returning if the tablet is involved in the merge
return;
}
// always return the information for migrating tablets
if (migrations.contains(tls.extent)) {
return;
}
// is the table supposed to be online or offline?
boolean shouldBeOnline = onlineTables.contains(tls.extent.tableId());
if (debug) {
log.debug("{} is {} and should be {} line", tls.extent, tls.getState(current), (shouldBeOnline ? "on" : "off"));
}
switch(tls.getState(current)) {
case ASSIGNED:
// we always want data about assigned tablets
return;
case HOSTED:
if (!shouldBeOnline)
return;
break;
case ASSIGNED_TO_DEAD_SERVER:
return;
case SUSPENDED:
case UNASSIGNED:
if (shouldBeOnline)
return;
break;
default:
throw new AssertionError("Inconceivable! The tablet is an unrecognized state: " + tls.getState(current));
}
// table is in the expected state so don't bother returning any information about it
getSource().next();
}
}
use of org.apache.accumulo.core.metadata.TabletLocationState in project accumulo by apache.
the class ZooTabletStateStore method unassign.
@Override
public void unassign(Collection<TabletLocationState> tablets, Map<TServerInstance, List<Path>> logsForDeadServers) throws DistributedStoreException {
if (tablets.size() != 1)
throw new IllegalArgumentException("There is only one root tablet");
TabletLocationState tls = tablets.iterator().next();
if (tls.extent.compareTo(RootTable.EXTENT) != 0)
throw new IllegalArgumentException("You can only store the root tablet location");
TabletMutator tabletMutator = ample.mutateTablet(tls.extent);
tabletMutator.deleteLocation(tls.futureOrCurrent(), LocationType.FUTURE);
tabletMutator.deleteLocation(tls.futureOrCurrent(), LocationType.CURRENT);
if (logsForDeadServers != null) {
List<Path> logs = logsForDeadServers.get(tls.futureOrCurrent());
if (logs != null) {
for (Path entry : logs) {
LogEntry logEntry = new LogEntry(RootTable.EXTENT, System.currentTimeMillis(), entry.toString());
tabletMutator.putWal(logEntry);
}
}
}
tabletMutator.mutate();
log.debug("unassign root tablet location");
}
use of org.apache.accumulo.core.metadata.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, Map<UUID, Path> recoveryLogs) {
Map<UUID, TServerInstance> result = new HashMap<>();
for (Entry<TServerInstance, Set<UUID>> entry : candidates.entrySet()) {
for (UUID id : entry.getValue()) {
if (result.put(id, entry.getKey()) != null) {
throw new IllegalArgumentException("WAL " + id + " owned by multiple tservers");
}
}
}
// remove any entries if there's a log reference (recovery hasn't finished)
for (TabletLocationState state : store) {
// 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) {
result.keySet().removeAll(idsToIgnore);
recoveryLogs.keySet().removeAll(idsToIgnore);
}
}
// 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) {
result.keySet().removeAll(idsToIgnore);
recoveryLogs.keySet().removeAll(idsToIgnore);
}
}
}
}
// 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);
}
}
recoveryLogs.keySet().removeAll(idsForServer);
}
}
return result;
}
use of org.apache.accumulo.core.metadata.TabletLocationState in project accumulo by apache.
the class FindOfflineTablets method checkTablets.
private static int checkTablets(ServerContext context, 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 && context.getTableManager().getTableState(locationState.extent.tableId()) != TableState.OFFLINE) {
System.out.println(locationState + " is " + state + " #walogs:" + locationState.walogs.size());
offline++;
}
}
return offline;
}
Aggregations