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;
}
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);
}
}
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);
}
}
}
}
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);
}
}
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);
}
Aggregations