Search in sources :

Example 1 with AccessLatency

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

the class ALRPStorageUnitQoSProvider method fetchRequirements.

@Override
public FileQoSRequirements fetchRequirements(FileQoSUpdate update) throws QoSException {
    FileQoSRequirements descriptor = initialize(update);
    if (descriptor == null) {
        /*
             *  Should only happen when a CLEAR CACHE LOCATION finds no locations.
             */
        return null;
    }
    FileAttributes attributes = descriptor.getAttributes();
    AccessLatency accessLatency = attributes.getAccessLatency();
    RetentionPolicy retentionPolicy = attributes.getRetentionPolicy();
    String unitKey = attributes.getStorageClass() + "@" + attributes.getHsm();
    SelectionUnit unit = poolSelectionUnit().getStorageUnit(unitKey);
    if (!(unit instanceof StorageUnit)) {
        throw new QoSException(unitKey + " does not correspond to a storage unit; " + "cannot retrieve requirements for " + descriptor.getPnfsId());
    }
    StorageUnit storageUnit = (StorageUnit) unit;
    Integer required = storageUnit.getRequiredCopies();
    List<String> onlyOneCopyPer = storageUnit.getOnlyOneCopyPer();
    if (retentionPolicy == CUSTODIAL) {
        /*
             *  REVISIT -- currently we support only one tape location.
             */
        descriptor.setRequiredTape(1);
    } else {
        descriptor.setRequiredTape(0);
    }
    if (accessLatency == ONLINE) {
        /*
             *  REVISIT -- current override of file AL based on storage unit
             *  REVISIT -- eventually we will want to override the storage unit default for a given file
             */
        descriptor.setRequiredDisk(required == null ? 1 : required);
        if (onlyOneCopyPer != null) {
            descriptor.setPartitionKeys(new HashSet<>(onlyOneCopyPer));
        }
    } else {
        descriptor.setRequiredDisk(0);
    }
    LOGGER.debug("fetchRequirements for {}, returning {}.", update, descriptor);
    return descriptor;
}
Also used : AccessLatency(diskCacheV111.util.AccessLatency) SelectionUnit(diskCacheV111.poolManager.PoolSelectionUnit.SelectionUnit) PoolSelectionUnit(diskCacheV111.poolManager.PoolSelectionUnit) StorageUnit(diskCacheV111.poolManager.StorageUnit) QoSException(org.dcache.qos.QoSException) FileQoSRequirements(org.dcache.qos.data.FileQoSRequirements) FileAttributes(org.dcache.vehicles.FileAttributes) RetentionPolicy(diskCacheV111.util.RetentionPolicy)

Example 2 with AccessLatency

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

the class FileUpdate method getAttributes.

/**
 * @return <code>null</code> if AccessLatency is not ONLINE, or if the file
 * is not found or there are no locations for it and the message being processed is for a clear
 * cache location; otherwise the file attribute set required to process resilience.
 */
public static FileAttributes getAttributes(PnfsId pnfsId, String pool, MessageType messageType, NamespaceAccess namespace) throws CacheException {
    try {
        FileAttributes attributes = namespace.getRequiredAttributes(pnfsId);
        if (attributes == null) {
            throw new FileNotFoundCacheException(String.format("No attributes " + "returned for %s", pnfsId));
        }
        LOGGER.trace("Got required attributes for {}.", pnfsId);
        if (attributes.getLocations().isEmpty()) {
            if (messageType == CLEAR_CACHE_LOCATION) {
                LOGGER.trace("ClearCacheLocationMessage for {}; " + "no current locations; " + "file probably deleted " + "from namespace.", pnfsId);
                return null;
            }
            if (messageType != ADD_CACHE_LOCATION) {
                /*
                     * Since the scan began or the broken file reported,
                     * the file has been removed.
                     */
                throw new FileNotFoundCacheException(String.format("File no longer found: %s", pnfsId));
            }
            /*
                 *  May be due to a race between PnfsManager and resilience
                 *  to process the message into/from the namespace.
                 *
                 *  We can assume here that this is a new file, so
                 *  we just add the originating location to the attribute
                 *  location list.
                 */
            LOGGER.trace("{} has no locations yet.", pnfsId);
            Collection<String> singleLoc = new ArrayList<>();
            /*
                 *  Pool can now be <code>null</code>
                 *  but only if message type is QOS_MODIFIED.
                 */
            if (pool == null) {
                if (messageType != QOS_MODIFIED) {
                    throw new CacheException(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, String.format("resilience File update for %s, " + "messageType %s, " + "has no pool location!", pnfsId, messageType));
                }
                return null;
            }
            singleLoc.add(pool);
            attributes.setLocations(singleLoc);
        }
        LOGGER.debug("After call to namespace, {} has locations {}.", pnfsId, attributes.getLocations());
        return attributes;
    } catch (FileNotFoundCacheException e) {
        LOGGER.debug("{}; {} has likely been deleted from the namespace.", e.getMessage(), pnfsId);
        return null;
    }
}
Also used : CacheException(diskCacheV111.util.CacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) ArrayList(java.util.ArrayList) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileAttributes(org.dcache.vehicles.FileAttributes)

