Search in sources :

Example 1 with TExternalCompactionJob

use of org.apache.accumulo.core.tabletserver.thrift.TExternalCompactionJob in project accumulo by apache.

the class ExternalCompactionUtil method getRunningCompaction.

/**
 * Get the compaction currently running on the Compactor
 *
 * @param compactorAddr
 *          compactor address
 * @param context
 *          context
 * @return external compaction job or null if none running
 */
public static TExternalCompactionJob getRunningCompaction(HostAndPort compactorAddr, ClientContext context) {
    CompactorService.Client client = null;
    try {
        client = ThriftUtil.getClient(new CompactorService.Client.Factory(), compactorAddr, context);
        TExternalCompactionJob job = client.getRunningCompaction(TraceUtil.traceInfo(), context.rpcCreds());
        if (job.getExternalCompactionId() != null) {
            LOG.debug("Compactor {} is running {}", compactorAddr, job.getExternalCompactionId());
            return job;
        }
    } catch (TException e) {
        LOG.debug("Failed to contact compactor {}", compactorAddr, e);
    } finally {
        ThriftUtil.returnClient(client, context);
    }
    return null;
}
Also used : TException(org.apache.thrift.TException) CompactorService(org.apache.accumulo.core.compaction.thrift.CompactorService) LoggerFactory(org.slf4j.LoggerFactory) TExternalCompactionJob(org.apache.accumulo.core.tabletserver.thrift.TExternalCompactionJob)

Example 2 with TExternalCompactionJob

use of org.apache.accumulo.core.tabletserver.thrift.TExternalCompactionJob in project accumulo by apache.

the class ExternalCompactionUtil method getCompactionsRunningOnCompactors.

/**
 * This method returns information from the Compactor about the job that is currently running. The
 * RunningCompactions are not fully populated. This method is used from the CompactionCoordinator
 * on a restart to re-populate the set of running compactions on the compactors.
 *
 * @param context
 *          server context
 * @return map of compactor and external compaction jobs
 */
public static List<RunningCompaction> getCompactionsRunningOnCompactors(ClientContext context) {
    final List<RunningCompactionFuture> rcFutures = new ArrayList<>();
    final ExecutorService executor = ThreadPools.createFixedThreadPool(16, "CompactorRunningCompactions", false);
    getCompactorAddrs(context).forEach((q, hp) -> {
        hp.forEach(hostAndPort -> {
            rcFutures.add(new RunningCompactionFuture(q, hostAndPort, executor.submit(() -> getRunningCompaction(hostAndPort, context))));
        });
    });
    executor.shutdown();
    final List<RunningCompaction> results = new ArrayList<>();
    rcFutures.forEach(rcf -> {
        try {
            TExternalCompactionJob job = rcf.getFuture().get();
            if (null != job && null != job.getExternalCompactionId()) {
                var compactorAddress = getHostPortString(rcf.getCompactor());
                results.add(new RunningCompaction(job, compactorAddress, rcf.getQueue()));
            }
        } catch (InterruptedException | ExecutionException e) {
            throw new RuntimeException(e);
        }
    });
    return results;
}
Also used : ArrayList(java.util.ArrayList) ExecutorService(java.util.concurrent.ExecutorService) TExternalCompactionJob(org.apache.accumulo.core.tabletserver.thrift.TExternalCompactionJob) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with TExternalCompactionJob

use of org.apache.accumulo.core.tabletserver.thrift.TExternalCompactionJob in project accumulo by apache.

the class CompactorTest method testCompactionSucceeds.

