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;
}
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;
}
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();
}
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();
}
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);
}
Aggregations