Search in sources :

Example 1 with LocalResource

use of org.apache.hyracks.storage.common.LocalResource in project asterixdb by apache.

the class PersistentLocalResourceRepository method get.

@Override
public LocalResource get(String relativePath) throws HyracksDataException {
    LocalResource resource = resourceCache.getIfPresent(relativePath);
    if (resource == null) {
        FileReference resourceFile = getLocalResourceFileByName(ioManager, relativePath);
        if (resourceFile.getFile().exists()) {
            resource = readLocalResource(resourceFile.getFile());
            resourceCache.put(relativePath, resource);
        }
    }
    return resource;
}
Also used : FileReference(org.apache.hyracks.api.io.FileReference) DatasetLocalResource(org.apache.asterix.common.dataflow.DatasetLocalResource) LocalResource(org.apache.hyracks.storage.common.LocalResource)

Example 2 with LocalResource

use of org.apache.hyracks.storage.common.LocalResource in project asterixdb by apache.

the class PersistentLocalResourceRepository method getIndexFileRef.

public IndexFileProperties getIndexFileRef(String absoluteFilePath) throws HyracksDataException {
    //TODO pass relative path
    final String[] tokens = absoluteFilePath.split(File.separator);
    if (tokens.length < 5) {
        throw new HyracksDataException("Invalid file format");
    }
    String fileName = tokens[tokens.length - 1];
    String index = tokens[tokens.length - 2];
    String dataverse = tokens[tokens.length - 3];
    String partition = tokens[tokens.length - 4];
    int partitionId = StoragePathUtil.getPartitionNumFromName(partition);
    String relativePath = getLocalResourceRelativePath(absoluteFilePath);
    final LocalResource lr = get(relativePath);
    int datasetId = lr == null ? -1 : ((DatasetLocalResource) lr.getResource()).getDatasetId();
    return new IndexFileProperties(partitionId, dataverse, index, fileName, datasetId);
}
Also used : IndexFileProperties(org.apache.asterix.common.storage.IndexFileProperties) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) DatasetLocalResource(org.apache.asterix.common.dataflow.DatasetLocalResource) LocalResource(org.apache.hyracks.storage.common.LocalResource)

Example 3 with LocalResource

use of org.apache.hyracks.storage.common.LocalResource in project asterixdb by apache.

the class PersistentLocalResourceRepository method loadAndGetAllResources.

public Map<Long, LocalResource> loadAndGetAllResources() throws IOException {
    //TODO During recovery, the memory usage currently is proportional to the number of resources available.
    //This could be fixed by traversing all resources on disk until the required resource is found.
    LOGGER.log(Level.INFO, "Loading all resources");
    Map<Long, LocalResource> resourcesMap = new HashMap<>();
    for (int i = 0; i < mountPoints.length; i++) {
        File storageRootDir = getStorageRootDirectoryIfExists(ioManager, nodeId, i);
        if (storageRootDir == null) {
            LOGGER.log(Level.INFO, "Getting storage root dir returned null. Returning");
            continue;
        }
        LOGGER.log(Level.INFO, "Getting storage root dir returned " + storageRootDir.getAbsolutePath());
        //load all local resources.
        File[] partitions = storageRootDir.listFiles();
        LOGGER.log(Level.INFO, "Number of partitions found = " + partitions.length);
        for (File partition : partitions) {
            File[] dataverseFileList = partition.listFiles();
            LOGGER.log(Level.INFO, "Reading partition = " + partition.getName() + ". Number of dataverses found: " + dataverseFileList.length);
            if (dataverseFileList != null) {
                for (File dataverseFile : dataverseFileList) {
                    loadDataverse(dataverseFile, resourcesMap);
                }
            }
        }
    }
    return resourcesMap;
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) File(java.io.File) DatasetLocalResource(org.apache.asterix.common.dataflow.DatasetLocalResource) LocalResource(org.apache.hyracks.storage.common.LocalResource)

Example 4 with LocalResource

use of org.apache.hyracks.storage.common.LocalResource in project asterixdb by apache.

the class PersistentLocalResourceRepository method getMaxResourceIdForIndex.

private long getMaxResourceIdForIndex(File indexFile, long maxSoFar) throws HyracksDataException {
    long maxResourceId = maxSoFar;
    if (indexFile.isDirectory()) {
        File[] metadataFiles = indexFile.listFiles(METADATA_FILES_FILTER);
        if (metadataFiles != null) {
            for (File metadataFile : metadataFiles) {
                LocalResource localResource = readLocalResource(metadataFile);
                maxResourceId = Math.max(maxResourceId, localResource.getId());
            }
        }
    }
    return maxResourceId;
}
Also used : File(java.io.File) DatasetLocalResource(org.apache.asterix.common.dataflow.DatasetLocalResource) LocalResource(org.apache.hyracks.storage.common.LocalResource)

Example 5 with LocalResource

use of org.apache.hyracks.storage.common.LocalResource in project asterixdb by apache.

the class ReplicaResourcesManager method getLaggingReplicaIndexesId2PathMap.

public Map<Long, String> getLaggingReplicaIndexesId2PathMap(String replicaId, long targetLSN) throws IOException {
    Map<Long, String> laggingReplicaIndexes = new HashMap<Long, String>();
    try {
        //for every index in replica
        Set<File> remoteIndexes = getReplicaIndexes(replicaId);
        for (File indexFolder : remoteIndexes) {
            if (getReplicaIndexMaxLSN(indexFolder) < targetLSN) {
                File localResource = new File(indexFolder + File.separator + PersistentLocalResourceRepository.METADATA_FILE_NAME);
                LocalResource resource = PersistentLocalResourceRepository.readLocalResource(localResource);
                laggingReplicaIndexes.put(resource.getId(), indexFolder.getAbsolutePath());
            }
        }
    } catch (HyracksDataException e) {
        e.printStackTrace();
    }
    return laggingReplicaIndexes;
}
Also used : HashMap(java.util.HashMap) File(java.io.File) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) LocalResource(org.apache.hyracks.storage.common.LocalResource)

Aggregations

LocalResource (org.apache.hyracks.storage.common.LocalResource)15 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)8 DatasetLocalResource (org.apache.asterix.common.dataflow.DatasetLocalResource)7 File (java.io.File)4 HashMap (java.util.HashMap)3 VSizeFrame (org.apache.hyracks.api.comm.VSizeFrame)3 FileReference (org.apache.hyracks.api.io.FileReference)3 DataOutput (java.io.DataOutput)2 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)2 FrameTupleAppender (org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender)2 ITreeIndex (org.apache.hyracks.storage.am.common.api.ITreeIndex)2 IResource (org.apache.hyracks.storage.common.IResource)2 IOException (java.io.IOException)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 IDatasetLifecycleManager (org.apache.asterix.common.api.IDatasetLifecycleManager)1 ClusterPartition (org.apache.asterix.common.cluster.ClusterPartition)1 AsterixVirtualBufferCacheProvider (org.apache.asterix.common.context.AsterixVirtualBufferCacheProvider)1 IStorageComponentProvider (org.apache.asterix.common.context.IStorageComponentProvider)1 ACIDException (org.apache.asterix.common.exceptions.ACIDException)1 IndexFileProperties (org.apache.asterix.common.storage.IndexFileProperties)1