Search in sources :

Example 1 with PoolAcceptFileMessage

use of diskCacheV111.vehicles.PoolAcceptFileMessage in project dcache by dCache.

the class SpaceManagerService method processMessage.

private void processMessage(Message message) throws DeadlockLoserDataAccessException {
    try {
        boolean isSuccessful = false;
        int attempts = 0;
        while (!isSuccessful) {
            try {
                processMessageTransactionally(message);
                isSuccessful = true;
            } catch (DeadlockLoserDataAccessException e) {
                LOGGER.debug("Transaction lost deadlock race and will be retried: {}", e.getMessage());
                throw e;
            } catch (TransientDataAccessException | RecoverableDataAccessException e) {
                if (attempts >= 3) {
                    throw e;
                }
                LOGGER.warn("Retriable data access error: {}", e.toString());
                attempts++;
            }
        }
    } catch (SpaceAuthorizationException e) {
        message.setFailedConditionally(CacheException.PERMISSION_DENIED, e);
    } catch (NoPoolConfiguredSpaceException e) {
        message.setFailed(NO_POOL_CONFIGURED, e.getMessage());
    } catch (NoFreeSpaceException e) {
        message.setFailedConditionally(CacheException.RESOURCE, e);
    } catch (SpaceException e) {
        message.setFailedConditionally(CacheException.INVALID_ARGS, e);
    } catch (IllegalArgumentException e) {
        LOGGER.error("Message processing failed: {}", e.getMessage(), e);
        message.setFailedConditionally(CacheException.INVALID_ARGS, e.getMessage());
    } catch (DeadlockLoserDataAccessException e) {
        throw e;
    } catch (DuplicateKeyException e) {
        /* For PoolAcceptFileMessage, a duplicate key failure is most likely caused by
             * the door resubmitting the message. We trust the door that it doesn't submit
             * these to several pools.
             */
        if ((message instanceof PoolAcceptFileMessage) && !message.isReply()) {
            LOGGER.info("Ignoring exception due to possibly duplicated PoolAcceptFileMessage: {}", e.getMessage());
        } else {
            throw e;
        }
    } catch (DataAccessException e) {
        LOGGER.error("Message processing failed: {}", e.toString());
        message.setFailedConditionally(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, "Internal failure during space management");
    } catch (RuntimeException e) {
        LOGGER.error("Message processing failed: {}", e.getMessage(), e);
        message.setFailedConditionally(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, "Internal failure during space management");
    }
}
Also used : CellEndpoint(dmg.cells.nucleus.CellEndpoint) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) TransientDataAccessException(org.springframework.dao.TransientDataAccessException) RecoverableDataAccessException(org.springframework.dao.RecoverableDataAccessException) PoolAcceptFileMessage(diskCacheV111.vehicles.PoolAcceptFileMessage) DeadlockLoserDataAccessException(org.springframework.dao.DeadlockLoserDataAccessException) TransientDataAccessException(org.springframework.dao.TransientDataAccessException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) DataAccessException(org.springframework.dao.DataAccessException) DeadlockLoserDataAccessException(org.springframework.dao.DeadlockLoserDataAccessException) RecoverableDataAccessException(org.springframework.dao.RecoverableDataAccessException)

Example 2 with PoolAcceptFileMessage

use of diskCacheV111.vehicles.PoolAcceptFileMessage in project dcache by dCache.

the class SpaceManagerService method selectPool.

/**
 * Called upon intercepting PoolMgrSelectWritePoolMsg requests.
 * <p>
 * Injects the link group name into the request message. Also adds SpaceToken and LinkGroup
 * flags to StorageInfo. These are accessed when space manager intercepts the subsequent
 * PoolAcceptFileMessage.
 */