Example 3 with AccessLatency

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

the class ChimeraNameSpaceProvider method createUploadPath.

@Override
public FsPath createUploadPath(Subject subject, FsPath path, FsPath rootPath, Long size, AccessLatency al, RetentionPolicy rp, String spaceToken, Set<CreateOption> options) throws CacheException {
    checkState(_uploadDirectory != null, "Upload directory is not configured.");
    try {
        /* Parent directory must exist.
             */
        ExtendedInode parentOfPath = options.contains(CreateOption.CREATE_PARENTS) ? installDirectory(subject, path.parent(), INHERIT_MODE) : lookupDirectory(subject, path.parent());
        FileAttributes attributesOfParent = !Subjects.isExemptFromNamespaceChecks(subject) ? getFileAttributesForPermissionHandler(parentOfPath) : null;
        /* File must not exist unless overwrite is enabled.
             */
        try {
            ExtendedInode inodeOfPath = parentOfPath.inodeOf(path.name(), STAT);
            if (!options.contains(CreateOption.OVERWRITE_EXISTING) || (inodeOfPath.statCache().getMode() & UnixPermission.S_TYPE) != UnixPermission.S_IFREG) {
                throw new FileExistsCacheException("File exists: " + path);
            }
            /* User must be authorized to delete existing file.
                 */
            if (!Subjects.isExemptFromNamespaceChecks(subject)) {
                FileAttributes attributesOfPath = getFileAttributesForPermissionHandler(inodeOfPath);
                if (_permissionHandler.canDeleteFile(subject, attributesOfParent, attributesOfPath) != ACCESS_ALLOWED) {
                    throw new PermissionDeniedCacheException("Access denied: " + path);
                }
            }
        } catch (FileNotFoundChimeraFsException ignored) {
        }
        /* User must be authorized to create file.
             */
        if (!Subjects.isExemptFromNamespaceChecks(subject)) {
            if (_permissionHandler.canCreateFile(subject, attributesOfParent) != ACCESS_ALLOWED) {
                throw new PermissionDeniedCacheException("Access denied: " + path);
            }
        }
        /* Attributes are inherited from real parent directory.
             */
        int mode = parentOfPath.statCache().getMode() & UnixPermission.S_PERMS;
        int gid;
        if ((mode & UnixPermission.S_ISGID) != 0) {
            gid = parentOfPath.statCache().getGid();
        } else if (Subjects.isNobody(subject) || _inheritFileOwnership) {
            gid = parentOfPath.statCache().getGid();
        } else {
            gid = Ints.checkedCast(Subjects.getPrimaryGid(subject));
        }
        int uid;
        if (Subjects.isNobody(subject) || _inheritFileOwnership) {
            uid = parentOfPath.statCache().getUid();
        } else {
            uid = Ints.checkedCast(Subjects.getUid(subject));
        }
        /* ACLs are copied from real parent to the temporary upload directory
             * such that the upload is allowed (in case write permissions rely
             * on ACLs) and such that the file will inherit the correct ACLs.
             */
        List<ACE> acl = _fs.getACL(parentOfPath);
        /* The temporary upload directory has the same tags as the real parent,
             * except target file specific properties are stored as tags local to
             * the upload directory.
             */
        Map<String, byte[]> tags = Maps.newHashMap(parentOfPath.getTags());
        if (spaceToken != null) {
            tags.put(TAG_WRITE_TOKEN, spaceToken.getBytes(UTF_8));
            /* If client provides space token to upload to, the access latency and
                 * retention policy tags of the upload directory must be disregarded.
                 */
            tags.remove(TAG_ACCESS_LATENCY);
            tags.remove(TAG_RETENTION_POLICY);
        }
        if (al != null) {
            tags.put(TAG_ACCESS_LATENCY, al.toString().getBytes(UTF_8));
        }
        if (rp != null) {
            tags.put(TAG_RETENTION_POLICY, rp.toString().getBytes(UTF_8));
        }
        if (size != null) {
            tags.put(TAG_EXPECTED_SIZE, size.toString().getBytes(UTF_8));
        }
        tags.put(TAG_PATH, path.toString().getBytes(UTF_8));
        /* Upload directory may optionally be relative to the user's root path. Whether
             * that's the case depends on if the configured upload directory is an absolute
             * or relative path.
             */
        FsPath uploadDirectory = rootPath.resolve(_uploadDirectory);
        if (_uploadSubDirectory != null) {
            uploadDirectory = uploadDirectory.chroot(String.format(_uploadSubDirectory, threadId.get()));
        }
        /* Upload directory must exist and have the right permissions.
             */
        ExtendedInode inodeOfUploadDir = installSystemDirectory(uploadDirectory, 0711, Collections.emptyList(), Collections.emptyMap());
        if (inodeOfUploadDir.statCache().getUid() != 0) {
            LOGGER.error("Owner must be root: {}", uploadDirectory);
            throw new CacheException("Owner must be root: " + uploadDirectory);
        }
        if ((inodeOfUploadDir.statCache().getMode() & UnixPermission.S_PERMS) != 0711) {
            LOGGER.error("File mode must be 0711: {}", uploadDirectory);
            throw new CacheException("File mode must be 0711: " + uploadDirectory);
        }
        /* Use cryptographically strong pseudo random UUID to create temporary upload directory.
             */
        UUID uuid = UUID.randomUUID();
        _fs.mkdir(inodeOfUploadDir, uuid.toString(), uid, gid, mode, acl, tags);
        return uploadDirectory.child(uuid.toString()).child(path.name());
    } catch (ChimeraFsException e) {
        LOGGER.error("Problem with database: {}", e.getMessage());
        throw new CacheException(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.getMessage());
    }
}
Also used : ACE(org.dcache.acl.ACE) 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) 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) UUID(java.util.UUID) FileAttributes(org.dcache.vehicles.FileAttributes) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) FsPath(diskCacheV111.util.FsPath)

