Search in sources :

Example 1 with PoolMgrSelectReadPoolMsg

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

the class FileOperationHandler method handleStaging.

/**
 * <p>Called when there are no available replicas, but the file
 * can be retrieved from an HSM.</p>
 *
 * <p>Issues a fire and forget request.  Task is considered complete at
 * that point.</p>
 *
 * <p>When staging actually completes on the PoolManager end, the new
 * cache location message should be processed by Resilience as a new FileOperation.</p>
 *
 * <p>Should staging not complete before the pool is once again scanned,
 * PoolManager should collapse the repeated staging request.</p>
 */
public void handleStaging(PnfsId pnfsId, ResilientFileTask task) {
    try {
        FileOperation operation = fileOpMap.getOperation(pnfsId);
        FileAttributes attributes = namespace.getRequiredAttributesForStaging(pnfsId);
        String poolGroup = poolInfoMap.getGroup(operation.getPoolGroup());
        LOGGER.trace("handleStaging {}, pool group {}.", pnfsId, poolGroup);
        migrationTaskService.schedule(() -> {
            try {
                PoolMgrSelectReadPoolMsg msg = new PoolMgrSelectReadPoolMsg(attributes, getProtocolInfo(), null);
                msg.setSubject(Subjects.ROOT);
                msg.setPoolGroup(poolGroup);
                CellMessage cellMessage = new CellMessage(new CellPath(poolManagerAddress), msg);
                ACTIVITY_LOGGER.info("Staging {}", pnfsId);
                endpoint.sendMessage(cellMessage);
                LOGGER.trace("handleStaging, sent select read pool message " + "for {} to poolManager.", pnfsId);
                completionHandler.taskCompleted(pnfsId);
            } catch (URISyntaxException e) {
                completionHandler.taskFailed(pnfsId, CacheExceptionUtils.getCacheException(CacheException.INVALID_ARGS, "could not construct HTTP protocol: %s.", pnfsId, Type.WAIT_FOR_STAGE, e.getMessage(), null));
            }
        }, 0, TimeUnit.MILLISECONDS);
    } catch (CacheException ce) {
        completionHandler.taskFailed(pnfsId, ce);
    }
}
Also used : PoolMgrSelectReadPoolMsg(diskCacheV111.vehicles.PoolMgrSelectReadPoolMsg) CellMessage(dmg.cells.nucleus.CellMessage) CellPath(dmg.cells.nucleus.CellPath) CacheException(diskCacheV111.util.CacheException) FileOperation(org.dcache.resilience.data.FileOperation) URISyntaxException(java.net.URISyntaxException) FileAttributes(org.dcache.vehicles.FileAttributes)

Example 2 with PoolMgrSelectReadPoolMsg

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

the class FileOperationHandler method handleStagingReply.

/**
 * <p>If the reply from the Pool Manager indicates that the file has
 * been staged to a pool outside the pool group, resend the message with refreshed attributes to
 * trigger a p2p by the Pool Manager to a readable resilient pool in the correct group.
 * Otherwise, discard the message.</p>
 */