@Test
public void testCompactionSucceeds() throws Exception {
    UUID uuid = UUID.randomUUID();
    Supplier<UUID> supplier = () -> uuid;
    ExternalCompactionId eci = ExternalCompactionId.generate(supplier.get());
    PowerMock.resetAll();
    PowerMock.suppress(PowerMock.methods(Halt.class, "halt"));
    PowerMock.suppress(PowerMock.constructor(AbstractServer.class));
    ServerAddress client = PowerMock.createNiceMock(ServerAddress.class);
    HostAndPort address = HostAndPort.fromString("localhost:10240");
    EasyMock.expect(client.getAddress()).andReturn(address);
    TExternalCompactionJob job = PowerMock.createNiceMock(TExternalCompactionJob.class);
    TKeyExtent extent = PowerMock.createNiceMock(TKeyExtent.class);
    EasyMock.expect(job.isSetExternalCompactionId()).andReturn(true).anyTimes();
    EasyMock.expect(job.getExternalCompactionId()).andReturn(eci.toString()).anyTimes();
    EasyMock.expect(job.getExtent()).andReturn(extent).anyTimes();
    EasyMock.expect(extent.getTable()).andReturn("testTable".getBytes()).anyTimes();
    AccumuloConfiguration conf = PowerMock.createNiceMock(AccumuloConfiguration.class);
    EasyMock.expect(conf.getTimeInMillis(Property.INSTANCE_ZK_TIMEOUT)).andReturn(86400000L);
    ServerContext context = PowerMock.createNiceMock(ServerContext.class);
    EasyMock.expect(context.getConfiguration()).andReturn(conf);
    ZooReaderWriter zrw = PowerMock.createNiceMock(ZooReaderWriter.class);
    ZooKeeper zk = PowerMock.createNiceMock(ZooKeeper.class);
    EasyMock.expect(context.getZooReaderWriter()).andReturn(zrw).anyTimes();
    EasyMock.expect(zrw.getZooKeeper()).andReturn(zk).anyTimes();
    VolumeManagerImpl vm = PowerMock.createNiceMock(VolumeManagerImpl.class);
    EasyMock.expect(context.getVolumeManager()).andReturn(vm);
    vm.close();
    PowerMock.replayAll();
    SuccessfulCompactor c = new SuccessfulCompactor(supplier, client, job, conf, context, eci);
    c.run();
    PowerMock.verifyAll();
    c.close();
    assertTrue(c.isCompletedCalled());
    assertFalse(c.isFailedCalled());
}
Also used : Halt(org.apache.accumulo.core.util.Halt) ExternalCompactionId(org.apache.accumulo.core.metadata.schema.ExternalCompactionId) ServerAddress(org.apache.accumulo.server.rpc.ServerAddress) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) VolumeManagerImpl(org.apache.accumulo.server.fs.VolumeManagerImpl) TKeyExtent(org.apache.accumulo.core.dataImpl.thrift.TKeyExtent) HostAndPort(org.apache.accumulo.core.util.HostAndPort) AbstractServer(org.apache.accumulo.server.AbstractServer) ZooKeeper(org.apache.zookeeper.ZooKeeper) ServerContext(org.apache.accumulo.server.ServerContext) UUID(java.util.UUID) TExternalCompactionJob(org.apache.accumulo.core.tabletserver.thrift.TExternalCompactionJob) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with TExternalCompactionJob

use of org.apache.accumulo.core.tabletserver.thrift.TExternalCompactionJob 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 5 with TExternalCompactionJob

use of org.apache.accumulo.core.tabletserver.thrift.TExternalCompactionJob in project accumulo by apache.

the class ThriftClientHandler method reserveCompactionJob.

@Override
public TExternalCompactionJob reserveCompactionJob(TInfo tinfo, TCredentials credentials, String queueName, long priority, String compactor, String externalCompactionId) throws ThriftSecurityException, TException {
    if (!security.canPerformSystemActions(credentials)) {
        throw new AccumuloSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED).asThriftException();
    }
    ExternalCompactionId eci = ExternalCompactionId.of(externalCompactionId);
    var extCompaction = server.getCompactionManager().reserveExternalCompaction(queueName, priority, compactor, eci);
    if (extCompaction != null) {
        return extCompaction.toThrift();
    }
    return new TExternalCompactionJob();
}
Also used : ExternalCompactionId(org.apache.accumulo.core.metadata.schema.ExternalCompactionId) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TExternalCompactionJob(org.apache.accumulo.core.tabletserver.thrift.TExternalCompactionJob)

Aggregations

TExternalCompactionJob (org.apache.accumulo.core.tabletserver.thrift.TExternalCompactionJob)13 ExternalCompactionId (org.apache.accumulo.core.metadata.schema.ExternalCompactionId)7 HostAndPort (org.apache.accumulo.core.util.HostAndPort)7 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)6 AbstractServer (org.apache.accumulo.server.AbstractServer)6 ServerContext (org.apache.accumulo.server.ServerContext)6 ServerAddress (org.apache.accumulo.server.rpc.ServerAddress)6 Test (org.junit.Test)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 TKeyExtent (org.apache.accumulo.core.dataImpl.thrift.TKeyExtent)4 TabletClientService (org.apache.accumulo.core.tabletserver.thrift.TabletClientService)4 ArrayList (java.util.ArrayList)3 UUID (java.util.UUID)3 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)3 TServerInstance (org.apache.accumulo.core.metadata.TServerInstance)3 TCredentials (org.apache.accumulo.core.securityImpl.thrift.TCredentials)3 Client (org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Client)3 Halt (org.apache.accumulo.core.util.Halt)3 RunningCompaction (org.apache.accumulo.core.util.compaction.RunningCompaction)3 ZooReaderWriter (org.apache.accumulo.fate.zookeeper.ZooReaderWriter)3