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;
}
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);
}
}
}
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);
}
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);
}
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);
}
}
Aggregations