Search in sources :

Example 11 with MetadataException

use of org.apache.asterix.metadata.MetadataException in project asterixdb by apache.

the class MetadataBootstrap method startDDLRecovery.

/**
     * Perform recovery of DDL operations metadata records
     */
public static void startDDLRecovery() throws MetadataException {
    // #. clean up any record which has pendingAdd/DelOp flag
    // as traversing all records from DATAVERSE_DATASET to DATASET_DATASET, and then to INDEX_DATASET.
    MetadataTransactionContext mdTxnCtx = null;
    MetadataManager.INSTANCE.acquireWriteLatch();
    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.info("Starting DDL recovery ...");
    }
    try {
        mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
        List<Dataverse> dataverses = MetadataManager.INSTANCE.getDataverses(mdTxnCtx);
        for (Dataverse dataverse : dataverses) {
            recoverDataverse(mdTxnCtx, dataverse);
        }
        // the commit wasn't there before. yet, everything was working correctly!!!!!!!!!!!
        MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
        if (LOGGER.isLoggable(Level.INFO)) {
            LOGGER.info("Completed DDL recovery.");
        }
    } catch (Exception e) {
        try {
            if (IS_DEBUG_MODE) {
                LOGGER.log(Level.SEVERE, "Failure during DDL recovery", e);
            }
            MetadataManager.INSTANCE.abortTransaction(mdTxnCtx);
        } catch (Exception e2) {
            e.addSuppressed(e2);
        }
        throw new MetadataException(e);
    } finally {
        MetadataManager.INSTANCE.releaseWriteLatch();
    }
}
Also used : MetadataTransactionContext(org.apache.asterix.metadata.MetadataTransactionContext) Dataverse(org.apache.asterix.metadata.entities.Dataverse) ACIDException(org.apache.asterix.common.exceptions.ACIDException) MetadataException(org.apache.asterix.metadata.MetadataException) RemoteException(java.rmi.RemoteException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) MetadataException(org.apache.asterix.metadata.MetadataException)

Example 12 with MetadataException

use of org.apache.asterix.metadata.MetadataException in project asterixdb by apache.

the class MetadataProvider method getIndexInsertOrDeleteOrUpsertRuntime.

private Pair<IOperatorDescriptor, AlgebricksPartitionConstraint> getIndexInsertOrDeleteOrUpsertRuntime(IndexOperation indexOp, IDataSourceIndex<String, DataSourceId> dataSourceIndex, IOperatorSchema propagatedSchema, IOperatorSchema[] inputSchemas, IVariableTypeEnvironment typeEnv, List<LogicalVariable> primaryKeys, List<LogicalVariable> secondaryKeys, List<LogicalVariable> additionalNonKeyFields, ILogicalExpression filterExpr, RecordDescriptor inputRecordDesc, JobGenContext context, JobSpecification spec, boolean bulkload, List<LogicalVariable> prevSecondaryKeys, LogicalVariable prevAdditionalFilteringKey) throws AlgebricksException {
    String indexName = dataSourceIndex.getId();
    String dataverseName = dataSourceIndex.getDataSource().getId().getDataverseName();
    String datasetName = dataSourceIndex.getDataSource().getId().getDatasourceName();
    Dataset dataset = MetadataManagerUtil.findExistingDataset(mdTxnCtx, dataverseName, datasetName);
    Index secondaryIndex;
    try {
        secondaryIndex = MetadataManager.INSTANCE.getIndex(mdTxnCtx, dataset.getDataverseName(), dataset.getDatasetName(), indexName);
    } catch (MetadataException e) {
        throw new AlgebricksException(e);
    }
    ArrayList<LogicalVariable> prevAdditionalFilteringKeys = null;
    if (indexOp == IndexOperation.UPSERT && prevAdditionalFilteringKey != null) {
        prevAdditionalFilteringKeys = new ArrayList<>();
        prevAdditionalFilteringKeys.add(prevAdditionalFilteringKey);
    }
    AsterixTupleFilterFactory filterFactory = createTupleFilterFactory(inputSchemas, typeEnv, filterExpr, context);
    switch(secondaryIndex.getIndexType()) {
        case BTREE:
            return getBTreeRuntime(dataverseName, datasetName, indexName, propagatedSchema, primaryKeys, secondaryKeys, additionalNonKeyFields, filterFactory, inputRecordDesc, context, spec, indexOp, bulkload, prevSecondaryKeys, prevAdditionalFilteringKeys);
        case RTREE:
            return getRTreeRuntime(dataverseName, datasetName, indexName, propagatedSchema, primaryKeys, secondaryKeys, additionalNonKeyFields, filterFactory, inputRecordDesc, context, spec, indexOp, bulkload, prevSecondaryKeys, prevAdditionalFilteringKeys);
        case SINGLE_PARTITION_WORD_INVIX:
        case SINGLE_PARTITION_NGRAM_INVIX:
        case LENGTH_PARTITIONED_WORD_INVIX:
        case LENGTH_PARTITIONED_NGRAM_INVIX:
            return getInvertedIndexRuntime(dataverseName, datasetName, indexName, propagatedSchema, primaryKeys, secondaryKeys, additionalNonKeyFields, filterFactory, inputRecordDesc, context, spec, indexOp, secondaryIndex.getIndexType(), bulkload, prevSecondaryKeys, prevAdditionalFilteringKeys);
        default:
            throw new AlgebricksException(indexOp.name() + "Insert, upsert, and delete not implemented for index type: " + secondaryIndex.getIndexType());
    }
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) Dataset(org.apache.asterix.metadata.entities.Dataset) AsterixTupleFilterFactory(org.apache.asterix.runtime.base.AsterixTupleFilterFactory) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) Index(org.apache.asterix.metadata.entities.Index) IDataSourceIndex(org.apache.hyracks.algebricks.core.algebra.metadata.IDataSourceIndex) MetadataException(org.apache.asterix.metadata.MetadataException)

