Search in sources :

Example 36 with TServerInstance

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

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

the class CompactionCoordinator method getCompactionJob.

/**
 * Return the next compaction job from the queue to a Compactor
 *
 * @param queueName
 *          queue
 * @param compactorAddress
 *          compactor address
 * @throws ThriftSecurityException
 *           when permission error
 * @return compaction job
 */
@Override
public TExternalCompactionJob getCompactionJob(TInfo tinfo, TCredentials credentials, String queueName, String compactorAddress, String externalCompactionId) throws ThriftSecurityException {
    // do not expect users to call this directly, expect compactors to call this method
    if (!security.canPerformSystemActions(credentials)) {
        throw new AccumuloSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED).asThriftException();
    }
    final String queue = queueName.intern();
    LOG.trace("getCompactionJob called for queue {} by compactor {}", queue, compactorAddress);
    TIME_COMPACTOR_LAST_CHECKED.put(queue, System.currentTimeMillis());
    TExternalCompactionJob result = null;
    PrioTserver prioTserver = QUEUE_SUMMARIES.getNextTserver(queue);
    while (prioTserver != null) {
        TServerInstance tserver = prioTserver.tserver;
        LOG.trace("Getting compaction for queue {} from tserver {}", queue, tserver.getHostAndPort());
        // Get a compaction from the tserver
        TabletClientService.Client client = null;
        try {
            client = getTabletServerConnection(tserver);
            TExternalCompactionJob job = client.reserveCompactionJob(TraceUtil.traceInfo(), getContext().rpcCreds(), queue, prioTserver.prio, compactorAddress, externalCompactionId);
            if (null == job.getExternalCompactionId()) {
                LOG.trace("No compactions found for queue {} on tserver {}, trying next tserver", queue, tserver.getHostAndPort(), compactorAddress);
                QUEUE_SUMMARIES.removeSummary(tserver, queue, prioTserver.prio);
                prioTserver = QUEUE_SUMMARIES.getNextTserver(queue);
                continue;
            }
            RUNNING.put(ExternalCompactionId.of(job.getExternalCompactionId()), new RunningCompaction(job, compactorAddress, queue));
            LOG.debug("Returning external job {} to {}", job.externalCompactionId, compactorAddress);
            result = job;
            break;
        } catch (TException e) {
            LOG.warn("Error from tserver {} while trying to reserve compaction, trying next tserver", ExternalCompactionUtil.getHostPortString(tserver.getHostAndPort()), e);
            QUEUE_SUMMARIES.removeSummary(tserver, queue, prioTserver.prio);
            prioTserver = QUEUE_SUMMARIES.getNextTserver(queue);
        } finally {
            ThriftUtil.returnClient(client, getContext());
        }
    }
    if (result == null) {
        LOG.trace("No tservers found for queue {}, returning empty job to compactor {}", queue, compactorAddress);
        result = new TExternalCompactionJob();
    }
    return result;
}
Also used : TException(org.apache.thrift.TException) PrioTserver(org.apache.accumulo.coordinator.QueueSummaries.PrioTserver) RunningCompaction(org.apache.accumulo.core.util.compaction.RunningCompaction) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TabletClientService(org.apache.accumulo.core.tabletserver.thrift.TabletClientService) TExternalCompactionJob(org.apache.accumulo.core.tabletserver.thrift.TExternalCompactionJob) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance)

Example 38 with TServerInstance

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

the class CompactionCoordinatorTest method testCoordinatorColdStartNoCompactions.

