Search in sources :

Example 6 with TServerConnection

use of org.apache.accumulo.server.manager.LiveTServerSet.TServerConnection in project accumulo by apache.

the class ShutdownTServerTest method testSingleShutdown.

@Test
public void testSingleShutdown() throws Exception {
    HostAndPort hap = HostAndPort.fromParts("localhost", 1234);
    final TServerInstance tserver = new TServerInstance(hap, "fake");
    final boolean force = false;
    final ShutdownTServer op = new ShutdownTServer(tserver, force);
    final Manager manager = EasyMock.createMock(Manager.class);
    final long tid = 1L;
    final TServerConnection tserverCnxn = EasyMock.createMock(TServerConnection.class);
    final TabletServerStatus status = new TabletServerStatus();
    status.tableMap = new HashMap<>();
    // Put in a table info record, don't care what
    status.tableMap.put("a_table", new TableInfo());
    manager.shutdownTServer(tserver);
    EasyMock.expectLastCall().once();
    EasyMock.expect(manager.onlineTabletServers()).andReturn(Collections.singleton(tserver));
    EasyMock.expect(manager.getConnection(tserver)).andReturn(tserverCnxn);
    EasyMock.expect(tserverCnxn.getTableMap(false)).andReturn(status);
    EasyMock.replay(tserverCnxn, manager);
    // FATE op is not ready
    long wait = op.isReady(tid, manager);
    assertTrue("Expected wait to be greater than 0", wait > 0);
    EasyMock.verify(tserverCnxn, manager);
    // Reset the mocks
    EasyMock.reset(tserverCnxn, manager);
    // reset the table map to the empty set to simulate all tablets unloaded
    status.tableMap = new HashMap<>();
    manager.shutdownTServer(tserver);
    EasyMock.expectLastCall().once();
    EasyMock.expect(manager.onlineTabletServers()).andReturn(Collections.singleton(tserver));
    EasyMock.expect(manager.getConnection(tserver)).andReturn(tserverCnxn);
    EasyMock.expect(tserverCnxn.getTableMap(false)).andReturn(status);
    EasyMock.expect(manager.getManagerLock()).andReturn(null);
    tserverCnxn.halt(null);
    EasyMock.expectLastCall().once();
    EasyMock.replay(tserverCnxn, manager);
    // FATE op is not ready
    wait = op.isReady(tid, manager);
    assertTrue("Expected wait to be 0", wait == 0);
    Repo<Manager> op2 = op.call(tid, manager);
    assertNull("Expected no follow on step", op2);
    EasyMock.verify(tserverCnxn, manager);
}
Also used : TServerConnection(org.apache.accumulo.server.manager.LiveTServerSet.TServerConnection) HostAndPort(org.apache.accumulo.core.util.HostAndPort) TableInfo(org.apache.accumulo.core.master.thrift.TableInfo) Manager(org.apache.accumulo.manager.Manager) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) ShutdownTServer(org.apache.accumulo.manager.tserverOps.ShutdownTServer) TabletServerStatus(org.apache.accumulo.core.master.thrift.TabletServerStatus) Test(org.junit.Test)

Example 7 with TServerConnection

use of org.apache.accumulo.server.manager.LiveTServerSet.TServerConnection in project accumulo by apache.

the class ShutdownTServer method isReady.

@Override
public long isReady(long tid, Manager manager) {
    TServerInstance server = new TServerInstance(hostAndPort, serverSession);
    // suppress assignment of tablets to the server
    if (force) {
        return 0;
    }
    // Inform the manager that we want this server to shutdown
    manager.shutdownTServer(server);
    if (manager.onlineTabletServers().contains(server)) {
        TServerConnection connection = manager.getConnection(server);
        if (connection != null) {
            try {
                TabletServerStatus status = connection.getTableMap(false);
                if (status.tableMap != null && status.tableMap.isEmpty()) {
                    log.info("tablet server hosts no tablets {}", server);
                    connection.halt(manager.getManagerLock());
                    log.info("tablet server asked to halt {}", server);
                    return 0;
                }
            } catch (TTransportException ex) {
            // expected
            } catch (Exception ex) {
                log.error("Error talking to tablet server {}: ", server, ex);
            }
            // tserver to ack the request and stop itself.
            return 1000;
        }
    }
    return 0;
}
Also used : TServerConnection(org.apache.accumulo.server.manager.LiveTServerSet.TServerConnection) TTransportException(org.apache.thrift.transport.TTransportException) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) TabletServerStatus(org.apache.accumulo.core.master.thrift.TabletServerStatus) TTransportException(org.apache.thrift.transport.TTransportException)

Example 8 with TServerConnection

use of org.apache.accumulo.server.manager.LiveTServerSet.TServerConnection 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 9 with TServerConnection

use of org.apache.accumulo.server.manager.LiveTServerSet.TServerConnection 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 10 with TServerConnection

use of org.apache.accumulo.server.manager.LiveTServerSet.TServerConnection in project accumulo by apache.

the class CompactionCoordinator method getTabletServerConnection.

/**
 * Return the Thrift client for the TServer
 *
 * @param tserver
 *          tserver instance
 * @return thrift client
 * @throws TTransportException
 *           thrift error
 */
protected TabletClientService.Client getTabletServerConnection(TServerInstance tserver) throws TTransportException {
    TServerConnection connection = tserverSet.getConnection(tserver);
    ServerContext serverContext = getContext();
    TTransport transport = serverContext.getTransportPool().getTransport(connection.getAddress(), 0, serverContext);
    return ThriftUtil.createClient(new TabletClientService.Client.Factory(), transport);
}
Also used : TServerConnection(org.apache.accumulo.server.manager.LiveTServerSet.TServerConnection) ServerContext(org.apache.accumulo.server.ServerContext) TTransport(org.apache.thrift.transport.TTransport)

Aggregations

TServerConnection (org.apache.accumulo.server.manager.LiveTServerSet.TServerConnection)13 TServerInstance (org.apache.accumulo.core.metadata.TServerInstance)9 TException (org.apache.thrift.TException)7 TabletServerStatus (org.apache.accumulo.core.master.thrift.TabletServerStatus)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)3 TableId (org.apache.accumulo.core.data.TableId)3 ServerContext (org.apache.accumulo.server.ServerContext)3 TreeMap (java.util.TreeMap)2 ThriftSecurityException (org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException)2 ThriftTableOperationException (org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException)2 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)2 TableInfo (org.apache.accumulo.core.master.thrift.TableInfo)2 TabletMetadata (org.apache.accumulo.core.metadata.schema.TabletMetadata)2 TabletsMetadata (org.apache.accumulo.core.metadata.schema.TabletsMetadata)2 ZooReaderWriter (org.apache.accumulo.fate.zookeeper.ZooReaderWriter)2 ShutdownTServer (org.apache.accumulo.manager.tserverOps.ShutdownTServer)2 Assignment (org.apache.accumulo.server.manager.state.Assignment)2