Search in sources :

Example 11 with TitanSchemaVertex

use of com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex in project titan by thinkaurelius.

the class ManagementLogger method sendCacheEviction.

public void sendCacheEviction(Set<TitanSchemaVertex> updatedTypes, Set<Callable<Boolean>> updatedTypeTriggers, Set<String> openInstances) {
    Preconditions.checkArgument(!openInstances.isEmpty());
    long evictionId = evictionTriggerCounter.incrementAndGet();
    evictionTriggerMap.put(evictionId, new EvictionTrigger(evictionId, updatedTypeTriggers, openInstances));
    DataOutput out = graph.getDataSerializer().getDataOutput(128);
    out.writeObjectNotNull(MgmtLogType.CACHED_TYPE_EVICTION);
    VariableLong.writePositive(out, evictionId);
    VariableLong.writePositive(out, updatedTypes.size());
    for (TitanSchemaVertex type : updatedTypes) {
        assert type.hasId();
        VariableLong.writePositive(out, type.longId());
    }
    sysLog.add(out.getStaticBuffer());
}
Also used : DataOutput(com.thinkaurelius.titan.graphdb.database.serialize.DataOutput) TitanSchemaVertex(com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex)

Example 12 with TitanSchemaVertex

use of com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex in project titan by thinkaurelius.

the class ManagementSystem method createCompositeIndex.

private TitanGraphIndex createCompositeIndex(String indexName, ElementCategory elementCategory, boolean unique, TitanSchemaType constraint, PropertyKey... keys) {
    checkIndexName(indexName);
    Preconditions.checkArgument(keys != null && keys.length > 0, "Need to provide keys to index [%s]", indexName);
    Preconditions.checkArgument(!unique || elementCategory == ElementCategory.VERTEX, "Unique indexes can only be created on vertices [%s]", indexName);
    boolean allSingleKeys = true;
    boolean oneNewKey = false;
    for (PropertyKey key : keys) {
        Preconditions.checkArgument(key != null && key instanceof PropertyKeyVertex, "Need to provide valid keys: %s", key);
        if (key.cardinality() != Cardinality.SINGLE)
            allSingleKeys = false;
        if (key.isNew())
            oneNewKey = true;
        else
            updatedTypes.add((PropertyKeyVertex) key);
    }
    Cardinality indexCardinality;
    if (unique)
        indexCardinality = Cardinality.SINGLE;
    else
        indexCardinality = (allSingleKeys ? Cardinality.SET : Cardinality.LIST);
    TypeDefinitionMap def = new TypeDefinitionMap();
    def.setValue(TypeDefinitionCategory.INTERNAL_INDEX, true);
    def.setValue(TypeDefinitionCategory.ELEMENT_CATEGORY, elementCategory);
    def.setValue(TypeDefinitionCategory.BACKING_INDEX, Token.INTERNAL_INDEX_NAME);
    def.setValue(TypeDefinitionCategory.INDEXSTORE_NAME, indexName);
    def.setValue(TypeDefinitionCategory.INDEX_CARDINALITY, indexCardinality);
    def.setValue(TypeDefinitionCategory.STATUS, oneNewKey ? SchemaStatus.ENABLED : SchemaStatus.INSTALLED);
    TitanSchemaVertex indexVertex = transaction.makeSchemaVertex(TitanSchemaCategory.GRAPHINDEX, indexName, def);
    for (int i = 0; i < keys.length; i++) {
        Parameter[] paras = { ParameterType.INDEX_POSITION.getParameter(i) };
        addSchemaEdge(indexVertex, keys[i], TypeDefinitionCategory.INDEX_FIELD, paras);
    }
    Preconditions.checkArgument(constraint == null || (elementCategory.isValidConstraint(constraint) && constraint instanceof TitanSchemaVertex));
    if (constraint != null) {
        addSchemaEdge(indexVertex, (TitanSchemaVertex) constraint, TypeDefinitionCategory.INDEX_SCHEMA_CONSTRAINT, null);
    }
    updateSchemaVertex(indexVertex);
    TitanGraphIndexWrapper index = new TitanGraphIndexWrapper(indexVertex.asIndexType());
    if (!oneNewKey)
        updateIndex(index, SchemaAction.REGISTER_INDEX);
    return index;
}
Also used : Cardinality(com.thinkaurelius.titan.core.Cardinality) TitanSchemaVertex(com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex) Parameter(com.thinkaurelius.titan.core.schema.Parameter) PropertyKeyVertex(com.thinkaurelius.titan.graphdb.types.vertices.PropertyKeyVertex) TypeDefinitionMap(com.thinkaurelius.titan.graphdb.types.TypeDefinitionMap) PropertyKey(com.thinkaurelius.titan.core.PropertyKey)

