Search in sources :

Example 1 with IndexRemoveJob

use of com.thinkaurelius.titan.graphdb.olap.job.IndexRemoveJob in project titan by thinkaurelius.

the class ManagementSystem method updateIndex.

/* --------------
    Schema Update
     --------------- */
@Override
public IndexJobFuture updateIndex(TitanIndex index, SchemaAction updateAction) {
    Preconditions.checkArgument(index != null, "Need to provide an index");
    Preconditions.checkArgument(updateAction != null, "Need to provide update action");
    TitanSchemaVertex schemaVertex = getSchemaVertex(index);
    Set<TitanSchemaVertex> dependentTypes;
    Set<PropertyKeyVertex> keySubset = ImmutableSet.of();
    if (index instanceof RelationTypeIndex) {
        dependentTypes = ImmutableSet.of((TitanSchemaVertex) ((InternalRelationType) schemaVertex).getBaseType());
        if (!updateAction.isApplicableStatus(schemaVertex.getStatus()))
            return null;
    } else if (index instanceof TitanGraphIndex) {
        IndexType indexType = schemaVertex.asIndexType();
        dependentTypes = Sets.newHashSet();
        if (indexType.isCompositeIndex()) {
            if (!updateAction.isApplicableStatus(schemaVertex.getStatus()))
                return null;
            for (PropertyKey key : ((TitanGraphIndex) index).getFieldKeys()) {
                dependentTypes.add((PropertyKeyVertex) key);
            }
        } else {
            keySubset = Sets.newHashSet();
            MixedIndexType cindexType = (MixedIndexType) indexType;
            Set<SchemaStatus> applicableStatus = updateAction.getApplicableStatus();
            for (ParameterIndexField field : cindexType.getFieldKeys()) {
                if (applicableStatus.contains(field.getStatus()))
                    keySubset.add((PropertyKeyVertex) field.getFieldKey());
            }
            if (keySubset.isEmpty())
                return null;
            dependentTypes.addAll(keySubset);
        }
    } else
        throw new UnsupportedOperationException("Updates not supported for index: " + index);
    IndexIdentifier indexId = new IndexIdentifier(index);
    StandardScanner.Builder builder;
    IndexJobFuture future;
    switch(updateAction) {
        case REGISTER_INDEX:
            setStatus(schemaVertex, SchemaStatus.INSTALLED, keySubset);
            updatedTypes.add(schemaVertex);
            updatedTypes.addAll(dependentTypes);
            setUpdateTrigger(new UpdateStatusTrigger(graph, schemaVertex, SchemaStatus.REGISTERED, keySubset));
            future = new EmptyIndexJobFuture();
            break;
        case REINDEX:
            builder = graph.getBackend().buildEdgeScanJob();
            builder.setFinishJob(indexId.getIndexJobFinisher(graph, SchemaAction.ENABLE_INDEX));
            builder.setJobId(indexId);
            builder.setJob(VertexJobConverter.convert(graph, new IndexRepairJob(indexId.indexName, indexId.relationTypeName)));
            try {
                future = builder.execute();
            } catch (BackendException e) {
                throw new TitanException(e);
            }
            break;
        case ENABLE_INDEX:
            setStatus(schemaVertex, SchemaStatus.ENABLED, keySubset);
            updatedTypes.add(schemaVertex);
            if (!keySubset.isEmpty())
                updatedTypes.addAll(dependentTypes);
            future = new EmptyIndexJobFuture();
            break;
        case DISABLE_INDEX:
            setStatus(schemaVertex, SchemaStatus.INSTALLED, keySubset);
            updatedTypes.add(schemaVertex);
            if (!keySubset.isEmpty())
                updatedTypes.addAll(dependentTypes);
            setUpdateTrigger(new UpdateStatusTrigger(graph, schemaVertex, SchemaStatus.DISABLED, keySubset));
            future = new EmptyIndexJobFuture();
            break;
        case REMOVE_INDEX:
            if (index instanceof RelationTypeIndex) {
                builder = graph.getBackend().buildEdgeScanJob();
            } else {
                TitanGraphIndex gindex = (TitanGraphIndex) index;
                if (gindex.isMixedIndex())
                    throw new UnsupportedOperationException("External mixed indexes must be removed in the indexing system directly.");
                builder = graph.getBackend().buildGraphIndexScanJob();
            }
            builder.setFinishJob(indexId.getIndexJobFinisher());
            builder.setJobId(indexId);
            builder.setJob(new IndexRemoveJob(graph, indexId.indexName, indexId.relationTypeName));
            try {
                future = builder.execute();
            } catch (BackendException e) {
                throw new TitanException(e);
            }
            break;
        default:
            throw new UnsupportedOperationException("Update action not supported: " + updateAction);
    }
    return future;
}
Also used : Set(java.util.Set) ImmutableSet(com.google.common.collect.ImmutableSet) HashSet(java.util.HashSet) TitanSchemaVertex(com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex) MixedIndexType(com.thinkaurelius.titan.graphdb.types.MixedIndexType) IndexRepairJob(com.thinkaurelius.titan.graphdb.olap.job.IndexRepairJob) ParameterIndexField(com.thinkaurelius.titan.graphdb.types.ParameterIndexField) RelationTypeIndex(com.thinkaurelius.titan.core.schema.RelationTypeIndex) TitanGraphIndex(com.thinkaurelius.titan.core.schema.TitanGraphIndex) BackendException(com.thinkaurelius.titan.diskstorage.BackendException) StandardScanner(com.thinkaurelius.titan.diskstorage.keycolumnvalue.scan.StandardScanner) TitanException(com.thinkaurelius.titan.core.TitanException) PropertyKeyVertex(com.thinkaurelius.titan.graphdb.types.vertices.PropertyKeyVertex) IndexType(com.thinkaurelius.titan.graphdb.types.IndexType) MixedIndexType(com.thinkaurelius.titan.graphdb.types.MixedIndexType) CompositeIndexType(com.thinkaurelius.titan.graphdb.types.CompositeIndexType) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) IndexRemoveJob(com.thinkaurelius.titan.graphdb.olap.job.IndexRemoveJob)

