Search in sources :

Example 1 with FireAndForgetTask

use of org.dcache.util.FireAndForgetTask in project dcache by dCache.

the class Job method start.

public void start() {
    _lock.lock();
    try {
        checkState(_state == State.NEW);
        _state = State.INITIALIZING;
        long refreshPeriod = _definition.refreshPeriod;
        ScheduledExecutorService executor = _context.getExecutor();
        _refreshTask = executor.scheduleWithFixedDelay(new FireAndForgetTask(() -> {
            _definition.sourceList.refresh();
            _definition.poolList.refresh();
        }), 0, refreshPeriod, TimeUnit.MILLISECONDS);
        executor.submit(new FireAndForgetTask(() -> {
            try {
                _context.getRepository().addListener(Job.this);
                populate();
                _lock.lock();
                try {
                    if (getState() == State.INITIALIZING) {
                        setState(State.RUNNING);
                    }
                } finally {
                    _lock.unlock();
                }
            } catch (InterruptedException e) {
                LOGGER.error("Migration job was interrupted");
            } finally {
                _lock.lock();
                try {
                    switch(getState()) {
                        case INITIALIZING:
                            setState(State.FAILED);
                            break;
                        case CANCELLING:
                            schedule();
                            break;
                    }
                } finally {
                    _lock.unlock();
                }
            }
        }));
    } finally {
        _lock.unlock();
    }
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) FireAndForgetTask(org.dcache.util.FireAndForgetTask)

Example 2 with FireAndForgetTask

use of org.dcache.util.FireAndForgetTask in project dcache by dCache.

the class Companion method done.

/**
 * Called at the end of the transfer to call callbacks and free resources associated with the
 * transfer.
 */
synchronized void done() {
    if (_thread != null) {
        throw new IllegalStateException("Cannot close a companion while the transfer is in progress");
    }
    if (_error != null) {
        if (_error instanceof Error) {
            LOGGER.error("P2P for {} failed due to a serious problem in the JVM.", _pnfsId, _error);
            // We should not attempt to recover from this!
            throw (Error) _error;
        } else if (_error instanceof RuntimeException) {
            LOGGER.error("P2P for {} failed due to a bug.  Please report" + " this to <support@dCache.org>", _pnfsId, _error);
        } else {
            LOGGER.error("P2P for {} failed: {}", _pnfsId, _error.toString());
        }
    } else {
        LOGGER.info("P2P for {} completed", _pnfsId);
    }
    if (_callback != null) {
        final Object error = _error;
        _executor.execute(new FireAndForgetTask(() -> {
            Throwable t;
            if (error == null) {
                t = null;
            } else if (error instanceof Throwable) {
                t = (Throwable) error;
            } else {
                t = new CacheException(error.toString());
            }
            _callback.cacheFileAvailable(_pnfsId, t);
        }));
    }
}
Also used : TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) FileInCacheException(diskCacheV111.util.FileInCacheException) CacheException(diskCacheV111.util.CacheException) FireAndForgetTask(org.dcache.util.FireAndForgetTask)

Example 3 with FireAndForgetTask

use of org.dcache.util.FireAndForgetTask in project dcache by dCache.

the class ResilientFileTask method call.

@Override
public Void call() {
    startTime = System.currentTimeMillis();
    FileAttributes attributes = FileAttributes.of().accessLatency(ONLINE).pnfsId(pnfsId).build();
    if (cancelled) {
        return null;
    }
    startSubTask = System.currentTimeMillis();
    type = handler.handleVerification(attributes);
    inVerify = System.currentTimeMillis() - startSubTask;
    switch(type) {
        case VOID:
            endTime = System.currentTimeMillis();
            break;
        case SET_STICKY:
            /*
                 * create a new copy by promoting a non-sticky copy to sticky
                 */
            startSubTask = System.currentTimeMillis();
            handler.getRemoveService().schedule(new FireAndForgetTask(() -> runPromote(attributes)), 0, TimeUnit.MILLISECONDS);
            break;
        case WAIT_FOR_STAGE:
            if (cancelled) {
                break;
            }
            startSubTask = System.currentTimeMillis();
            /*
                 * We do not want the resilience sessionID in the logging
                 * context; the new cache location needs to be processed.
                 *
                 * Task completes immediately after message is sent.
                 */
            handler.handleStaging(pnfsId, this);
            copyTerminated();
            break;
        case COPY:
            if (cancelled) {
                break;
            }
            startSubTask = System.currentTimeMillis();
            Task innerTask = handler.handleMakeOneCopy(attributes);
            if (cancelled) {
                break;
            }
            if (innerTask != null) {
                MessageGuard.setResilienceSession();
                migrationTask = innerTask;
                innerTask.run();
            } else {
                copyTerminated();
            }
            break;
        case REMOVE:
            if (cancelled) {
                break;
            }
            startSubTask = System.currentTimeMillis();
            handler.getRemoveService().schedule(new FireAndForgetTask(() -> runRemove(attributes)), 0, TimeUnit.MILLISECONDS);
            break;
    }
    return null;
}
Also used : FireAndForgetTask(org.dcache.util.FireAndForgetTask) Task(org.dcache.pool.migration.Task) FireAndForgetTask(org.dcache.util.FireAndForgetTask) FileAttributes(org.dcache.vehicles.FileAttributes)

