Search in sources :

Example 16 with MasterWorkerInfo

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

the class BlockMaster method generateBlockInfo.

/**
   * Creates a {@link BlockInfo} form a given {@link MasterBlockInfo}, by populating worker
   * locations.
   *
   * @param masterBlockInfo the {@link MasterBlockInfo}
   * @return a {@link BlockInfo} from a {@link MasterBlockInfo}. Populates worker locations
   */
@GuardedBy("masterBlockInfo")
private BlockInfo generateBlockInfo(MasterBlockInfo masterBlockInfo) {
    // "Join" to get all the addresses of the workers.
    List<BlockLocation> locations = new ArrayList<>();
    List<MasterBlockLocation> blockLocations = masterBlockInfo.getBlockLocations();
    // Sort the block locations by their alias ordinal in the master storage tier mapping
    Collections.sort(blockLocations, new Comparator<MasterBlockLocation>() {

        @Override
        public int compare(MasterBlockLocation o1, MasterBlockLocation o2) {
            return mGlobalStorageTierAssoc.getOrdinal(o1.getTierAlias()) - mGlobalStorageTierAssoc.getOrdinal(o2.getTierAlias());
        }
    });
    for (MasterBlockLocation masterBlockLocation : blockLocations) {
        MasterWorkerInfo workerInfo = mWorkers.getFirstByField(ID_INDEX, masterBlockLocation.getWorkerId());
        if (workerInfo != null) {
            // worker metadata is intentionally not locked here because:
            // - it would be an incorrect order (correct order is lock worker first, then block)
            // - only uses getters of final variables
            locations.add(new BlockLocation().setWorkerId(masterBlockLocation.getWorkerId()).setWorkerAddress(workerInfo.getWorkerAddress()).setTierAlias(masterBlockLocation.getTierAlias()));
        }
    }
    return new BlockInfo().setBlockId(masterBlockInfo.getBlockId()).setLength(masterBlockInfo.getLength()).setLocations(locations);
}
Also used : MasterBlockLocation(alluxio.master.block.meta.MasterBlockLocation) BlockInfo(alluxio.wire.BlockInfo) MasterBlockInfo(alluxio.master.block.meta.MasterBlockInfo) ArrayList(java.util.ArrayList) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo) MasterBlockLocation(alluxio.master.block.meta.MasterBlockLocation) BlockLocation(alluxio.wire.BlockLocation) GuardedBy(javax.annotation.concurrent.GuardedBy)

Example 17 with MasterWorkerInfo

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

the class BlockMaster method removeBlocks.

/**
   * Removes blocks from workers.
   *
   * @param blockIds a list of block ids to remove from Alluxio space
   * @param delete whether to delete blocks' metadata in Master
   */
public void removeBlocks(List<Long> blockIds, boolean delete) {
    for (long blockId : blockIds) {
        MasterBlockInfo block = mBlocks.get(blockId);
        if (block == null) {
            continue;
        }
        HashSet<Long> workerIds = new HashSet<>();
        synchronized (block) {
            // Technically, 'block' should be confirmed to still be in the data structure. A
            // concurrent removeBlock call can remove it. However, we are intentionally ignoring this
            // race, since deleting the same block again is a noop.
            workerIds.addAll(block.getWorkers());
            // 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);
                mBlocks.remove(blockId);
            }
        }
        // metadata, since it is essentially an asynchronous signal to the worker to remove the block.
        for (long workerId : workerIds) {
            MasterWorkerInfo worker = mWorkers.getFirstByField(ID_INDEX, workerId);
            if (worker != null) {
                synchronized (worker) {
                    worker.updateToRemovedBlock(true, blockId);
                }
            }
        }
    }
}
Also used : MasterBlockInfo(alluxio.master.block.meta.MasterBlockInfo) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo) ConcurrentHashSet(alluxio.collections.ConcurrentHashSet) HashSet(java.util.HashSet)

Example 18 with MasterWorkerInfo

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