Example 4 with AccessLatency

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

the class PerformanceTest method processOperation.

private void processOperation(Operation aOp, String path) {
    try {
        switch(aOp) {
            case CREATE_ENTRY:
                provider.createFile(Subjects.ROOT, path, FileAttributes.of().uid(UID).gid(GID).mode(0664).build(), EnumSet.noneOf(FileAttribute.class));
                break;
            case PATH_TO_PNFS_ID:
                getPnfsid(path);
                break;
            case FILE_META_DATA:
                provider.getFileAttributes(Subjects.ROOT, getPnfsid(path), EnumSet.of(OWNER, OWNER_GROUP, MODE, TYPE, SIZE, CREATION_TIME, ACCESS_TIME, MODIFICATION_TIME, CHANGE_TIME));
                break;
            case DELETE_ENTRY:
                provider.deleteEntry(Subjects.ROOT, EnumSet.allOf(FileType.class), path, EnumSet.noneOf(FileAttribute.class));
                break;
            case PNFS_ID_TO_PATH:
                provider.pnfsidToPath(Subjects.ROOT, getPnfsid(path));
                break;
            case FIND:
                provider.find(Subjects.ROOT, getPnfsid(path));
                break;
            case ADD_CHECKSUM:
                provider.setFileAttributes(Subjects.ROOT, getPnfsid(path), FileAttributes.ofChecksum(CHECKSUM), EnumSet.noneOf(FileAttribute.class));
                break;
            case GET_CHECKSUMS:
                provider.getFileAttributes(Subjects.ROOT, getPnfsid(path), EnumSet.of(FileAttribute.CHECKSUM)).getChecksums();
                break;
            case SET_FILE_ATTR:
                provider.setFileAttributes(Subjects.ROOT, getPnfsid(path), FileAttributes.of().accessLatency(ONLINE).retentionPolicy(REPLICA).build(), EnumSet.noneOf(FileAttribute.class));
                break;
            case GET_FILE_ATTR:
                provider.getFileAttributes(Subjects.ROOT, getPnfsid(path), EnumSet.allOf(FileAttribute.class));
                break;
            case ADD_CACHE_LOC:
                provider.addCacheLocation(Subjects.ROOT, getPnfsid(path), CACHE_LOCATION);
                break;
            case GET_CACHE_LOC:
                provider.getCacheLocation(Subjects.ROOT, getPnfsid(path));
                break;
            case STORAGE_INFO:
                provider.getFileAttributes(Subjects.ROOT, getPnfsid(path), EnumSet.of(FileAttribute.STORAGEINFO)).getStorageInfo();
                break;
            case SET_STORAGE_INFO:
                StorageInfo info = provider.getFileAttributes(Subjects.ROOT, getPnfsid(path), EnumSet.of(FileAttribute.STORAGEINFO)).getStorageInfo();
                info.setHsm("hsm");
                info.setKey("store", "test");
                info.setKey("group", "disk");
                info.addLocation(URI.create("osm://hsm/?store=test&group=disk&bdif=1234"));
                provider.setFileAttributes(Subjects.ROOT, getPnfsid(path), FileAttributes.ofStorageInfo(info), EnumSet.noneOf(FileAttribute.class));
                break;
            case MKDIR:
                provider.createDirectory(Subjects.ROOT, path, FileAttributes.of().uid(UID).gid(GID).mode(0755).build());
                break;
            case RMDIR:
                provider.deleteEntry(Subjects.ROOT, EnumSet.of(FileType.DIR), path, EnumSet.noneOf(FileAttribute.class));
                break;
            default:
                break;
        }
    } catch (CacheException e) {
        System.err.println("Exception " + aOp.getUserInput() + " :" + e.getMessage());
    }
}
Also used : FileType(org.dcache.namespace.FileType) CacheException(diskCacheV111.util.CacheException) StorageInfo(diskCacheV111.vehicles.StorageInfo) FileAttribute(org.dcache.namespace.FileAttribute)

