Search in sources :

Example 16 with TabletLocationState

use of org.apache.accumulo.core.metadata.TabletLocationState in project accumulo by apache.

the class UnloadTabletHandler method run.

@Override
public void run() {
    Tablet t = null;
    synchronized (server.unopenedTablets) {
        if (server.unopenedTablets.contains(extent)) {
            server.unopenedTablets.remove(extent);
            // enqueueManagerMessage(new TabletUnloadedMessage(extent));
            return;
        }
    }
    synchronized (server.openingTablets) {
        while (server.openingTablets.contains(extent)) {
            try {
                log.info("Waiting for tablet {} to finish opening before unloading.", extent);
                server.openingTablets.wait();
            } catch (InterruptedException e) {
            }
        }
    }
    synchronized (server.onlineTablets) {
        if (server.onlineTablets.snapshot().containsKey(extent)) {
            t = server.onlineTablets.snapshot().get(extent);
        }
    }
    if (t == null) {
        // unload request is crossing the successful unloaded message
        if (!server.recentlyUnloadedCache.containsKey(extent)) {
            log.info("told to unload tablet that was not being served {}", extent);
            server.enqueueManagerMessage(new TabletStatusMessage(TabletLoadState.UNLOAD_FAILURE_NOT_SERVING, extent));
        }
        return;
    }
    try {
        t.close(!goalState.equals(TUnloadTabletGoal.DELETED));
    } catch (Exception e) {
        if ((t.isClosing() || t.isClosed()) && e instanceof IllegalStateException) {
            log.debug("Failed to unload tablet {}... it was already closing or closed : {}", extent, e.getMessage());
        } else {
            log.error("Failed to close tablet {}... Aborting migration", extent, e);
            server.enqueueManagerMessage(new TabletStatusMessage(TabletLoadState.UNLOAD_ERROR, extent));
        }
        return;
    }
    // stop serving tablet - client will get not serving tablet
    // exceptions
    server.recentlyUnloadedCache.put(extent, System.currentTimeMillis());
    server.onlineTablets.remove(extent);
    try {
        TServerInstance instance = new TServerInstance(server.clientAddress, server.getLock().getSessionId());
        TabletLocationState tls = null;
        try {
            tls = new TabletLocationState(extent, null, instance, null, null, null, false);
        } catch (BadLocationStateException e) {
            log.error("Unexpected error", e);
        }
        if (!goalState.equals(TUnloadTabletGoal.SUSPENDED) || extent.isRootTablet() || (extent.isMeta() && !server.getConfiguration().getBoolean(Property.MANAGER_METADATA_SUSPENDABLE))) {
            TabletStateStore.unassign(server.getContext(), tls, null);
        } else {
            TabletStateStore.suspend(server.getContext(), tls, null, requestTimeSkew + NANOSECONDS.toMillis(System.nanoTime()));
        }
    } catch (DistributedStoreException ex) {
        log.warn("Unable to update storage", ex);
    } catch (KeeperException e) {
        log.warn("Unable determine our zookeeper session information", e);
    } catch (InterruptedException e) {
        log.warn("Interrupted while getting our zookeeper session information", e);
    }
    // tell the manager how it went
    server.enqueueManagerMessage(new TabletStatusMessage(TabletLoadState.UNLOADED, extent));
    // roll tablet stats over into tablet server's statsKeeper object as
    // historical data
    server.statsKeeper.saveMajorMinorTimes(t.getTabletStats());
}
Also used : TabletStatusMessage(org.apache.accumulo.tserver.managermessage.TabletStatusMessage) TabletLocationState(org.apache.accumulo.core.metadata.TabletLocationState) DistributedStoreException(org.apache.accumulo.server.manager.state.DistributedStoreException) Tablet(org.apache.accumulo.tserver.tablet.Tablet) BadLocationStateException(org.apache.accumulo.core.metadata.TabletLocationState.BadLocationStateException) KeeperException(org.apache.zookeeper.KeeperException) DistributedStoreException(org.apache.accumulo.server.manager.state.DistributedStoreException) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) BadLocationStateException(org.apache.accumulo.core.metadata.TabletLocationState.BadLocationStateException) KeeperException(org.apache.zookeeper.KeeperException)

Example 17 with TabletLocationState

use of org.apache.accumulo.core.metadata.TabletLocationState in project accumulo by apache.

the class ManagerAssignmentIT method test.

