Search in sources :

Example 1 with FileIsNewCacheException

use of diskCacheV111.util.FileIsNewCacheException in project dcache by dCache.

the class ConsistentReplicaStore method get.

/**
 * Retrieves a CacheRepositoryEntry from the wrapped meta data store. If the entry is missing or
 * fails consistency checks, the entry is reconstructed with information from PNFS.
 */
@Override
public ReplicaRecord get(PnfsId id) throws IllegalArgumentException, CacheException {
    ReplicaRecord entry = _replicaStore.get(id);
    if (entry != null && isBroken(entry)) {
        LOGGER.warn("Recovering {}...", id);
        try {
            /* It is safe to remove FROM_STORE/FROM_POOL replicas: We have
                 * another copy anyway. Files in REMOVED or DESTROYED
                 * were about to be deleted, so we can finish the job.
                 */
            switch(entry.getState()) {
                case FROM_POOL:
                case FROM_STORE:
                case REMOVED:
                case DESTROYED:
                    _replicaStore.remove(id);
                    _pnfsHandler.clearCacheLocation(id);
                    LOGGER.info("Recovering: Removed {} because it was not fully staged.", id);
                    return null;
            }
            entry = rebuildEntry(entry);
        } catch (IOException e) {
            throw new DiskErrorCacheException("I/O error in healer: " + messageOrClassName(e), e);
        } catch (FileNotFoundCacheException e) {
            _replicaStore.remove(id);
            LOGGER.warn("Recovering: Removed {} because name space entry was deleted.", id);
            return null;
        } catch (FileIsNewCacheException e) {
            _replicaStore.remove(id);
            LOGGER.warn("Recovering: Removed {}: {}", id, e.getMessage());
            return null;
        } catch (TimeoutCacheException e) {
            throw e;
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new CacheException("Pool is shutting down", e);
        } catch (CacheException | NoSuchAlgorithmException e) {
            entry.update("Failed to recover replica: " + e.getMessage(), r -> r.setState(ReplicaState.BROKEN));
            LOGGER.error(AlarmMarkerFactory.getMarker(PredefinedAlarm.BROKEN_FILE, id.toString(), _poolName), "Marked {} bad: {}.", id, e.getMessage());
        }
    }
    return entry;
}
Also used : AlarmMarkerFactory(org.dcache.alarms.AlarmMarkerFactory) ReplicaStatePolicy(org.dcache.pool.classic.ReplicaStatePolicy) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) AccessLatency(diskCacheV111.util.AccessLatency) PredefinedAlarm(org.dcache.alarms.PredefinedAlarm) LoggerFactory(org.slf4j.LoggerFactory) Exceptions.messageOrClassName(org.dcache.util.Exceptions.messageOrClassName) DiskErrorCacheException(diskCacheV111.util.DiskErrorCacheException) RETENTION_POLICY(org.dcache.namespace.FileAttribute.RETENTION_POLICY) PnfsHandler(diskCacheV111.util.PnfsHandler) CacheException(diskCacheV111.util.CacheException) Iterables.concat(com.google.common.collect.Iterables.concat) SIZE(org.dcache.namespace.FileAttribute.SIZE) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) EnumSet(java.util.EnumSet) ChecksumModule(org.dcache.pool.classic.ChecksumModule) FileAttributes(org.dcache.vehicles.FileAttributes) STORAGEINFO(org.dcache.namespace.FileAttribute.STORAGEINFO) PnfsId(diskCacheV111.util.PnfsId) Logger(org.slf4j.Logger) OpenOption(java.nio.file.OpenOption) LOCATIONS(org.dcache.namespace.FileAttribute.LOCATIONS) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) Set(java.util.Set) IOException(java.io.IOException) Sets(com.google.common.collect.Sets) Checksum(org.dcache.util.Checksum) List(java.util.List) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) FileAttribute(org.dcache.namespace.FileAttribute) Collections(java.util.Collections) ACCESS_LATENCY(org.dcache.namespace.FileAttribute.ACCESS_LATENCY) CHECKSUM(org.dcache.namespace.FileAttribute.CHECKSUM) RetentionPolicy(diskCacheV111.util.RetentionPolicy) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) DiskErrorCacheException(diskCacheV111.util.DiskErrorCacheException) CacheException(diskCacheV111.util.CacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) DiskErrorCacheException(diskCacheV111.util.DiskErrorCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Example 2 with FileIsNewCacheException

use of diskCacheV111.util.FileIsNewCacheException in project dcache by dCache.

the class ChimeraNameSpaceProvider method commitUpload.

@Override
public FileAttributes commitUpload(Subject subject, FsPath temporaryPath, FsPath finalPath, Set<CreateOption> options, Set<FileAttribute> attributesToFetch) throws CacheException {
    try {
        FsPath temporaryDir = getParentOfFile(temporaryPath);
        FsPath finalDir = getParentOfFile(finalPath);
        checkIsTemporaryDirectory(temporaryPath, temporaryDir);
        /* File must have been created...
             */
        ExtendedInode uploadDirInode;
        ExtendedInode temporaryDirInode;
        ExtendedInode inodeOfFile;
        try {
            uploadDirInode = new ExtendedInode(_fs, _fs.path2inode(temporaryDir.parent().toString()));
            temporaryDirInode = uploadDirInode.inodeOf(temporaryDir.name(), STAT);
            inodeOfFile = temporaryDirInode.inodeOf(temporaryPath.name(), STAT);
        } catch (FileNotFoundChimeraFsException e) {
            throw new FileNotFoundCacheException("No such file or directory: " + temporaryPath, e);
        }
        /* ...and upload must have completed...
             */
        ImmutableList<StorageLocatable> locations = inodeOfFile.getLocations();
        if (locations.isEmpty()) {
            throw new FileIsNewCacheException("Upload has not completed.");
        }
        /* ...and it must have the correct size.
             */
        ImmutableList<String> size = inodeOfFile.getTag(TAG_EXPECTED_SIZE);
        if (!size.isEmpty()) {
            long expectedSize = Long.parseLong(size.get(0));
            long actualSize = inodeOfFile.statCache().getSize();
            if (expectedSize != actualSize) {
                throw new FileCorruptedCacheException(expectedSize, actualSize);
            }
        }
        /* Target directory must exist.
             */
        ExtendedInode finalDirInode;
        try {
            finalDirInode = new ExtendedInode(_fs, _fs.path2inode(finalDir.toString()));
        } catch (FileNotFoundChimeraFsException e) {
            throw new FileNotFoundCacheException("No such file or directory: " + finalDir, e);
        }
        /* File must not exist unless overwrite is enabled.
             */
        try {
            ExtendedInode inodeOfExistingFile = finalDirInode.inodeOf(finalPath.name(), STAT);
            if (!options.contains(CreateOption.OVERWRITE_EXISTING)) {
                throw new FileExistsCacheException("File exists: " + finalPath);
            }
            /* User must be authorized to delete existing file.
                 */
            if (!Subjects.isExemptFromNamespaceChecks(subject)) {
                FileAttributes attributesOfParent = getFileAttributesForPermissionHandler(finalDirInode);
                FileAttributes attributesOfFile = getFileAttributesForPermissionHandler(inodeOfExistingFile);
                if (_permissionHandler.canDeleteFile(subject, attributesOfParent, attributesOfFile) != ACCESS_ALLOWED) {
                    throw new PermissionDeniedCacheException("Overwrite denied: " + finalPath);
                }
            }
        } catch (FileNotFoundChimeraFsException ignored) {
        }
        /* Read file attributes before moving the file. Otherwise the cached parent will
             * be gone.
             */
        FileAttributes attributes = getFileAttributes(inodeOfFile, attributesToFetch);
        /* File is moved to correct directory.
             */
        _fs.rename(inodeOfFile, temporaryDirInode, temporaryPath.name(), finalDirInode, finalPath.name());
        /* Delete temporary upload directory and any files in it.
             */
        removeRecursively(uploadDirInode, temporaryDir.name(), temporaryDirInode, i -> {
        });
        return attributes;
    } catch (ChimeraFsException e) {
        throw new CacheException(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.getMessage());
    } catch (NumberFormatException e) {
        throw new FileCorruptedCacheException("Failed to commit file: " + e.getMessage());
    }
}
Also used : FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) LockedCacheException(diskCacheV111.util.LockedCacheException) AttributeExistsCacheException(diskCacheV111.util.AttributeExistsCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) NotFileCacheException(diskCacheV111.util.NotFileCacheException) CacheException(diskCacheV111.util.CacheException) NoAttributeCacheException(diskCacheV111.util.NoAttributeCacheException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) StorageLocatable(org.dcache.chimera.StorageLocatable) FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) ChimeraFsException(org.dcache.chimera.ChimeraFsException) DirNotEmptyChimeraFsException(org.dcache.chimera.DirNotEmptyChimeraFsException) FileExistsChimeraFsException(org.dcache.chimera.FileExistsChimeraFsException) FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileAttributes(org.dcache.vehicles.FileAttributes) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) FsPath(diskCacheV111.util.FsPath)

