Search in sources :

Example 6 with CellPath

use of dmg.cells.nucleus.CellPath in project dcache by dCache.

the class HsmCleaner method flush.

/**
 * Submits requests queued for a given HSM if there is not already a pending request registered
 * for this HSM.
 *
 * @param hsm the name of an HSM instance
 */
private synchronized void flush(String hsm) {
    // Don't allow flushing when not having leadership
    if (!_hasHaLeadership) {
        return;
    }
    Collection<URI> locations = _locationsToDelete.get(hsm);
    if (locations == null || locations.isEmpty()) {
        return;
    }
    if (_requestTimeoutPerHsm.containsKey(hsm)) {
        return;
    }
    /* To avoid excessively large requests, we limit the number
         * of files per request.
         */
    if (locations.size() > _maxFilesPerRequest) {
        Collection<URI> subset = new ArrayList<>(_maxFilesPerRequest);
        Iterator<URI> iterator = locations.iterator();
        for (int i = 0; i < _maxFilesPerRequest; i++) {
            subset.add(iterator.next());
        }
        locations = subset;
    }
    PoolInformation pool = _pools.getPoolWithHSM(hsm);
    if (pool != null) {
        String name = pool.getName();
        PoolRemoveFilesFromHSMMessage message = new PoolRemoveFilesFromHSMMessage(name, hsm, locations);
        _poolStub.notify(new CellPath(name), message);
        Timeout timeout = new Timeout(hsm, name);
        _timer.schedule(timeout, _hsmTimeoutUnit.toMillis(_hsmTimeout));
        _requestTimeoutPerHsm.put(hsm, timeout);
    } else {
        /* If there is no available pool, then we report failure on
             * all files.
             */
        LOGGER.warn("No pools attached to {} are available", hsm);
        Iterator<URI> i = _locationsToDelete.get(hsm).iterator();
        while (i.hasNext()) {
            URI location = i.next();
            assert location.getAuthority().equals(hsm);
            _failureSink.accept(location);
            i.remove();
        }
    }
}
Also used : CellPath(dmg.cells.nucleus.CellPath) ArrayList(java.util.ArrayList) URI(java.net.URI) PoolRemoveFilesFromHSMMessage(diskCacheV111.vehicles.PoolRemoveFilesFromHSMMessage)

Example 7 with CellPath

use of dmg.cells.nucleus.CellPath 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 8 with CellPath

use of dmg.cells.nucleus.CellPath in project dcache by dCache.

the class PinRequestProcessor method setStickyFlag.

private void setStickyFlag(final PinTask task, final String poolName, CellAddressCore poolAddress) {
    /* The pin lifetime should be from the moment the file is
         * actually pinned. Due to staging and pool to pool transfers
         * this may be much later than when the pin was requested.
         */
    Date pinExpiration = task.freezeExpirationTime();
    /* To allow for some drift in clocks we add a safety margin to
         * the lifetime of the sticky bit.
         */
    long poolExpiration = (pinExpiration == null) ? -1 : pinExpiration.getTime() + CLOCK_DRIFT_MARGIN;
    PoolSetStickyMessage msg = new PoolSetStickyMessage(poolName, task.getPnfsId(), true, task.getSticky(), poolExpiration);
    CellStub.addCallback(_poolStub.send(new CellPath(poolAddress), msg), new AbstractMessageCallback<PoolSetStickyMessage>() {

        @Override
        public void success(PoolSetStickyMessage msg) {
            try {
                setToPinned(task);
                task.success();
            } 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) {
            switch(rc) {
                case CacheException.POOL_DISABLED:
                    /* Pool manager had outdated
                               * information about the pool. Give
                               * it a chance to be updated and
                               * then retry.
                               */
                    retry(task, RETRY_DELAY, "pool " + poolName + " declared itself disabled");
                    break;
                case CacheException.FILE_NOT_IN_REPOSITORY:
                    /* Pnfs manager had stale location
                               * information. The pool clears
                               * this information as a result of
                               * this error, so we retry in a
                               * moment.
                               */
                    retry(task, SMALL_DELAY, "file not on pool " + poolName);
                    break;
                default:
                    fail(task, rc, error.toString());
                    break;
            }
        }

        @Override
        public void noroute(CellPath path) {
            /* The pool must have gone down. Give
                       * pool manager a moment to notice this
                       * and then retry.
                       */
            retry(task, RETRY_DELAY, "no route to pool at " + poolAddress);
        }

        @Override
        public void timeout(String error) {
            /* No response from pool. Typically this is
                       * because the pool is overloaded.
                       */
            fail(task, CacheException.TIMEOUT, error);
        }
    }, _executor);
}
Also used : CellPath(dmg.cells.nucleus.CellPath) FileNotOnlineCacheException(diskCacheV111.util.FileNotOnlineCacheException) CacheException(diskCacheV111.util.CacheException) PoolSetStickyMessage(diskCacheV111.vehicles.PoolSetStickyMessage) Date(java.util.Date)

Example 9 with CellPath

use of dmg.cells.nucleus.CellPath 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 10 with CellPath

use of dmg.cells.nucleus.CellPath 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

CellPath (dmg.cells.nucleus.CellPath)77 CacheException (diskCacheV111.util.CacheException)20 CellMessage (dmg.cells.nucleus.CellMessage)19 CellAddressCore (dmg.cells.nucleus.CellAddressCore)15 PnfsId (diskCacheV111.util.PnfsId)14 FileAttributes (org.dcache.vehicles.FileAttributes)14 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)12 NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)9 CellStub (org.dcache.cells.CellStub)9 PnfsGetFileAttributes (org.dcache.vehicles.PnfsGetFileAttributes)9 HashSet (java.util.HashSet)8 ExecutionException (java.util.concurrent.ExecutionException)8 FileAttribute (org.dcache.namespace.FileAttribute)8 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)7 PoolMoverKillMessage (diskCacheV111.vehicles.PoolMoverKillMessage)7 Map (java.util.Map)7 PoolMgrSelectReadPoolMsg (diskCacheV111.vehicles.PoolMgrSelectReadPoolMsg)6 IOException (java.io.IOException)6 PoolV2Mode (diskCacheV111.pools.PoolV2Mode)5