Search in sources :

Example 1 with CancelFlagFuture

use of org.apache.accumulo.core.util.CancelFlagFuture in project accumulo by apache.

the class Gatherer method gather.

public Future<SummaryCollection> gather(ExecutorService es) {
    int numFiles;
    try {
        numFiles = countFiles();
    } catch (TableNotFoundException | AccumuloException | AccumuloSecurityException e) {
        throw new RuntimeException(e);
    }
    log.debug("Gathering summaries from {} files", numFiles);
    if (numFiles == 0) {
        return CompletableFuture.completedFuture(new SummaryCollection());
    }
    // have each tablet server process ~100K files
    int numRequest = Math.max(numFiles / 100_000, 1);
    List<CompletableFuture<SummaryCollection>> futures = new ArrayList<>();
    AtomicBoolean cancelFlag = new AtomicBoolean(false);
    TInfo tinfo = Tracer.traceInfo();
    for (int i = 0; i < numRequest; i++) {
        futures.add(CompletableFuture.supplyAsync(new GatherRequest(tinfo, i, numRequest, cancelFlag), es));
    }
    Future<SummaryCollection> future = CompletableFutureUtil.merge(futures, (sc1, sc2) -> SummaryCollection.merge(sc1, sc2, factory), SummaryCollection::new);
    return new CancelFlagFuture<>(future, cancelFlag);
}
Also used : TInfo(org.apache.accumulo.core.trace.thrift.TInfo) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ArrayList(java.util.ArrayList) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) CancelFlagFuture(org.apache.accumulo.core.util.CancelFlagFuture) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException)

Aggregations

ArrayList (java.util.ArrayList)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 TInfo (org.apache.accumulo.core.trace.thrift.TInfo)1 CancelFlagFuture (org.apache.accumulo.core.util.CancelFlagFuture)1