use of org.apache.accumulo.coordinator.QueueSummaries.PrioTserver 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;
}
Aggregations