Example 4 with FireAndForgetTask

use of org.dcache.util.FireAndForgetTask in project dcache by dCache.

the class DefaultPostTransferService method execute.

@Override
public void execute(final Mover<?> mover, final CompletionHandler<Void, Void> completionHandler) {
    _executor.execute(new FireAndForgetTask(() -> {
        ReplicaDescriptor handle = mover.getIoHandle();
        try {
            try {
                if (mover.getIoMode().contains(StandardOpenOption.WRITE)) {
                    handle.addChecksums(mover.getExpectedChecksums());
                    _checksumModule.enforcePostTransferPolicy(handle, mover.getActualChecksums());
                }
                handle.commit();
            } finally {
                handle.close();
            }
            completionHandler.completed(null, null);
        } catch (InterruptedIOException | InterruptedException e) {
            LOGGER.warn("Transfer was forcefully killed during post-processing");
            mover.setTransferStatus(CacheException.DEFAULT_ERROR_CODE, "Transfer was forcefully killed");
            completionHandler.failed(e, null);
        } catch (CacheException e) {
            LOGGER.warn("Transfer failed in post-processing: {}", e.getMessage());
            mover.setTransferStatus(e.getRc(), "Post-processing failed: " + e.getMessage());
            completionHandler.failed(e, null);
        } catch (IOException e) {
            LOGGER.warn("Transfer failed in post-processing: {}", e.toString());
            mover.setTransferStatus(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, "Transfer failed in post-processing: " + messageOrClassName(e));
            completionHandler.failed(e, null);
        } catch (RuntimeException e) {
            LOGGER.error("Transfer failed in post-processing. Please report this bug to support@dcache.org.", e);
            mover.setTransferStatus(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, "Transfer failed due to unexpected exception: " + e.getMessage());
            completionHandler.failed(e, null);
        } catch (Throwable e) {
            Thread t = Thread.currentThread();
            t.getUncaughtExceptionHandler().uncaughtException(t, e);
            mover.setTransferStatus(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, "Transfer failed due to unexpected exception: " + e.getMessage());
            completionHandler.failed(e, null);
        }
        MoverInfoMessage moverInfoMessage = generateBillingMessage(mover, handle.getReplicaSize());
        // as current thread is used to serialize the message, send finish to the door before notifying the billing.
        sendFinished(mover, moverInfoMessage);
        sendBillingInfo(moverInfoMessage);
    }));
}
Also used : MoverInfoMessage(diskCacheV111.vehicles.MoverInfoMessage) ReplicaDescriptor(org.dcache.pool.repository.ReplicaDescriptor) CacheException(diskCacheV111.util.CacheException) FireAndForgetTask(org.dcache.util.FireAndForgetTask) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Example 5 with FireAndForgetTask

use of org.dcache.util.FireAndForgetTask in project dcache by dCache.

the class StateMaintainer method enqueueUpdate.

@Override
public void enqueueUpdate(final StateUpdate pendingUpdate) {
    LOGGER.trace("enqueing job to process update {}", pendingUpdate);
    final NDC ndc = NDC.cloneNdc();
    _pendingRequestCount.incrementAndGet();
    _scheduler.execute(new FireAndForgetTask(() -> {
        CDC.reset(_myAddress);
        NDC.set(ndc);
        try {
            LOGGER.trace("starting job to process update {}", pendingUpdate);
            _caretaker.processUpdate(pendingUpdate);
            checkScheduledExpungeActivity();
            LOGGER.trace("finished job to process update {}", pendingUpdate);
        } finally {
            _pendingRequestCount.decrementAndGet();
            pendingUpdate.updateComplete();
            CDC.clear();
        }
    }));
}
Also used : FireAndForgetTask(org.dcache.util.FireAndForgetTask) NDC(org.dcache.util.NDC)

Aggregations

FireAndForgetTask (org.dcache.util.FireAndForgetTask)10 CacheException (diskCacheV111.util.CacheException)2 FileInCacheException (diskCacheV111.util.FileInCacheException)1 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)1 MoverInfoMessage (diskCacheV111.vehicles.MoverInfoMessage)1 DelayedReply (dmg.cells.nucleus.DelayedReply)1 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 Task (org.dcache.pool.migration.Task)1 ReplicaDescriptor (org.dcache.pool.repository.ReplicaDescriptor)1 NDC (org.dcache.util.NDC)1 PingMoversTask (org.dcache.util.PingMoversTask)1 Expression (org.dcache.util.expression.Expression)1 FileAttributes (org.dcache.vehicles.FileAttributes)1 XrootdTpcInfoCleanerTask (org.dcache.xrootd.tpc.XrootdTpcInfoCleanerTask)1 Required (org.springframework.beans.factory.annotation.Required)1