Search in sources :

Example 76 with ClosedByInterruptException

use of java.nio.channels.ClosedByInterruptException in project hbase by apache.

the class ExceptionUtil method asInterrupt.

/**
 * @return an InterruptedIOException if t was an interruption, null otherwise
 */
public static InterruptedIOException asInterrupt(Throwable t) {
    if (t instanceof SocketTimeoutException) {
        return null;
    }
    if (t instanceof InterruptedIOException) {
        return (InterruptedIOException) t;
    }
    if (t instanceof InterruptedException || t instanceof ClosedByInterruptException) {
        InterruptedIOException iie = new InterruptedIOException("Origin: " + t.getClass().getSimpleName());
        iie.initCause(t);
        return iie;
    }
    return null;
}
Also used : ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) InterruptedIOException(java.io.InterruptedIOException) SocketTimeoutException(java.net.SocketTimeoutException)

Example 77 with ClosedByInterruptException

use of java.nio.channels.ClosedByInterruptException in project hbase by apache.

the class FileIOEngine method accessFile.

private void accessFile(FileAccessor accessor, ByteBuff buff, long globalOffset) throws IOException {
    int startFileNum = getFileNum(globalOffset);
    int remainingAccessDataLen = buff.remaining();
    int endFileNum = getFileNum(globalOffset + remainingAccessDataLen - 1);
    int accessFileNum = startFileNum;
    long accessOffset = getAbsoluteOffsetInFile(accessFileNum, globalOffset);
    int bufLimit = buff.limit();
    while (true) {
        FileChannel fileChannel = fileChannels[accessFileNum];
        int accessLen = 0;
        if (endFileNum > accessFileNum) {
            // short the limit;
            buff.limit((int) (buff.limit() - remainingAccessDataLen + sizePerFile - accessOffset));
        }
        try {
            accessLen = accessor.access(fileChannel, buff, accessOffset);
        } catch (ClosedByInterruptException e) {
            throw e;
        } catch (ClosedChannelException e) {
            refreshFileConnection(accessFileNum, e);
            continue;
        }
        // recover the limit
        buff.limit(bufLimit);
        if (accessLen < remainingAccessDataLen) {
            remainingAccessDataLen -= accessLen;
            accessFileNum++;
            accessOffset = 0;
        } else {
            break;
        }
        if (accessFileNum >= fileChannels.length) {
            throw new IOException("Required data len " + StringUtils.byteDesc(buff.remaining()) + " exceed the engine's capacity " + StringUtils.byteDesc(capacity) + " where offset=" + globalOffset);
        }
    }
}
Also used : ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) ClosedChannelException(java.nio.channels.ClosedChannelException) FileChannel(java.nio.channels.FileChannel) IllegalArgumentIOException(org.apache.hadoop.hbase.exceptions.IllegalArgumentIOException) IOException(java.io.IOException)

Example 78 with ClosedByInterruptException

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

the class DetachedLogTailScanner method getFirstTransactionIdAfterCheckpoint.

private StartCommitEntries getFirstTransactionIdAfterCheckpoint(LogFile logFile, LogPosition logPosition) throws IOException {
    boolean corruptedTransactionLogs = false;
    LogEntryStart start = null;
    LogEntryCommit commit = null;
    LogPosition lookupPosition = null;
    long logVersion = logPosition.getLogVersion();
    try {
        while (logFile.versionExists(logVersion)) {
            lookupPosition = lookupPosition == null ? logPosition : logFile.extractHeader(logVersion).getStartPosition();
            try (var reader = logFile.getReader(lookupPosition, NO_MORE_CHANNELS);
                var cursor = new LogEntryCursor(logEntryReader, reader)) {
                LogEntry entry;
                while ((start == null || commit == null) && cursor.next()) {
                    entry = cursor.get();
                    if (commit == null && entry instanceof LogEntryCommit) {
                        commit = (LogEntryCommit) entry;
                    } else if (start == null && entry instanceof LogEntryStart) {
                        start = (LogEntryStart) entry;
                    }
                }
            }
            if ((start != null) && (commit != null)) {
                return new StartCommitEntries(start, commit);
            }
            verifyReaderPosition(logVersion, logEntryReader.lastPosition());
            logVersion++;
        }
    } catch (Error | ClosedByInterruptException e) {
        // These should not be parsing errors
        throw e;
    } catch (Throwable t) {
        monitor.corruptedLogFile(logVersion, t);
        if (failOnCorruptedLogFiles) {
            throwUnableToCleanRecover(t);
        }
        corruptedTransactionLogs = true;
    }
    return new StartCommitEntries(start, commit, corruptedTransactionLogs);
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) LogEntryCursor(org.neo4j.kernel.impl.transaction.log.LogEntryCursor) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 79 with ClosedByInterruptException

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

the class InlinedLogTailScanner method findLogTail.

