@Override public Iterator<JournalEntry> getJournalEntryIterator() { return mUfsModes.entrySet().stream() .map(e -> JournalEntry.newBuilder().setUpdateUfsMode(UpdateUfsModeEntry.newBuilder() .setUfsPath(e.getKey()) .setUfsMode(File.UfsMode.valueOf(e.getValue().name()))) .build()) .iterator(); } }
@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()); }
@Override public Journal.JournalEntry next() { if (!hasNext()) { throw new NoSuchElementException(); } long mountId = mEntry.getKey(); long txId = mEntry.getValue(); mEntry = null; File.ActiveSyncTxIdEntry txIdEntry = File.ActiveSyncTxIdEntry.newBuilder().setMountId(mountId) .setTxId(txId).build(); return Journal.JournalEntry.newBuilder().setActiveSyncTxId(txIdEntry).build(); }
@Override public void commitBlockInUFS(long blockId, long length) throws UnavailableException { LOG.debug("Commit block in ufs. blockId: {}, length: {}", blockId, length); try (JournalContext journalContext = createJournalContext(); LockResource lr = lockBlock(blockId)) { if (mBlockStore.getBlock(blockId).isPresent()) { // Block metadata already exists, so do not need to create a new one. return; } mBlockStore.putBlock(blockId, BlockMeta.newBuilder().setLength(length).build()); BlockInfoEntry blockInfo = BlockInfoEntry.newBuilder().setBlockId(blockId).setLength(length).build(); journalContext.append(JournalEntry.newBuilder().setBlockInfo(blockInfo).build()); } }
/** * Updates an inode's state. This is used for state common to both files and directories. * * @param context journal context supplier * @param entry update inode entry */ public void applyAndJournal(Supplier<JournalContext> context, UpdateInodeEntry entry) { try { apply(entry); context.get().append(JournalEntry.newBuilder().setUpdateInode(entry).build()); } catch (Throwable t) { ProcessUtils.fatalError(LOG, t, "Failed to apply %s", entry); throw t; // fatalError will usually system.exit } }
/** * Apply AddSyncPoint entry and journal the entry. * @param context journal context * @param entry addSyncPoint entry */ public void applyAndJournal(Supplier<JournalContext> context, AddSyncPointEntry entry) { try { apply(entry); context.get().append(Journal.JournalEntry.newBuilder().setAddSyncPoint(entry).build()); } catch (Throwable t) { ProcessUtils.fatalError(LOG, t, "Failed to apply %s", entry); throw t; // fatalError will usually system.exit } }
/** * Sets an ACL for an inode. * * @param context journal context supplier * @param entry set acl entry */ public void applyAndJournal(Supplier<JournalContext> context, SetAclEntry entry) { try { apply(entry); context.get().append(JournalEntry.newBuilder().setSetAcl(entry).build()); } catch (Throwable t) { ProcessUtils.fatalError(LOG, t, "Failed to apply %s", entry); throw t; // fatalError will usually system.exit } }
/** * Updates an inode directory's state. * * @param context journal context supplier * @param entry update inode directory entry */ public void applyAndJournal(Supplier<JournalContext> context, UpdateInodeDirectoryEntry entry) { try { apply(entry); context.get().append(JournalEntry.newBuilder().setUpdateInodeDirectory(entry).build()); } catch (Throwable t) { ProcessUtils.fatalError(LOG, t, "Failed to apply %s", entry); throw t; // fatalError will usually system.exit } }
/** * Apply removeSyncPoint entry and journal the entry. * @param context journal context * @param entry removeSyncPoint entry */ public void applyAndJournal(Supplier<JournalContext> context, RemoveSyncPointEntry entry) { try { apply(entry); context.get().append(Journal.JournalEntry.newBuilder().setRemoveSyncPoint(entry).build()); } catch (Throwable t) { ProcessUtils.fatalError(LOG, t, "Failed to apply %s", entry); throw t; // fatalError will usually system.exit } }
/** * @param context journal context * @param entry update ufs mode entry */ public void applyAndJournal(Supplier<JournalContext> context, UpdateUfsModeEntry entry) { apply(entry); context.get().append(JournalEntry.newBuilder().setUpdateUfsMode(entry).build()); }
public void applyAndJournal(Supplier<JournalContext> context, InodeDirectoryIdGeneratorEntry entry) { apply(entry); context.get().append(JournalEntry.newBuilder().setInodeDirectoryIdGenerator(entry).build()); }
/** * Creates a dummy journal entry with the given sequence number. * * @param sequenceNumber the sequence number * @return the journal entry */ private Journal.JournalEntry newEntry(long sequenceNumber) { return Journal.JournalEntry.newBuilder().setSequenceNumber(sequenceNumber).build(); } }
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++; }
/** * Creates a dummy journal entry with the given sequence number. * * @param sequenceNumber the sequence number * @return the journal entry */ private Journal.JournalEntry newEntry(long sequenceNumber) { return Journal.JournalEntry.newBuilder().setSequenceNumber(sequenceNumber).build(); } }
@Override public Iterator<JournalEntry> getJournalEntryIterator() { return CommonUtils.singleElementIterator( JournalEntry.newBuilder().setInodeDirectoryIdGenerator( InodeDirectoryIdGeneratorEntry.newBuilder() .setContainerId(mNextDirectoryId.getContainerId()) .setSequenceNumber(mNextDirectoryId.getSequenceNumber()) .build() ).build()); }
/** * Creates a dummy journal entry with the given sequence number. * * @param sequenceNumber the sequence number * @return the journal entry */ private Journal.JournalEntry newEntry(long sequenceNumber) { return Journal.JournalEntry.newBuilder().setSequenceNumber(sequenceNumber).build(); } }
/** * Creates a dummy journal entry with the given sequence number. * * @param sequenceNumber the sequence number * @return the journal entry */ private Journal.JournalEntry newEntry(long sequenceNumber) { return Journal.JournalEntry.newBuilder().setSequenceNumber(sequenceNumber).build(); } }
/** * @param context journal context * @param entry add mount point entry */ public void applyAndJournal(Supplier<JournalContext> context, AddMountPointEntry entry) { apply(entry); context.get().append(JournalEntry.newBuilder().setAddMountPoint(entry).build()); }
/** * @return a {@link JournalEntry} representing the state of the container id generator */ private JournalEntry getContainerIdJournalEntry() { BlockContainerIdGeneratorEntry blockContainerIdGenerator = BlockContainerIdGeneratorEntry.newBuilder().setNextContainerId(mJournaledNextContainerId) .build(); return JournalEntry.newBuilder().setBlockContainerIdGenerator(blockContainerIdGenerator) .build(); }
/** * @param context journal context * @param entry delete mount point entry */ public void applyAndJournal(Supplier<JournalContext> context, DeleteMountPointEntry entry) { apply(entry); context.get().append(JournalEntry.newBuilder().setDeleteMountPoint(entry).build()); }