@Test
public void testCoordinatorColdStartNoCompactions() throws Exception {
    PowerMock.resetAll();
    PowerMock.suppress(PowerMock.constructor(AbstractServer.class));
    PowerMock.suppress(PowerMock.methods(ThriftUtil.class, "returnClient"));
    PowerMock.suppress(PowerMock.methods(DeadCompactionDetector.class, "detectDeadCompactions", "detectDanglingFinalStateMarkers"));
    AccumuloConfiguration conf = PowerMock.createNiceMock(AccumuloConfiguration.class);
    ServerContext context = PowerMock.createNiceMock(ServerContext.class);
    PowerMock.mockStatic(ExternalCompactionUtil.class);
    List<RunningCompaction> runningCompactions = new ArrayList<>();
    EasyMock.expect(ExternalCompactionUtil.getCompactionsRunningOnCompactors(context)).andReturn(runningCompactions);
    CompactionFinalizer finalizer = PowerMock.createNiceMock(CompactionFinalizer.class);
    LiveTServerSet tservers = PowerMock.createNiceMock(LiveTServerSet.class);
    EasyMock.expect(tservers.getCurrentServers()).andReturn(Collections.emptySet()).anyTimes();
    ServerAddress client = PowerMock.createNiceMock(ServerAddress.class);
    HostAndPort address = HostAndPort.fromString("localhost:10240");
    EasyMock.expect(client.getAddress()).andReturn(address).anyTimes();
    TServerInstance tsi = PowerMock.createNiceMock(TServerInstance.class);
    EasyMock.expect(tsi.getHostPort()).andReturn("localhost:9997").anyTimes();
    TabletClientService.Client tsc = PowerMock.createNiceMock(TabletClientService.Client.class);
    EasyMock.expect(tsc.getCompactionQueueInfo(EasyMock.anyObject(), EasyMock.anyObject())).andReturn(Collections.emptyList()).anyTimes();
    AuditedSecurityOperation security = PowerMock.createNiceMock(AuditedSecurityOperation.class);
    PowerMock.replayAll();
    TestCoordinator coordinator = new TestCoordinator(conf, finalizer, tservers, client, tsc, context, security);
    coordinator.resetInternals();
    assertEquals(0, coordinator.getQueues().size());
    assertEquals(0, coordinator.getIndex().size());
    assertEquals(0, coordinator.getRunning().size());
    coordinator.run();
    assertEquals(0, coordinator.getQueues().size());
    assertEquals(0, coordinator.getIndex().size());
    assertEquals(0, coordinator.getRunning().size());
    PowerMock.verifyAll();
    coordinator.resetInternals();
    coordinator.close();
}
Also used : ThriftUtil(org.apache.accumulo.core.rpc.ThriftUtil) RunningCompaction(org.apache.accumulo.core.util.compaction.RunningCompaction) ArrayList(java.util.ArrayList) ServerAddress(org.apache.accumulo.server.rpc.ServerAddress) AuditedSecurityOperation(org.apache.accumulo.server.security.AuditedSecurityOperation) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) LiveTServerSet(org.apache.accumulo.server.manager.LiveTServerSet) HostAndPort(org.apache.accumulo.core.util.HostAndPort) AbstractServer(org.apache.accumulo.server.AbstractServer) Client(org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Client) ServerContext(org.apache.accumulo.server.ServerContext) TabletClientService(org.apache.accumulo.core.tabletserver.thrift.TabletClientService) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 39 with TServerInstance

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

the class CompactionCoordinatorTest method testCoordinatorRestartNoRunningCompactions.