@Test
public void test() throws Exception {
    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
        String tableName = super.getUniqueNames(1)[0];
        c.tableOperations().create(tableName);
        String tableId = c.tableOperations().tableIdMap().get(tableName);
        // wait for the table to be online
        TabletLocationState newTablet;
        do {
            UtilWaitThread.sleep(250);
            newTablet = getTabletLocationState(c, tableId);
        } while (newTablet.current == null);
        assertNull(newTablet.last);
        assertNull(newTablet.future);
        // put something in it
        try (BatchWriter bw = c.createBatchWriter(tableName)) {
            Mutation m = new Mutation("a");
            m.put("b", "c", "d");
            bw.addMutation(m);
        }
        // give it a last location
        c.tableOperations().flush(tableName, null, null, true);
        TabletLocationState flushed = getTabletLocationState(c, tableId);
        assertEquals(newTablet.current, flushed.current);
        assertEquals(flushed.current, flushed.last);
        assertNull(newTablet.future);
        // take the tablet offline
        c.tableOperations().offline(tableName, true);
        TabletLocationState offline = getTabletLocationState(c, tableId);
        assertNull(offline.future);
        assertNull(offline.current);
        assertEquals(flushed.current, offline.last);
        // put it back online
        c.tableOperations().online(tableName, true);
        TabletLocationState online = getTabletLocationState(c, tableId);
        assertNull(online.future);
        assertNotNull(online.current);
        assertEquals(online.current, online.last);
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) TabletLocationState(org.apache.accumulo.core.metadata.TabletLocationState) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Test(org.junit.Test)

Example 18 with TabletLocationState

use of org.apache.accumulo.core.metadata.TabletLocationState in project accumulo by apache.

the class ManagerRepairsDualAssignmentIT method test.

@Test
public void test() throws Exception {
    // make some tablets, spread 'em around
    try (AccumuloClient c = Accumulo.newClient().from(getClientProperties()).build()) {
        ClientContext context = (ClientContext) c;
        ServerContext serverContext = cluster.getServerContext();
        String table = this.getUniqueNames(1)[0];
        c.securityOperations().grantTablePermission("root", MetadataTable.NAME, TablePermission.WRITE);
        c.securityOperations().grantTablePermission("root", RootTable.NAME, TablePermission.WRITE);
        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));
        }
        NewTableConfiguration ntc = new NewTableConfiguration().withSplits(partitions);
        c.tableOperations().create(table, ntc);
        // scan the metadata table and get the two table location states
        Set<TServerInstance> states = new HashSet<>();
        Set<TabletLocationState> oldLocations = new HashSet<>();
        TabletStateStore store = TabletStateStore.getStoreForLevel(DataLevel.USER, context);
        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<>();
        @SuppressWarnings("deprecation") TableId repTable = org.apache.accumulo.core.replication.ReplicationTable.ID;
        // 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(repTable, 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
        TabletMutator tabletMutator = serverContext.getAmple().mutateTablet(moved.extent);
        tabletMutator.putLocation(moved.current, LocationType.CURRENT);
        tabletMutator.mutate();
        // wait for the manager to fix the problem
        waitForCleanStore(store);
        // now jam up the metadata table
        tabletMutator = serverContext.getAmple().mutateTablet(new KeyExtent(MetadataTable.ID, null, null));
        tabletMutator.putLocation(moved.current, LocationType.CURRENT);
        tabletMutator.mutate();
        waitForCleanStore(TabletStateStore.getStoreForLevel(DataLevel.METADATA, context));
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) TableId(org.apache.accumulo.core.data.TableId) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) TabletMutator(org.apache.accumulo.core.metadata.schema.Ample.TabletMutator) Text(org.apache.hadoop.io.Text) TabletStateStore(org.apache.accumulo.server.manager.state.TabletStateStore) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) ServerContext(org.apache.accumulo.server.ServerContext) TreeSet(java.util.TreeSet) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) TabletLocationState(org.apache.accumulo.core.metadata.TabletLocationState) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 19 with TabletLocationState

use of org.apache.accumulo.core.metadata.TabletLocationState in project accumulo by apache.

the class TablesResource method getParticipatingTabletServers.

/**
 * Generates a list of participating tservers for a table
 *
 * @param tableIdStr
 *          Table ID to find participating tservers
 * @return List of participating tservers
 */
