Search in sources :

Example 1 with RegisterWorkerPOptions

use of alluxio.grpc.RegisterWorkerPOptions in project alluxio by Alluxio.

the class DefaultBlockMaster method workerRegisterStart.

protected void workerRegisterStart(WorkerRegisterContext context, RegisterWorkerPRequest chunk) {
    final List<String> storageTiers = chunk.getStorageTiersList();
    final Map<String, Long> totalBytesOnTiers = chunk.getTotalBytesOnTiersMap();
    final Map<String, Long> usedBytesOnTiers = chunk.getUsedBytesOnTiersMap();
    final Map<String, StorageList> lostStorage = chunk.getLostStorageMap();
    final Map<alluxio.proto.meta.Block.BlockLocation, List<Long>> currentBlocksOnLocation = BlockMasterWorkerServiceHandler.reconstructBlocksOnLocationMap(chunk.getCurrentBlocksList(), context.getWorkerId());
    RegisterWorkerPOptions options = chunk.getOptions();
    MasterWorkerInfo worker = context.mWorker;
    Preconditions.checkState(worker != null, "No worker metadata found in the WorkerRegisterContext!");
    mActiveRegisterContexts.put(worker.getId(), context);
    // The worker is locked so we can operate on its blocks without race conditions
    // We start with assuming all blocks in (mBlocks + mToRemoveBlocks) do not exist.
    // With each batch we receive, we mark them not-to-be-removed.
    // Eventually what's left in the mToRemove will be the ones that do not exist anymore.
    worker.markAllBlocksToRemove();
    worker.updateUsage(mGlobalStorageTierAssoc, storageTiers, totalBytesOnTiers, usedBytesOnTiers);
    processWorkerAddedBlocks(worker, currentBlocksOnLocation);
    processWorkerOrphanedBlocks(worker);
    worker.addLostStorage(lostStorage);
    // TODO(jiacheng): This block can be moved to a non-locked section
    if (options.getConfigsCount() > 0) {
        for (BiConsumer<Address, List<ConfigProperty>> function : mWorkerRegisteredListeners) {
            WorkerNetAddress workerAddress = worker.getWorkerAddress();
            function.accept(new Address(workerAddress.getHost(), workerAddress.getRpcPort()), options.getConfigsList());
        }
    }
}
Also used : Address(alluxio.wire.Address) WorkerNetAddress(alluxio.wire.WorkerNetAddress) StorageList(alluxio.grpc.StorageList) BlockLocation(alluxio.proto.meta.Block.BlockLocation) RegisterWorkerPOptions(alluxio.grpc.RegisterWorkerPOptions) WorkerNetAddress(alluxio.wire.WorkerNetAddress) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo) ArrayList(java.util.ArrayList) StorageList(alluxio.grpc.StorageList) List(java.util.List)

Example 2 with RegisterWorkerPOptions

use of alluxio.grpc.RegisterWorkerPOptions in project alluxio by Alluxio.

the class BlockMasterWorkerServiceHandler method registerWorker.