the class BlockMaster method workerRegister.

/**
   * Updates metadata when a worker registers with the master.
   *
   * @param workerId the worker id of the worker registering
   * @param storageTiers a list of storage tier aliases in order of their position in the worker's
   *        hierarchy
   * @param totalBytesOnTiers a mapping from storage tier alias to total bytes
   * @param usedBytesOnTiers a mapping from storage tier alias to the used byes
   * @param currentBlocksOnTiers a mapping from storage tier alias to a list of blocks
   * @throws NoWorkerException if workerId cannot be found
   */
public void workerRegister(long workerId, List<String> storageTiers, Map<String, Long> totalBytesOnTiers, Map<String, Long> usedBytesOnTiers, Map<String, List<Long>> currentBlocksOnTiers) throws NoWorkerException {
    MasterWorkerInfo worker = mWorkers.getFirstByField(ID_INDEX, workerId);
    if (worker == null) {
        throw new NoWorkerException(ExceptionMessage.NO_WORKER_FOUND.getMessage(workerId));
    }
    // Gather all blocks on this worker.
    HashSet<Long> blocks = new HashSet<>();
    for (List<Long> blockIds : currentBlocksOnTiers.values()) {
        blocks.addAll(blockIds);
    }
    synchronized (worker) {
        worker.updateLastUpdatedTimeMs();
        // Detect any lost blocks on this worker.
        Set<Long> removedBlocks = worker.register(mGlobalStorageTierAssoc, storageTiers, totalBytesOnTiers, usedBytesOnTiers, blocks);
        processWorkerRemovedBlocks(worker, removedBlocks);
        processWorkerAddedBlocks(worker, currentBlocksOnTiers);
    }
    LOG.info("registerWorker(): {}", worker);
}
Also used : NoWorkerException(alluxio.exception.NoWorkerException) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo) ConcurrentHashSet(alluxio.collections.ConcurrentHashSet) HashSet(java.util.HashSet)

Example 19 with MasterWorkerInfo

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

the class DefaultBlockMaster method generateBlockInfo.

/**
 * Generates block info, including worker locations, for a block id.
 * This requires no locks on the {@link MasterWorkerInfo} because it is only reading
 * final fields.
 *
 * @param blockId a block id
 * @return optional block info, empty if the block does not exist
 */
