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