Search in sources :

Example 1 with CompactionPolicy

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

the class CompactionPolicyTupleTranslator method createCompactionPolicyFromARecord.

private CompactionPolicy createCompactionPolicyFromARecord(ARecord compactionPolicyRecord) {
    CompactionPolicy compactionPolicy = null;
    String dataverseName = ((AString) compactionPolicyRecord.getValueByPos(MetadataRecordTypes.COMPACTION_POLICY_ARECORD_DATAVERSE_NAME_FIELD_INDEX)).getStringValue();
    String policyName = ((AString) compactionPolicyRecord.getValueByPos(MetadataRecordTypes.COMPACTION_POLICY_ARECORD_POLICY_NAME_FIELD_INDEX)).getStringValue();
    String className = ((AString) compactionPolicyRecord.getValueByPos(MetadataRecordTypes.COMPACTION_POLICY_ARECORD_CLASSNAME_FIELD_INDEX)).getStringValue();
    compactionPolicy = new CompactionPolicy(dataverseName, policyName, className);
    return compactionPolicy;
}
Also used : CompactionPolicy(org.apache.asterix.metadata.entities.CompactionPolicy) AString(org.apache.asterix.om.base.AString) AString(org.apache.asterix.om.base.AString)

Example 2 with CompactionPolicy

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

the class MetadataBootstrap method insertInitialCompactionPolicies.

private static void insertInitialCompactionPolicies(MetadataTransactionContext mdTxnCtx) throws MetadataException {
    String[] builtInCompactionPolicyClassNames = new String[] { ConstantMergePolicyFactory.class.getName(), PrefixMergePolicyFactory.class.getName(), NoMergePolicyFactory.class.getName(), CorrelatedPrefixMergePolicyFactory.class.getName() };
    for (String policyClassName : builtInCompactionPolicyClassNames) {
        CompactionPolicy compactionPolicy = getCompactionPolicyEntity(policyClassName);
        MetadataManager.INSTANCE.addCompactionPolicy(mdTxnCtx, compactionPolicy);
    }
}
Also used : CompactionPolicy(org.apache.asterix.metadata.entities.CompactionPolicy)

Example 3 with CompactionPolicy

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

the class QueryTranslator method validateCompactionPolicy.

protected static void validateCompactionPolicy(String compactionPolicy, Map<String, String> compactionPolicyProperties, MetadataTransactionContext mdTxnCtx, boolean isExternalDataset) throws CompilationException, Exception {
    CompactionPolicy compactionPolicyEntity = MetadataManager.INSTANCE.getCompactionPolicy(mdTxnCtx, MetadataConstants.METADATA_DATAVERSE_NAME, compactionPolicy);
    if (compactionPolicyEntity == null) {
        throw new CompilationException("Unknown compaction policy: " + compactionPolicy);
    }
    String compactionPolicyFactoryClassName = compactionPolicyEntity.getClassName();
    ILSMMergePolicyFactory mergePolicyFactory = (ILSMMergePolicyFactory) Class.forName(compactionPolicyFactoryClassName).newInstance();
    if (isExternalDataset && mergePolicyFactory.getName().compareTo("correlated-prefix") == 0) {
        throw new CompilationException("The correlated-prefix merge policy cannot be used with external dataset.");
    }
    if (compactionPolicyProperties == null) {
        if (mergePolicyFactory.getName().compareTo("no-merge") != 0) {
            throw new CompilationException("Compaction policy properties are missing.");
        }
    } else {
        for (Map.Entry<String, String> entry : compactionPolicyProperties.entrySet()) {
            if (!mergePolicyFactory.getPropertiesNames().contains(entry.getKey())) {
                throw new CompilationException("Invalid compaction policy property: " + entry.getKey());
            }
        }
        for (String p : mergePolicyFactory.getPropertiesNames()) {
            if (!compactionPolicyProperties.containsKey(p)) {
                throw new CompilationException("Missing compaction policy property: " + p);
            }
        }
    }
}
Also used : CompilationException(org.apache.asterix.common.exceptions.CompilationException) CompactionPolicy(org.apache.asterix.metadata.entities.CompactionPolicy) Map(java.util.Map) BuiltinTypeMap(org.apache.asterix.metadata.entities.BuiltinTypeMap) HashMap(java.util.HashMap) ILSMMergePolicyFactory(org.apache.hyracks.storage.am.lsm.common.api.ILSMMergePolicyFactory)

