Search in sources :

Example 1 with IResource

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

the class DatasetLocalResourceFactory method createResource.

@Override
public IResource createResource(FileReference fileRef) {
    IResource resource = resourceFactory.createResource(fileRef);
    // Currently, we get the partition number from the relative path
    int partition = StoragePathUtil.getPartitionNumFromRelativePath(fileRef.getRelativePath());
    return new DatasetLocalResource(datasetId, partition, resource);
}
Also used : DatasetLocalResource(org.apache.asterix.common.dataflow.DatasetLocalResource) IResource(org.apache.hyracks.storage.common.IResource)

Example 2 with IResource

use of org.apache.hyracks.storage.common.IResource 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 3 with IResource

use of org.apache.hyracks.storage.common.IResource 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)

Aggregations

IResource (org.apache.hyracks.storage.common.IResource)3 LocalResource (org.apache.hyracks.storage.common.LocalResource)2 IOException (java.io.IOException)1 DatasetLocalResource (org.apache.asterix.common.dataflow.DatasetLocalResource)1 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1 IIndex (org.apache.hyracks.storage.common.IIndex)1 ILocalResourceRepository (org.apache.hyracks.storage.common.ILocalResourceRepository)1