Search in sources :

Example 11 with LocalResource

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

the class IndexBuilder method build.

@Override
public void build() throws HyracksDataException {
    IResourceLifecycleManager<IIndex> lcManager = storageManager.getLifecycleManager(ctx);
    synchronized (lcManager) {
        // The previous resource Id needs to be removed since calling IIndex.create() may possibly destroy any
        // physical artifact that the LocalResourceRepository is managing (e.g. a file containing the resource Id).
        // Once the index has been created, a new resource Id can be generated.
        ILocalResourceRepository localResourceRepository = storageManager.getLocalResourceRepository(ctx);
        LocalResource lr = localResourceRepository.get(resourceRef.getRelativePath());
        long resourceId = lr == null ? -1 : lr.getId();
        if (resourceId != -1) {
            localResourceRepository.delete(resourceRef.getRelativePath());
        }
        resourceId = resourceIdFactory.createId();
        IResource resource = localResourceFactory.createResource(resourceRef);
        lr = new LocalResource(resourceId, ITreeIndexFrame.Constants.VERSION, durable, resource);
        IIndex index = lcManager.get(resourceRef.getRelativePath());
        if (index != null) {
            //how is this right?????????? <needs to be fixed>
            //The reason for this is to handle many cases such as:
            //1. Crash while delete index is running (we don't do global cleanup on restart)
            //2. Node leaves and then join with old data
            lcManager.unregister(resourceRef.getRelativePath());
        } else {
            index = resource.createInstance(ctx);
        }
        index.create();
        try {
            localResourceRepository.insert(lr);
        } catch (IOException e) {
            throw HyracksDataException.create(e);
        }
        lcManager.register(resourceRef.getRelativePath(), index);
    }
}
Also used : IIndex(org.apache.hyracks.storage.common.IIndex) IOException(java.io.IOException) ILocalResourceRepository(org.apache.hyracks.storage.common.ILocalResourceRepository) IResource(org.apache.hyracks.storage.common.IResource) LocalResource(org.apache.hyracks.storage.common.LocalResource)

Example 12 with LocalResource

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

the class IndexDataflowHelper method readIndex.

private LocalResource readIndex() throws HyracksDataException {
    // Get local resource
    LocalResource lr = getResource();
    if (lr == null) {
        throw new HyracksDataException("Index resource couldn't be found. Has it been created yet? Was it deleted?");
    }
    IResource resource = lr.getResource();
    index = resource.createInstance(ctx);
    return lr;
}
Also used : HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IResource(org.apache.hyracks.storage.common.IResource) LocalResource(org.apache.hyracks.storage.common.LocalResource)

Example 13 with LocalResource

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

the class IndexDataflowHelper method open.

@Override
public void open() throws HyracksDataException {
    //Get local resource file
    synchronized (lcManager) {
        index = lcManager.get(resourceRef.getRelativePath());
        if (index == null) {
            LocalResource lr = readIndex();
            lcManager.register(lr.getPath(), index);
        }
        lcManager.open(resourceRef.getRelativePath());
    }
}
Also used : LocalResource(org.apache.hyracks.storage.common.LocalResource)

Example 14 with LocalResource

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

the class PersistentLocalResourceRepository method loadIndex.

private void loadIndex(File indexFile, Map<Long, LocalResource> resourcesMap) throws HyracksDataException {
    LOGGER.log(Level.INFO, "Loading index:" + indexFile.getName());
    if (indexFile.isDirectory()) {
        File[] metadataFiles = indexFile.listFiles(METADATA_FILES_FILTER);
        if (metadataFiles != null) {
            for (File metadataFile : metadataFiles) {
                LocalResource localResource = readLocalResource(metadataFile);
                LOGGER.log(Level.INFO, "Resource loaded " + localResource.getId() + ":" + localResource.getPath());
                resourcesMap.put(localResource.getId(), localResource);
            }
        }
    }
}
Also used : File(java.io.File) DatasetLocalResource(org.apache.asterix.common.dataflow.DatasetLocalResource) LocalResource(org.apache.hyracks.storage.common.LocalResource)

Example 15 with LocalResource

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

the class DatasetLifecycleManager method register.

@Override
public synchronized void register(String resourcePath, IIndex index) throws HyracksDataException {
    validateDatasetLifecycleManagerState();
    int did = getDIDfromResourcePath(resourcePath);
    LocalResource resource = resourceRepository.get(resourcePath);
    DatasetResource datasetResource = datasets.get(did);
    if (datasetResource == null) {
        datasetResource = getDatasetLifecycle(did);
    }
    datasetResource.register(resource, index);
}
Also used : DatasetLocalResource(org.apache.asterix.common.dataflow.DatasetLocalResource) 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