Search in sources :

Example 1 with PersistentLocation

use of es.bsc.compss.types.data.location.PersistentLocation in project compss by bsc-wdc.

the class LogicalData method loadFromStorage.

/**
 * Loads the value of the LogicalData from a file
 *
 * @throws CannotLoadException
 * @throws IOException
 * @throws ClassNotFoundException
 * @throws StorageException
 * @throws UnstartedNodeException
 *
 * @throws Exception
 */
public synchronized void loadFromStorage() throws CannotLoadException {
    if (value != null) {
        // Value is already loaded in memory
        return;
    }
    for (DataLocation loc : this.locations) {
        switch(loc.getType()) {
            case PRIVATE:
            case SHARED:
                // Get URI and deserialize object if possible
                MultiURI u = loc.getURIInHost(Comm.getAppHost());
                if (u == null) {
                    continue;
                }
                String path = u.getPath();
                if (path.startsWith(File.separator)) {
                    try {
                        this.value = Serializer.deserialize(path);
                    } catch (ClassNotFoundException | IOException e) {
                        // Check next location since deserialization was invalid
                        this.value = null;
                        continue;
                    }
                    String targetPath = Protocol.OBJECT_URI.getSchema() + this.name;
                    SimpleURI uri = new SimpleURI(targetPath);
                    try {
                        DataLocation tgtLoc = DataLocation.createLocation(Comm.getAppHost(), uri);
                        addLocation(tgtLoc);
                    } catch (IOException e) {
                        // Check next location since location was invalid
                        this.value = null;
                        continue;
                    }
                }
                return;
            case PERSISTENT:
                PersistentLocation pLoc = (PersistentLocation) loc;
                if (Tracer.isActivated()) {
                    Tracer.emitEvent(Tracer.Event.STORAGE_GETBYID.getId(), Tracer.Event.STORAGE_GETBYID.getType());
                }
                try {
                    this.value = StorageItf.getByID(pLoc.getId());
                    this.id = pLoc.getId();
                } catch (StorageException se) {
                    // Check next location since cannot retrieve the object from the storage Back-end
                    continue;
                } finally {
                    if (Tracer.isActivated()) {
                        Tracer.emitEvent(Tracer.EVENT_END, Tracer.Event.STORAGE_GETBYID.getType());
                    }
                }
                String targetPath = Protocol.OBJECT_URI.getSchema() + this.name;
                SimpleURI uri = new SimpleURI(targetPath);
                try {
                    DataLocation tgtLoc = DataLocation.createLocation(Comm.getAppHost(), uri);
                    addLocation(tgtLoc);
                } catch (IOException e) {
                    // Check next location since location was invalid
                    this.value = null;
                    continue;
                }
                return;
        }
    }
    // Any location has been able to load the value
    throw new CannotLoadException("Object has not any valid location available in the master");
}
Also used : MultiURI(es.bsc.compss.types.uri.MultiURI) PersistentLocation(es.bsc.compss.types.data.location.PersistentLocation) CannotLoadException(es.bsc.compss.exceptions.CannotLoadException) SimpleURI(es.bsc.compss.types.uri.SimpleURI) DataLocation(es.bsc.compss.types.data.location.DataLocation) IOException(java.io.IOException) StorageException(storage.StorageException)

Example 2 with PersistentLocation

use of es.bsc.compss.types.data.location.PersistentLocation in project compss by bsc-wdc.

the class DataInfoProvider method blockDataAndGetResultFile.

/**
 * Blocks dataId and retrieves its result file
 *
 * @param dataId
 * @param listener
 * @return
 */
public ResultFile blockDataAndGetResultFile(int dataId, ResultListener listener) {
    DataInstanceId lastVersion;
    FileInfo fileInfo = (FileInfo) idToData.get(dataId);
    if (fileInfo != null && !fileInfo.isCurrentVersionToDelete()) {
        // If current version is to delete do not
        // transfer
        String[] splitPath = fileInfo.getOriginalLocation().getPath().split(File.separator);
        String origName = splitPath[splitPath.length - 1];
        if (origName.startsWith("compss-serialized-obj_")) {
            // Do not transfer objects serialized by the bindings
            if (DEBUG) {
                LOGGER.debug("Discarding file " + origName + " as a result");
            }
            return null;
        }
        fileInfo.blockDeletions();
        lastVersion = fileInfo.getCurrentDataVersion().getDataInstanceId();
        ResultFile rf = new ResultFile(lastVersion, fileInfo.getOriginalLocation());
        DataInstanceId fId = rf.getFileInstanceId();
        String renaming = fId.getRenaming();
        // Look for the last available version
        while (renaming != null && !Comm.existsData(renaming)) {
            renaming = DataInstanceId.previousVersionRenaming(renaming);
        }
        if (renaming == null) {
            LOGGER.error(RES_FILE_TRANSFER_ERR + ": Cannot transfer file " + fId.getRenaming() + " nor any of its previous versions");
            return null;
        }
        // Check if data is a PSCO and must be consolidated
        for (DataLocation loc : Comm.getData(renaming).getLocations()) {
            if (loc instanceof PersistentLocation) {
                String pscoId = ((PersistentLocation) loc).getId();
                if (Tracer.isActivated()) {
                    Tracer.emitEvent(Tracer.Event.STORAGE_CONSOLIDATE.getId(), Tracer.Event.STORAGE_CONSOLIDATE.getType());
                }
                try {
                    StorageItf.consolidateVersion(pscoId);
                } catch (StorageException e) {
                    LOGGER.error("Cannot consolidate PSCO " + pscoId, e);
                } finally {
                    if (Tracer.isActivated()) {
                        Tracer.emitEvent(Tracer.EVENT_END, Tracer.Event.STORAGE_CONSOLIDATE.getType());
                    }
                }
                LOGGER.debug("Returned because persistent object");
                return rf;
            }
        }
        // If no PSCO location is found, perform normal getData
        listener.addOperation();
        Comm.getAppHost().getData(renaming, rf.getOriginalLocation(), new FileTransferable(), listener);
        return rf;
    } else if (fileInfo != null && fileInfo.isCurrentVersionToDelete()) {
        if (DEBUG) {
            String[] splitPath = fileInfo.getOriginalLocation().getPath().split(File.separator);
            String origName = splitPath[splitPath.length - 1];
            LOGGER.debug("Trying to delete file " + origName);
        }
        if (fileInfo.delete()) {
        // idToData.remove(dataId);
        }
    }
    return null;
}
Also used : FileTransferable(es.bsc.compss.types.data.operation.FileTransferable) PersistentLocation(es.bsc.compss.types.data.location.PersistentLocation) DataLocation(es.bsc.compss.types.data.location.DataLocation) StorageException(storage.StorageException)

Aggregations

DataLocation (es.bsc.compss.types.data.location.DataLocation)2 PersistentLocation (es.bsc.compss.types.data.location.PersistentLocation)2 StorageException (storage.StorageException)2 CannotLoadException (es.bsc.compss.exceptions.CannotLoadException)1 FileTransferable (es.bsc.compss.types.data.operation.FileTransferable)1 MultiURI (es.bsc.compss.types.uri.MultiURI)1 SimpleURI (es.bsc.compss.types.uri.SimpleURI)1 IOException (java.io.IOException)1