Example 13 with TitanSchemaVertex

use of com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex 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 14 with TitanSchemaVertex

use of com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex in project titan by thinkaurelius.

the class ManagementSystem method setTypeModifier.

private void setTypeModifier(final TitanSchemaElement element, final ModifierType modifierType, final Object value) {
    Preconditions.checkArgument(element != null, "null schema element");
    TypeDefinitionCategory cat = modifierType.getCategory();
    if (cat.hasDataType() && null != value) {
        Preconditions.checkArgument(cat.getDataType().equals(value.getClass()), "modifier value is not of expected type " + cat.getDataType());
    }
    TitanSchemaVertex typeVertex;
    if (element instanceof TitanSchemaVertex) {
        typeVertex = (TitanSchemaVertex) element;
    } else if (element instanceof TitanGraphIndex) {
        IndexType index = ((TitanGraphIndexWrapper) element).getBaseIndex();
        assert index instanceof IndexTypeWrapper;
        SchemaSource base = ((IndexTypeWrapper) index).getSchemaBase();
        typeVertex = (TitanSchemaVertex) base;
    } else
        throw new IllegalArgumentException("Invalid schema element: " + element);
    // remove any pre-existing value for the modifier, or return if an identical value has already been set
    for (TitanEdge e : typeVertex.getEdges(TypeDefinitionCategory.TYPE_MODIFIER, Direction.OUT)) {
        TitanSchemaVertex v = (TitanSchemaVertex) e.vertex(Direction.IN);
        TypeDefinitionMap def = v.getDefinition();
        Object existingValue = def.getValue(modifierType.getCategory());
        if (null != existingValue) {
            if (existingValue.equals(value)) {
                //Already has the right value, don't need to do anything
                return;
            } else {
                e.remove();
                v.remove();
            }
        }
    }
    if (null != value) {
        TypeDefinitionMap def = new TypeDefinitionMap();
        def.setValue(cat, value);
        TitanSchemaVertex cVertex = transaction.makeSchemaVertex(TitanSchemaCategory.TYPE_MODIFIER, null, def);
        addSchemaEdge(typeVertex, cVertex, TypeDefinitionCategory.TYPE_MODIFIER, null);
    }
    updateSchemaVertex(typeVertex);
    updatedTypes.add(typeVertex);
}
Also used : TypeDefinitionCategory(com.thinkaurelius.titan.graphdb.types.TypeDefinitionCategory) IndexTypeWrapper(com.thinkaurelius.titan.graphdb.types.indextype.IndexTypeWrapper) TitanSchemaVertex(com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex) IndexType(com.thinkaurelius.titan.graphdb.types.IndexType) MixedIndexType(com.thinkaurelius.titan.graphdb.types.MixedIndexType) CompositeIndexType(com.thinkaurelius.titan.graphdb.types.CompositeIndexType) TitanGraphIndex(com.thinkaurelius.titan.core.schema.TitanGraphIndex) SchemaSource(com.thinkaurelius.titan.graphdb.types.SchemaSource) TypeDefinitionMap(com.thinkaurelius.titan.graphdb.types.TypeDefinitionMap) TitanEdge(com.thinkaurelius.titan.core.TitanEdge)

Example 15 with TitanSchemaVertex

use of com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex in project titan by thinkaurelius.

the class StandardTitanTx method makeSchemaVertex.

/*
     * ------------------------------------ Schema Handling ------------------------------------
     */