private void selectPool(PoolMgrSelectWritePoolMsg selectWritePool) throws DataAccessException, SpaceException {
    LOGGER.trace("selectPool({})", selectWritePool);
    FileAttributes fileAttributes = selectWritePool.getFileAttributes();
    ProtocolInfo protocolInfo = selectWritePool.getProtocolInfo();
    String defaultSpaceToken = fileAttributes.getStorageInfo().getMap().get("writeToken");
    Subject subject = selectWritePool.getSubject();
    if (defaultSpaceToken != null) {
        LOGGER.trace("selectPool: file is not found, using default space token");
        Space space;
        try {
            space = db.getSpace(Long.parseLong(defaultSpaceToken));
        } catch (EmptyResultDataAccessException | NumberFormatException e) {
            throw new IllegalArgumentException("No such space reservation: " + defaultSpaceToken);
        }
        LinkGroup linkGroup = db.getLinkGroup(space.getLinkGroupId());
        String linkGroupName = linkGroup.getName();
        if (!isWriteableInLinkgroup(protocolInfo, fileAttributes, linkGroupName)) {
            // FIXME provide better information for the user
            throw new NoPoolConfiguredSpaceException("Space reservation " + defaultSpaceToken + " may not be used for this write " + "request [net=" + hostnameFrom(protocolInfo) + ",protocol=" + protocolFrom(protocolInfo) + ",store=" + storageFrom(fileAttributes) + ",cache=" + nullToEmpty(fileAttributes.getCacheClass()) + ",linkgroup=" + nullToEmpty(linkGroupName) + "]");
        }
        selectWritePool.setLinkGroup(linkGroupName);
        StorageInfo storageInfo = selectWritePool.getStorageInfo();
        storageInfo.setKey("SpaceToken", Long.toString(space.getId()));
        storageInfo.setKey("LinkGroupId", Long.toString(linkGroup.getId()));
        if (!fileAttributes.isDefined(FileAttribute.ACCESS_LATENCY)) {
            fileAttributes.setAccessLatency(space.getAccessLatency());
        } else if (fileAttributes.getAccessLatency() != space.getAccessLatency()) {
            throw new SpaceException("Access latency conflicts with access latency defined by default space reservation.");
        }
        if (!fileAttributes.isDefined(FileAttribute.RETENTION_POLICY)) {
            fileAttributes.setRetentionPolicy(space.getRetentionPolicy());
        } else if (fileAttributes.getRetentionPolicy() != space.getRetentionPolicy()) {
            throw new SpaceException("Retention policy conflicts with retention policy defined by default space reservation.");
        }
        if (space.getDescription() != null) {
            storageInfo.setKey("SpaceTokenDescription", space.getDescription());
        }
        LOGGER.trace("selectPool: found linkGroup = {}, forwarding message", linkGroupName);
    } else if (allowUnreservedUploadsToLinkGroups) {
        LOGGER.trace("Upload outside a reservation, identifying appropriate linkgroup");
        LinkGroup linkGroup = findLinkGroupForWrite(subject, protocolInfo, fileAttributes, selectWritePool.getPreallocated());
        if (linkGroup != null) {
            String linkGroupName = linkGroup.getName();
            selectWritePool.setLinkGroup(linkGroupName);
            fileAttributes.getStorageInfo().setKey("LinkGroupId", Long.toString(linkGroup.getId()));
            LOGGER.trace("selectPool: found linkGroup = {}, forwarding message", linkGroupName);
        }
    } else if (isWriteableOutsideLinkgroup(protocolInfo, fileAttributes)) {
        LOGGER.debug("Upload proceeding outside of any linkgroup.");
    } else {
        throw new NoPoolConfiguredSpaceException("No write pools configured outside of a linkgroup.");
    }
}
Also used : Subject(javax.security.auth.Subject) StorageInfo(diskCacheV111.vehicles.StorageInfo) ProtocolInfo(diskCacheV111.vehicles.ProtocolInfo) IpProtocolInfo(diskCacheV111.vehicles.IpProtocolInfo) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) FileAttributes(org.dcache.vehicles.FileAttributes)

Example 3 with PoolAcceptFileMessage

use of diskCacheV111.vehicles.PoolAcceptFileMessage in project dcache by dCache.

the class Transfer method startMoverAsync.

/**
 * Creates a mover for the transfer.
 */
