use of org.apache.accumulo.core.metadata.TabletState 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;
}
use of org.apache.accumulo.core.metadata.TabletState in project accumulo by apache.
the class CleanUp method isReady.
@Override
public long isReady(long tid, Manager manager) throws Exception {
if (!manager.hasCycled(creationTime)) {
return 50;
}
boolean done = true;
Range tableRange = new KeyExtent(tableId, null, null).toMetaRange();
Scanner scanner = manager.getContext().createScanner(MetadataTable.NAME, Authorizations.EMPTY);
MetaDataTableScanner.configureScanner(scanner, manager);
scanner.setRange(tableRange);
for (Entry<Key, Value> entry : scanner) {
TabletLocationState locationState = MetaDataTableScanner.createTabletLocationState(entry.getKey(), entry.getValue());
TabletState state = locationState.getState(manager.onlineTabletServers());
if (!state.equals(TabletState.UNASSIGNED)) {
// This code will even wait on tablets that are assigned to dead tablets servers. This is
// intentional because the manager may make metadata writes for these tablets. See #587
log.debug("Still waiting for table({}) to be deleted; Target tablet state: UNASSIGNED, " + "Current tablet state: {}, locationState: {}", tableId, state, locationState);
done = false;
break;
}
}
if (!done)
return 50;
return 0;
}
use of org.apache.accumulo.core.metadata.TabletState in project accumulo by apache.
the class TabletMetadataTest method testLocationStates.
@Test
public void testLocationStates() {
KeyExtent extent = new KeyExtent(TableId.of("5"), new Text("df"), new Text("da"));
TServerInstance ser1 = new TServerInstance(HostAndPort.fromParts("server1", 8555), "s001");
TServerInstance ser2 = new TServerInstance(HostAndPort.fromParts("server2", 8111), "s002");
TServerInstance deadSer = new TServerInstance(HostAndPort.fromParts("server3", 8000), "s003");
Set<TServerInstance> tservers = new LinkedHashSet<>();
tservers.add(ser1);
tservers.add(ser2);
EnumSet<ColumnType> colsToFetch = EnumSet.of(LOCATION, LAST, SUSPEND);
// test assigned
Mutation mutation = TabletColumnFamily.createPrevRowMutation(extent);
mutation.at().family(FutureLocationColumnFamily.NAME).qualifier(ser1.getSession()).put(ser1.getHostPort());
SortedMap<Key, Value> rowMap = toRowMap(mutation);
TabletMetadata tm = TabletMetadata.convertRow(rowMap.entrySet().iterator(), colsToFetch, false);
TabletState state = tm.getTabletState(tservers);
assertEquals(TabletState.ASSIGNED, state);
assertEquals(ser1, tm.getLocation());
assertEquals(ser1.getSession(), tm.getLocation().getSession());
assertEquals(LocationType.FUTURE, tm.getLocation().getType());
assertFalse(tm.hasCurrent());
// test hosted
mutation = TabletColumnFamily.createPrevRowMutation(extent);
mutation.at().family(CurrentLocationColumnFamily.NAME).qualifier(ser2.getSession()).put(ser2.getHostPort());
rowMap = toRowMap(mutation);
tm = TabletMetadata.convertRow(rowMap.entrySet().iterator(), colsToFetch, false);
assertEquals(TabletState.HOSTED, tm.getTabletState(tservers));
assertEquals(ser2, tm.getLocation());
assertEquals(ser2.getSession(), tm.getLocation().getSession());
assertEquals(LocationType.CURRENT, tm.getLocation().getType());
assertTrue(tm.hasCurrent());
// test ASSIGNED_TO_DEAD_SERVER
mutation = TabletColumnFamily.createPrevRowMutation(extent);
mutation.at().family(CurrentLocationColumnFamily.NAME).qualifier(deadSer.getSession()).put(deadSer.getHostPort());
rowMap = toRowMap(mutation);
tm = TabletMetadata.convertRow(rowMap.entrySet().iterator(), colsToFetch, false);
assertEquals(TabletState.ASSIGNED_TO_DEAD_SERVER, tm.getTabletState(tservers));
assertEquals(deadSer, tm.getLocation());
assertEquals(deadSer.getSession(), tm.getLocation().getSession());
assertEquals(LocationType.CURRENT, tm.getLocation().getType());
assertTrue(tm.hasCurrent());
// test UNASSIGNED
mutation = TabletColumnFamily.createPrevRowMutation(extent);
rowMap = toRowMap(mutation);
tm = TabletMetadata.convertRow(rowMap.entrySet().iterator(), colsToFetch, false);
assertEquals(TabletState.UNASSIGNED, tm.getTabletState(tservers));
assertNull(tm.getLocation());
assertFalse(tm.hasCurrent());
// test SUSPENDED
mutation = TabletColumnFamily.createPrevRowMutation(extent);
mutation.at().family(SuspendLocationColumn.SUSPEND_COLUMN.getColumnFamily()).qualifier(SuspendLocationColumn.SUSPEND_COLUMN.getColumnQualifier()).put(SuspendingTServer.toValue(ser2, 1000L));
rowMap = toRowMap(mutation);
tm = TabletMetadata.convertRow(rowMap.entrySet().iterator(), colsToFetch, false);
assertEquals(TabletState.SUSPENDED, tm.getTabletState(tservers));
assertEquals(1000L, tm.getSuspend().suspensionTime);
assertEquals(ser2.getHostAndPort(), tm.getSuspend().server);
assertNull(tm.getLocation());
assertFalse(tm.hasCurrent());
}
use of org.apache.accumulo.core.metadata.TabletState in project accumulo by apache.
the class TabletGroupWatcher method run.
@Override
public void run() {
int[] oldCounts = new int[TabletState.values().length];
EventCoordinator.Listener eventListener = this.manager.nextEvent.getListener();
WalStateManager wals = new WalStateManager(manager.getContext());
while (manager.stillManager()) {
// slow things down a little, otherwise we spam the logs when there are many wake-up events
sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
int totalUnloaded = 0;
int unloaded = 0;
ClosableIterator<TabletLocationState> iter = null;
try {
Map<TableId, MergeStats> mergeStatsCache = new HashMap<>();
Map<TableId, MergeStats> currentMerges = new HashMap<>();
for (MergeInfo merge : manager.merges()) {
if (merge.getExtent() != null) {
currentMerges.put(merge.getExtent().tableId(), new MergeStats(merge));
}
}
// Get the current status for the current list of tservers
SortedMap<TServerInstance, TabletServerStatus> currentTServers = new TreeMap<>();
for (TServerInstance entry : manager.tserverSet.getCurrentServers()) {
currentTServers.put(entry, manager.tserverStatus.get(entry));
}
if (currentTServers.isEmpty()) {
eventListener.waitForEvents(Manager.TIME_TO_WAIT_BETWEEN_SCANS);
synchronized (this) {
lastScanServers = Collections.emptySortedSet();
}
continue;
}
TabletLists tLists = new TabletLists(manager, currentTServers);
ManagerState managerState = manager.getManagerState();
int[] counts = new int[TabletState.values().length];
stats.begin();
// Walk through the tablets in our store, and work tablets
// towards their goal
iter = store.iterator();
while (iter.hasNext()) {
TabletLocationState tls = iter.next();
if (tls == null) {
continue;
}
// ignore entries for tables that do not exist in zookeeper
if (manager.getTableManager().getTableState(tls.extent.tableId()) == null)
continue;
// Don't overwhelm the tablet servers with work
if (tLists.unassigned.size() + unloaded > Manager.MAX_TSERVER_WORK_CHUNK * currentTServers.size()) {
flushChanges(tLists, wals);
tLists.reset();
unloaded = 0;
eventListener.waitForEvents(Manager.TIME_TO_WAIT_BETWEEN_SCANS);
}
TableId tableId = tls.extent.tableId();
TableConfiguration tableConf = manager.getContext().getTableConfiguration(tableId);
MergeStats mergeStats = mergeStatsCache.computeIfAbsent(tableId, k -> {
var mStats = currentMerges.get(k);
return mStats != null ? mStats : new MergeStats(new MergeInfo());
});
TabletGoalState goal = manager.getGoalState(tls, mergeStats.getMergeInfo());
TServerInstance location = tls.getLocation();
TabletState state = tls.getState(currentTServers.keySet());
TabletLogger.missassigned(tls.extent, goal.toString(), state.toString(), tls.future, tls.current, tls.walogs.size());
stats.update(tableId, state);
mergeStats.update(tls.extent, state, tls.chopped, !tls.walogs.isEmpty());
sendChopRequest(mergeStats.getMergeInfo(), state, tls);
sendSplitRequest(mergeStats.getMergeInfo(), state, tls);
// Always follow through with assignments
if (state == TabletState.ASSIGNED) {
goal = TabletGoalState.HOSTED;
}
// if we are shutting down all the tabletservers, we have to do it in order
if ((goal == TabletGoalState.SUSPENDED && state == TabletState.HOSTED) && manager.serversToShutdown.equals(currentTServers.keySet())) {
if (dependentWatcher != null && dependentWatcher.assignedOrHosted() > 0) {
goal = TabletGoalState.HOSTED;
}
}
if (goal == TabletGoalState.HOSTED) {
if ((state != TabletState.HOSTED && !tls.walogs.isEmpty()) && manager.recoveryManager.recoverLogs(tls.extent, tls.walogs))
continue;
switch(state) {
case HOSTED:
if (location.equals(manager.migrations.get(tls.extent)))
manager.migrations.remove(tls.extent);
break;
case ASSIGNED_TO_DEAD_SERVER:
hostDeadTablet(tLists, tls, location, wals);
break;
case SUSPENDED:
hostSuspendedTablet(tLists, tls, location, tableConf);
break;
case UNASSIGNED:
hostUnassignedTablet(tLists, tls.extent, location);
break;
case ASSIGNED:
// Send another reminder
tLists.assigned.add(new Assignment(tls.extent, tls.future));
break;
}
} else {
switch(state) {
case SUSPENDED:
// Request a move to UNASSIGNED, so as to allow balancing to continue.
tLists.suspendedToGoneServers.add(tls);
cancelOfflineTableMigrations(tls.extent);
break;
case UNASSIGNED:
cancelOfflineTableMigrations(tls.extent);
break;
case ASSIGNED_TO_DEAD_SERVER:
unassignDeadTablet(tLists, tls, wals);
break;
case HOSTED:
TServerConnection client = manager.tserverSet.getConnection(location);
if (client != null) {
client.unloadTablet(manager.managerLock, tls.extent, goal.howUnload(), manager.getSteadyTime());
unloaded++;
totalUnloaded++;
} else {
Manager.log.warn("Could not connect to server {}", location);
}
break;
case ASSIGNED:
break;
}
}
counts[state.ordinal()]++;
}
flushChanges(tLists, wals);
// provide stats after flushing changes to avoid race conditions w/ delete table
stats.end(managerState);
// Report changes
for (TabletState state : TabletState.values()) {
int i = state.ordinal();
if (counts[i] > 0 && counts[i] != oldCounts[i]) {
manager.nextEvent.event("[%s]: %d tablets are %s", store.name(), counts[i], state.name());
}
}
Manager.log.debug(String.format("[%s]: scan time %.2f seconds", store.name(), stats.getScanTime() / 1000.));
oldCounts = counts;
if (totalUnloaded > 0) {
manager.nextEvent.event("[%s]: %d tablets unloaded", store.name(), totalUnloaded);
}
updateMergeState(mergeStatsCache);
synchronized (this) {
lastScanServers = ImmutableSortedSet.copyOf(currentTServers.keySet());
}
if (manager.tserverSet.getCurrentServers().equals(currentTServers.keySet())) {
Manager.log.debug(String.format("[%s] sleeping for %.2f seconds", store.name(), Manager.TIME_TO_WAIT_BETWEEN_SCANS / 1000.));
eventListener.waitForEvents(Manager.TIME_TO_WAIT_BETWEEN_SCANS);
} else {
Manager.log.info("Detected change in current tserver set, re-running state machine.");
}
} catch (Exception ex) {
Manager.log.error("Error processing table state for store " + store.name(), ex);
if (ex.getCause() != null && ex.getCause() instanceof BadLocationStateException) {
repairMetadata(((BadLocationStateException) ex.getCause()).getEncodedEndRow());
} else {
sleepUninterruptibly(Manager.WAIT_BETWEEN_ERRORS, TimeUnit.MILLISECONDS);
}
} finally {
if (iter != null) {
try {
iter.close();
} catch (IOException ex) {
Manager.log.warn("Error closing TabletLocationState iterator: " + ex, ex);
}
}
}
}
}
Aggregations