Example 5 with AccessLatency

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

the class PnfsManagerTest method testDefaultALandRP.

@Test
public void testDefaultALandRP() throws ChimeraFsException {
    /*
         * this test relays on the fact that default values in PnfsManager
         * is CUSTODIAL/NEARLINE
         */
    // use back door to create the tag
    FsInode dirInode = _fs.path2inode("/pnfs/testRoot");
    _fs.createTag(dirInode, "AccessLatency");
    _fs.createTag(dirInode, "RetentionPolicy");
    String al = "ONLINE";
    String rp = "OUTPUT";
    _fs.setTag(dirInode, "AccessLatency", al.getBytes(), 0, al.getBytes().length);
    _fs.setTag(dirInode, "RetentionPolicy", rp.getBytes(), 0, rp.getBytes().length);
    PnfsCreateEntryMessage pnfsCreateEntryMessage = new PnfsCreateEntryMessage("/pnfs/testRoot/testDefaultALandRP", FileAttributes.ofFileType(REGULAR));
    _pnfsManager.createEntry(pnfsCreateEntryMessage);
    FileAttributes fileAttributes = pnfsCreateEntryMessage.getFileAttributes();
    assertEquals("AccessLatensy is not taken from the parent directory", AccessLatency.ONLINE, fileAttributes.getAccessLatency());
    assertEquals("RetentionPolicy is not taken from the parent directory", RetentionPolicy.OUTPUT, fileAttributes.getRetentionPolicy());
}
Also used : FsInode(org.dcache.chimera.FsInode) PnfsCreateEntryMessage(diskCacheV111.vehicles.PnfsCreateEntryMessage) FileAttributes(org.dcache.vehicles.FileAttributes) PnfsSetFileAttributes(org.dcache.vehicles.PnfsSetFileAttributes) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) Test(org.junit.Test)

Aggregations

AccessLatency (diskCacheV111.util.AccessLatency)12 RetentionPolicy (diskCacheV111.util.RetentionPolicy)10 FileAttributes (org.dcache.vehicles.FileAttributes)10 CacheException (diskCacheV111.util.CacheException)8 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)6 StorageInfo (diskCacheV111.vehicles.StorageInfo)6 Test (org.junit.Test)6 URI (java.net.URI)5 PnfsGetFileAttributes (org.dcache.vehicles.PnfsGetFileAttributes)4 PnfsSetFileAttributes (org.dcache.vehicles.PnfsSetFileAttributes)4 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)3 PnfsId (diskCacheV111.util.PnfsId)3 PnfsCreateEntryMessage (diskCacheV111.vehicles.PnfsCreateEntryMessage)3 Space (diskCacheV111.services.space.Space)2 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)2 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)2 FileLocality (diskCacheV111.util.FileLocality)2 FsPath (diskCacheV111.util.FsPath)2 NotDirCacheException (diskCacheV111.util.NotDirCacheException)2 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)2