public ListenableFuture<Void> startMoverAsync(long timeout) {
    FileAttributes fileAttributes = getFileAttributes();
    Pool pool = getPool();
    if (fileAttributes == null || pool == null) {
        throw new IllegalStateException("Need PNFS ID, file attributes and pool before a mover can be started");
    }
    ProtocolInfo protocolInfo = getProtocolInfoForPool();
    PoolIoFileMessage message;
    if (isWrite()) {
        long allocated = _allocated;
        if (allocated == 0 && fileAttributes.isDefined(SIZE)) {
            allocated = fileAttributes.getSize();
        }
        message = new PoolAcceptFileMessage(pool.getName(), protocolInfo, fileAttributes, pool.getAssumption(), _maximumSize, allocated);
    } else {
        message = new PoolDeliverFileMessage(pool.getName(), protocolInfo, fileAttributes, pool.getAssumption());
    }
    message.setBillingPath(getBillingPath());
    message.setTransferPath(getTransferPath());
    message.setIoQueueName(getIoQueue());
    message.setInitiator(getTransaction());
    message.setId(_id);
    message.setSubject(_subject);
    /*
         * SpaceManager needs to spy mover shutdown to adjust the space reservation. for this reason we have to
         * proxy mover start messages through SpaceManager. However, reads can be sent directly to pools.
         *
         * REVISIT: this should happen only when space manager is enabled.
         */
    ListenableFuture<PoolIoFileMessage> reply = isWrite() ? _poolManager.startAsync(pool.getAddress(), message, timeout) : _poolStub.send(new CellPath(pool.getAddress()), message, timeout);
    reply = catchingAsync(reply, NoRouteToCellException.class, x -> {
        // invalidate pool selection to let the door to start over
        clearPoolSelection();
        return immediateFailedFuture(x);
    });
    setStatusUntil("Pool " + pool + ": Creating mover", reply);
    return CellStub.transformAsync(reply, msg -> {
        setMoverId(msg.getMoverId());
        return immediateFuture(null);
    });
}
Also used : CellPath(dmg.cells.nucleus.CellPath) ProtocolInfo(diskCacheV111.vehicles.ProtocolInfo) DoorTransferFinishedMessage(diskCacheV111.vehicles.DoorTransferFinishedMessage) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) Pool(diskCacheV111.vehicles.Pool) Restriction(org.dcache.auth.attributes.Restriction) Futures.transformAsync(com.google.common.util.concurrent.Futures.transformAsync) LoggerFactory(org.slf4j.LoggerFactory) RequestState(diskCacheV111.poolManager.RequestContainerV5.RequestState) PoolMoverKillMessage(diskCacheV111.vehicles.PoolMoverKillMessage) Restrictions(org.dcache.auth.attributes.Restrictions) InetAddress(java.net.InetAddress) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) PnfsHandler(diskCacheV111.util.PnfsHandler) Future(java.util.concurrent.Future) PoolAcceptFileMessage(diskCacheV111.vehicles.PoolAcceptFileMessage) Duration(java.time.Duration) PoolManagerStub(org.dcache.poolmanager.PoolManagerStub) CheckStagePermission(diskCacheV111.util.CheckStagePermission) IoJobInfo(diskCacheV111.vehicles.IoJobInfo) SIZE(org.dcache.namespace.FileAttribute.SIZE) ThreadFactory(java.util.concurrent.ThreadFactory) EnumSet(java.util.EnumSet) CDC(dmg.cells.nucleus.CDC) FileAttributes(org.dcache.vehicles.FileAttributes) Longs(com.google.common.primitives.Longs) PNFSID(org.dcache.namespace.FileAttribute.PNFSID) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) PoolDeliverFileMessage(diskCacheV111.vehicles.PoolDeliverFileMessage) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) Set(java.util.Set) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) TimebasedCounter(dmg.util.TimebasedCounter) Executors(java.util.concurrent.Executors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) DoorRequestInfoMessage(diskCacheV111.vehicles.DoorRequestInfoMessage) PoolMgrSelectWritePoolMsg(diskCacheV111.vehicles.PoolMgrSelectWritePoolMsg) PnfsCreateEntryMessage(diskCacheV111.vehicles.PnfsCreateEntryMessage) CellPath(dmg.cells.nucleus.CellPath) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) PoolMgrSelectPoolMsg(diskCacheV111.vehicles.PoolMgrSelectPoolMsg) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) FsPath(diskCacheV111.util.FsPath) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) CellAddressCore(dmg.cells.nucleus.CellAddressCore) IoDoorEntry(diskCacheV111.vehicles.IoDoorEntry) MathUtils.subWithInfinity(org.dcache.util.MathUtils.subWithInfinity) MathUtils.addWithInfinity(org.dcache.util.MathUtils.addWithInfinity) HashSet(java.util.HashSet) OptionalLong(java.util.OptionalLong) CacheException(diskCacheV111.util.CacheException) CellStub(org.dcache.cells.CellStub) MoverInfoMessage(diskCacheV111.vehicles.MoverInfoMessage) TYPE(org.dcache.namespace.FileAttribute.TYPE) Objects.requireNonNull(java.util.Objects.requireNonNull) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) Nullable(javax.annotation.Nullable) FileType(org.dcache.namespace.FileType) Futures.immediateFuture(com.google.common.util.concurrent.Futures.immediateFuture) STORAGEINFO(org.dcache.namespace.FileAttribute.STORAGEINFO) PnfsId(diskCacheV111.util.PnfsId) Logger(org.slf4j.Logger) BaseEncoding(com.google.common.io.BaseEncoding) PoolIoFileMessage(diskCacheV111.vehicles.PoolIoFileMessage) REGULAR(org.dcache.namespace.FileType.REGULAR) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) IOException(java.io.IOException) NotFileCacheException(diskCacheV111.util.NotFileCacheException) PoolMgrSelectReadPoolMsg(diskCacheV111.vehicles.PoolMgrSelectReadPoolMsg) Subject(javax.security.auth.Subject) Futures.catchingAsync(com.google.common.util.concurrent.Futures.catchingAsync) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Futures(com.google.common.util.concurrent.Futures) MDC(org.slf4j.MDC) Futures.immediateFailedFuture(com.google.common.util.concurrent.Futures.immediateFailedFuture) AccessMask(org.dcache.acl.enums.AccessMask) AsyncFunction(com.google.common.util.concurrent.AsyncFunction) FileAttribute(org.dcache.namespace.FileAttribute) Collections(java.util.Collections) PoolDeliverFileMessage(diskCacheV111.vehicles.PoolDeliverFileMessage) PoolIoFileMessage(diskCacheV111.vehicles.PoolIoFileMessage) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) ProtocolInfo(diskCacheV111.vehicles.ProtocolInfo) Pool(diskCacheV111.vehicles.Pool) PoolAcceptFileMessage(diskCacheV111.vehicles.PoolAcceptFileMessage) FileAttributes(org.dcache.vehicles.FileAttributes) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes)