Example 2 with IndexRemoveJob

use of com.thinkaurelius.titan.graphdb.olap.job.IndexRemoveJob in project titan by thinkaurelius.

the class MapReduceIndexJobs method cassandraRemove.

public static ScanMetrics cassandraRemove(Properties titanProperties, String indexName, String relationType, String partitionerName, Configuration hadoopBaseConf) throws InterruptedException, IOException, ClassNotFoundException {
    IndexRemoveJob job = new IndexRemoveJob();
    CassandraHadoopScanRunner cr = new CassandraHadoopScanRunner(job);
    ModifiableConfiguration mc = getIndexJobConf(indexName, relationType);
    copyPropertiesToInputAndOutputConf(hadoopBaseConf, titanProperties);
    cr.partitionerOverride(partitionerName);
    cr.scanJobConf(mc);
    cr.scanJobConfRoot(GraphDatabaseConfiguration.class.getName() + "#JOB_NS");
    cr.baseHadoopConf(hadoopBaseConf);
    return cr.run();
}
Also used : CassandraHadoopScanRunner(com.thinkaurelius.titan.hadoop.scan.CassandraHadoopScanRunner) ModifiableConfiguration(com.thinkaurelius.titan.diskstorage.configuration.ModifiableConfiguration) IndexRemoveJob(com.thinkaurelius.titan.graphdb.olap.job.IndexRemoveJob)

Example 3 with IndexRemoveJob

use of com.thinkaurelius.titan.graphdb.olap.job.IndexRemoveJob in project titan by thinkaurelius.

the class MapReduceIndexJobs method hbaseRemove.

public static ScanMetrics hbaseRemove(Properties titanProperties, String indexName, String relationType, Configuration hadoopBaseConf) throws InterruptedException, IOException, ClassNotFoundException {
    IndexRemoveJob job = new IndexRemoveJob();
    HBaseHadoopScanRunner cr = new HBaseHadoopScanRunner(job);
    ModifiableConfiguration mc = getIndexJobConf(indexName, relationType);
    copyPropertiesToInputAndOutputConf(hadoopBaseConf, titanProperties);
    cr.scanJobConf(mc);
    cr.scanJobConfRoot(GraphDatabaseConfiguration.class.getName() + "#JOB_NS");
    cr.baseHadoopConf(hadoopBaseConf);
    return cr.run();
}
Also used : HBaseHadoopScanRunner(com.thinkaurelius.titan.hadoop.scan.HBaseHadoopScanRunner) ModifiableConfiguration(com.thinkaurelius.titan.diskstorage.configuration.ModifiableConfiguration) IndexRemoveJob(com.thinkaurelius.titan.graphdb.olap.job.IndexRemoveJob)

Aggregations

IndexRemoveJob (com.thinkaurelius.titan.graphdb.olap.job.IndexRemoveJob)3 ModifiableConfiguration (com.thinkaurelius.titan.diskstorage.configuration.ModifiableConfiguration)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 PropertyKey (com.thinkaurelius.titan.core.PropertyKey)1 TitanException (com.thinkaurelius.titan.core.TitanException)1 RelationTypeIndex (com.thinkaurelius.titan.core.schema.RelationTypeIndex)1 TitanGraphIndex (com.thinkaurelius.titan.core.schema.TitanGraphIndex)1 BackendException (com.thinkaurelius.titan.diskstorage.BackendException)1 StandardScanner (com.thinkaurelius.titan.diskstorage.keycolumnvalue.scan.StandardScanner)1 IndexRepairJob (com.thinkaurelius.titan.graphdb.olap.job.IndexRepairJob)1 CompositeIndexType (com.thinkaurelius.titan.graphdb.types.CompositeIndexType)1 IndexType (com.thinkaurelius.titan.graphdb.types.IndexType)1 MixedIndexType (com.thinkaurelius.titan.graphdb.types.MixedIndexType)1 ParameterIndexField (com.thinkaurelius.titan.graphdb.types.ParameterIndexField)1 PropertyKeyVertex (com.thinkaurelius.titan.graphdb.types.vertices.PropertyKeyVertex)1 TitanSchemaVertex (com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex)1 CassandraHadoopScanRunner (com.thinkaurelius.titan.hadoop.scan.CassandraHadoopScanRunner)1 HBaseHadoopScanRunner (com.thinkaurelius.titan.hadoop.scan.HBaseHadoopScanRunner)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1