Example 13 with MetadataException

use of org.apache.asterix.metadata.MetadataException in project asterixdb by apache.

the class BuiltinTypeMap method getTypeFromTypeName.

public static IAType getTypeFromTypeName(MetadataNode metadataNode, JobId jobId, String dataverseName, String typeName, boolean optional) throws MetadataException {
    IAType type = _builtinTypeMap.get(typeName);
    if (type == null) {
        try {
            Datatype dt = metadataNode.getDatatype(jobId, dataverseName, typeName);
            type = dt.getDatatype();
        } catch (RemoteException e) {
            throw new MetadataException(e);
        }
    }
    if (optional) {
        type = AUnionType.createUnknownableType(type);
    }
    return type;
}
Also used : RemoteException(java.rmi.RemoteException) MetadataException(org.apache.asterix.metadata.MetadataException) IAType(org.apache.asterix.om.types.IAType)

Example 14 with MetadataException

use of org.apache.asterix.metadata.MetadataException in project asterixdb by apache.

the class InvertedIndexPOperator method contributeRuntimeOperator.

@Override
public void contributeRuntimeOperator(IHyracksJobBuilder builder, JobGenContext context, ILogicalOperator op, IOperatorSchema opSchema, IOperatorSchema[] inputSchemas, IOperatorSchema outerPlanSchema) throws AlgebricksException {
    AbstractUnnestMapOperator unnestMapOp = (AbstractUnnestMapOperator) op;
    ILogicalExpression unnestExpr = unnestMapOp.getExpressionRef().getValue();
    if (unnestExpr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
        throw new IllegalStateException();
    }
    AbstractFunctionCallExpression unnestFuncExpr = (AbstractFunctionCallExpression) unnestExpr;
    if (unnestFuncExpr.getFunctionIdentifier() != BuiltinFunctions.INDEX_SEARCH) {
        return;
    }
    InvertedIndexJobGenParams jobGenParams = new InvertedIndexJobGenParams();
    jobGenParams.readFromFuncArgs(unnestFuncExpr.getArguments());
    MetadataProvider metadataProvider = (MetadataProvider) context.getMetadataProvider();
    Dataset dataset;
    try {
        dataset = metadataProvider.findDataset(jobGenParams.getDataverseName(), jobGenParams.getDatasetName());
    } catch (MetadataException e) {
        throw new AlgebricksException(e);
    }
    int[] keyIndexes = getKeyIndexes(jobGenParams.getKeyVarList(), inputSchemas);
    int[] minFilterFieldIndexes = getKeyIndexes(unnestMapOp.getMinFilterVars(), inputSchemas);
    int[] maxFilterFieldIndexes = getKeyIndexes(unnestMapOp.getMaxFilterVars(), inputSchemas);
    boolean retainNull = false;
    if (op.getOperatorTag() == LogicalOperatorTag.LEFT_OUTER_UNNEST_MAP) {
        // By nature, LEFT_OUTER_UNNEST_MAP should generate null values for non-matching tuples.
        retainNull = true;
    }
    // Build runtime.
    Pair<IOperatorDescriptor, AlgebricksPartitionConstraint> invIndexSearch = buildInvertedIndexRuntime(metadataProvider, context, builder.getJobSpec(), unnestMapOp, opSchema, jobGenParams.getRetainInput(), retainNull, jobGenParams.getDatasetName(), dataset, jobGenParams.getIndexName(), jobGenParams.getSearchKeyType(), keyIndexes, jobGenParams.getSearchModifierType(), jobGenParams.getSimilarityThreshold(), minFilterFieldIndexes, maxFilterFieldIndexes, jobGenParams.getIsFullTextSearch());
    // Contribute operator in hyracks job.
    builder.contributeHyracksOperator(unnestMapOp, invIndexSearch.first);
    builder.contributeAlgebricksPartitionConstraint(invIndexSearch.first, invIndexSearch.second);
    ILogicalOperator srcExchange = unnestMapOp.getInputs().get(0).getValue();
    builder.contributeGraphEdge(srcExchange, 0, unnestMapOp, 0);
}
Also used : Dataset(org.apache.asterix.metadata.entities.Dataset) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) MetadataException(org.apache.asterix.metadata.MetadataException) InvertedIndexJobGenParams(org.apache.asterix.optimizer.rules.am.InvertedIndexJobGenParams) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) MetadataProvider(org.apache.asterix.metadata.declared.MetadataProvider) IOperatorDescriptor(org.apache.hyracks.api.dataflow.IOperatorDescriptor) AbstractUnnestMapOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractUnnestMapOperator) AlgebricksPartitionConstraint(org.apache.hyracks.algebricks.common.constraints.AlgebricksPartitionConstraint)