Example 4 with PoolAcceptFileMessage

use of diskCacheV111.vehicles.PoolAcceptFileMessage in project dcache by dCache.

the class PoolV4 method createMover.

// //////////////////////////////////////////////////////////////
// 
// The io File Part
// 
// 
public Mover<?> createMover(CellMessage envelop, PoolIoFileMessage message) throws CacheException {
    CellPath source = envelop.getSourcePath().revert();
    FileAttributes attributes = message.getFileAttributes();
    PnfsId pnfsId = attributes.getPnfsId();
    ProtocolInfo pi = message.getProtocolInfo();
    MoverFactory moverFactory = _transferServices.getMoverFactory(pi);
    ReplicaDescriptor handle;
    try {
        if (message instanceof PoolAcceptFileMessage) {
            OptionalLong maximumSize = ((PoolAcceptFileMessage) message).getMaximumSize();
            List<StickyRecord> stickyRecords = _replicaStatePolicy.getStickyRecords(attributes);
            ReplicaState targetState = _replicaStatePolicy.getTargetState(attributes);
            handle = _repository.createEntry(attributes, ReplicaState.FROM_CLIENT, targetState, stickyRecords, moverFactory.getChannelCreateOptions(), maximumSize);
        } else {
            Set<? extends OpenOption> openFlags = message.isPool2Pool() ? EnumSet.of(Repository.OpenFlags.NOATIME) : EnumSet.noneOf(Repository.OpenFlags.class);
            handle = _repository.openEntry(pnfsId, openFlags);
        }
    } catch (FileNotInCacheException e) {
        throw new FileNotInCacheException("File " + pnfsId + " does not exist in " + _poolName, e);
    } catch (FileInCacheException e) {
        throw new FileInCacheException("File " + pnfsId + " already exists in " + _poolName, e);
    }
    try {
        return moverFactory.createMover(handle, message, source);
    } catch (Throwable t) {
        handle.close();
        throw t;
    }
}
Also used : CellPath(dmg.cells.nucleus.CellPath) PnfsId(diskCacheV111.util.PnfsId) ReplicaState(org.dcache.pool.repository.ReplicaState) StickyRecord(org.dcache.pool.repository.StickyRecord) MoverFactory(org.dcache.pool.movers.MoverFactory) ReplicaDescriptor(org.dcache.pool.repository.ReplicaDescriptor) FileInCacheException(diskCacheV111.util.FileInCacheException) ProtocolInfo(diskCacheV111.vehicles.ProtocolInfo) DCapProtocolInfo(diskCacheV111.vehicles.DCapProtocolInfo) OptionalLong(java.util.OptionalLong) PoolAcceptFileMessage(diskCacheV111.vehicles.PoolAcceptFileMessage) FileAttributes(org.dcache.vehicles.FileAttributes) FileNotInCacheException(diskCacheV111.util.FileNotInCacheException)