Example 3 with FileIsNewCacheException

use of diskCacheV111.util.FileIsNewCacheException in project dcache by dCache.

the class Storage method putDone.

@Override
public void putDone(SRMUser user, String localTransferPath, URI surl, boolean overwrite) throws SRMException {
    try {
        Subject subject = asDcacheUser(user).getSubject();
        Restriction restriction = asDcacheUser(user).getRestriction();
        FsPath fullPath = getPath(surl);
        checkNonBrokenUpload(localTransferPath);
        EnumSet<CreateOption> options = EnumSet.noneOf(CreateOption.class);
        if (overwrite) {
            options.add(CreateOption.OVERWRITE_EXISTING);
        }
        PnfsCommitUpload msg = new PnfsCommitUpload(subject, restriction, FsPath.create(localTransferPath), fullPath, options, EnumSet.of(PNFSID, SIZE, STORAGEINFO));
        msg = _pnfsStub.sendAndWait(msg);
        DoorRequestInfoMessage infoMsg = new DoorRequestInfoMessage(getCellAddress());
        infoMsg.setSubject(subject);
        infoMsg.setBillingPath(fullPath.toString());
        infoMsg.setTransferPath(localTransferPath);
        infoMsg.setTransaction(CDC.getSession());
        infoMsg.setPnfsId(msg.getFileAttributes().getPnfsId());
        infoMsg.setResult(0, "");
        infoMsg.setFileSize(msg.getFileAttributes().getSizeIfPresent().orElse(0L));
        infoMsg.setStorageInfo(msg.getFileAttributes().getStorageInfo());
        Origin origin = Subjects.getOrigin(subject);
        if (origin != null) {
            infoMsg.setClient(origin.getAddress().getHostAddress());
        }
        _billingStub.notify(infoMsg);
    } catch (FileNotFoundCacheException e) {
        throw new SRMInvalidPathException(e.getMessage(), e);
    } catch (FileIsNewCacheException | FileCorruptedCacheException e) {
        throw new SRMException(e.getMessage(), e);
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException("Permission denied.", e);
    } catch (FileExistsCacheException e) {
        throw new SRMDuplicationException(surl + " exists.", e);
    } catch (CacheException e) {
        throw new SRMInternalErrorException(e.getMessage(), e);
    } catch (InterruptedException e) {
        throw new SRMInternalErrorException("Operation interrupted", e);
    } catch (NoRouteToCellException e) {
        throw new SRMInternalErrorException("Internal communication failure", e);
    }
}
Also used : DoorRequestInfoMessage(diskCacheV111.vehicles.DoorRequestInfoMessage) Origin(org.dcache.auth.Origin) SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) CacheException(diskCacheV111.util.CacheException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) Subject(javax.security.auth.Subject) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) Restriction(org.dcache.auth.attributes.Restriction) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMException(org.dcache.srm.SRMException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) CreateOption(org.dcache.namespace.CreateOption) PnfsCommitUpload(diskCacheV111.vehicles.PnfsCommitUpload) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) SRMDuplicationException(org.dcache.srm.SRMDuplicationException) FsPath(diskCacheV111.util.FsPath)

