Search in sources :

Example 21 with ClosedByInterruptException

use of java.nio.channels.ClosedByInterruptException in project neo4j by neo4j.

the class TransactionLogsRecovery method init.

@Override
public void init() throws Exception {
    RecoveryStartInformation recoveryStartInformation = recoveryService.getRecoveryStartInformation();
    if (!recoveryStartInformation.isRecoveryRequired()) {
        schemaLife.init();
        return;
    }
    Stopwatch recoveryStartTime = Stopwatch.start();
    LogPosition recoveryStartPosition = recoveryStartInformation.getTransactionLogPosition();
    monitor.recoveryRequired(recoveryStartPosition);
    LogPosition recoveryToPosition = recoveryStartPosition;
    LogPosition lastTransactionPosition = recoveryStartPosition;
    CommittedTransactionRepresentation lastTransaction = null;
    CommittedTransactionRepresentation lastReversedTransaction = null;
    if (!recoveryStartInformation.isMissingLogs()) {
        try {
            long lowestRecoveredTxId = TransactionIdStore.BASE_TX_ID;
            try (var transactionsToRecover = recoveryService.getTransactionsInReverseOrder(recoveryStartPosition);
                var recoveryVisitor = recoveryService.getRecoveryApplier(REVERSE_RECOVERY, pageCacheTracer, REVERSE_RECOVERY_TAG)) {
                while (transactionsToRecover.next()) {
                    recoveryStartupChecker.checkIfCanceled();
                    CommittedTransactionRepresentation transaction = transactionsToRecover.get();
                    if (lastReversedTransaction == null) {
                        lastReversedTransaction = transaction;
                        initProgressReporter(recoveryStartInformation, lastReversedTransaction);
                    }
                    recoveryVisitor.visit(transaction);
                    lowestRecoveredTxId = transaction.getCommitEntry().getTxId();
                    reportProgress();
                }
            }
            monitor.reverseStoreRecoveryCompleted(lowestRecoveredTxId);
            // We cannot initialise the schema (tokens, schema cache, indexing service, etc.) until we have returned the store to a consistent state.
            // We need to be able to read the store before we can even figure out what indexes, tokens, etc. we have. Hence we defer the initialisation
            // of the schema life until after we've done the reverse recovery.
            schemaLife.init();
            try (var transactionsToRecover = recoveryService.getTransactions(recoveryStartPosition);
                var recoveryVisitor = recoveryService.getRecoveryApplier(RECOVERY, pageCacheTracer, RECOVERY_TAG)) {
                while (transactionsToRecover.next()) {
                    recoveryStartupChecker.checkIfCanceled();
                    lastTransaction = transactionsToRecover.get();
                    long txId = lastTransaction.getCommitEntry().getTxId();
                    recoveryVisitor.visit(lastTransaction);
                    monitor.transactionRecovered(txId);
                    numberOfRecoveredTransactions++;
                    lastTransactionPosition = transactionsToRecover.position();
                    recoveryToPosition = lastTransactionPosition;
                    reportProgress();
                }
                recoveryToPosition = transactionsToRecover.position();
            }
        } catch (Error | ClosedByInterruptException | DatabaseStartAbortedException e) {
            // the users are able to workaround this if truncations is really needed.
            throw e;
        } catch (Throwable t) {
            if (failOnCorruptedLogFiles) {
                throwUnableToCleanRecover(t);
            }
            if (lastTransaction != null) {
                LogEntryCommit commitEntry = lastTransaction.getCommitEntry();
                monitor.failToRecoverTransactionsAfterCommit(t, commitEntry, recoveryToPosition);
            } else {
                monitor.failToRecoverTransactionsAfterPosition(t, recoveryStartPosition);
            }
        }
        progressReporter.completed();
        logsTruncator.truncate(recoveryToPosition);
    }
    try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer(RECOVERY_COMPLETED_TAG))) {
        final boolean missingLogs = recoveryStartInformation.isMissingLogs();
        recoveryService.transactionsRecovered(lastTransaction, lastTransactionPosition, recoveryToPosition, recoveryStartInformation.getCheckpointPosition(), missingLogs, cursorContext);
    }
    monitor.recoveryCompleted(numberOfRecoveredTransactions, recoveryStartTime.elapsed(MILLISECONDS));
}
Also used : CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) DatabaseStartAbortedException(org.neo4j.dbms.database.DatabaseStartAbortedException) Stopwatch(org.neo4j.time.Stopwatch) CursorContext(org.neo4j.io.pagecache.context.CursorContext) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 22 with ClosedByInterruptException

use of java.nio.channels.ClosedByInterruptException in project claw-compiler by C2SM-RCM.

the class GMakeJobServerConnection method getSlot.

public boolean getSlot() throws Exception {
    if (pipeRd == null) {
        throw new Exception("Connection to GNU Make server not established");
    }
    Callable<Byte> task = new Callable<Byte>() {

        @Override
        public Byte call() throws Exception {
            try {
                ByteBuffer buf = ByteBuffer.allocate(1);
                final int numReadBytes = pipeRd.getChannel().read(buf);
                return buf.array()[0];
            } catch (ClosedByInterruptException e) {
                return null;
            } catch (Exception e) {
                return null;
            }
        }
    };
    Byte slot = null;
    try {
        slot = exec.invokeAll(Arrays.asList(task), TIMEOUT, TimeUnit.MILLISECONDS).get(0).get();
    } catch (CancellationException e) {
    }
    if (slot != null) {
        jobSlots.add(slot);
    }
    return slot != null;
}
Also used : ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) CancellationException(java.util.concurrent.CancellationException) ByteBuffer(java.nio.ByteBuffer) CancellationException(java.util.concurrent.CancellationException) IOException(java.io.IOException) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) Callable(java.util.concurrent.Callable)