Example 5 with PoolAcceptFileMessage

use of diskCacheV111.vehicles.PoolAcceptFileMessage in project dcache by dCache.

the class TransferManagerHandler method startMoverOnThePool.

public void startMoverOnThePool() {
    PoolIoFileMessage poolMessage = store ? new PoolAcceptFileMessage(pool.getName(), protocol_info, fileAttributes, pool.getAssumption(), OptionalLong.empty()) : new PoolDeliverFileMessage(pool.getName(), protocol_info, fileAttributes, pool.getAssumption());
    poolMessage.setBillingPath(info.getBillingPath());
    poolMessage.setTransferPath(info.getTransferPath());
    poolMessage.setSubject(transferRequest.getSubject());
    if (manager.getIoQueueName() != null) {
        poolMessage.setIoQueueName(manager.getIoQueueName());
    }
    poolMessage.setInitiator(info.getTransaction());
    poolMessage.setId(id);
    setState(WAITING_FIRST_POOL_REPLY_STATE);
    manager.persist(this);
    CellStub.addCallback(manager.getPoolManagerStub().startAsync(pool.getAddress(), poolMessage), this, executor);
}
Also used : PoolDeliverFileMessage(diskCacheV111.vehicles.PoolDeliverFileMessage) PoolIoFileMessage(diskCacheV111.vehicles.PoolIoFileMessage) PoolAcceptFileMessage(diskCacheV111.vehicles.PoolAcceptFileMessage)

Aggregations

PoolAcceptFileMessage (diskCacheV111.vehicles.PoolAcceptFileMessage)4 FileAttributes (org.dcache.vehicles.FileAttributes)4 PnfsId (diskCacheV111.util.PnfsId)3 ProtocolInfo (diskCacheV111.vehicles.ProtocolInfo)3 PoolDeliverFileMessage (diskCacheV111.vehicles.PoolDeliverFileMessage)2 Subject (javax.security.auth.Subject)2 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Sets (com.google.common.collect.Sets)1 BaseEncoding (com.google.common.io.BaseEncoding)1 Longs (com.google.common.primitives.Longs)1 AsyncFunction (com.google.common.util.concurrent.AsyncFunction)1 Futures (com.google.common.util.concurrent.Futures)1 Futures.catchingAsync (com.google.common.util.concurrent.Futures.catchingAsync)1 Futures.immediateFailedFuture (com.google.common.util.concurrent.Futures.immediateFailedFuture)1 Futures.immediateFuture (com.google.common.util.concurrent.Futures.immediateFuture)1 Futures.transformAsync (com.google.common.util.concurrent.Futures.transformAsync)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1