@Override
public void registerWorker(RegisterWorkerPRequest request, StreamObserver<RegisterWorkerPResponse> responseObserver) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Register worker request is {} bytes, containing {} blocks", request.getSerializedSize(), request.getCurrentBlocksCount());
    }
    final long workerId = request.getWorkerId();
    RegisterWorkerPOptions options = request.getOptions();
    RpcUtils.call(LOG, (RpcUtils.RpcCallableThrowsIOException<RegisterWorkerPResponse>) () -> {
        // The exception will be propagated to the worker side and the worker should retry.
        if (ServerConfiguration.getBoolean(PropertyKey.MASTER_WORKER_REGISTER_LEASE_ENABLED) && !mBlockMaster.hasRegisterLease(workerId)) {
            String errorMsg = String.format("Worker %s does not have a lease or the lease " + "has expired. The worker should acquire a new lease and retry to register.", workerId);
            LOG.warn(errorMsg);
            throw new RegisterLeaseNotFoundException(errorMsg);
        }
        LOG.debug("Worker {} proceeding to register...", workerId);
        final List<String> storageTiers = request.getStorageTiersList();
        final Map<String, Long> totalBytesOnTiers = request.getTotalBytesOnTiersMap();
        final Map<String, Long> usedBytesOnTiers = request.getUsedBytesOnTiersMap();
        final Map<String, StorageList> lostStorageMap = request.getLostStorageMap();
        final Map<Block.BlockLocation, List<Long>> currBlocksOnLocationMap = reconstructBlocksOnLocationMap(request.getCurrentBlocksList(), workerId);
        // If the register is unsuccessful, the lease will be kept around until the expiry.
        // The worker can retry and use the existing lease.
        mBlockMaster.workerRegister(workerId, storageTiers, totalBytesOnTiers, usedBytesOnTiers, currBlocksOnLocationMap, lostStorageMap, options);
        LOG.info("Worker {} finished registering, releasing its lease.", workerId);
        mBlockMaster.releaseRegisterLease(workerId);
        return RegisterWorkerPResponse.getDefaultInstance();
    }, "registerWorker", true, "request=%s", responseObserver, workerId);
}
Also used : RpcUtils(alluxio.RpcUtils) RegisterWorkerPResponse(alluxio.grpc.RegisterWorkerPResponse) Block(alluxio.proto.meta.Block) List(java.util.List) StorageList(alluxio.grpc.StorageList) RegisterWorkerPOptions(alluxio.grpc.RegisterWorkerPOptions) RegisterLeaseNotFoundException(alluxio.exception.RegisterLeaseNotFoundException) Map(java.util.Map)

Example 3 with RegisterWorkerPOptions

use of alluxio.grpc.RegisterWorkerPOptions in project alluxio by Alluxio.

the class BlockMasterClient method register.

/**
 * The method the worker should execute to register with the block master.
 *
 * @param workerId the worker id of the worker registering
 * @param storageTierAliases a list of storage tier aliases in ordinal order
 * @param totalBytesOnTiers mapping from storage tier alias to total bytes
 * @param usedBytesOnTiers mapping from storage tier alias to used bytes
 * @param currentBlocksOnLocation mapping from storage tier alias to the list of list of blocks
 * @param lostStorage mapping from storage tier alias to the list of lost storage paths
 * @param configList a list of configurations
 */