Example 23 with ClosedByInterruptException

use of java.nio.channels.ClosedByInterruptException in project helios by spotify.

the class TaskHistoryWriter method add.

private void add(TaskStatusEvent item) throws InterruptedException {
    // If too many "globally", toss them
    while (count.get() >= MAX_TOTAL_SIZE) {
        getNext();
    }
    final JobId key = item.getStatus().getJob().getId();
    final Deque<TaskStatusEvent> deque = getDeque(key);
    synchronized (deque) {
        // if too many in the particular deque, toss them
        while (deque.size() >= MAX_QUEUE_SIZE) {
            deque.remove();
            count.decrementAndGet();
        }
        deque.add(item);
        count.incrementAndGet();
    }
    try {
        backingStore.set(items);
    } catch (ClosedByInterruptException e) {
        log.debug("Writing task status event to backing store was interrupted");
    } catch (IOException e) {
        // We are best effort after all...
        log.warn("Failed to write task status event to backing store", e);
    }
}
Also used : ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) TaskStatusEvent(com.spotify.helios.common.descriptors.TaskStatusEvent) IOException(java.io.IOException) JobId(com.spotify.helios.common.descriptors.JobId)

Example 24 with ClosedByInterruptException

use of java.nio.channels.ClosedByInterruptException in project jimfs by google.

the class JimfsFileChannelTest method assertClosedByInterrupt.

/**
 * Asserts that when the given operation is run on an interrupted thread, {@code
 * ClosedByInterruptException} is thrown, the channel is closed and the thread is no longer
 * interrupted.
 */
private static void assertClosedByInterrupt(FileChannelMethod method) throws IOException {
    FileChannel channel = channel(regularFile(10), READ, WRITE);
    Thread.currentThread().interrupt();
    try {
        method.call(channel);
        fail("expected the method to throw ClosedByInterruptException or " + "FileLockInterruptionException");
    } catch (ClosedByInterruptException | FileLockInterruptionException expected) {
        assertFalse("expected the channel to be closed", channel.isOpen());
        assertTrue("expected the thread to still be interrupted", Thread.interrupted());
    } finally {
        // ensure the thread isn't interrupted when this method returns
        Thread.interrupted();
    }
}
Also used : ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) FileLockInterruptionException(java.nio.channels.FileLockInterruptionException) FileChannel(java.nio.channels.FileChannel)

Example 25 with ClosedByInterruptException

use of java.nio.channels.ClosedByInterruptException in project j2objc by google.

the class OldServerSocketChannelTest method test_accept_Block_NoConnect_interrupt.

public void test_accept_Block_NoConnect_interrupt() throws IOException {
    assertTrue(this.serverChannel.isBlocking());
    ServerSocket gotSocket = this.serverChannel.socket();
    gotSocket.bind(null);
    class MyThread extends Thread {

        public String errMsg = null;

        public void run() {
            try {
                serverChannel.accept();
                errMsg = "should throw ClosedByInterruptException";
            } catch (ClosedByInterruptException e) {
            // expected
            } catch (Exception e) {
                errMsg = "caught wrong Exception: " + e.getClass() + ": " + e.getMessage();
            }
        }
    }
    MyThread thread = new MyThread();
    thread.start();
    try {
        Thread.currentThread().sleep(TIME_UNIT);
        thread.interrupt();
    } catch (InterruptedException e) {
        fail("Should not throw a InterruptedException");
    }
    if (thread.errMsg != null) {
        fail(thread.errMsg);
    }
}
Also used : ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) ServerSocket(java.net.ServerSocket) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) IOException(java.io.IOException)

Aggregations

ClosedByInterruptException (java.nio.channels.ClosedByInterruptException)79 IOException (java.io.IOException)48 ByteBuffer (java.nio.ByteBuffer)15 ClosedChannelException (java.nio.channels.ClosedChannelException)11 SocketTimeoutException (java.net.SocketTimeoutException)9 InetSocketAddress (java.net.InetSocketAddress)7 MappedByteBuffer (java.nio.MappedByteBuffer)7 SocketChannel (java.nio.channels.SocketChannel)7 File (java.io.File)6 ServerSocketChannel (java.nio.channels.ServerSocketChannel)6 ServerSocket (java.net.ServerSocket)5 FileChannel (java.nio.channels.FileChannel)5 FileLockInterruptionException (java.nio.channels.FileLockInterruptionException)5 InterruptedIOException (java.io.InterruptedIOException)4 Path (java.nio.file.Path)4 Test (org.junit.Test)4 BuildId (com.facebook.buck.model.BuildId)3 FileNotFoundException (java.io.FileNotFoundException)3 InputStream (java.io.InputStream)3 SocketException (java.net.SocketException)3