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);
}
}
}
}
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));
}
}
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());
}
}
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);
}
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;
}
Aggregations