Search in sources :

Example 1 with MasterBlockInfo

use of alluxio.master.block.meta.MasterBlockInfo 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 MasterBlockInfo

use of alluxio.master.block.meta.MasterBlockInfo 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 MasterBlockInfo

use of alluxio.master.block.meta.MasterBlockInfo 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 MasterBlockInfo

use of alluxio.master.block.meta.MasterBlockInfo in project alluxio by Alluxio.

the class BlockMaster method processWorkerRemovedBlocks.

/**
   * Updates the worker and block metadata for blocks removed from a worker.
   *
   * @param workerInfo The worker metadata object
   * @param removedBlockIds A list of block ids removed from the worker
   */
@GuardedBy("workerInfo")
private void processWorkerRemovedBlocks(MasterWorkerInfo workerInfo, Collection<Long> removedBlockIds) {
    for (long removedBlockId : removedBlockIds) {
        MasterBlockInfo block = mBlocks.get(removedBlockId);
        // TODO(calvin): Investigate if this branching logic can be simplified.
        if (block == null) {
            // LOG.warn("Worker {} informs the removed block {}, but block metadata does not exist"
            //    + " on Master!", workerInfo.getId(), removedBlockId);
            // TODO(pfxuan): [ALLUXIO-1804] should find a better way to handle the removed blocks.
            // Ideally, the delete/free I/O flow should never reach this point. Because Master may
            // update the block metadata only after receiving the acknowledgement from Workers.
            workerInfo.removeBlock(removedBlockId);
            // Continue to remove the remaining blocks.
            continue;
        }
        synchronized (block) {
            LOG.info("Block {} is removed on worker {}.", removedBlockId, workerInfo.getId());
            workerInfo.removeBlock(block.getBlockId());
            block.removeWorker(workerInfo.getId());
            if (block.getNumLocations() == 0) {
                mLostBlocks.add(removedBlockId);
            }
        }
    }
}
Also used : MasterBlockInfo(alluxio.master.block.meta.MasterBlockInfo) GuardedBy(javax.annotation.concurrent.GuardedBy)

Example 5 with MasterBlockInfo

use of alluxio.master.block.meta.MasterBlockInfo in project alluxio by Alluxio.

the class BlockMaster method processWorkerAddedBlocks.

/**
   * Updates the worker and block metadata for blocks added to a worker.
   *
   * @param workerInfo The worker metadata object
   * @param addedBlockIds A mapping from storage tier alias to a list of block ids added
   */
@GuardedBy("workerInfo")
private void processWorkerAddedBlocks(MasterWorkerInfo workerInfo, Map<String, List<Long>> addedBlockIds) {
    for (Map.Entry<String, List<Long>> entry : addedBlockIds.entrySet()) {
        for (long blockId : entry.getValue()) {
            MasterBlockInfo block = mBlocks.get(blockId);
            if (block != null) {
                synchronized (block) {
                    workerInfo.addBlock(blockId);
                    block.addWorker(workerInfo.getId(), entry.getKey());
                    mLostBlocks.remove(blockId);
                }
            } else {
                LOG.warn("Failed to register workerId: {} to blockId: {}", workerInfo.getId(), blockId);
            }
        }
    }
}
Also used : MasterBlockInfo(alluxio.master.block.meta.MasterBlockInfo) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) GuardedBy(javax.annotation.concurrent.GuardedBy)

Aggregations

MasterBlockInfo (alluxio.master.block.meta.MasterBlockInfo)8 BlockInfoEntry (alluxio.proto.journal.Block.BlockInfoEntry)4 MasterWorkerInfo (alluxio.master.block.meta.MasterWorkerInfo)3 GuardedBy (javax.annotation.concurrent.GuardedBy)3 ArrayList (java.util.ArrayList)2 ConcurrentHashSet (alluxio.collections.ConcurrentHashSet)1 NoWorkerException (alluxio.exception.NoWorkerException)1 MasterBlockLocation (alluxio.master.block.meta.MasterBlockLocation)1 BlockInfo (alluxio.wire.BlockInfo)1 BlockLocation (alluxio.wire.BlockLocation)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1