Search in sources :

Example 1 with Block

use of alluxio.master.metastore.BlockStore.Block 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 2 with Block

use of alluxio.master.metastore.BlockStore.Block 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)

Aggregations

Block (alluxio.master.metastore.BlockStore.Block)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 WorkerRange (alluxio.client.block.options.GetWorkerReportOptions.WorkerRange)1 SystemClock (alluxio.clock.SystemClock)1 ConcurrentHashSet (alluxio.collections.ConcurrentHashSet)1 IndexDefinition (alluxio.collections.IndexDefinition)1 IndexedSet (alluxio.collections.IndexedSet)1 PropertyKey (alluxio.conf.PropertyKey)1 ServerConfiguration (alluxio.conf.ServerConfiguration)1 BlockInfoException (alluxio.exception.BlockInfoException)1 ExceptionMessage (alluxio.exception.ExceptionMessage)1 InvalidArgumentException (alluxio.exception.status.InvalidArgumentException)1 NotFoundException (alluxio.exception.status.NotFoundException)1 UnavailableException (alluxio.exception.status.UnavailableException)1 Command (alluxio.grpc.Command)1