public final TitanSchemaVertex makeSchemaVertex(TitanSchemaCategory schemaCategory, String name, TypeDefinitionMap definition) {
    verifyOpen();
    Preconditions.checkArgument(!schemaCategory.hasName() || StringUtils.isNotBlank(name), "Need to provide a valid name for type [%s]", schemaCategory);
    schemaCategory.verifyValidDefinition(definition);
    TitanSchemaVertex schemaVertex;
    if (schemaCategory.isRelationType()) {
        if (schemaCategory == TitanSchemaCategory.PROPERTYKEY) {
            schemaVertex = new PropertyKeyVertex(this, IDManager.getTemporaryVertexID(IDManager.VertexIDType.UserPropertyKey, temporaryIds.nextID()), ElementLifeCycle.New);
        } else {
            assert schemaCategory == TitanSchemaCategory.EDGELABEL;
            schemaVertex = new EdgeLabelVertex(this, IDManager.getTemporaryVertexID(IDManager.VertexIDType.UserEdgeLabel, temporaryIds.nextID()), ElementLifeCycle.New);
        }
    } else if (schemaCategory == TitanSchemaCategory.VERTEXLABEL) {
        schemaVertex = new VertexLabelVertex(this, IDManager.getTemporaryVertexID(IDManager.VertexIDType.GenericSchemaType, temporaryIds.nextID()), ElementLifeCycle.New);
    } else {
        schemaVertex = new TitanSchemaVertex(this, IDManager.getTemporaryVertexID(IDManager.VertexIDType.GenericSchemaType, temporaryIds.nextID()), ElementLifeCycle.New);
    }
    graph.assignID(schemaVertex, BaseVertexLabel.DEFAULT_VERTEXLABEL);
    Preconditions.checkArgument(schemaVertex.longId() > 0);
    if (schemaCategory.hasName())
        addProperty(schemaVertex, BaseKey.SchemaName, schemaCategory.getSchemaName(name));
    addProperty(schemaVertex, BaseKey.VertexExists, Boolean.TRUE);
    addProperty(schemaVertex, BaseKey.SchemaCategory, schemaCategory);
    updateSchemaVertex(schemaVertex);
    addProperty(schemaVertex, BaseKey.SchemaUpdateTime, times.getTime(times.getTime()));
    for (Map.Entry<TypeDefinitionCategory, Object> def : definition.entrySet()) {
        TitanVertexProperty p = addProperty(schemaVertex, BaseKey.SchemaDefinitionProperty, def.getValue());
        p.property(BaseKey.SchemaDefinitionDesc.name(), TypeDefinitionDescription.of(def.getKey()));
    }
    vertexCache.add(schemaVertex, schemaVertex.longId());
    if (schemaCategory.hasName())
        newTypeCache.put(schemaCategory.getSchemaName(name), schemaVertex.longId());
    return schemaVertex;
}
Also used : TitanSchemaVertex(com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex) EdgeLabelVertex(com.thinkaurelius.titan.graphdb.types.vertices.EdgeLabelVertex) PropertyKeyVertex(com.thinkaurelius.titan.graphdb.types.vertices.PropertyKeyVertex) NonBlockingHashMap(org.cliffc.high_scale_lib.NonBlockingHashMap)

Aggregations

TitanSchemaVertex (com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex)15 TitanGraphIndex (com.thinkaurelius.titan.core.schema.TitanGraphIndex)4 CompositeIndexType (com.thinkaurelius.titan.graphdb.types.CompositeIndexType)4 MixedIndexType (com.thinkaurelius.titan.graphdb.types.MixedIndexType)4 TypeDefinitionMap (com.thinkaurelius.titan.graphdb.types.TypeDefinitionMap)4 TitanException (com.thinkaurelius.titan.core.TitanException)3 RelationTypeIndex (com.thinkaurelius.titan.core.schema.RelationTypeIndex)3 InternalRelation (com.thinkaurelius.titan.graphdb.internal.InternalRelation)3 InternalRelationType (com.thinkaurelius.titan.graphdb.internal.InternalRelationType)3 IndexType (com.thinkaurelius.titan.graphdb.types.IndexType)3 PropertyKeyVertex (com.thinkaurelius.titan.graphdb.types.vertices.PropertyKeyVertex)3 PropertyKey (com.thinkaurelius.titan.core.PropertyKey)2 RelationType (com.thinkaurelius.titan.core.RelationType)2 Parameter (com.thinkaurelius.titan.core.schema.Parameter)2 BackendException (com.thinkaurelius.titan.diskstorage.BackendException)2 DataOutput (com.thinkaurelius.titan.graphdb.database.serialize.DataOutput)2 InternalVertex (com.thinkaurelius.titan.graphdb.internal.InternalVertex)2 TitanSchemaCategory (com.thinkaurelius.titan.graphdb.internal.TitanSchemaCategory)2 ParameterIndexField (com.thinkaurelius.titan.graphdb.types.ParameterIndexField)2 IndexTypeWrapper (com.thinkaurelius.titan.graphdb.types.indextype.IndexTypeWrapper)2