private Optional<BlockInfo> generateBlockInfo(long blockId) throws UnavailableException {
    if (mSafeModeManager.isInSafeMode()) {
        throw new UnavailableException(ExceptionMessage.MASTER_IN_SAFEMODE.getMessage());
    }
    BlockMeta block;
    List<BlockLocation> blockLocations;
    try (LockResource r = lockBlock(blockId)) {
        Optional<BlockMeta> blockOpt = mBlockStore.getBlock(blockId);
        if (!blockOpt.isPresent()) {
            return Optional.empty();
        }
        block = blockOpt.get();
        blockLocations = new ArrayList<>(mBlockStore.getLocations(blockId));
    }
    // Sort the block locations by their alias ordinal in the master storage tier mapping
    Collections.sort(blockLocations, Comparator.comparingInt(o -> mGlobalStorageTierAssoc.getOrdinal(o.getTier())));
    List<alluxio.wire.BlockLocation> locations = new ArrayList<>();
    for (BlockLocation location : blockLocations) {
        MasterWorkerInfo workerInfo = mWorkers.getFirstByField(ID_INDEX, location.getWorkerId());
        if (workerInfo != null) {
            // worker metadata is intentionally not locked here because:
            // - it would be an incorrect order (correct order is lock worker first, then block)
            // - only uses getters of final variables
            locations.add(new alluxio.wire.BlockLocation().setWorkerId(location.getWorkerId()).setWorkerAddress(workerInfo.getWorkerAddress()).setTierAlias(location.getTier()).setMediumType(location.getMediumType()));
        }
    }
    return Optional.of(new BlockInfo().setBlockId(blockId).setLength(block.getLength()).setLocations(locations));
}
Also used : Arrays(java.util.Arrays) SystemClock(alluxio.clock.SystemClock) LoadingCache(com.google.common.cache.LoadingCache) Server(alluxio.Server) BlockInfo(alluxio.wire.BlockInfo) PropertyKey(alluxio.conf.PropertyKey) GrpcService(alluxio.grpc.GrpcService) Future(java.util.concurrent.Future) WorkerInfo(alluxio.wire.WorkerInfo) Map(java.util.Map) MetricsMaster(alluxio.master.metrics.MetricsMaster) GetWorkerReportOptions(alluxio.client.block.options.GetWorkerReportOptions) EnumSet(java.util.EnumSet) RegisterLease(alluxio.wire.RegisterLease) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo) IndexedSet(alluxio.collections.IndexedSet) ConcurrentHashSet(alluxio.collections.ConcurrentHashSet) Set(java.util.Set) ConfigProperty(alluxio.grpc.ConfigProperty) Block(alluxio.master.metastore.BlockStore.Block) Command(alluxio.grpc.Command) GuardedBy(javax.annotation.concurrent.GuardedBy) ServiceType(alluxio.grpc.ServiceType) BlockStore(alluxio.master.metastore.BlockStore) Metric(alluxio.metrics.Metric) ArrayList(java.util.ArrayList) GrpcUtils(alluxio.grpc.GrpcUtils) BlockInfoException(alluxio.exception.BlockInfoException) BiConsumer(java.util.function.BiConsumer) MetricsSystem(alluxio.metrics.MetricsSystem) Nullable(javax.annotation.Nullable) IdUtils(alluxio.util.IdUtils) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) ExecutorServiceFactory(alluxio.util.executor.ExecutorServiceFactory) Lock(java.util.concurrent.locks.Lock) RegisterWorkerPOptions(alluxio.grpc.RegisterWorkerPOptions) Preconditions(com.google.common.base.Preconditions) ExecutorServiceFactories(alluxio.util.executor.ExecutorServiceFactories) StorageList(alluxio.grpc.StorageList) CommonUtils(alluxio.util.CommonUtils) Address(alluxio.wire.Address) NotThreadSafe(javax.annotation.concurrent.NotThreadSafe) CloseableIterator(alluxio.resource.CloseableIterator) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) HeartbeatThread(alluxio.heartbeat.HeartbeatThread) MasterStorageTierAssoc(alluxio.MasterStorageTierAssoc) GetRegisterLeasePRequest(alluxio.grpc.GetRegisterLeasePRequest) MetricKey(alluxio.metrics.MetricKey) BlockInfoEntry(alluxio.proto.journal.Block.BlockInfoEntry) InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) IndexDefinition(alluxio.collections.IndexDefinition) ImmutableSet(com.google.common.collect.ImmutableSet) ServerConfiguration(alluxio.conf.ServerConfiguration) StorageTierAssoc(alluxio.StorageTierAssoc) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SuppressFBWarnings(alluxio.annotation.SuppressFBWarnings) CheckpointName(alluxio.master.journal.checkpoint.CheckpointName) Collectors(java.util.stream.Collectors) CacheLoader(com.google.common.cache.CacheLoader) List(java.util.List) CoreMasterContext(alluxio.master.CoreMasterContext) Optional(java.util.Optional) WorkerRange(alluxio.client.block.options.GetWorkerReportOptions.WorkerRange) Gauge(com.codahale.metrics.Gauge) CacheBuilder(com.google.common.cache.CacheBuilder) RegisterWorkerPRequest(alluxio.grpc.RegisterWorkerPRequest) BlockContainerIdGeneratorEntry(alluxio.proto.journal.Block.BlockContainerIdGeneratorEntry) JournalContext(alluxio.master.journal.JournalContext) UnavailableException(alluxio.exception.status.UnavailableException) WorkerLostStorageInfo(alluxio.grpc.WorkerLostStorageInfo) WorkerNetAddress(alluxio.wire.WorkerNetAddress) HashMap(java.util.HashMap) CommandType(alluxio.grpc.CommandType) NetworkAddressUtils(alluxio.util.network.NetworkAddressUtils) Function(java.util.function.Function) MetricInfo(alluxio.metrics.MetricInfo) JournalEntry(alluxio.proto.journal.Journal.JournalEntry) HashSet(java.util.HashSet) Constants(alluxio.Constants) NoSuchElementException(java.util.NoSuchElementException) CoreMaster(alluxio.master.CoreMaster) Striped(com.google.common.util.concurrent.Striped) Logger(org.slf4j.Logger) HeartbeatContext(alluxio.heartbeat.HeartbeatContext) Iterator(java.util.Iterator) BlockMeta(alluxio.proto.meta.Block.BlockMeta) ExceptionMessage(alluxio.exception.ExceptionMessage) HeartbeatExecutor(alluxio.heartbeat.HeartbeatExecutor) NotFoundException(alluxio.exception.status.NotFoundException) LockResource(alluxio.resource.LockResource) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) WorkerMetaLockSection(alluxio.master.block.meta.WorkerMetaLockSection) DeleteBlockEntry(alluxio.proto.journal.Block.DeleteBlockEntry) Clock(java.time.Clock) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) BlockLocation(alluxio.proto.meta.Block.BlockLocation) Collections(java.util.Collections) UnavailableException(alluxio.exception.status.UnavailableException) ArrayList(java.util.ArrayList) BlockLocation(alluxio.proto.meta.Block.BlockLocation) LockResource(alluxio.resource.LockResource) BlockInfo(alluxio.wire.BlockInfo) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo) BlockMeta(alluxio.proto.meta.Block.BlockMeta)

