JournalEntry entry = it.next().toBuilder().setSequenceNumber(snapshotSN).build();
@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()); }
public synchronized void write(JournalEntry entry) throws IOException, JournalClosedException { try { maybeRecoverFromUfsFailures(); maybeRotateLog(); } catch (IOJournalClosedException e) { throw e.toJournalClosedException(); } try { JournalEntry entryToWrite = entry.toBuilder().setSequenceNumber(mNextSequenceNumber).build(); entryToWrite.writeDelimitedTo(mJournalOutputStream); LOG.debug("Adding journal entry (seq={}) to retryList with {} entries.", entryToWrite.getSequenceNumber(), mEntriesToFlush.size()); mEntriesToFlush.add(entryToWrite); mNextSequenceNumber++; } catch (IOJournalClosedException e) { throw e.toJournalClosedException(); } catch (IOException e) { // Set mNeedsRecovery to true so that {@code maybeRecoverFromUfsFailures} // can know a UFS failure has occurred. mNeedsRecovery = true; throw new IOException(ExceptionMessage.JOURNAL_WRITE_FAILURE .getMessageWithUrl(RuntimeConstants.ALLUXIO_DEBUG_DOCS_URL, mJournalOutputStream.currentLog(), e.getMessage()), e); } }
if (entry.getSequenceNumber() > lastPersistSeq) { try { entry.toBuilder().build().writeDelimitedTo(mJournalOutputStream); retryEndSeq = entry.getSequenceNumber(); } catch (IOJournalClosedException e) {
public synchronized void write(JournalEntry entry) throws IOException, JournalClosedException { try { maybeRecoverFromUfsFailures(); maybeRotateLog(); } catch (IOJournalClosedException e) { throw e.toJournalClosedException(); } try { JournalEntry entryToWrite = entry.toBuilder().setSequenceNumber(mNextSequenceNumber).build(); entryToWrite.writeDelimitedTo(mJournalOutputStream); LOG.debug("Adding journal entry (seq={}) to retryList with {} entries.", entryToWrite.getSequenceNumber(), mEntriesToFlush.size()); mEntriesToFlush.add(entryToWrite); mNextSequenceNumber++; } catch (IOJournalClosedException e) { throw e.toJournalClosedException(); } catch (IOException e) { // Set mNeedsRecovery to true so that {@code maybeRecoverFromUfsFailures} // can know a UFS failure has occurred. mNeedsRecovery = true; throw new IOException(ExceptionMessage.JOURNAL_WRITE_FAILURE .getMessageWithUrl(RuntimeConstants.ALLUXIO_DEBUG_DOCS_URL, mJournalOutputStream.currentLog(), e.getMessage()), e); } }
/** * The given entry should not have its sequence number set. This method will add the proper * sequence number to the passed in entry. * * @param entry an entry to write to the journal checkpoint file */ @Override public synchronized void write(JournalEntry entry) throws IOException { if (mIsClosed) { throw new IOException(ExceptionMessage.JOURNAL_WRITE_AFTER_CLOSE.getMessage()); } if (mRotateLogForNextWrite) { rotateLog(); mRotateLogForNextWrite = false; } try { mJournalFormatter.serialize( entry.toBuilder().setSequenceNumber(mJournalWriter.getNextSequenceNumber()).build(), mDataOutputStream); } catch (IOException e) { mRotateLogForNextWrite = true; throw new IOException(ExceptionMessage.JOURNAL_WRITE_FAILURE.getMessageWithUrl( RuntimeConstants.ALLUXIO_DEBUG_DOCS_URL, mCurrentLog, e.getMessage()), e); } }
/** * Writes an entry to the checkpoint file. * * The entry should not have its sequence number set. This method will add the proper sequence * number to the passed in entry. * * @param entry an entry to write to the journal checkpoint file */ @Override public synchronized void write(JournalEntry entry) throws IOException { if (mIsClosed) { throw new IOException(ExceptionMessage.JOURNAL_WRITE_AFTER_CLOSE.getMessage()); } mJournal.getJournalFormatter().serialize( entry.toBuilder().setSequenceNumber(getNextSequenceNumber()).build(), mOutputStream); }
/** * Writes a backup to the specified stream. * * @param os the stream to write to */ public void backup(OutputStream os) throws IOException { int count = 0; GzipCompressorOutputStream zipStream = new GzipCompressorOutputStream(os); for (Master master : mRegistry.getServers()) { Iterator<JournalEntry> it = master.getJournalEntryIterator(); while (it.hasNext()) { it.next().toBuilder().clearSequenceNumber().build().writeDelimitedTo(zipStream); count++; } } // finish() instead of close() since close would close os, which is owned by the caller. zipStream.finish(); LOG.info("Created backup with {} entries", count); }
public void write(JournalEntry entry) throws IOException { if (mClosed) { throw new IOException(ExceptionMessage.JOURNAL_WRITE_AFTER_CLOSE.getMessage()); } try { entry.toBuilder().setSequenceNumber(mNextSequenceNumber).build() .writeDelimitedTo(mTmpCheckpointStream); } catch (IOException e) { throw e; } mNextSequenceNumber++; }
if (entry.getSequenceNumber() > lastPersistSeq) { try { entry.toBuilder().build().writeDelimitedTo(mJournalOutputStream); retryEndSeq = entry.getSequenceNumber(); } catch (IOJournalClosedException e) {
/** * Applies the journal entry, ignoring empty entries and expanding multi-entries. * * @param entry the entry to apply */ private void applyEntry(JournalEntry entry) { Preconditions.checkState( entry.getAllFields().size() <= 1 || (entry.getAllFields().size() == 2 && entry.hasSequenceNumber()), "Raft journal entries should never set multiple fields in addition to sequence " + "number, but found %s", entry); if (entry.getJournalEntriesCount() > 0) { // This entry aggregates multiple entries. for (JournalEntry e : entry.getJournalEntriesList()) { applyEntry(e); } } else if (entry.getSequenceNumber() < 0) { // Negative sequence numbers indicate special entries used to indicate that a new primary is // starting to serve. mLastPrimaryStartSequenceNumber = entry.getSequenceNumber(); } else if (entry.toBuilder().clearSequenceNumber().build() .equals(JournalEntry.getDefaultInstance())) { // Ignore empty entries, they are created during snapshotting. } else { applySingleEntry(entry); } }
/** * The given entry should not have its sequence number set. This method will add the proper * sequence number to the passed in entry. * * @param entry an entry to write to the journal checkpoint file */ @Override public synchronized void write(JournalEntry entry) throws IOException { if (mIsClosed) { throw new IOException(ExceptionMessage.JOURNAL_WRITE_AFTER_CLOSE.getMessage()); } if (mRotateLogForNextWrite) { rotateLog(); mRotateLogForNextWrite = false; } try { mJournalFormatter.serialize( entry.toBuilder().setSequenceNumber(mJournalWriter.getNextSequenceNumber()).build(), mDataOutputStream); } catch (IOException e) { mRotateLogForNextWrite = true; throw new IOException(ExceptionMessage.JOURNAL_WRITE_FAILURE.getMessageWithUrl( RuntimeConstants.ALLUXIO_DEBUG_DOCS_URL, mCurrentLog, e.getMessage()), e); } }
/** * Applies the journal entry, handling empty entries and multi-entries. * * @param entry the entry to apply */ private void applyEntry(JournalEntry entry) { Preconditions.checkState( entry.getAllFields().size() <= 1 || (entry.getAllFields().size() == 2 && entry.hasSequenceNumber()), "Raft journal entries should never set multiple fields in addition to sequence " + "number, but found %s", entry); if (entry.getJournalEntriesCount() > 0) { // This entry aggregates multiple entries. for (JournalEntry e : entry.getJournalEntriesList()) { applyEntry(e); } } else if (entry.toBuilder().clearSequenceNumber().build() .equals(JournalEntry.getDefaultInstance())) { // Ignore empty entries, they are created during snapshotting. } else { printEntry(entry); } }
/** * Writes a backup to the specified stream. * * @param os the stream to write to */ public void backup(OutputStream os) throws IOException { int count = 0; GzipCompressorOutputStream zipStream = new GzipCompressorOutputStream(os); for (Master master : mRegistry.getServers()) { Iterator<JournalEntry> it = master.getJournalEntryIterator(); while (it.hasNext()) { it.next().toBuilder().clearSequenceNumber().build().writeDelimitedTo(zipStream); count++; } } // finish() instead of close() since close would close os, which is owned by the caller. zipStream.finish(); LOG.info("Created backup with {} entries", count); }
/** * Writes an entry to the checkpoint file. * * The entry should not have its sequence number set. This method will add the proper sequence * number to the passed in entry. * * @param entry an entry to write to the journal checkpoint file */ @Override public synchronized void write(JournalEntry entry) throws IOException { if (mIsClosed) { throw new IOException(ExceptionMessage.JOURNAL_WRITE_AFTER_CLOSE.getMessage()); } mJournal.getJournalFormatter().serialize( entry.toBuilder().setSequenceNumber(getNextSequenceNumber()).build(), mOutputStream); }
public static Builder newBuilder() { return DEFAULT_INSTANCE.toBuilder(); } public static Builder newBuilder(alluxio.proto.journal.Journal.JournalEntry prototype) {
public void write(JournalEntry entry) throws IOException { if (mClosed) { throw new IOException(ExceptionMessage.JOURNAL_WRITE_AFTER_CLOSE.getMessage()); } try { entry.toBuilder().setSequenceNumber(mNextSequenceNumber).build() .writeDelimitedTo(mTmpCheckpointStream); } catch (IOException e) { throw e; } mNextSequenceNumber++; }
public static Builder newBuilder(alluxio.proto.journal.Journal.JournalEntry prototype) { return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); } public Builder toBuilder() {