Example 15 with MetadataException

use of org.apache.asterix.metadata.MetadataException in project asterixdb by apache.

the class LangExpressionToPlanTranslator method lookupUserDefinedFunction.

private AbstractFunctionCallExpression lookupUserDefinedFunction(FunctionSignature signature, List<Mutable<ILogicalExpression>> args) throws MetadataException {
    if (signature.getNamespace() == null) {
        return null;
    }
    Function function = MetadataManager.INSTANCE.getFunction(metadataProvider.getMetadataTxnContext(), signature);
    if (function == null) {
        return null;
    }
    AbstractFunctionCallExpression f;
    if (function.getLanguage().equalsIgnoreCase(Function.LANGUAGE_JAVA)) {
        IFunctionInfo finfo = ExternalFunctionCompilerUtil.getExternalFunctionInfo(metadataProvider.getMetadataTxnContext(), function);
        f = new ScalarFunctionCallExpression(finfo, args);
    } else if (function.getLanguage().equalsIgnoreCase(Function.LANGUAGE_AQL)) {
        IFunctionInfo finfo = FunctionUtil.getFunctionInfo(signature);
        f = new ScalarFunctionCallExpression(finfo, args);
    } else {
        throw new MetadataException(" User defined functions written in " + function.getLanguage() + " are not supported");
    }
    return f;
}
Also used : Function(org.apache.asterix.metadata.entities.Function) IFunctionInfo(org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) MetadataException(org.apache.asterix.metadata.MetadataException) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)

Aggregations

MetadataException (org.apache.asterix.metadata.MetadataException)19 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)12 Index (org.apache.asterix.metadata.entities.Index)9 AlgebricksPartitionConstraint (org.apache.hyracks.algebricks.common.constraints.AlgebricksPartitionConstraint)8 Dataset (org.apache.asterix.metadata.entities.Dataset)7 Pair (org.apache.hyracks.algebricks.common.utils.Pair)7 IFileSplitProvider (org.apache.hyracks.dataflow.std.file.IFileSplitProvider)7 IIndexDataflowHelperFactory (org.apache.hyracks.storage.am.common.dataflow.IIndexDataflowHelperFactory)7 IndexDataflowHelperFactory (org.apache.hyracks.storage.am.common.dataflow.IndexDataflowHelperFactory)7 RemoteException (java.rmi.RemoteException)6 IDataSourceIndex (org.apache.hyracks.algebricks.core.algebra.metadata.IDataSourceIndex)6 DatasetCardinalityHint (org.apache.asterix.metadata.dataset.hints.DatasetHints.DatasetCardinalityHint)5 ACIDException (org.apache.asterix.common.exceptions.ACIDException)4 MetadataTransactionContext (org.apache.asterix.metadata.MetadataTransactionContext)4 ARecordType (org.apache.asterix.om.types.ARecordType)4 AlgebricksAbsolutePartitionConstraint (org.apache.hyracks.algebricks.common.constraints.AlgebricksAbsolutePartitionConstraint)4 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)4 RecordDescriptor (org.apache.hyracks.api.dataflow.value.RecordDescriptor)4 IAType (org.apache.asterix.om.types.IAType)3 JobEventListenerFactory (org.apache.asterix.runtime.job.listener.JobEventListenerFactory)3