public void handleStagingReply(PoolMgrSelectReadPoolMsg reply) {
    PnfsId pnfsId = reply.getPnfsId();
    try {
        if (reply.getReturnCode() == CacheException.OUT_OF_DATE) {
            FileAttributes attributes = namespace.getRequiredAttributesForStaging(pnfsId);
            /*
                 *  Check to see if one of the new locations is not resilient.
                 */
            Collection<String> locations = attributes.getLocations();
            List<String> valid = poolInfoMap.getReadableLocations(locations).stream().filter(poolInfoMap::isResilientPool).collect(Collectors.toList());
            LOGGER.trace("{}, handleStagingReply, readable resilience " + "locations are now {}.", valid);
            if (valid.size() == 0) {
                LOGGER.trace("{}, handleStagingReply, " + "PoolManager staged to" + " a non-resilient pool, " + "requesting p2p.", pnfsId);
                /*
                     *  Figure out on which pool group this should be.
                     *
                     *  It's possible that the file was "resilient" when the
                     *  stage request was sent and a subsequently configuration
                     *  change has resulted in the file no longer being
                     *  "resilient".  If this happens, the file may have no
                     *  corresponding resilient pool group.
                     *
                     *  Another possibility is the lack of resilient pool group
                     *  is due to a bug somewhere.
                     */
                Integer gIndex = null;
                for (String loc : locations) {
                    Integer pIndex = poolInfoMap.getPoolIndex(loc);
                    gIndex = poolInfoMap.getResilientPoolGroup(pIndex);
                    if (gIndex != null) {
                        break;
                    }
                }
                if (gIndex == null) {
                    LOGGER.warn("{}, handleStagingReply, file no longer" + " hosted on resilient pool group", pnfsId);
                    return;
                }
                final String poolGroup = poolInfoMap.getGroup(gIndex);
                LOGGER.trace("{}, handleStagingReply, resilient pool group " + "for p2p request: {}.", pnfsId, poolGroup);
                migrationTaskService.schedule(() -> {
                    PoolMgrSelectReadPoolMsg msg = new PoolMgrSelectReadPoolMsg(attributes, reply.getProtocolInfo(), reply.getContext(), reply.getAllowedStates());
                    msg.setSubject(reply.getSubject());
                    msg.setPoolGroup(poolGroup);
                    CellMessage cellMessage = new CellMessage(new CellPath(poolManagerAddress), msg);
                    ACTIVITY_LOGGER.info("Selecting read pool for file {}" + " staged to a non-resilient pool", pnfsId);
                    endpoint.sendMessage(cellMessage);
                    LOGGER.trace("handleStagingReply, resent select read pool " + "message for {} to poolManager.", pnfsId);
                }, 0, TimeUnit.MILLISECONDS);
                return;
            }
        }
        LOGGER.trace("{} handleStagingReply {}, nothing to do.", pnfsId, reply);
    } catch (CacheException ce) {
        LOGGER.error("handleStagingReply failed: {}.", ce.toString());
    }
}
Also used : PoolMgrSelectReadPoolMsg(diskCacheV111.vehicles.PoolMgrSelectReadPoolMsg) CellMessage(dmg.cells.nucleus.CellMessage) CellPath(dmg.cells.nucleus.CellPath) CacheException(diskCacheV111.util.CacheException) PnfsId(diskCacheV111.util.PnfsId) FileAttributes(org.dcache.vehicles.FileAttributes)

Example 3 with PoolMgrSelectReadPoolMsg

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

the class PinRequestProcessor method askPoolManager.

private void askPoolManager(final PinTask task) {
    PoolMgrSelectReadPoolMsg msg = new PoolMgrSelectReadPoolMsg(task.getFileAttributes(), task.getProtocolInfo(), task.getReadPoolSelectionContext(), checkStaging(task));
    msg.setSubject(task.getSubject());
    CellStub.addCallback(_poolManagerStub.sendAsync(msg), new AbstractMessageCallback<PoolMgrSelectReadPoolMsg>() {

        @Override
        public void success(PoolMgrSelectReadPoolMsg msg) {
            try {
                /* Pool manager expects us
                           * to keep some state
                           * between retries.
                           */
                task.setReadPoolSelectionContext(msg.getContext());
                /* Store the pool name in
                           * the DB so we know what to
                           * clean up if something
                           * fails.
                           */
                Pool pool = msg.getPool();
                task.getFileAttributes().getLocations().add(pool.getName());
                setPool(task, pool.getName());
                setStickyFlag(task, pool.getName(), pool.getAddress());
            } catch (CacheException e) {
                fail(task, e.getRc(), e.getMessage());
            } catch (RuntimeException e) {
                fail(task, CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.toString());
            }
        }

        @Override
        public void failure(int rc, Object error) {
            /* Pool manager expects us to
                       * keep some state between
                       * retries.
                       */
            task.setReadPoolSelectionContext(getReply().getContext());
            switch(rc) {
                case CacheException.OUT_OF_DATE:
                    /* Pool manager asked for a
                               * refresh of the request.
                               * Retry right away.
                               */
                    retry(task, 0, "PoolManager requested a retry");
                    break;
                case CacheException.FILE_NOT_IN_REPOSITORY:
                case CacheException.PERMISSION_DENIED:
                    fail(task, rc, error.toString());
                    break;
                default:
                    /* Ideally we would delegate the retry to the door,
                               * but for the time being the retry is dealed with
                               * by pin manager.
                               */
                    retry(task, RETRY_DELAY, "PoolManager request failed: " + error);
                    break;
            }
        }

        @Override
        public void noroute(CellPath path) {
            /* Pool manager is
                       * unreachable. We expect this
                       * to be transient and retry in
                       * a moment.
                       */
            retry(task, RETRY_DELAY, "no route to PoolManager at " + path);
        }

        @Override
        public void timeout(String message) {
            /* Pool manager did not
                       * respond. We expect this to be
                       * transient and retry in a
                       * moment.
                       */
            retry(task, SMALL_DELAY, "timeout with PoolManager: " + message);
        }
    }, _executor);
}
Also used : PoolMgrSelectReadPoolMsg(diskCacheV111.vehicles.PoolMgrSelectReadPoolMsg) CellPath(dmg.cells.nucleus.CellPath) FileNotOnlineCacheException(diskCacheV111.util.FileNotOnlineCacheException) CacheException(diskCacheV111.util.CacheException) Pool(diskCacheV111.vehicles.Pool) SelectedPool(org.dcache.poolmanager.SelectedPool)

