Search in sources :

Example 41 with TServerInstance

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

the class ManagerClientServiceHandler method shutdownTabletServer.

@Override
public void shutdownTabletServer(TInfo info, TCredentials c, String tabletServer, boolean force) throws ThriftSecurityException {
    if (!manager.security.canPerformSystemActions(c))
        throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
    final TServerInstance doomed = manager.tserverSet.find(tabletServer);
    if (!force) {
        final TServerConnection server = manager.tserverSet.getConnection(doomed);
        if (server == null) {
            Manager.log.warn("No server found for name {}", tabletServer);
            return;
        }
    }
    long tid = manager.fate.startTransaction();
    String msg = "Shutdown tserver " + tabletServer;
    manager.fate.seedTransaction(tid, new TraceRepo<>(new ShutdownTServer(doomed, force)), false, msg);
    manager.fate.waitForCompletion(tid);
    manager.fate.delete(tid);
    log.debug("FATE op shutting down " + tabletServer + " finished");
}
Also used : TServerConnection(org.apache.accumulo.server.manager.LiveTServerSet.TServerConnection) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) ShutdownTServer(org.apache.accumulo.manager.tserverOps.ShutdownTServer)

Example 42 with TServerInstance

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

the class ManagerClientServiceHandler method waitForFlush.

@Override
public void waitForFlush(TInfo tinfo, TCredentials c, String tableIdStr, ByteBuffer startRowBB, ByteBuffer endRowBB, long flushID, long maxLoops) throws ThriftSecurityException, ThriftTableOperationException {
    TableId tableId = TableId.of(tableIdStr);
    NamespaceId namespaceId = getNamespaceIdFromTableId(TableOperation.FLUSH, tableId);
    if (!manager.security.canFlush(c, tableId, namespaceId))
        throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
    Text startRow = ByteBufferUtil.toText(startRowBB);
    Text endRow = ByteBufferUtil.toText(endRowBB);
    if (endRow != null && startRow != null && startRow.compareTo(endRow) >= 0)
        throw new ThriftTableOperationException(tableId.canonical(), null, TableOperation.FLUSH, TableOperationExceptionType.BAD_RANGE, "start row must be less than end row");
    Set<TServerInstance> serversToFlush = new HashSet<>(manager.tserverSet.getCurrentServers());
    for (long l = 0; l < maxLoops; l++) {
        for (TServerInstance instance : serversToFlush) {
            try {
                final TServerConnection server = manager.tserverSet.getConnection(instance);
                if (server != null)
                    server.flush(manager.managerLock, tableId, ByteBufferUtil.toBytes(startRowBB), ByteBufferUtil.toBytes(endRowBB));
            } catch (TException ex) {
                Manager.log.error(ex.toString());
            }
        }
        if (tableId.equals(RootTable.ID))
            // this code does not properly handle the root tablet. See #798
            break;
        if (l == maxLoops - 1)
            break;
        sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
        serversToFlush.clear();
        try (TabletsMetadata tablets = TabletsMetadata.builder(manager.getContext()).forTable(tableId).overlapping(startRow, endRow).fetch(FLUSH_ID, LOCATION, LOGS, PREV_ROW).build()) {
            int tabletsToWaitFor = 0;
            int tabletCount = 0;
            for (TabletMetadata tablet : tablets) {
                int logs = tablet.getLogs().size();
                // when tablet is not online and has no logs, there is no reason to wait for it
                if ((tablet.hasCurrent() || logs > 0) && tablet.getFlushId().orElse(-1) < flushID) {
                    tabletsToWaitFor++;
                    if (tablet.hasCurrent())
                        serversToFlush.add(tablet.getLocation());
                }
                tabletCount++;
            }
            if (tabletsToWaitFor == 0)
                break;
            if (tabletCount == 0 && !manager.getContext().tableNodeExists(tableId))
                throw new ThriftTableOperationException(tableId.canonical(), null, TableOperation.FLUSH, TableOperationExceptionType.NOTFOUND, null);
        } catch (TabletDeletedException e) {
            Manager.log.debug("Failed to scan {} table to wait for flush {}", MetadataTable.NAME, tableId, e);
        }
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) TException(org.apache.thrift.TException) Text(org.apache.hadoop.io.Text) TabletDeletedException(org.apache.accumulo.core.metadata.schema.TabletDeletedException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) TServerConnection(org.apache.accumulo.server.manager.LiveTServerSet.TServerConnection) TabletsMetadata(org.apache.accumulo.core.metadata.schema.TabletsMetadata) TabletMetadata(org.apache.accumulo.core.metadata.schema.TabletMetadata) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) NamespaceId(org.apache.accumulo.core.data.NamespaceId) HashSet(java.util.HashSet)