// TODO(yupeng): rename to workerBlockReport or workerInitialize?
public void register(final long workerId, final List<String> storageTierAliases, final Map<String, Long> totalBytesOnTiers, final Map<String, Long> usedBytesOnTiers, final Map<BlockStoreLocation, List<Long>> currentBlocksOnLocation, final Map<String, List<String>> lostStorage, final List<ConfigProperty> configList) throws IOException {
    final RegisterWorkerPOptions options = RegisterWorkerPOptions.newBuilder().addAllConfigs(configList).build();
    final List<LocationBlockIdListEntry> currentBlocks = convertBlockListMapToProto(currentBlocksOnLocation);
    final Map<String, StorageList> lostStorageMap = lostStorage.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> StorageList.newBuilder().addAllStorage(e.getValue()).build()));
    final RegisterWorkerPRequest request = RegisterWorkerPRequest.newBuilder().setWorkerId(workerId).addAllStorageTiers(storageTierAliases).putAllTotalBytesOnTiers(totalBytesOnTiers).putAllUsedBytesOnTiers(usedBytesOnTiers).addAllCurrentBlocks(currentBlocks).putAllLostStorage(lostStorageMap).setOptions(options).build();
    retryRPC(() -> {
        mClient.registerWorker(request);
        return null;
    }, LOG, "Register", "workerId=%d", workerId);
}
Also used : WorkerNetAddress(alluxio.wire.WorkerNetAddress) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) PropertyKey(alluxio.conf.PropertyKey) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) BlockMasterWorkerServiceGrpc(alluxio.grpc.BlockMasterWorkerServiceGrpc) BlockHeartbeatPOptions(alluxio.grpc.BlockHeartbeatPOptions) Constants(alluxio.Constants) GetRegisterLeasePRequest(alluxio.grpc.GetRegisterLeasePRequest) GrpcUtils(alluxio.grpc.GrpcUtils) GetWorkerIdPRequest(alluxio.grpc.GetWorkerIdPRequest) Map(java.util.Map) BlockHeartbeatPRequest(alluxio.grpc.BlockHeartbeatPRequest) LocationBlockIdListEntry(alluxio.grpc.LocationBlockIdListEntry) AbstractMasterClient(alluxio.AbstractMasterClient) Metric(alluxio.grpc.Metric) RetryPolicy(alluxio.retry.RetryPolicy) BlockIdList(alluxio.grpc.BlockIdList) CommitBlockInUfsPRequest(alluxio.grpc.CommitBlockInUfsPRequest) FailedToAcquireRegisterLeaseException(alluxio.exception.FailedToAcquireRegisterLeaseException) Logger(org.slf4j.Logger) BlockStoreLocationProto(alluxio.grpc.BlockStoreLocationProto) GetRegisterLeasePResponse(alluxio.grpc.GetRegisterLeasePResponse) IOException(java.io.IOException) ThreadSafe(javax.annotation.concurrent.ThreadSafe) ConfigProperty(alluxio.grpc.ConfigProperty) Command(alluxio.grpc.Command) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) RegisterWorkerPOptions(alluxio.grpc.RegisterWorkerPOptions) MasterClientContext(alluxio.master.MasterClientContext) CommitBlockPRequest(alluxio.grpc.CommitBlockPRequest) ServiceType(alluxio.grpc.ServiceType) VisibleForTesting(com.google.common.annotations.VisibleForTesting) RegisterWorkerPRequest(alluxio.grpc.RegisterWorkerPRequest) StorageList(alluxio.grpc.StorageList) StorageList(alluxio.grpc.StorageList) RegisterWorkerPRequest(alluxio.grpc.RegisterWorkerPRequest) RegisterWorkerPOptions(alluxio.grpc.RegisterWorkerPOptions) HashMap(java.util.HashMap) Map(java.util.Map) LocationBlockIdListEntry(alluxio.grpc.LocationBlockIdListEntry)

Aggregations

RegisterWorkerPOptions (alluxio.grpc.RegisterWorkerPOptions)3 StorageList (alluxio.grpc.StorageList)3 List (java.util.List)3 WorkerNetAddress (alluxio.wire.WorkerNetAddress)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 AbstractMasterClient (alluxio.AbstractMasterClient)1 Constants (alluxio.Constants)1 RpcUtils (alluxio.RpcUtils)1 PropertyKey (alluxio.conf.PropertyKey)1 FailedToAcquireRegisterLeaseException (alluxio.exception.FailedToAcquireRegisterLeaseException)1 RegisterLeaseNotFoundException (alluxio.exception.RegisterLeaseNotFoundException)1 BlockHeartbeatPOptions (alluxio.grpc.BlockHeartbeatPOptions)1 BlockHeartbeatPRequest (alluxio.grpc.BlockHeartbeatPRequest)1 BlockIdList (alluxio.grpc.BlockIdList)1 BlockMasterWorkerServiceGrpc (alluxio.grpc.BlockMasterWorkerServiceGrpc)1 BlockStoreLocationProto (alluxio.grpc.BlockStoreLocationProto)1 Command (alluxio.grpc.Command)1 CommitBlockInUfsPRequest (alluxio.grpc.CommitBlockInUfsPRequest)1 CommitBlockPRequest (alluxio.grpc.CommitBlockPRequest)1