Example 4 with PoolMgrSelectReadPoolMsg

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

the class HsmRestoreTest method testRestoreNoLocationsOnePoolCantStage.

@Test
public void testRestoreNoLocationsOnePoolCantStage() throws Exception {
    PnfsId pnfsId = new PnfsId("000000000000000000000000000000000001");
    /*
         * pre-configure pool selection unit
         */
    List<String> pools = new ArrayList<>(3);
    pools.add("pool1");
    pools.add("pool2");
    PoolMonitorHelper.prepareSelectionUnit(_selectionUnit, _access, pools);
    /*
         * prepare reply for GetStorageInfo
         */
    _storageInfo.addLocation(new URI("osm://osm?"));
    _storageInfo.setIsNew(false);
    PnfsGetFileAttributes fileAttributesMessage = new PnfsGetFileAttributes(pnfsId, EnumSet.noneOf(FileAttribute.class));
    FileAttributes attributes = new FileAttributes();
    StorageInfos.injectInto(_storageInfo, attributes);
    attributes.setPnfsId(pnfsId);
    attributes.setLocations(Collections.<String>emptyList());
    attributes.setSize(5);
    attributes.setAccessLatency(StorageInfo.DEFAULT_ACCESS_LATENCY);
    attributes.setRetentionPolicy(StorageInfo.DEFAULT_RETENTION_POLICY);
    attributes.setChecksums(Collections.emptySet());
    fileAttributesMessage.setFileAttributes(attributes);
    _cell.prepareMessage(new CellPath("PnfsManager"), fileAttributesMessage, true);
    /*
         * make pools know to 'PoolManager'
         */
    long serialId = System.currentTimeMillis();
    PoolV2Mode poolMode = new PoolV2Mode(PoolV2Mode.ENABLED);
    Set<String> connectedHSM = new HashSet<>(1);
    connectedHSM.add("osm");
    for (String pool : pools) {
        PoolCostInfo poolCostInfo = new PoolCostInfo(pool, IoQueueManager.DEFAULT_QUEUE);
        poolCostInfo.setSpaceUsage(100, 20, 30, 50);
        poolCostInfo.setQueueSizes(0, 10, 0, 0, 10, 0);
        poolCostInfo.addExtendedMoverQueueSizes(IoQueueManager.DEFAULT_QUEUE, 0, 10, 0, 0, 0);
        CellMessage envelope = new CellMessage(new CellAddressCore("PoolManager"), null);
        envelope.addSourceAddress(new CellAddressCore(pool));
        PoolManagerPoolUpMessage poolUpMessage = new PoolManagerPoolUpMessage(pool, serialId, poolMode, poolCostInfo);
        prepareSelectionUnit(pool, poolMode, connectedHSM);
        _costModule.messageArrived(envelope, poolUpMessage);
    }
    final AtomicInteger stageRequests1 = new AtomicInteger(0);
    final AtomicInteger stageRequests2 = new AtomicInteger(0);
    final AtomicInteger replyRequest = new AtomicInteger(0);
    MessageAction messageAction1 = new StageMessageAction(stageRequests1);
    MessageAction messageAction2 = new StageMessageAction(stageRequests2);
    MessageAction messageAction3 = new StageMessageAction(replyRequest);
    _cell.registerAction("pool1", PoolFetchFileMessage.class, messageAction1);
    _cell.registerAction("pool2", PoolFetchFileMessage.class, messageAction2);
    _cell.registerAction("door", PoolMgrSelectReadPoolMsg.class, messageAction3);
    PoolMgrSelectReadPoolMsg selectReadPool = new PoolMgrSelectReadPoolMsg(attributes, _protocolInfo, null);
    CellMessage cellMessage = new CellMessage(new CellAddressCore("PoolManager"), selectReadPool);
    cellMessage.getSourcePath().add(new CellAddressCore("door", "local"));
    _rc.messageArrived(cellMessage, selectReadPool);
    // first pool replies with an error
    CellMessage m = __messages.remove(0);
    PoolFetchFileMessage ff = (PoolFetchFileMessage) m.getMessageObject();
    ff.setFailed(17, "pech");
    _rc.messageArrived(m, m.getMessageObject());
    // pool manager bounces request back to door
    m = __messages.remove(0);
    selectReadPool = (PoolMgrSelectReadPoolMsg) m.getMessageObject();
    assertEquals("Unexpected reply from pool manager", 17, selectReadPool.getReturnCode());
    // resubmit request
    PoolMgrSelectReadPoolMsg selectReadPool2 = new PoolMgrSelectReadPoolMsg(attributes, _protocolInfo, selectReadPool.getContext());
    CellMessage cellMessage2 = new CellMessage(new CellAddressCore("PoolManager"), selectReadPool2);
    _rc.messageArrived(cellMessage2, selectReadPool2);
    assertEquals("No stage request sent to pools1", 1, stageRequests1.get());
    assertEquals("No stage request sent to pools2", 1, stageRequests2.get());
}
Also used : CellPath(dmg.cells.nucleus.CellPath) PoolMgrSelectReadPoolMsg(diskCacheV111.vehicles.PoolMgrSelectReadPoolMsg) CellAddressCore(dmg.cells.nucleus.CellAddressCore) PoolFetchFileMessage(diskCacheV111.vehicles.PoolFetchFileMessage) PnfsId(diskCacheV111.util.PnfsId) ArrayList(java.util.ArrayList) URI(java.net.URI) CellMessage(dmg.cells.nucleus.CellMessage) PoolManagerPoolUpMessage(diskCacheV111.vehicles.PoolManagerPoolUpMessage) PoolV2Mode(diskCacheV111.pools.PoolV2Mode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MessageAction(org.dcache.tests.cells.MockCellEndpoint.MessageAction) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) FileAttributes(org.dcache.vehicles.FileAttributes) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) PoolCostInfo(diskCacheV111.pools.PoolCostInfo) FileAttribute(org.dcache.namespace.FileAttribute) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with PoolMgrSelectReadPoolMsg

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