Example 43 with TServerInstance

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

the class QueueSummaries method getNextTserver.

synchronized PrioTserver getNextTserver(String queue) {
    Entry<Short, TreeSet<TServerInstance>> entry = getNextTserverEntry(queue);
    if (entry == null) {
        // no tserver, so remove any last entry if it exists
        LAST.remove(queue);
        return null;
    }
    final Short priority = entry.getKey();
    final TreeSet<TServerInstance> tservers = entry.getValue();
    PrioTserver last = LAST.get(queue);
    TServerInstance nextTserver = null;
    if (last != null && last.prio == priority) {
        TServerInstance higher = tservers.higher(last.tserver);
        if (higher == null) {
            nextTserver = tservers.first();
        } else {
            nextTserver = higher;
        }
    } else {
        nextTserver = tservers.first();
    }
    PrioTserver result = new PrioTserver(nextTserver, priority);
    LAST.put(queue, result);
    return result;
}
Also used : TreeSet(java.util.TreeSet) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance)

Example 44 with TServerInstance

use of org.apache.accumulo.core.metadata.TServerInstance 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 45 with TServerInstance

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

the class RegexGroupBalanceIT method getCounts.

private Table<String, String, MutableInt> getCounts(AccumuloClient client, String tablename) throws TableNotFoundException {
    try (Scanner s = client.createScanner(MetadataTable.NAME, Authorizations.EMPTY)) {
        s.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
        TableId tableId = TableId.of(client.tableOperations().tableIdMap().get(tablename));
        s.setRange(TabletsSection.getRange(tableId));
        Table<String, String, MutableInt> groupLocationCounts = HashBasedTable.create();
        for (Entry<Key, Value> entry : s) {
            String group = entry.getKey().getRow().toString();
            if (group.endsWith("<")) {
                group = "03";
            } else {
                group = group.substring(tableId.canonical().length() + 1).substring(0, 2);
            }
            String loc = new TServerInstance(entry.getValue(), entry.getKey().getColumnQualifier()).getHostPortSession();
            MutableInt count = groupLocationCounts.get(group, loc);
            if (count == null) {
                count = new MutableInt(0);
                groupLocationCounts.put(group, loc, count);
            }
            count.increment();
        }
        return groupLocationCounts;
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) Scanner(org.apache.accumulo.core.client.Scanner) MutableInt(org.apache.commons.lang3.mutable.MutableInt) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance)

Aggregations

TServerInstance (org.apache.accumulo.core.metadata.TServerInstance)89 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)32 ArrayList (java.util.ArrayList)31 Test (org.junit.Test)30 HashMap (java.util.HashMap)21 ServerContext (org.apache.accumulo.server.ServerContext)18 TabletLocationState (org.apache.accumulo.core.metadata.TabletLocationState)17 HostAndPort (org.apache.accumulo.core.util.HostAndPort)14 HashSet (java.util.HashSet)13 TabletServerStatus (org.apache.accumulo.core.master.thrift.TabletServerStatus)13 TableId (org.apache.accumulo.core.data.TableId)12 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)11 List (java.util.List)10 LiveTServerSet (org.apache.accumulo.server.manager.LiveTServerSet)10 TException (org.apache.thrift.TException)10 TreeMap (java.util.TreeMap)9 UUID (java.util.UUID)9 TreeSet (java.util.TreeSet)8 Key (org.apache.accumulo.core.data.Key)8 Value (org.apache.accumulo.core.data.Value)8