Search in sources :

Example 1 with BlockInfoEntry

use of alluxio.proto.journal.Block.BlockInfoEntry in project alluxio by Alluxio.

the class BlockMaster method commitBlockInUFS.

/**
   * Marks a block as committed, but without a worker location. This means the block is only in ufs.
   *
   * @param blockId the id of the block to commit
   * @param length the length of the block
   */
public void commitBlockInUFS(long blockId, long length) {
    LOG.debug("Commit block in ufs. blockId: {}, length: {}", blockId, length);
    if (mBlocks.get(blockId) != null) {
        // Block metadata already exists, so do not need to create a new one.
        return;
    }
    // The block has not been committed previously, so add the metadata to commit the block.
    MasterBlockInfo block = new MasterBlockInfo(blockId, length);
    try (JournalContext journalContext = createJournalContext()) {
        synchronized (block) {
            if (mBlocks.putIfAbsent(blockId, block) == null) {
                // Successfully added the new block metadata. Append a journal entry for the new metadata.
                BlockInfoEntry blockInfo = BlockInfoEntry.newBuilder().setBlockId(blockId).setLength(length).build();
                appendJournalEntry(JournalEntry.newBuilder().setBlockInfo(blockInfo).build(), journalContext);
            }
        }
    }
}
Also used : MasterBlockInfo(alluxio.master.block.meta.MasterBlockInfo) BlockInfoEntry(alluxio.proto.journal.Block.BlockInfoEntry)

Example 2 with BlockInfoEntry

use of alluxio.proto.journal.Block.BlockInfoEntry in project alluxio by Alluxio.

the class BlockMaster method processJournalEntry.

@Override
public void processJournalEntry(JournalEntry entry) throws IOException {
    // TODO(gene): A better way to process entries besides a huge switch?
    if (entry.hasBlockContainerIdGenerator()) {
        mJournaledNextContainerId = (entry.getBlockContainerIdGenerator()).getNextContainerId();
        mBlockContainerIdGenerator.setNextContainerId((mJournaledNextContainerId));
    } else if (entry.hasBlockInfo()) {
        BlockInfoEntry blockInfoEntry = entry.getBlockInfo();
        if (mBlocks.containsKey(blockInfoEntry.getBlockId())) {
            // Update the existing block info.
            MasterBlockInfo blockInfo = mBlocks.get(blockInfoEntry.getBlockId());
            blockInfo.updateLength(blockInfoEntry.getLength());
        } else {
            mBlocks.put(blockInfoEntry.getBlockId(), new MasterBlockInfo(blockInfoEntry.getBlockId(), blockInfoEntry.getLength()));
        }
    } else {
        throw new IOException(ExceptionMessage.UNEXPECTED_JOURNAL_ENTRY.getMessage(entry));
    }
}
Also used : MasterBlockInfo(alluxio.master.block.meta.MasterBlockInfo) IOException(java.io.IOException) BlockInfoEntry(alluxio.proto.journal.Block.BlockInfoEntry)

Example 3 with BlockInfoEntry

use of alluxio.proto.journal.Block.BlockInfoEntry in project alluxio by Alluxio.

the class BlockMaster method streamToJournalCheckpoint.

@Override
public void streamToJournalCheckpoint(JournalOutputStream outputStream) throws IOException {
    outputStream.writeEntry(getContainerIdJournalEntry());
    for (MasterBlockInfo blockInfo : mBlocks.values()) {
        BlockInfoEntry blockInfoEntry = BlockInfoEntry.newBuilder().setBlockId(blockInfo.getBlockId()).setLength(blockInfo.getLength()).build();
        outputStream.writeEntry(JournalEntry.newBuilder().setBlockInfo(blockInfoEntry).build());
    }
}
Also used : MasterBlockInfo(alluxio.master.block.meta.MasterBlockInfo) BlockInfoEntry(alluxio.proto.journal.Block.BlockInfoEntry)

Example 4 with BlockInfoEntry

use of alluxio.proto.journal.Block.BlockInfoEntry in project alluxio by Alluxio.

the class DefaultBlockMaster method getJournalEntryIterator.