@Test
public void testCoordinatorRestartNoRunningCompactions() throws Exception {
    PowerMock.resetAll();
    PowerMock.suppress(PowerMock.constructor(AbstractServer.class));
    PowerMock.suppress(PowerMock.methods(ThriftUtil.class, "returnClient"));
    PowerMock.suppress(PowerMock.methods(DeadCompactionDetector.class, "detectDeadCompactions", "detectDanglingFinalStateMarkers"));
    AccumuloConfiguration conf = PowerMock.createNiceMock(AccumuloConfiguration.class);
    ServerContext context = PowerMock.createNiceMock(ServerContext.class);
    TCredentials creds = PowerMock.createNiceMock(TCredentials.class);
    EasyMock.expect(context.rpcCreds()).andReturn(creds);
    CompactionFinalizer finalizer = PowerMock.createNiceMock(CompactionFinalizer.class);
    LiveTServerSet tservers = PowerMock.createNiceMock(LiveTServerSet.class);
    TServerInstance instance = PowerMock.createNiceMock(TServerInstance.class);
    HostAndPort tserverAddress = HostAndPort.fromString("localhost:9997");
    EasyMock.expect(instance.getHostAndPort()).andReturn(tserverAddress).anyTimes();
    EasyMock.expect(tservers.getCurrentServers()).andReturn(Sets.newHashSet(instance)).once();
    tservers.startListeningForTabletServerChanges();
    PowerMock.mockStatic(ExternalCompactionUtil.class);
    List<RunningCompaction> runningCompactions = new ArrayList<>();
    EasyMock.expect(ExternalCompactionUtil.getCompactionsRunningOnCompactors(context)).andReturn(runningCompactions);
    ServerAddress client = PowerMock.createNiceMock(ServerAddress.class);
    HostAndPort address = HostAndPort.fromString("localhost:10240");
    EasyMock.expect(client.getAddress()).andReturn(address).anyTimes();
    EasyMock.expect(instance.getHostPort()).andReturn("localhost:9997").anyTimes();
    TabletClientService.Client tsc = PowerMock.createNiceMock(TabletClientService.Client.class);
    TCompactionQueueSummary queueSummary = PowerMock.createNiceMock(TCompactionQueueSummary.class);
    EasyMock.expect(tsc.getCompactionQueueInfo(EasyMock.anyObject(), EasyMock.anyObject())).andReturn(Collections.singletonList(queueSummary)).anyTimes();
    EasyMock.expect(queueSummary.getQueue()).andReturn("R2DQ").anyTimes();
    EasyMock.expect(queueSummary.getPriority()).andReturn((short) 1).anyTimes();
    AuditedSecurityOperation security = PowerMock.createNiceMock(AuditedSecurityOperation.class);
    PowerMock.replayAll();
    TestCoordinator coordinator = new TestCoordinator(conf, finalizer, tservers, client, tsc, context, security);
    coordinator.resetInternals();
    assertEquals(0, coordinator.getQueues().size());
    assertEquals(0, coordinator.getIndex().size());
    assertEquals(0, coordinator.getRunning().size());
    coordinator.run();
    assertEquals(1, coordinator.getQueues().size());
    QueueAndPriority qp = QueueAndPriority.get("R2DQ".intern(), (short) 1);
    Map<Short, TreeSet<TServerInstance>> m = coordinator.getQueues().get("R2DQ".intern());
    assertNotNull(m);
    assertEquals(1, m.size());
    assertTrue(m.containsKey((short) 1));
    Set<TServerInstance> t = m.get((short) 1);
    assertNotNull(t);
    assertEquals(1, t.size());
    TServerInstance queuedTsi = t.iterator().next();
    assertEquals(instance.getHostPortSession(), queuedTsi.getHostPortSession());
    assertEquals(1, coordinator.getIndex().size());
    assertTrue(coordinator.getIndex().containsKey(queuedTsi));
    Set<QueueAndPriority> i = coordinator.getIndex().get(queuedTsi);
    assertEquals(1, i.size());
    assertEquals(qp, i.iterator().next());
    assertEquals(0, coordinator.getRunning().size());
    PowerMock.verifyAll();
    coordinator.resetInternals();
    coordinator.close();
}
Also used : ThriftUtil(org.apache.accumulo.core.rpc.ThriftUtil) ArrayList(java.util.ArrayList) ServerAddress(org.apache.accumulo.server.rpc.ServerAddress) AuditedSecurityOperation(org.apache.accumulo.server.security.AuditedSecurityOperation) TCompactionQueueSummary(org.apache.accumulo.core.tabletserver.thrift.TCompactionQueueSummary) LiveTServerSet(org.apache.accumulo.server.manager.LiveTServerSet) HostAndPort(org.apache.accumulo.core.util.HostAndPort) Client(org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Client) TreeSet(java.util.TreeSet) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) TCredentials(org.apache.accumulo.core.securityImpl.thrift.TCredentials) RunningCompaction(org.apache.accumulo.core.util.compaction.RunningCompaction) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) AbstractServer(org.apache.accumulo.server.AbstractServer) ServerContext(org.apache.accumulo.server.ServerContext) TabletClientService(org.apache.accumulo.core.tabletserver.thrift.TabletClientService) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 40 with TServerInstance

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

the class ManagerClientServiceHandler method reportSplitExtent.

@Override
public void reportSplitExtent(TInfo info, TCredentials credentials, String serverName, TabletSplit split) {
    KeyExtent oldTablet = KeyExtent.fromThrift(split.oldTablet);
    if (manager.migrations.remove(oldTablet) != null) {
        Manager.log.info("Canceled migration of {}", split.oldTablet);
    }
    for (TServerInstance instance : manager.tserverSet.getCurrentServers()) {
        if (serverName.equals(instance.getHostPort())) {
            manager.nextEvent.event("%s reported split %s, %s", serverName, KeyExtent.fromThrift(split.newTablets.get(0)), KeyExtent.fromThrift(split.newTablets.get(1)));
            return;
        }
    }
    Manager.log.warn("Got a split from a server we don't recognize: {}", serverName);
}
Also used : TKeyExtent(org.apache.accumulo.core.dataImpl.thrift.TKeyExtent) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) 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