Example 4 with FileIsNewCacheException

use of diskCacheV111.util.FileIsNewCacheException in project dcache by dCache.

the class Transfer method readNameSpaceEntryAsync.

private ListenableFuture<Void> readNameSpaceEntryAsync(boolean allowWrite, long timeout) {
    Set<FileAttribute> attr = EnumSet.of(PNFSID, TYPE, STORAGEINFO, SIZE);
    attr.addAll(_additionalAttributes);
    attr.addAll(PoolMgrSelectReadPoolMsg.getRequiredAttributes());
    Set<AccessMask> mask;
    if (allowWrite) {
        mask = EnumSet.of(AccessMask.READ_DATA, AccessMask.WRITE_DATA);
    } else {
        mask = EnumSet.of(AccessMask.READ_DATA);
    }
    PnfsId pnfsId = getPnfsId();
    PnfsGetFileAttributes request;
    if (pnfsId != null) {
        request = new PnfsGetFileAttributes(pnfsId, attr);
        if (_path != null) {
            // Needed for restriction check.
            request.setPnfsPath(_path.toString());
        }
    } else {
        request = new PnfsGetFileAttributes(_path.toString(), attr);
    }
    request.setAccessMask(mask);
    request.setUpdateAtime(true);
    ListenableFuture<PnfsGetFileAttributes> reply = _pnfs.requestAsync(request, timeout);
    setStatusUntil("PnfsManager: Fetching storage info", reply);
    return CellStub.transformAsync(reply, msg -> {
        FileAttributes attributes = msg.getFileAttributes();
        /* We can only transfer regular files.
                   */
        FileType type = attributes.getFileType();
        if (type == FileType.DIR || type == FileType.SPECIAL) {
            throw new NotFileCacheException("Not a regular file");
        }
        /* I/O mode must match completeness of the file.
                   */
        if (!attributes.getStorageInfo().isCreatedOnly()) {
            setWrite(false);
        } else if (allowWrite) {
            setWrite(true);
        } else {
            throw new FileIsNewCacheException();
        }
        setFileAttributes(attributes);
        return immediateFuture(null);
    });
}
Also used : NotFileCacheException(diskCacheV111.util.NotFileCacheException) FileType(org.dcache.namespace.FileType) PnfsId(diskCacheV111.util.PnfsId) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) AccessMask(org.dcache.acl.enums.AccessMask) FileAttributes(org.dcache.vehicles.FileAttributes) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) FileAttribute(org.dcache.namespace.FileAttribute)

