Search in sources :

Example 6 with BlockMeta

use of alluxio.proto.meta.Block.BlockMeta in project alluxio by Alluxio.

the class DefaultBlockMaster method removeBlocks.

@Override
public void removeBlocks(Collection<Long> blockIds, boolean delete) throws UnavailableException {
    try (JournalContext journalContext = createJournalContext()) {
        for (long blockId : blockIds) {
            Set<Long> workerIds;
            try (LockResource r = lockBlock(blockId)) {
                Optional<BlockMeta> block = mBlockStore.getBlock(blockId);
                if (!block.isPresent()) {
                    continue;
                }
                List<BlockLocation> locations = mBlockStore.getLocations(blockId);
                workerIds = new HashSet<>(locations.size());
                for (BlockLocation loc : locations) {
                    workerIds.add(loc.getWorkerId());
                }
                // processWorkerRemovedBlocks
                if (delete) {
                    // Make sure blockId is removed from mLostBlocks when the block metadata is deleted.
                    // Otherwise blockId in mLostBlock can be dangling index if the metadata is gone.
                    mLostBlocks.remove(blockId);
                    mBlockStore.removeBlock(blockId);
                    JournalEntry entry = JournalEntry.newBuilder().setDeleteBlock(DeleteBlockEntry.newBuilder().setBlockId(blockId)).build();
                    journalContext.append(entry);
                }
            }
            // workerRegister should be changed to address this race condition.
            for (long workerId : workerIds) {
                MasterWorkerInfo worker = mWorkers.getFirstByField(ID_INDEX, workerId);
                if (worker != null) {
                    try (LockResource r = worker.lockWorkerMeta(EnumSet.of(WorkerMetaLockSection.BLOCKS), false)) {
                        worker.updateToRemovedBlock(true, blockId);
                    }
                }
            }
        }
    }
}
Also used : LockResource(alluxio.resource.LockResource) JournalContext(alluxio.master.journal.JournalContext) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo) BlockLocation(alluxio.proto.meta.Block.BlockLocation) BlockMeta(alluxio.proto.meta.Block.BlockMeta) JournalEntry(alluxio.proto.journal.Journal.JournalEntry)

Aggregations

BlockMeta (alluxio.proto.meta.Block.BlockMeta)6 LockResource (alluxio.resource.LockResource)5 MasterWorkerInfo (alluxio.master.block.meta.MasterWorkerInfo)3 JournalContext (alluxio.master.journal.JournalContext)3 BlockInfoEntry (alluxio.proto.journal.Block.BlockInfoEntry)3 BlockLocation (alluxio.proto.meta.Block.BlockLocation)3 NotFoundException (alluxio.exception.status.NotFoundException)2 StorageList (alluxio.grpc.StorageList)2 JournalEntry (alluxio.proto.journal.Journal.JournalEntry)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Constants (alluxio.Constants)1 MasterStorageTierAssoc (alluxio.MasterStorageTierAssoc)1 Server (alluxio.Server)1 StorageTierAssoc (alluxio.StorageTierAssoc)1 SuppressFBWarnings (alluxio.annotation.SuppressFBWarnings)1 GetWorkerReportOptions (alluxio.client.block.options.GetWorkerReportOptions)1