Example 20 with MasterWorkerInfo

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

the class DefaultBlockMaster method getWorkerId.

@Override
public long getWorkerId(WorkerNetAddress workerNetAddress) {
    MasterWorkerInfo existingWorker = mWorkers.getFirstByField(ADDRESS_INDEX, workerNetAddress);
    if (existingWorker != null) {
        // This worker address is already mapped to a worker id.
        long oldWorkerId = existingWorker.getId();
        LOG.warn("The worker {} already exists as id {}.", workerNetAddress, oldWorkerId);
        return oldWorkerId;
    }
    existingWorker = findUnregisteredWorker(workerNetAddress);
    if (existingWorker != null) {
        return existingWorker.getId();
    }
    // Generate a new worker id.
    long workerId = IdUtils.getRandomNonNegativeLong();
    while (!mTempWorkers.add(new MasterWorkerInfo(workerId, workerNetAddress))) {
        workerId = IdUtils.getRandomNonNegativeLong();
    }
    LOG.info("getWorkerId(): WorkerNetAddress: {} id: {}", workerNetAddress, workerId);
    return workerId;
}
Also used : MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo)

Aggregations

MasterWorkerInfo (alluxio.master.block.meta.MasterWorkerInfo)34 RegisterWorkerPRequest (alluxio.grpc.RegisterWorkerPRequest)10 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)9 LockResource (alluxio.resource.LockResource)8 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 StorageList (alluxio.grpc.StorageList)7 List (java.util.List)7 ConcurrentHashSet (alluxio.collections.ConcurrentHashSet)6 Command (alluxio.grpc.Command)6 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 Map (java.util.Map)6 BlockLocation (alluxio.proto.meta.Block.BlockLocation)5 WorkerInfo (alluxio.wire.WorkerInfo)5 NotFoundException (alluxio.exception.status.NotFoundException)4 UnavailableException (alluxio.exception.status.UnavailableException)4 Address (alluxio.wire.Address)4 BlockInfo (alluxio.wire.BlockInfo)4 WorkerNetAddress (alluxio.wire.WorkerNetAddress)4