Example 5 with FileIsNewCacheException

use of diskCacheV111.util.FileIsNewCacheException in project dcache by dCache.

the class TransferManagerHandler method success.

@Override
public void success(Message message) {
    try {
        if (message instanceof PnfsCreateEntryMessage) {
            PnfsCreateEntryMessage create_msg = (PnfsCreateEntryMessage) message;
            if (state == WAITING_FOR_PNFS_ENTRY_CREATION_INFO_STATE) {
                setState(RECEIVED_PNFS_ENTRY_CREATION_INFO_STATE);
                createEntryResponseArrived(create_msg);
                return;
            }
            LOGGER.error(this.toString() + " got unexpected PnfsCreateEntryMessage " + " : " + create_msg + " ; Ignoring");
        } else if (message instanceof PnfsGetFileAttributes) {
            PnfsGetFileAttributes attributesMessage = (PnfsGetFileAttributes) message;
            if (state == WAITING_FOR_PNFS_INFO_STATE) {
                setState(RECEIVED_PNFS_INFO_STATE);
                FileAttributes attributes = attributesMessage.getFileAttributes();
                if (!attributes.isDefined(SIZE)) {
                    sendErrorReply(CacheException.FILE_IS_NEW, new FileIsNewCacheException());
                    return;
                }
                storageInfoArrived(attributesMessage.getPnfsId(), attributes);
                return;
            } else if (state == WAITING_FOR_PNFS_CHECK_BEFORE_DELETE_STATE) {
                state = RECEIVED_PNFS_CHECK_BEFORE_DELETE_STATE;
                deletePnfsEntry();
                return;
            } else if (state == WAITING_FOR_CREATED_FILE_INFO_STATE) {
                state = RECEIVED_CREATED_FILE_INFO_STATE;
                getFileAttributesArrived(attributesMessage.getFileAttributes());
                return;
            }
            LOGGER.error(this.toString() + " got unexpected PnfsGetStorageInfoMessage " + " : " + attributesMessage + " ; Ignoring");
        } else if (message instanceof PoolMgrSelectPoolMsg) {
            PoolMgrSelectPoolMsg select_pool_msg = (PoolMgrSelectPoolMsg) message;
            if (state == WAITING_FOR_POOL_INFO_STATE) {
                setState(RECEIVED_POOL_INFO_STATE);
                poolInfoArrived(select_pool_msg);
                return;
            }
            LOGGER.error(this.toString() + " got unexpected PoolMgrSelectPoolMsg " + " : " + select_pool_msg + " ; Ignoring");
        } else if (message instanceof PoolIoFileMessage) {
            PoolIoFileMessage first_pool_reply = (PoolIoFileMessage) message;
            if (state == WAITING_FIRST_POOL_REPLY_STATE) {
                setState(RECEIVED_FIRST_POOL_REPLY_STATE);
                poolFirstReplyArrived(first_pool_reply);
                return;
            }
            LOGGER.error(this.toString() + " got unexpected PoolIoFileMessage " + " : " + first_pool_reply + " ; Ignoring");
        } else if (message instanceof PnfsDeleteEntryMessage) {
            PnfsDeleteEntryMessage deleteReply = (PnfsDeleteEntryMessage) message;
            if (state == WAITING_FOR_PNFS_ENTRY_DELETE) {
                setState(RECEIVED_PNFS_ENTRY_DELETE);
                LOGGER.debug("Received PnfsDeleteEntryMessage, Deleted  : {}", deleteReply.getPnfsPath());
                sendErrorReply();
            }
        }
        manager.persist(this);
    } catch (RuntimeException e) {
        LOGGER.error("Bug detected in transfermanager, please report this to <support@dCache.org>", e);
        failure(1, "Bug detected: " + e);
    }
}
Also used : PoolMgrSelectPoolMsg(diskCacheV111.vehicles.PoolMgrSelectPoolMsg) PoolIoFileMessage(diskCacheV111.vehicles.PoolIoFileMessage) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) PnfsCreateEntryMessage(diskCacheV111.vehicles.PnfsCreateEntryMessage) PnfsDeleteEntryMessage(diskCacheV111.vehicles.PnfsDeleteEntryMessage) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileAttributes(org.dcache.vehicles.FileAttributes) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes)

Aggregations

FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)8 CacheException (diskCacheV111.util.CacheException)6 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)6 FileAttributes (org.dcache.vehicles.FileAttributes)6 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)5 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)4 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)4 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)3 FsPath (diskCacheV111.util.FsPath)3 NotDirCacheException (diskCacheV111.util.NotDirCacheException)3 NotFileCacheException (diskCacheV111.util.NotFileCacheException)3 PnfsId (diskCacheV111.util.PnfsId)3 AccessLatency (diskCacheV111.util.AccessLatency)2 DiskErrorCacheException (diskCacheV111.util.DiskErrorCacheException)2 RetentionPolicy (diskCacheV111.util.RetentionPolicy)2 NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)2 Subject (javax.security.auth.Subject)2 FileAttribute (org.dcache.namespace.FileAttribute)2 Iterables.concat (com.google.common.collect.Iterables.concat)1 Sets (com.google.common.collect.Sets)1