the class HsmRestoreTest method testRestoreNoLocations.

@Test
public void testRestoreNoLocations() throws Exception {
    PnfsId pnfsId = new PnfsId("000000000000000000000000000000000001");
    /*
         * pre-configure pool selection unit
         */
    List<String> pools = new ArrayList<>(3);
    pools.add("pool1");
    pools.add("pool2");
    PoolMonitorHelper.prepareSelectionUnit(_selectionUnit, _access, pools);
    /*
         * prepare reply for GetStorageInfo
         */
    _storageInfo.addLocation(new URI("osm://osm?"));
    _storageInfo.setIsNew(false);
    PnfsGetFileAttributes fileAttributesMessage = new PnfsGetFileAttributes(pnfsId, EnumSet.noneOf(FileAttribute.class));
    FileAttributes attributes = new FileAttributes();
    StorageInfos.injectInto(_storageInfo, attributes);
    attributes.setPnfsId(pnfsId);
    attributes.setLocations(Collections.<String>emptyList());
    attributes.setSize(5);
    attributes.setAccessLatency(StorageInfo.DEFAULT_ACCESS_LATENCY);
    attributes.setRetentionPolicy(StorageInfo.DEFAULT_RETENTION_POLICY);
    attributes.setChecksums(Collections.emptySet());
    fileAttributesMessage.setFileAttributes(attributes);
    _cell.prepareMessage(new CellPath("PnfsManager"), fileAttributesMessage, true);
    /*
         * make pools know to 'PoolManager'
         */
    long serialId = System.currentTimeMillis();
    PoolV2Mode poolMode = new PoolV2Mode(PoolV2Mode.ENABLED);
    Set<String> connectedHSM = new HashSet<>(1);
    connectedHSM.add("osm");
    for (String pool : pools) {
        PoolCostInfo poolCostInfo = new PoolCostInfo(pool, IoQueueManager.DEFAULT_QUEUE);
        poolCostInfo.setSpaceUsage(100, 20, 30, 50);
        poolCostInfo.setQueueSizes(0, 10, 0, 0, 10, 0);
        poolCostInfo.addExtendedMoverQueueSizes(IoQueueManager.DEFAULT_QUEUE, 0, 10, 0, 0, 0);
        CellMessage envelope = new CellMessage(new CellAddressCore("irrelevant"), null);
        envelope.addSourceAddress(new CellAddressCore(pool));
        PoolManagerPoolUpMessage poolUpMessage = new PoolManagerPoolUpMessage(pool, serialId, poolMode, poolCostInfo);
        prepareSelectionUnit(pool, poolMode, connectedHSM);
        _costModule.messageArrived(envelope, poolUpMessage);
    }
    final AtomicInteger stageRequests = new AtomicInteger(0);
    MessageAction messageAction = new StageMessageAction(stageRequests);
    _cell.registerAction("pool1", PoolFetchFileMessage.class, messageAction);
    _cell.registerAction("pool2", PoolFetchFileMessage.class, messageAction);
    PoolMgrSelectReadPoolMsg selectReadPool = new PoolMgrSelectReadPoolMsg(attributes, _protocolInfo, null);
    CellMessage cellMessage = new CellMessage(new CellAddressCore("PoolManager"), selectReadPool);
    _rc.messageArrived(cellMessage, selectReadPool);
    assertEquals("No stage request sent to pools", 1, stageRequests.get());
}
Also used : CellPath(dmg.cells.nucleus.CellPath) PoolMgrSelectReadPoolMsg(diskCacheV111.vehicles.PoolMgrSelectReadPoolMsg) CellAddressCore(dmg.cells.nucleus.CellAddressCore) PnfsId(diskCacheV111.util.PnfsId) ArrayList(java.util.ArrayList) URI(java.net.URI) CellMessage(dmg.cells.nucleus.CellMessage) PoolManagerPoolUpMessage(diskCacheV111.vehicles.PoolManagerPoolUpMessage) PoolV2Mode(diskCacheV111.pools.PoolV2Mode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MessageAction(org.dcache.tests.cells.MockCellEndpoint.MessageAction) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) FileAttributes(org.dcache.vehicles.FileAttributes) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) PoolCostInfo(diskCacheV111.pools.PoolCostInfo) FileAttribute(org.dcache.namespace.FileAttribute) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

PoolMgrSelectReadPoolMsg (diskCacheV111.vehicles.PoolMgrSelectReadPoolMsg)12 CellMessage (dmg.cells.nucleus.CellMessage)8 FileAttributes (org.dcache.vehicles.FileAttributes)8 CellPath (dmg.cells.nucleus.CellPath)7 PnfsId (diskCacheV111.util.PnfsId)6 Test (org.junit.Test)6 PoolCostInfo (diskCacheV111.pools.PoolCostInfo)5 CellAddressCore (dmg.cells.nucleus.CellAddressCore)5 PnfsGetFileAttributes (org.dcache.vehicles.PnfsGetFileAttributes)5 PoolV2Mode (diskCacheV111.pools.PoolV2Mode)4 CacheException (diskCacheV111.util.CacheException)4 PoolManagerPoolUpMessage (diskCacheV111.vehicles.PoolManagerPoolUpMessage)4 URI (java.net.URI)4 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 FileAttribute (org.dcache.namespace.FileAttribute)4 MessageAction (org.dcache.tests.cells.MockCellEndpoint.MessageAction)4 PoolFetchFileMessage (diskCacheV111.vehicles.PoolFetchFileMessage)3 ProtocolInfo (diskCacheV111.vehicles.ProtocolInfo)3