Search in sources :

Example 1 with TabletLocationState

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);
    }
}
Also used : TabletLocationState(org.apache.accumulo.core.metadata.TabletLocationState) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance)

Example 2 with TabletLocationState

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();
    }
}
Also used : Value(org.apache.accumulo.core.data.Value) TabletLocationState(org.apache.accumulo.core.metadata.TabletLocationState) Key(org.apache.accumulo.core.data.Key) BadLocationStateException(org.apache.accumulo.core.metadata.TabletLocationState.BadLocationStateException)

Example 3 with TabletLocationState

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");
}
Also used : Path(org.apache.hadoop.fs.Path) TabletLocationState(org.apache.accumulo.core.metadata.TabletLocationState) TabletMutator(org.apache.accumulo.core.metadata.schema.Ample.TabletMutator) LogEntry(org.apache.accumulo.core.tabletserver.log.LogEntry)

Example 4 with TabletLocationState

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;
}
Also used : Path(org.apache.hadoop.fs.Path) HashSet(java.util.HashSet) LiveTServerSet(org.apache.accumulo.server.manager.LiveTServerSet) Set(java.util.Set) HashMap(java.util.HashMap) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) TabletLocationState(org.apache.accumulo.core.metadata.TabletLocationState) WalState(org.apache.accumulo.server.log.WalStateManager.WalState) UUID(java.util.UUID)

Example 5 with TabletLocationState

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;
}
Also used : TabletState(org.apache.accumulo.core.metadata.TabletState) TabletLocationState(org.apache.accumulo.core.metadata.TabletLocationState)

Aggregations

TabletLocationState (org.apache.accumulo.core.metadata.TabletLocationState)35 Test (org.junit.Test)19 TServerInstance (org.apache.accumulo.core.metadata.TServerInstance)15 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)8 TableId (org.apache.accumulo.core.data.TableId)7 Range (org.apache.accumulo.core.data.Range)6 BadLocationStateException (org.apache.accumulo.core.metadata.TabletLocationState.BadLocationStateException)6 Text (org.apache.hadoop.io.Text)6 ArrayList (java.util.ArrayList)5 Value (org.apache.accumulo.core.data.Value)5 MetaDataTableScanner (org.apache.accumulo.server.manager.state.MetaDataTableScanner)5 Key (org.apache.accumulo.core.data.Key)4 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)3 TabletMutator (org.apache.accumulo.core.metadata.schema.Ample.TabletMutator)3 MergeStats (org.apache.accumulo.manager.state.MergeStats)3 ServerContext (org.apache.accumulo.server.ServerContext)3 Assignment (org.apache.accumulo.server.manager.state.Assignment)3 TabletStateStore (org.apache.accumulo.server.manager.state.TabletStateStore)3