@Override
public CloseableIterator<JournalEntry> getJournalEntryIterator() {
    Iterator<Block> blockStoreIterator = mBlockStore.iterator();
    Iterator<JournalEntry> blockIterator = new Iterator<JournalEntry>() {

        @Override
        public boolean hasNext() {
            return blockStoreIterator.hasNext();
        }

        @Override
        public JournalEntry next() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            Block block = blockStoreIterator.next();
            BlockInfoEntry blockInfoEntry = BlockInfoEntry.newBuilder().setBlockId(block.getId()).setLength(block.getMeta().getLength()).build();
            return JournalEntry.newBuilder().setBlockInfo(blockInfoEntry).build();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException("BlockMaster#Iterator#remove is not supported.");
        }
    };
    CloseableIterator<JournalEntry> closeableIterator = CloseableIterator.create(blockIterator, (whatever) -> {
        if (blockStoreIterator instanceof CloseableIterator) {
            final CloseableIterator<Block> c = (CloseableIterator<Block>) blockStoreIterator;
            c.close();
        } else {
        // no op
        }
    });
    return CloseableIterator.concat(CloseableIterator.noopCloseable(CommonUtils.singleElementIterator(getContainerIdJournalEntry())), closeableIterator);
}
Also used : CloseableIterator(alluxio.resource.CloseableIterator) CloseableIterator(alluxio.resource.CloseableIterator) Iterator(java.util.Iterator) Block(alluxio.master.metastore.BlockStore.Block) JournalEntry(alluxio.proto.journal.Journal.JournalEntry) NoSuchElementException(java.util.NoSuchElementException) BlockInfoEntry(alluxio.proto.journal.Block.BlockInfoEntry)

Example 5 with BlockInfoEntry

use of alluxio.proto.journal.Block.BlockInfoEntry in project alluxio by Alluxio.

the class DefaultBlockMaster method processJournalEntry.

@Override
public boolean processJournalEntry(JournalEntry entry) {
    // TODO(gene): A better way to process entries besides a huge switch?
    if (entry.hasBlockContainerIdGenerator()) {
        mJournaledNextContainerId = (entry.getBlockContainerIdGenerator()).getNextContainerId();
        mBlockContainerIdGenerator.setNextContainerId((mJournaledNextContainerId));
    } else if (entry.hasDeleteBlock()) {
        mBlockStore.removeBlock(entry.getDeleteBlock().getBlockId());
    } else if (entry.hasBlockInfo()) {
        BlockInfoEntry blockInfoEntry = entry.getBlockInfo();
        long length = blockInfoEntry.getLength();
        Optional<BlockMeta> block = mBlockStore.getBlock(blockInfoEntry.getBlockId());
        if (block.isPresent()) {
            long oldLen = block.get().getLength();
            if (oldLen != Constants.UNKNOWN_SIZE) {
                LOG.warn("Attempting to update block length ({}) to a different length ({}).", oldLen, length);
                return true;
            }
        }
        mBlockStore.putBlock(blockInfoEntry.getBlockId(), BlockMeta.newBuilder().setLength(blockInfoEntry.getLength()).build());
    } else {
        return false;
    }
    return true;
}
Also used : BlockMeta(alluxio.proto.meta.Block.BlockMeta) BlockInfoEntry(alluxio.proto.journal.Block.BlockInfoEntry)

Aggregations

BlockInfoEntry (alluxio.proto.journal.Block.BlockInfoEntry)8 MasterBlockInfo (alluxio.master.block.meta.MasterBlockInfo)4 MasterWorkerInfo (alluxio.master.block.meta.MasterWorkerInfo)2 JournalContext (alluxio.master.journal.JournalContext)2 BlockMeta (alluxio.proto.meta.Block.BlockMeta)2 LockResource (alluxio.resource.LockResource)2 NoWorkerException (alluxio.exception.NoWorkerException)1 NotFoundException (alluxio.exception.status.NotFoundException)1 Block (alluxio.master.metastore.BlockStore.Block)1 JournalEntry (alluxio.proto.journal.Journal.JournalEntry)1 CloseableIterator (alluxio.resource.CloseableIterator)1 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 NoSuchElementException (java.util.NoSuchElementException)1