Search in sources :

Example 26 with UncheckedInterruptedException

use of org.apache.cassandra.utils.concurrent.UncheckedInterruptedException in project cassandra by apache.

the class HintsDispatchExecutor method shutdownBlocking.

/*
     * It's safe to terminate dispatch in process and to deschedule dispatch.
     */
void shutdownBlocking() {
    scheduledDispatches.clear();
    executor.shutdownNow();
    try {
        executor.awaitTermination(1, TimeUnit.MINUTES);
    } catch (InterruptedException e) {
        throw new UncheckedInterruptedException(e);
    }
}
Also used : UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException)

Example 27 with UncheckedInterruptedException

use of org.apache.cassandra.utils.concurrent.UncheckedInterruptedException in project cassandra by apache.

the class HintsService method transferHints.

/**
 * Transfer all local hints to the hostId supplied by hostIdSupplier
 *
 * Flushes the buffer to make sure all hints are on disk and closes the hint writers
 * so we don't leave any hint files around.
 *
 * After that, we serially dispatch all the hints in the HintsCatalog.
 *
 * If we fail delivering all hints, we will ask the hostIdSupplier for a new target host
 * and retry delivering any remaining hints there, once, with a delay of 10 seconds before retrying.
 *
 * @param hostIdSupplier supplier of stream target host ids. This is generally
 *                       the closest one according to the DynamicSnitch
 * @return When this future is done, it either has streamed all hints to remote nodes or has failed with a proper
 *         log message
 */
public Future transferHints(Supplier<UUID> hostIdSupplier) {
    Future flushFuture = writeExecutor.flushBufferPool(bufferPool);
    Future closeFuture = writeExecutor.closeAllWriters();
    try {
        flushFuture.get();
        closeFuture.get();
    } catch (InterruptedException e) {
        throw new UncheckedInterruptedException(e);
    } catch (ExecutionException e) {
        throw new RuntimeException(e);
    }
    // unpause dispatch, or else transfer() will return immediately
    resumeDispatch();
    // wait for the current dispatch session to end
    catalog.stores().forEach(dispatchExecutor::completeDispatchBlockingly);
    return dispatchExecutor.transfer(catalog, hostIdSupplier);
}
Also used : ScheduledFuture(java.util.concurrent.ScheduledFuture) Future(org.apache.cassandra.utils.concurrent.Future) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException) ExecutionException(java.util.concurrent.ExecutionException) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException)

Example 28 with UncheckedInterruptedException

use of org.apache.cassandra.utils.concurrent.UncheckedInterruptedException in project cassandra by apache.

the class SimpleClient method execute.

public Message.Response execute(Message.Request request, boolean throwOnErrorResponse) {
    try {
        request.attach(connection);
        lastWriteFuture = channel.writeAndFlush(Collections.singletonList(request));
        Message.Response msg = responseHandler.responses.poll(TIMEOUT_SECONDS, TimeUnit.SECONDS);
        if (msg == null)
            throw new RuntimeException("timeout");
        if (throwOnErrorResponse && msg instanceof ErrorMessage)
            throw new RuntimeException((Throwable) ((ErrorMessage) msg).error);
        return msg;
    } catch (InterruptedException e) {
        throw new UncheckedInterruptedException(e);
    }
}
Also used : UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException)

Aggregations

UncheckedInterruptedException (org.apache.cassandra.utils.concurrent.UncheckedInterruptedException)28 ExecutionException (java.util.concurrent.ExecutionException)9 TimeoutException (java.util.concurrent.TimeoutException)4 WriteTimeoutException (org.apache.cassandra.exceptions.WriteTimeoutException)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 IOException (java.io.IOException)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 ScheduledFuture (java.util.concurrent.ScheduledFuture)2 WriteFailureException (org.apache.cassandra.exceptions.WriteFailureException)2 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)2 Preconditions (com.google.common.base.Preconditions)1 CacheLoader (com.google.common.cache.CacheLoader)1 Iterables (com.google.common.collect.Iterables)1 Iterables.concat (com.google.common.collect.Iterables.concat)1 Ints (com.google.common.primitives.Ints)1 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)1 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 IOError (java.io.IOError)1 InputStreamReader (java.io.InputStreamReader)1