protected LogTailInformation findLogTail() throws IOException {
    LogFile logFile = logFiles.getLogFile();
    final long highestLogVersion = logFile.getHighestLogVersion();
    long version = highestLogVersion;
    long versionToSearchForCommits = highestLogVersion;
    LogEntryStart latestStartEntry = null;
    long oldestStartEntryTransaction = NO_TRANSACTION_ID;
    long oldestVersionFound = -1;
    byte latestLogEntryVersion = 0;
    boolean startRecordAfterCheckpoint = false;
    boolean corruptedTransactionLogs = false;
    while (version >= logFile.getLowestLogVersion() && version >= INITIAL_LOG_VERSION) {
        log.info("Scanning log file with version %d for checkpoint entries", version);
        oldestVersionFound = version;
        CheckpointInfo latestCheckPoint = null;
        StoreId storeId = StoreId.UNKNOWN;
        try (LogVersionedStoreChannel channel = logFile.openForVersion(version);
            var readAheadChannel = new ReadAheadLogChannel(channel, memoryTracker);
            LogEntryCursor cursor = new LogEntryCursor(logEntryReader, readAheadChannel)) {
            LogHeader logHeader = logFile.extractHeader(version);
            storeId = logHeader.getStoreId();
            LogEntry entry;
            long position = logHeader.getStartPosition().getByteOffset();
            long channelVersion = version;
            while (cursor.next()) {
                entry = cursor.get();
                // Collect data about latest checkpoint
                if (entry instanceof LogEntryInlinedCheckPoint) {
                    latestCheckPoint = new CheckpointInfo((LogEntryInlinedCheckPoint) entry, storeId, new LogPosition(channelVersion, position));
                } else if (entry instanceof LogEntryCommit) {
                    if (oldestStartEntryTransaction == NO_TRANSACTION_ID) {
                        oldestStartEntryTransaction = ((LogEntryCommit) entry).getTxId();
                    }
                } else if (entry instanceof LogEntryStart) {
                    LogEntryStart startEntry = (LogEntryStart) entry;
                    if (version == versionToSearchForCommits) {
                        latestStartEntry = startEntry;
                    }
                    startRecordAfterCheckpoint = true;
                }
                // Collect data about latest entry version, only in first log file
                if (version == versionToSearchForCommits || latestLogEntryVersion == 0) {
                    latestLogEntryVersion = entry.getVersion().version();
                }
                position = channel.position();
                channelVersion = channel.getVersion();
            }
            verifyReaderPosition(version, logEntryReader.lastPosition());
        } catch (Error | ClosedByInterruptException e) {
            // These should not be parsing errors
            throw e;
        } catch (Throwable t) {
            monitor.corruptedLogFile(version, t);
            if (failOnCorruptedLogFiles) {
                throwUnableToCleanRecover(t);
            }
            corruptedTransactionLogs = true;
        }
        if (latestCheckPoint != null) {
            return checkpointTailInformation(highestLogVersion, latestStartEntry, oldestVersionFound, latestLogEntryVersion, latestCheckPoint, corruptedTransactionLogs, storeId);
        }
        version--;
        // if we have found no commits in the latest log, keep searching in the next one
        if (latestStartEntry == null) {
            versionToSearchForCommits--;
        }
    }
    return new LogTailInformation(corruptedTransactionLogs || startRecordAfterCheckpoint, oldestStartEntryTransaction, oldestVersionFound == UNKNOWN, highestLogVersion, latestLogEntryVersion);
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) LogTailInformation(org.neo4j.kernel.impl.transaction.log.files.LogTailInformation) LogEntryCursor(org.neo4j.kernel.impl.transaction.log.LogEntryCursor) LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) StoreId(org.neo4j.storageengine.api.StoreId) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) LogEntryInlinedCheckPoint(org.neo4j.kernel.impl.transaction.log.entry.LogEntryInlinedCheckPoint) ReadAheadLogChannel(org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 80 with ClosedByInterruptException

use of java.nio.channels.ClosedByInterruptException in project aeron by real-logic.

the class RecordingWriter method onBlock.

/**
 * {@inheritDoc}
 */
public void onBlock(final DirectBuffer termBuffer, final int termOffset, final int length, final int sessionId, final int termId) {
    try {
        final boolean isPaddingFrame = termBuffer.getShort(typeOffset(termOffset)) == PADDING_FRAME_TYPE;
        final int dataLength = isPaddingFrame ? HEADER_LENGTH : length;
        final ByteBuffer byteBuffer;
        if (null == checksum || isPaddingFrame) {
            byteBuffer = termBuffer.byteBuffer();
            byteBuffer.limit(termOffset + dataLength).position(termOffset);
        } else {
            checksumBuffer.putBytes(0, termBuffer, termOffset, dataLength);
            computeChecksum(checksum, checksumBuffer, dataLength);
            byteBuffer = checksumBuffer.byteBuffer();
            byteBuffer.limit(dataLength).position(0);
        }
        int fileOffset = segmentOffset;
        do {
            fileOffset += recordingFileChannel.write(byteBuffer, fileOffset);
        } while (byteBuffer.remaining() > 0);
        if (forceWrites) {
            recordingFileChannel.force(forceMetadata);
        }
        segmentOffset += length;
        if (segmentOffset >= segmentLength) {
            onFileRollOver();
        }
    } catch (final ClosedByInterruptException ex) {
        close();
        throw new ArchiveException("file closed by interrupt, recording aborted", ex, ArchiveException.GENERIC);
    } catch (final IOException ex) {
        close();
        checkErrorType(ex, length);
    } catch (final Exception ex) {
        close();
        LangUtil.rethrowUnchecked(ex);
    }
}
Also used : ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) IOException(java.io.IOException) ArchiveException(io.aeron.archive.client.ArchiveException) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) ArchiveException(io.aeron.archive.client.ArchiveException)

Aggregations

ClosedByInterruptException (java.nio.channels.ClosedByInterruptException)81 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