@Path("{tableId}")
@GET
public TabletServers getParticipatingTabletServers(@PathParam("tableId") @NotNull @Pattern(regexp = ALPHA_NUM_REGEX_TABLE_ID) String tableIdStr) {
    String rootTabletLocation = monitor.getContext().getRootTabletLocation();
    TableId tableId = TableId.of(tableIdStr);
    ManagerMonitorInfo mmi = monitor.getMmi();
    // fail fast if unable to get monitor info
    if (mmi == null) {
        return new TabletServers();
    }
    TabletServers tabletServers = new TabletServers(mmi.tServerInfo.size());
    if (tableIdStr.isBlank()) {
        return tabletServers;
    }
    TreeSet<String> locs = new TreeSet<>();
    if (RootTable.ID.equals(tableId)) {
        locs.add(rootTabletLocation);
    } else {
        String systemTableName = MetadataTable.ID.equals(tableId) ? RootTable.NAME : MetadataTable.NAME;
        MetaDataTableScanner scanner = new MetaDataTableScanner(monitor.getContext(), new Range(TabletsSection.encodeRow(tableId, new Text()), TabletsSection.encodeRow(tableId, null)), systemTableName);
        while (scanner.hasNext()) {
            TabletLocationState state = scanner.next();
            if (state.current != null) {
                try {
                    locs.add(state.current.getHostPort());
                } catch (Exception ex) {
                    scanner.close();
                    return tabletServers;
                }
            }
        }
        scanner.close();
    }
    List<TabletServerStatus> tservers = new ArrayList<>();
    for (TabletServerStatus tss : mmi.tServerInfo) {
        try {
            if (tss.name != null && locs.contains(tss.name)) {
                tservers.add(tss);
            }
        } catch (Exception ex) {
            return tabletServers;
        }
    }
    // Adds tservers to the list
    for (TabletServerStatus status : tservers) {
        if (status == null) {
            status = NO_STATUS;
        }
        TableInfo summary = status.tableMap.get(tableId.canonical());
        if (summary == null) {
            continue;
        }
        TabletServer tabletServerInfo = new TabletServer();
        tabletServerInfo.server.updateTabletServerInfo(monitor, status, summary);
        tabletServers.addTablet(tabletServerInfo);
    }
    return tabletServers;
}
Also used : TableId(org.apache.accumulo.core.data.TableId) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) TabletServers(org.apache.accumulo.monitor.rest.tservers.TabletServers) TreeSet(java.util.TreeSet) MetaDataTableScanner(org.apache.accumulo.server.manager.state.MetaDataTableScanner) TabletServer(org.apache.accumulo.monitor.rest.tservers.TabletServer) ManagerMonitorInfo(org.apache.accumulo.core.manager.thrift.ManagerMonitorInfo) TabletLocationState(org.apache.accumulo.core.metadata.TabletLocationState) TableInfo(org.apache.accumulo.core.master.thrift.TableInfo) TabletServerStatus(org.apache.accumulo.core.master.thrift.TabletServerStatus) Path(jakarta.ws.rs.Path) GET(jakarta.ws.rs.GET)

Example 20 with TabletLocationState

use of org.apache.accumulo.core.metadata.TabletLocationState in project accumulo by apache.

the class SuspendedTabletsIT method shutdownAndResumeTserver.

@Test
public void shutdownAndResumeTserver() throws Exception {
    // Run the test body. When we get to the point where we need tservers to go away, stop them via
    // a clean shutdown.
    suspensionTestBody((ctx, locs, count) -> {
        Set<TServerInstance> tserverSet = new HashSet<>();
        Set<TServerInstance> metadataServerSet = new HashSet<>();
        TabletLocator tl = TabletLocator.getLocator(ctx, MetadataTable.ID);
        for (TabletLocationState tls : locs.locationStates.values()) {
            if (tls.current != null) {
                // add to set of all servers
                tserverSet.add(tls.current);
                // get server that the current tablets metadata is on
                TabletLocator.TabletLocation tab = tl.locateTablet(ctx, tls.extent.toMetaRow(), false, false);
                // add it to the set of servers with metadata
                metadataServerSet.add(new TServerInstance(tab.tablet_location, Long.valueOf(tab.tablet_session, 16)));
            }
        }
        // remove servers with metadata on them from the list of servers to be shutdown
        assertEquals("Expecting a single tServer in metadataServerSet", 1, metadataServerSet.size());
        tserverSet.removeAll(metadataServerSet);
        assertEquals("Expecting " + (TSERVERS - 1) + " tServers in shutdown-list", TSERVERS - 1, tserverSet.size());
        List<TServerInstance> tserversList = new ArrayList<>(tserverSet);
        Collections.shuffle(tserversList, random);
        for (int i1 = 0; i1 < count; ++i1) {
            final String tserverName = tserversList.get(i1).getHostPortSession();
            ManagerClient.executeVoid(ctx, client -> {
                log.info("Sending shutdown command to {} via ManagerClientService", tserverName);
                client.shutdownTabletServer(null, ctx.rpcCreds(), tserverName, false);
            });
        }
        log.info("Waiting for tserver process{} to die", count == 1 ? "" : "es");
        for (int i2 = 0; i2 < 10; ++i2) {
            List<ProcessReference> deadProcs = new ArrayList<>();
            for (ProcessReference pr1 : getCluster().getProcesses().get(ServerType.TABLET_SERVER)) {
                Process p = pr1.getProcess();
                if (!p.isAlive()) {
                    deadProcs.add(pr1);
                }
            }
            for (ProcessReference pr2 : deadProcs) {
                log.info("Process {} is dead, informing cluster control about this", pr2.getProcess());
                getCluster().getClusterControl().killProcess(ServerType.TABLET_SERVER, pr2);
                --count;
            }
            if (count == 0) {
                return;
            } else {
                Thread.sleep(SECONDS.toMillis(2));
            }
        }
        throw new IllegalStateException("Tablet servers didn't die!");
    });
}
Also used : ProcessReference(org.apache.accumulo.miniclusterImpl.ProcessReference) ArrayList(java.util.ArrayList) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) TabletLocator(org.apache.accumulo.core.clientImpl.TabletLocator) TabletLocationState(org.apache.accumulo.core.metadata.TabletLocationState) HashSet(java.util.HashSet) Test(org.junit.Test)

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