Search in sources :

Example 11 with UncheckedInterruptedException

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

the class FBUtilities method exec.

/**
 * Starts and waits for the given @param pb to finish.
 * @throws java.io.IOException on non-zero exit code
 */
public static void exec(ProcessBuilder pb) throws IOException {
    Process p = pb.start();
    try {
        int errCode = p.waitFor();
        if (errCode != 0) {
            try (BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
                BufferedReader err = new BufferedReader(new InputStreamReader(p.getErrorStream()))) {
                String lineSep = LINE_SEPARATOR.getString();
                StringBuilder sb = new StringBuilder();
                String str;
                while ((str = in.readLine()) != null) sb.append(str).append(lineSep);
                while ((str = err.readLine()) != null) sb.append(str).append(lineSep);
                throw new IOException("Exception while executing the command: " + StringUtils.join(pb.command(), " ") + ", command error Code: " + errCode + ", command output: " + sb.toString());
            }
        }
    } catch (InterruptedException e) {
        throw new UncheckedInterruptedException(e);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException) IOException(java.io.IOException) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException)

Example 12 with UncheckedInterruptedException

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

the class JVMStabilityInspector method inspectThrowable.

public static void inspectThrowable(Throwable t, Consumer<Throwable> fn) throws OutOfMemoryError {
    boolean isUnstable = false;
    if (t instanceof OutOfMemoryError) {
        if (Boolean.getBoolean("cassandra.printHeapHistogramOnOutOfMemoryError")) {
            // time span.
            synchronized (lock) {
                if (printingHeapHistogram)
                    return;
                printingHeapHistogram = true;
            }
            HeapUtils.logHeapHistogram();
        }
        logger.error("OutOfMemory error letting the JVM handle the error:", t);
        StorageService.instance.removeShutdownHook();
        forceHeapSpaceOomMaybe((OutOfMemoryError) t);
        // the JVM behavior in case of OOM (CASSANDRA-13006).
        throw (OutOfMemoryError) t;
    } else if (t instanceof UnrecoverableIllegalStateException) {
        isUnstable = true;
    }
    if (t instanceof InterruptedException)
        throw new UncheckedInterruptedException((InterruptedException) t);
    if (DatabaseDescriptor.getDiskFailurePolicy() == Config.DiskFailurePolicy.die)
        if (t instanceof FSError || t instanceof CorruptSSTableException)
            isUnstable = true;
    // Check for file handle exhaustion
    if (t instanceof FileNotFoundException || t instanceof FileSystemException || t instanceof SocketException)
        if (t.getMessage() != null && t.getMessage().contains("Too many open files"))
            isUnstable = true;
    if (isUnstable) {
        if (!StorageService.instance.isDaemonSetupCompleted())
            FileUtils.handleStartupFSError(t);
        killer.killCurrentJVM(t);
    }
    try {
        fn.accept(t);
    } catch (Exception | Error e) {
        logger.warn("Unexpected error while handling unexpected error", e);
    }
    if (t.getCause() != null)
        inspectThrowable(t.getCause(), fn);
}
Also used : SocketException(java.net.SocketException) FSError(org.apache.cassandra.io.FSError) FileNotFoundException(java.io.FileNotFoundException) FSError(org.apache.cassandra.io.FSError) UnrecoverableIllegalStateException(org.apache.cassandra.exceptions.UnrecoverableIllegalStateException) CorruptSSTableException(org.apache.cassandra.io.sstable.CorruptSSTableException) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException) SocketException(java.net.SocketException) UnrecoverableIllegalStateException(org.apache.cassandra.exceptions.UnrecoverableIllegalStateException) FileSystemException(java.nio.file.FileSystemException) FileNotFoundException(java.io.FileNotFoundException) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException) CorruptSSTableException(org.apache.cassandra.io.sstable.CorruptSSTableException) FileSystemException(java.nio.file.FileSystemException) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException)

Example 13 with UncheckedInterruptedException

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

the class AbstractWriteResponseHandler method get.

public void get() throws WriteTimeoutException, WriteFailureException {
    long timeoutNanos = currentTimeoutNanos();
    boolean success;
    try {
        success = condition.await(timeoutNanos, NANOSECONDS);
    } catch (InterruptedException e) {
        throw new UncheckedInterruptedException(e);
    }
    if (!success) {
        int blockedFor = blockFor();
        int acks = ackCount();
        // avoid sending confusing info to the user (see CASSANDRA-6491).
        if (acks >= blockedFor)
            acks = blockedFor - 1;
        throw new WriteTimeoutException(writeType, replicaPlan.consistencyLevel(), acks, blockedFor);
    }
    if (blockFor() + failures > candidateReplicaCount()) {
        throw new WriteFailureException(replicaPlan.consistencyLevel(), ackCount(), blockFor(), writeType, failureReasonByEndpoint);
    }
}
Also used : WriteTimeoutException(org.apache.cassandra.exceptions.WriteTimeoutException) WriteFailureException(org.apache.cassandra.exceptions.WriteFailureException) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException)

Example 14 with UncheckedInterruptedException

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

the class SimpleClient method execute.

public Map<Message.Request, Message.Response> execute(List<Message.Request> requests) {
    try {
        Map<Message.Request, Message.Response> rrMap = new HashMap<>();
        if (version.isGreaterOrEqualTo(ProtocolVersion.V5)) {
            for (int i = 0; i < requests.size(); i++) {
                Message.Request message = requests.get(i);
                message.setStreamId(i);
                message.attach(connection);
            }
            lastWriteFuture = channel.writeAndFlush(requests);
            long deadline = currentTimeMillis() + TimeUnit.SECONDS.toMillis(TIMEOUT_SECONDS);
            for (int i = 0; i < requests.size(); i++) {
                Message.Response msg = responseHandler.responses.poll(deadline - currentTimeMillis(), TimeUnit.MILLISECONDS);
                if (msg == null)
                    throw new RuntimeException("timeout");
                if (msg instanceof ErrorMessage)
                    throw new RuntimeException((Throwable) ((ErrorMessage) msg).error);
                rrMap.put(requests.get(msg.getStreamId()), msg);
            }
        } else {
            // V4 doesn't support batching
            for (Message.Request request : requests) rrMap.put(request, execute(request));
        }
        return rrMap;
    } catch (InterruptedException e) {
        throw new UncheckedInterruptedException(e);
    }
}
Also used : UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException)

Example 15 with UncheckedInterruptedException

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

the class FBUtilities method waitOnFirstFuture.

/**
 * Only wait for the first future to finish from a list of futures. Will block until at least 1 future finishes.
 * @param futures The futures to wait on
 * @return future that completed.
 */
public static <T, F extends Future<? extends T>> F waitOnFirstFuture(Iterable<? extends F> futures, long delay) {
    while (true) {
        Iterator<? extends F> iter = futures.iterator();
        if (!iter.hasNext())
            throw new IllegalArgumentException();
        while (true) {
            F f = iter.next();
            boolean isDone;
            if ((isDone = f.isDone()) || !iter.hasNext()) {
                try {
                    f.get(delay, TimeUnit.MILLISECONDS);
                } catch (InterruptedException e) {
                    throw new UncheckedInterruptedException(e);
                } catch (ExecutionException e) {
                    throw new RuntimeException(e);
                } catch (TimeoutException e) {
                    if (// prevent infinite loops on bad implementations (not encountered)
                    !isDone)
                        break;
                }
                return f;
            }
        }
    }
}
Also used : UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException) ExecutionException(java.util.concurrent.ExecutionException) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException) TimeoutException(java.util.concurrent.TimeoutException)

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