Search in sources :

Example 61 with Dataset

use of org.apache.asterix.metadata.entities.Dataset in project asterixdb by apache.

the class MetadataNode method initializeDatasetIdFactory.

@Override
public void initializeDatasetIdFactory(JobId jobId) throws MetadataException, RemoteException {
    int mostRecentDatasetId = MetadataIndexImmutableProperties.FIRST_AVAILABLE_USER_DATASET_ID;
    try {
        String resourceName = MetadataPrimaryIndexes.DATASET_DATASET.getFile().getRelativePath();
        IIndex indexInstance = datasetLifecycleManager.get(resourceName);
        datasetLifecycleManager.open(resourceName);
        try {
            IIndexAccessor indexAccessor = indexInstance.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
            IIndexCursor rangeCursor = indexAccessor.createSearchCursor(false);
            DatasetTupleTranslator tupleReaderWriter = tupleTranslatorProvider.getDatasetTupleTranslator(false);
            IValueExtractor<Dataset> valueExtractor = new MetadataEntityValueExtractor<>(tupleReaderWriter);
            RangePredicate rangePred = new RangePredicate(null, null, true, true, null, null);
            indexAccessor.search(rangeCursor, rangePred);
            int datasetId;
            try {
                while (rangeCursor.hasNext()) {
                    rangeCursor.next();
                    final ITupleReference ref = rangeCursor.getTuple();
                    final Dataset ds = valueExtractor.getValue(jobId, ref);
                    datasetId = ds.getDatasetId();
                    if (mostRecentDatasetId < datasetId) {
                        mostRecentDatasetId = datasetId;
                    }
                }
            } finally {
                rangeCursor.close();
            }
        } finally {
            datasetLifecycleManager.close(resourceName);
        }
    } catch (HyracksDataException e) {
        throw new MetadataException(e);
    }
    DatasetIdFactory.initialize(mostRecentDatasetId);
}
Also used : IIndex(org.apache.hyracks.storage.common.IIndex) RangePredicate(org.apache.hyracks.storage.am.btree.impls.RangePredicate) DatasetTupleTranslator(org.apache.asterix.metadata.entitytupletranslators.DatasetTupleTranslator) ExtensionMetadataDataset(org.apache.asterix.metadata.api.ExtensionMetadataDataset) Dataset(org.apache.asterix.metadata.entities.Dataset) AString(org.apache.asterix.om.base.AString) AMutableString(org.apache.asterix.om.base.AMutableString) IIndexAccessor(org.apache.hyracks.storage.common.IIndexAccessor) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) MetadataEntityValueExtractor(org.apache.asterix.metadata.valueextractors.MetadataEntityValueExtractor) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) IIndexCursor(org.apache.hyracks.storage.common.IIndexCursor)

Example 62 with Dataset

use of org.apache.asterix.metadata.entities.Dataset in project asterixdb by apache.

the class MetadataManager method getDatasetIndexes.

@Override
public List<Index> getDatasetIndexes(MetadataTransactionContext ctx, String dataverseName, String datasetName) throws MetadataException {
    List<Index> datasetIndexes = new ArrayList<>();
    Dataset dataset = findDataset(ctx, dataverseName, datasetName);
    if (dataset == null) {
        return datasetIndexes;
    }
    if (dataset.getDatasetDetails().isTemp()) {
        // for temp datsets
        datasetIndexes = cache.getDatasetIndexes(dataverseName, datasetName);
    } else {
        try {
            // for persistent datasets
            datasetIndexes = metadataNode.getDatasetIndexes(ctx.getJobId(), dataverseName, datasetName);
        } catch (RemoteException e) {
            throw new MetadataException(e);
        }
    }
    return datasetIndexes;
}
Also used : Dataset(org.apache.asterix.metadata.entities.Dataset) ArrayList(java.util.ArrayList) Index(org.apache.asterix.metadata.entities.Index) RemoteException(java.rmi.RemoteException)

Example 63 with Dataset

use of org.apache.asterix.metadata.entities.Dataset in project asterixdb by apache.

the class MetadataManager method addIndex.

@Override
public void addIndex(MetadataTransactionContext ctx, Index index) throws MetadataException {
    String dataverseName = index.getDataverseName();
    String datasetName = index.getDatasetName();
    Dataset dataset = findDataset(ctx, dataverseName, datasetName);
    if (dataset == null || !dataset.getDatasetDetails().isTemp()) {
        try {
            metadataNode.addIndex(ctx.getJobId(), index);
        } catch (RemoteException e) {
            throw new MetadataException(e);
        }
    }
    ctx.addIndex(index);
}
Also used : Dataset(org.apache.asterix.metadata.entities.Dataset) RemoteException(java.rmi.RemoteException)

Example 64 with Dataset

use of org.apache.asterix.metadata.entities.Dataset in project asterixdb by apache.

the class MetadataManager method dropDataset.

@Override
public void dropDataset(MetadataTransactionContext ctx, String dataverseName, String datasetName) throws MetadataException {
    Dataset dataset = findDataset(ctx, dataverseName, datasetName);
    // If a dataset is not in the cache, then it could not be a temp dataset
    if (dataset == null || !dataset.getDatasetDetails().isTemp()) {
        try {
            metadataNode.dropDataset(ctx.getJobId(), dataverseName, datasetName);
        } catch (RemoteException e) {
            throw new MetadataException(e);
        }
    }
    // Drops the dataset from cache
    ctx.dropDataset(dataverseName, datasetName);
}
Also used : Dataset(org.apache.asterix.metadata.entities.Dataset) RemoteException(java.rmi.RemoteException)

Example 65 with Dataset

use of org.apache.asterix.metadata.entities.Dataset in project asterixdb by apache.

the class MetadataManager method dropIndex.

@Override
public void dropIndex(MetadataTransactionContext ctx, String dataverseName, String datasetName, String indexName) throws MetadataException {
    Dataset dataset = findDataset(ctx, dataverseName, datasetName);
    // If the dataset is a temp dataset, then we do not need to call any MedataNode operations.
    if (dataset == null || !dataset.getDatasetDetails().isTemp()) {
        try {
            metadataNode.dropIndex(ctx.getJobId(), dataverseName, datasetName, indexName);
        } catch (RemoteException e) {
            throw new MetadataException(e);
        }
    }
    ctx.dropIndex(dataverseName, datasetName, indexName);
}
Also used : Dataset(org.apache.asterix.metadata.entities.Dataset) RemoteException(java.rmi.RemoteException)

Aggregations

Dataset (org.apache.asterix.metadata.entities.Dataset)77 ArrayList (java.util.ArrayList)33 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)32 Index (org.apache.asterix.metadata.entities.Index)25 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)23 MetadataException (org.apache.asterix.metadata.MetadataException)19 ARecordType (org.apache.asterix.om.types.ARecordType)19 IAType (org.apache.asterix.om.types.IAType)18 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)18 List (java.util.List)17 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)16 RemoteException (java.rmi.RemoteException)15 AsterixException (org.apache.asterix.common.exceptions.AsterixException)15 MetadataProvider (org.apache.asterix.metadata.declared.MetadataProvider)15 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)15 IOException (java.io.IOException)14 MetadataTransactionContext (org.apache.asterix.metadata.MetadataTransactionContext)14 CompilationException (org.apache.asterix.common.exceptions.CompilationException)13 AlgebricksPartitionConstraint (org.apache.hyracks.algebricks.common.constraints.AlgebricksPartitionConstraint)12 ACIDException (org.apache.asterix.common.exceptions.ACIDException)11