/** * @return a regular (non-IOException) version of this exception */ public JournalClosedException toJournalClosedException() { return new JournalClosedException(getMessage()); } }
/** * @return an IOException version of this exception */ public IOJournalClosedException toIOException() { return new IOJournalClosedException(getMessage()); }
private void checkJournalWriterOpen() throws IOJournalClosedException { if (mClosed) { throw new JournalClosedException("Journal writer is closed").toIOException(); } } }
/** * Waits for the flush counter to be flushed to the journal. If the counter is * {@link #INVALID_FLUSH_COUNTER}, this is a noop. */ private void waitForJournalFlush() throws UnavailableException { if (mFlushCounter == INVALID_FLUSH_COUNTER) { // Check this before the precondition. return; } RetryPolicy retry = new TimeoutRetry(FLUSH_RETRY_TIMEOUT_MS, FLUSH_RETRY_INTERVAL_MS); while (retry.attempt()) { try { mAsyncJournalWriter.flush(mFlushCounter); return; } catch (IOException e) { LOG.warn("Journal flush failed. retrying...", e); } catch (JournalClosedException e) { throw new UnavailableException(String.format("Failed to complete request: %s", e.getMessage()), e); } catch (Throwable e) { ProcessUtils.fatalError(LOG, e, "Journal flush failed"); } } ProcessUtils.fatalError(LOG, "Journal flush failed after %d attempts", retry.getAttemptCount()); }
@Override public void flush() throws IOException, JournalClosedException { if (mClosed) { throw new JournalClosedException("Cannot flush. Journal writer has been closed"); } if (mJournalEntryBuilder != null) { long flushSN = mNextSequenceNumberToWrite.get() - 1; try { // It is ok to submit the same entries multiple times because we de-duplicate by sequence // number when applying them. This could happen if submit fails and we re-submit the same // entry on retry. mLastSubmittedSequenceNumber.set(flushSN); mClient.submit(new JournalEntryCommand(mJournalEntryBuilder.build())).get(FLUSH_TIMEOUT_S, TimeUnit.SECONDS); mLastCommittedSequenceNumber.set(flushSN); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IOException(e); } catch (ExecutionException e) { throw new IOException(e.getCause()); } catch (TimeoutException e) { throw new IOException( String.format("Timed out after waiting %s seconds for journal flush", FLUSH_TIMEOUT_S), e); } mJournalEntryBuilder = null; } }
private void checkJournalWriterOpen() throws IOJournalClosedException { if (mClosed) { throw new JournalClosedException("Journal writer is closed").toIOException(); } } }
/** * @return an IOException version of this exception */ public IOJournalClosedException toIOException() { return new IOJournalClosedException(getMessage()); }
@Override public void write(JournalEntry entry) throws JournalClosedException { if (mClosed) { throw new JournalClosedException("Cannot write to journal. Journal writer has been closed"); } Preconditions.checkState(entry.getAllFields().size() <= 1, "Raft journal entries should never set multiple fields, but found %s", entry); if (mJournalEntryBuilder == null) { mJournalEntryBuilder = JournalEntry.newBuilder(); } mJournalEntryBuilder.addJournalEntries(entry.toBuilder() .setSequenceNumber(mNextSequenceNumberToWrite.getAndIncrement()).build()); }
/** * Waits for the flush counter to be flushed to the journal. If the counter is * {@link #INVALID_FLUSH_COUNTER}, this is a noop. */ private void waitForJournalFlush() throws UnavailableException { if (mFlushCounter == INVALID_FLUSH_COUNTER) { // Check this before the precondition. return; } RetryPolicy retry = new TimeoutRetry(FLUSH_RETRY_TIMEOUT_MS, FLUSH_RETRY_INTERVAL_MS); while (retry.attempt()) { try { mAsyncJournalWriter.flush(mFlushCounter); return; } catch (IOException e) { LOG.warn("Journal flush failed. retrying...", e); } catch (JournalClosedException e) { throw new UnavailableException(String.format("Failed to complete request: %s", e.getMessage()), e); } catch (Throwable e) { ProcessUtils.fatalError(LOG, e, "Journal flush failed"); } } ProcessUtils.fatalError(LOG, "Journal flush failed after %d attempts", retry.getAttemptCount()); }
/** * @return a regular (non-IOException) version of this exception */ public JournalClosedException toJournalClosedException() { return new JournalClosedException(getMessage()); } }