Search in sources :

Example 1 with ReplicaStoreCache

use of org.dcache.pool.repository.ReplicaStoreCache in project dcache by dCache.

the class ReplicaRepository method setReplicaStore.

public void setReplicaStore(ReplicaStore store) {
    _stateLock.readLock().lock();
    try {
        checkUninitialized();
        _store = new ReplicaStoreCache(store, new StateChangeListener() {

            @Override
            public void stateChanged(StateChangeEvent event) {
                PnfsId id = event.getPnfsId();
                if (event.getOldState() != NEW || event.getNewState() != REMOVED) {
                    if (event.getOldState() == NEW) {
                        long size = event.getNewEntry().getReplicaSize();
                        /* Usually space has to be allocated before writing the
                             * data to disk, however during pool startup we are notified
                             * about "new" files that already consume space, so we
                             * adjust the allocation here.
                             */
                        if (size > 0) {
                            _account.growTotalAndUsed(id, size);
                        }
                        scheduleExpirationTask(event.getNewEntry());
                    }
                    updateRemovable(event.getNewEntry());
                    if (event.getOldState() != PRECIOUS && event.getNewState() == PRECIOUS) {
                        _account.adjustPrecious(id, event.getNewEntry().getReplicaSize());
                    } else if (event.getOldState() == PRECIOUS && event.getNewState() != PRECIOUS) {
                        _account.adjustPrecious(id, -event.getOldEntry().getReplicaSize());
                    }
                    _stateChangeListeners.stateChanged(event);
                }
                switch(event.getNewState()) {
                    case REMOVED:
                        if (event.getOldState() != NEW) {
                            LOGGER.info("remove entry {}: {}", id, event.getWhy());
                        }
                        _pnfs.clearCacheLocation(id, _volatile);
                        ScheduledFuture<?> oldTask = _tasks.remove(id);
                        if (oldTask != null) {
                            oldTask.cancel(false);
                        }
                        break;
                    case DESTROYED:
                        /* It is essential to free after we removed the file: This is the opposite
                             * of what happens during allocation, in which we allocate before writing
                             * to disk. We rely on never having anything on disk that we haven't accounted
                             * for in the Account object.
                             */
                        long size = event.getOldEntry().getReplicaSize();
                        if (size > 0L) {
                            _account.free(id, size);
                        }
                        break;
                }
            }

            @Override
            public void accessTimeChanged(EntryChangeEvent event) {
                updateRemovable(event.getNewEntry());
                _stateChangeListeners.accessTimeChanged(event);
            }

            @Override
            public void stickyChanged(StickyChangeEvent event) {
                updateRemovable(event.getNewEntry());
                _stateChangeListeners.stickyChanged(event);
                scheduleExpirationTask(event.getNewEntry());
            }
        }, new FaultListener() {

            @Override
            public void faultOccurred(FaultEvent event) {
                for (FaultListener listener : _faultListeners) {
                    listener.faultOccurred(event);
                }
            }
        });
    } finally {
        _stateLock.readLock().unlock();
    }
}
Also used : ReplicaStoreCache(org.dcache.pool.repository.ReplicaStoreCache) PnfsId(diskCacheV111.util.PnfsId) StateChangeListener(org.dcache.pool.repository.StateChangeListener) FaultListener(org.dcache.pool.FaultListener) StickyChangeEvent(org.dcache.pool.repository.StickyChangeEvent) FaultEvent(org.dcache.pool.FaultEvent) StateChangeEvent(org.dcache.pool.repository.StateChangeEvent) EntryChangeEvent(org.dcache.pool.repository.EntryChangeEvent)

Aggregations

PnfsId (diskCacheV111.util.PnfsId)1 FaultEvent (org.dcache.pool.FaultEvent)1 FaultListener (org.dcache.pool.FaultListener)1 EntryChangeEvent (org.dcache.pool.repository.EntryChangeEvent)1 ReplicaStoreCache (org.dcache.pool.repository.ReplicaStoreCache)1 StateChangeEvent (org.dcache.pool.repository.StateChangeEvent)1 StateChangeListener (org.dcache.pool.repository.StateChangeListener)1 StickyChangeEvent (org.dcache.pool.repository.StickyChangeEvent)1