Search in sources :

Example 6 with TabletLocationState

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;
}
Also used : BatchScanner(org.apache.accumulo.core.client.BatchScanner) MetaDataTableScanner(org.apache.accumulo.server.master.state.MetaDataTableScanner) Scanner(org.apache.accumulo.core.client.Scanner) TabletState(org.apache.accumulo.server.master.state.TabletState) Value(org.apache.accumulo.core.data.Value) TabletLocationState(org.apache.accumulo.server.master.state.TabletLocationState) Range(org.apache.accumulo.core.data.Range) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) Key(org.apache.accumulo.core.data.Key)

Example 7 with TabletLocationState

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);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) Listener(org.apache.accumulo.server.master.LiveTServerSet.Listener) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) RootTable(org.apache.accumulo.core.metadata.RootTable) Table(org.apache.accumulo.core.client.impl.Table) DistributedStoreException(org.apache.accumulo.server.master.state.DistributedStoreException) Range(org.apache.accumulo.core.data.Range) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) LiveTServerSet(org.apache.accumulo.server.master.LiveTServerSet) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MetaDataTableScanner(org.apache.accumulo.server.master.state.MetaDataTableScanner) TabletLocationState(org.apache.accumulo.server.master.state.TabletLocationState) ZooTabletStateStore(org.apache.accumulo.server.master.state.ZooTabletStateStore)

Example 8 with TabletLocationState

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));
}
Also used : Connector(org.apache.accumulo.core.client.Connector) ClientContext(org.apache.accumulo.core.client.impl.ClientContext) Text(org.apache.hadoop.io.Text) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) MetaDataStateStore(org.apache.accumulo.server.master.state.MetaDataStateStore) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) TreeSet(java.util.TreeSet) RootTabletStateStore(org.apache.accumulo.server.master.state.RootTabletStateStore) TabletLocationState(org.apache.accumulo.server.master.state.TabletLocationState) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Credentials(org.apache.accumulo.core.client.impl.Credentials) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with TabletLocationState

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

Example 10 with TabletLocationState

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

Aggregations

TabletLocationState (org.apache.accumulo.server.master.state.TabletLocationState)15 KeyExtent (org.apache.accumulo.core.data.impl.KeyExtent)8 Range (org.apache.accumulo.core.data.Range)7 Table (org.apache.accumulo.core.client.impl.Table)6 MetaDataTableScanner (org.apache.accumulo.server.master.state.MetaDataTableScanner)6 TServerInstance (org.apache.accumulo.server.master.state.TServerInstance)6 MetadataTable (org.apache.accumulo.core.metadata.MetadataTable)5 Text (org.apache.hadoop.io.Text)5 RootTable (org.apache.accumulo.core.metadata.RootTable)4 Assignment (org.apache.accumulo.server.master.state.Assignment)4 ArrayList (java.util.ArrayList)3 AccumuloException (org.apache.accumulo.core.client.AccumuloException)3 BatchWriter (org.apache.accumulo.core.client.BatchWriter)3 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)3 Connector (org.apache.accumulo.core.client.Connector)3 Mutation (org.apache.accumulo.core.data.Mutation)3 Value (org.apache.accumulo.core.data.Value)3 BadLocationStateException (org.apache.accumulo.server.master.state.TabletLocationState.BadLocationStateException)3 ZooTabletStateStore (org.apache.accumulo.server.master.state.ZooTabletStateStore)3 Test (org.junit.Test)3