Example 4 with CompactionPolicy

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

the class MetadataNode method getCompactionPolicy.

@Override
public CompactionPolicy getCompactionPolicy(JobId jobId, String dataverse, String policyName) throws MetadataException, RemoteException {
    try {
        ITupleReference searchKey = createTuple(dataverse, policyName);
        CompactionPolicyTupleTranslator tupleReaderWriter = tupleTranslatorProvider.getCompactionPolicyTupleTranslator(false);
        List<CompactionPolicy> results = new ArrayList<>();
        IValueExtractor<CompactionPolicy> valueExtractor = new MetadataEntityValueExtractor<>(tupleReaderWriter);
        searchIndex(jobId, MetadataPrimaryIndexes.COMPACTION_POLICY_DATASET, searchKey, valueExtractor, results);
        if (!results.isEmpty()) {
            return results.get(0);
        }
        return null;
    } catch (HyracksDataException e) {
        throw new MetadataException(e);
    }
}
Also used : MetadataEntityValueExtractor(org.apache.asterix.metadata.valueextractors.MetadataEntityValueExtractor) CompactionPolicyTupleTranslator(org.apache.asterix.metadata.entitytupletranslators.CompactionPolicyTupleTranslator) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) ArrayList(java.util.ArrayList) CompactionPolicy(org.apache.asterix.metadata.entities.CompactionPolicy) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 5 with CompactionPolicy

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

the class DatasetUtil method getMergePolicyFactory.

public static Pair<ILSMMergePolicyFactory, Map<String, String>> getMergePolicyFactory(Dataset dataset, MetadataTransactionContext mdTxnCtx) throws AlgebricksException {
    String policyName = dataset.getCompactionPolicy();
    CompactionPolicy compactionPolicy = MetadataManager.INSTANCE.getCompactionPolicy(mdTxnCtx, MetadataConstants.METADATA_DATAVERSE_NAME, policyName);
    String compactionPolicyFactoryClassName = compactionPolicy.getClassName();
    ILSMMergePolicyFactory mergePolicyFactory;
    Map<String, String> properties = dataset.getCompactionPolicyProperties();
    try {
        mergePolicyFactory = (ILSMMergePolicyFactory) Class.forName(compactionPolicyFactoryClassName).newInstance();
        if (mergePolicyFactory.getName().compareTo(CorrelatedPrefixMergePolicyFactory.NAME) == 0) {
            properties.put(CorrelatedPrefixMergePolicyFactory.KEY_DATASET_ID, Integer.toString(dataset.getDatasetId()));
        }
    } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
        throw new AlgebricksException(e);
    }
    return new Pair<>(mergePolicyFactory, properties);
}
Also used : AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) CompactionPolicy(org.apache.asterix.metadata.entities.CompactionPolicy) AMutableString(org.apache.asterix.om.base.AMutableString) AString(org.apache.asterix.om.base.AString) ILSMMergePolicyFactory(org.apache.hyracks.storage.am.lsm.common.api.ILSMMergePolicyFactory) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Aggregations

CompactionPolicy (org.apache.asterix.metadata.entities.CompactionPolicy)5 AString (org.apache.asterix.om.base.AString)2 ILSMMergePolicyFactory (org.apache.hyracks.storage.am.lsm.common.api.ILSMMergePolicyFactory)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CompilationException (org.apache.asterix.common.exceptions.CompilationException)1 BuiltinTypeMap (org.apache.asterix.metadata.entities.BuiltinTypeMap)1 CompactionPolicyTupleTranslator (org.apache.asterix.metadata.entitytupletranslators.CompactionPolicyTupleTranslator)1 MetadataEntityValueExtractor (org.apache.asterix.metadata.valueextractors.MetadataEntityValueExtractor)1 AMutableString (org.apache.asterix.om.base.AMutableString)1 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)1 Pair (org.apache.hyracks.algebricks.common.utils.Pair)1 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)1