Java Code Examples for com.thinkaurelius.titan.core.schema.TitanGraphIndex

The following are top voted examples for showing how to use com.thinkaurelius.titan.core.schema.TitanGraphIndex. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: titan1withtp3.1   File: ManagementSystem.java   View source code 6 votes vote down vote up
@Override
public Iterable<TitanGraphIndex> getGraphIndexes(final Class<? extends Element> elementType) {
    return Iterables.transform(Iterables.filter(Iterables.transform(
            QueryUtil.getVertices(transaction, BaseKey.SchemaCategory, TitanSchemaCategory.GRAPHINDEX),
            new Function<TitanVertex, IndexType>() {
                @Nullable
                @Override
                public IndexType apply(@Nullable TitanVertex titanVertex) {
                    assert titanVertex instanceof TitanSchemaVertex;
                    return ((TitanSchemaVertex) titanVertex).asIndexType();
                }
            }), new Predicate<IndexType>() {
        @Override
        public boolean apply(@Nullable IndexType indexType) {
            return indexType.getElement().subsumedBy(elementType);
        }
    }), new Function<IndexType, TitanGraphIndex>() {
        @Nullable
        @Override
        public TitanGraphIndex apply(@Nullable IndexType indexType) {
            return new TitanGraphIndexWrapper(indexType);
        }
    });
}
 
Example 2
Project: titan1withtp3.1   File: ManagementSystem.java   View source code 6 votes vote down vote up
private TitanGraphIndex createMixedIndex(String indexName, ElementCategory elementCategory,
                                         TitanSchemaType constraint, String backingIndex) {
    Preconditions.checkArgument(graph.getIndexSerializer().containsIndex(backingIndex), "Unknown external index backend: %s", backingIndex);
    checkIndexName(indexName);

    TypeDefinitionMap def = new TypeDefinitionMap();
    def.setValue(TypeDefinitionCategory.INTERNAL_INDEX, false);
    def.setValue(TypeDefinitionCategory.ELEMENT_CATEGORY, elementCategory);
    def.setValue(TypeDefinitionCategory.BACKING_INDEX, backingIndex);
    def.setValue(TypeDefinitionCategory.INDEXSTORE_NAME, indexName);
    def.setValue(TypeDefinitionCategory.INDEX_CARDINALITY, Cardinality.LIST);
    def.setValue(TypeDefinitionCategory.STATUS, SchemaStatus.ENABLED);
    TitanSchemaVertex indexVertex = transaction.makeSchemaVertex(TitanSchemaCategory.GRAPHINDEX, indexName, def);

    Preconditions.checkArgument(constraint == null || (elementCategory.isValidConstraint(constraint) && constraint instanceof TitanSchemaVertex));
    if (constraint != null) {
        addSchemaEdge(indexVertex, (TitanSchemaVertex) constraint, TypeDefinitionCategory.INDEX_SCHEMA_CONSTRAINT, null);
    }
    updateSchemaVertex(indexVertex);
    return new TitanGraphIndexWrapper(indexVertex.asIndexType());
}
 
Example 3
Project: titan1withtp3.1   File: IndexRemoveJob.java   View source code 6 votes vote down vote up
@Override
protected void validateIndexStatus() {
    if (index instanceof RelationTypeIndex) {
        //Nothing specific to be done
    } else if (index instanceof TitanGraphIndex) {
        TitanGraphIndex gindex = (TitanGraphIndex)index;
        if (gindex.isMixedIndex())
            throw new UnsupportedOperationException("Cannot remove mixed indexes through Titan. This can " +
                    "only be accomplished in the indexing system directly.");
        CompositeIndexType indexType = (CompositeIndexType)mgmt.getSchemaVertex(index).asIndexType();
        graphIndexId = indexType.getID();
    } else throw new UnsupportedOperationException("Unsupported index found: "+index);

    //Must be a relation type index or a composite graph index
    TitanSchemaVertex schemaVertex = mgmt.getSchemaVertex(index);
    SchemaStatus actualStatus = schemaVertex.getStatus();
    Preconditions.checkArgument(actualStatus==SchemaStatus.DISABLED,"The index [%s] must be disabled before it can be removed",indexName);
}
 
Example 4
Project: titan1.0.1.kafka   File: ManagementSystem.java   View source code 6 votes vote down vote up
@Override
public Iterable<TitanGraphIndex> getGraphIndexes(final Class<? extends Element> elementType) {
    return Iterables.transform(Iterables.filter(Iterables.transform(
            QueryUtil.getVertices(transaction, BaseKey.SchemaCategory, TitanSchemaCategory.GRAPHINDEX),
            new Function<TitanVertex, IndexType>() {
                @Nullable
                @Override
                public IndexType apply(@Nullable TitanVertex titanVertex) {
                    assert titanVertex instanceof TitanSchemaVertex;
                    return ((TitanSchemaVertex) titanVertex).asIndexType();
                }
            }), new Predicate<IndexType>() {
        @Override
        public boolean apply(@Nullable IndexType indexType) {
            return indexType.getElement().subsumedBy(elementType);
        }
    }), new Function<IndexType, TitanGraphIndex>() {
        @Nullable
        @Override
        public TitanGraphIndex apply(@Nullable IndexType indexType) {
            return new TitanGraphIndexWrapper(indexType);
        }
    });
}
 
Example 5
Project: titan1.0.1.kafka   File: ManagementSystem.java   View source code 6 votes vote down vote up
private TitanGraphIndex createMixedIndex(String indexName, ElementCategory elementCategory,
                                         TitanSchemaType constraint, String backingIndex) {
    Preconditions.checkArgument(graph.getIndexSerializer().containsIndex(backingIndex), "Unknown external index backend: %s", backingIndex);
    checkIndexName(indexName);

    TypeDefinitionMap def = new TypeDefinitionMap();
    def.setValue(TypeDefinitionCategory.INTERNAL_INDEX, false);
    def.setValue(TypeDefinitionCategory.ELEMENT_CATEGORY, elementCategory);
    def.setValue(TypeDefinitionCategory.BACKING_INDEX, backingIndex);
    def.setValue(TypeDefinitionCategory.INDEXSTORE_NAME, indexName);
    def.setValue(TypeDefinitionCategory.INDEX_CARDINALITY, Cardinality.LIST);
    def.setValue(TypeDefinitionCategory.STATUS, SchemaStatus.ENABLED);
    TitanSchemaVertex indexVertex = transaction.makeSchemaVertex(TitanSchemaCategory.GRAPHINDEX, indexName, def);

    Preconditions.checkArgument(constraint == null || (elementCategory.isValidConstraint(constraint) && constraint instanceof TitanSchemaVertex));
    if (constraint != null) {
        addSchemaEdge(indexVertex, (TitanSchemaVertex) constraint, TypeDefinitionCategory.INDEX_SCHEMA_CONSTRAINT, null);
    }
    updateSchemaVertex(indexVertex);
    return new TitanGraphIndexWrapper(indexVertex.asIndexType());
}
 
Example 6
Project: titan1.0.1.kafka   File: IndexRemoveJob.java   View source code 6 votes vote down vote up
@Override
protected void validateIndexStatus() {
    if (index instanceof RelationTypeIndex) {
        //Nothing specific to be done
    } else if (index instanceof TitanGraphIndex) {
        TitanGraphIndex gindex = (TitanGraphIndex)index;
        if (gindex.isMixedIndex())
            throw new UnsupportedOperationException("Cannot remove mixed indexes through Titan. This can " +
                    "only be accomplished in the indexing system directly.");
        CompositeIndexType indexType = (CompositeIndexType)mgmt.getSchemaVertex(index).asIndexType();
        graphIndexId = indexType.getID();
    } else throw new UnsupportedOperationException("Unsupported index found: "+index);

    //Must be a relation type index or a composite graph index
    TitanSchemaVertex schemaVertex = mgmt.getSchemaVertex(index);
    SchemaStatus actualStatus = schemaVertex.getStatus();
    Preconditions.checkArgument(actualStatus==SchemaStatus.DISABLED,"The index [%s] must be disabled before it can be removed",indexName);
}
 
Example 7
Project: titan0.5.4-hbase1.1.1-custom   File: ManagementSystem.java   View source code 6 votes vote down vote up
@Override
public Iterable<TitanGraphIndex> getGraphIndexes(final Class<? extends Element> elementType) {
    return Iterables.transform(Iterables.filter(Iterables.transform(
            transaction.getVertices(BaseKey.SchemaCategory, TitanSchemaCategory.GRAPHINDEX),
            new Function<TitanVertex, IndexType>() {
                @Nullable
                @Override
                public IndexType apply(@Nullable TitanVertex titanVertex) {
                    assert titanVertex instanceof TitanSchemaVertex;
                    return ((TitanSchemaVertex) titanVertex).asIndexType();
                }
            }), new Predicate<IndexType>() {
        @Override
        public boolean apply(@Nullable IndexType indexType) {
            return indexType.getElement().subsumedBy(elementType);
        }
    }), new Function<IndexType, TitanGraphIndex>() {
        @Nullable
        @Override
        public TitanGraphIndex apply(@Nullable IndexType indexType) {
            return new TitanGraphIndexWrapper(indexType);
        }
    });
}
 
Example 8
Project: titan0.5.4-hbase1.1.1-custom   File: ManagementSystem.java   View source code 6 votes vote down vote up
private TitanGraphIndex createMixedIndex(String indexName, ElementCategory elementCategory,
                                         TitanSchemaType constraint, String backingIndex) {
    Preconditions.checkArgument(graph.getIndexSerializer().containsIndex(backingIndex),"Unknown external index backend: %s",backingIndex);
    checkIndexName(indexName);

    TypeDefinitionMap def = new TypeDefinitionMap();
    def.setValue(TypeDefinitionCategory.INTERNAL_INDEX,false);
    def.setValue(TypeDefinitionCategory.ELEMENT_CATEGORY,elementCategory);
    def.setValue(TypeDefinitionCategory.BACKING_INDEX,backingIndex);
    def.setValue(TypeDefinitionCategory.INDEXSTORE_NAME,indexName);
    def.setValue(TypeDefinitionCategory.INDEX_CARDINALITY, Cardinality.LIST);
    def.setValue(TypeDefinitionCategory.STATUS,SchemaStatus.ENABLED);
    TitanSchemaVertex indexVertex = transaction.makeSchemaVertex(TitanSchemaCategory.GRAPHINDEX,indexName,def);

    Preconditions.checkArgument(constraint==null || (elementCategory.isValidConstraint(constraint) && constraint instanceof TitanSchemaVertex));
    if (constraint!=null) {
        addSchemaEdge(indexVertex,(TitanSchemaVertex)constraint,TypeDefinitionCategory.INDEX_SCHEMA_CONSTRAINT,null);
    }
    updateSchemaVertex(indexVertex);
    return new TitanGraphIndexWrapper(indexVertex.asIndexType());
}
 
Example 9
Project: titan1withtp3.1   File: TitanGraphTest.java   View source code 5 votes vote down vote up
@Test
public void testIndexQueryWithLabelsAndContainsIN() {
    // This test is based on the steps to reproduce #882

    String labelName = "labelName";

    VertexLabel label = mgmt.makeVertexLabel(labelName).make();
    PropertyKey uid = mgmt.makePropertyKey("uid").dataType(String.class).make();
    TitanGraphIndex uidCompositeIndex = mgmt.buildIndex("uidIndex", Vertex.class).indexOnly(label).addKey(uid).unique().buildCompositeIndex();
    mgmt.setConsistency(uidCompositeIndex, ConsistencyModifier.LOCK);
    finishSchema();

    TitanVertex foo = graph.addVertex(labelName);
    TitanVertex bar = graph.addVertex(labelName);
    foo.property("uid", "foo");
    bar.property("uid", "bar");
    graph.tx().commit();

    Iterable<TitanVertex> vertexes = graph.query()
            .has("uid", Contain.IN, ImmutableList.of("foo", "bar"))
            .has(LABEL_NAME, labelName)
            .vertices();
    assertEquals(2, Iterables.size(vertexes));
    for (TitanVertex v : vertexes) {
        assertEquals(labelName, v.vertexLabel().name());
    }
}
 
Example 10
Project: titan1withtp3.1   File: TitanGraphTest.java   View source code 5 votes vote down vote up
@Test
public void testVertexTTLWithCompositeIndex() throws Exception {
    if (!features.hasCellTTL()) {
        return;
    }

    PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
    PropertyKey time = mgmt.makePropertyKey("time").dataType(Long.class).make();
    TitanGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name).buildCompositeIndex();
    TitanGraphIndex index2 = mgmt.buildIndex("index2", Vertex.class).addKey(name).addKey(time).buildCompositeIndex();
    VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make();
    mgmt.setTTL(label1, Duration.ofSeconds(1));
    assertEquals(Duration.ZERO, mgmt.getTTL(name));
    assertEquals(Duration.ZERO, mgmt.getTTL(time));
    assertEquals(Duration.ofSeconds(1), mgmt.getTTL(label1));
    mgmt.commit();

    TitanVertex v1 = tx.addVertex(T.label, "event", "name", "some event", "time", System.currentTimeMillis());
    tx.commit();
    Object id = v1.id();

    v1 = getV(graph, id);
    assertNotNull(v1);
    assertNotEmpty(graph.query().has("name", "some event").vertices());

    Thread.sleep(1001);
    graph.tx().rollback();

    v1 = getV(graph, id);
    assertNull(v1);
    assertEmpty(graph.query().has("name", "some event").vertices());
}
 
Example 11
Project: titan1withtp3.1   File: TitanIndexTest.java   View source code 5 votes vote down vote up
private void setupChainGraph(int numV, String[] strs, boolean sameNameMapping) {
    clopen(option(INDEX_NAME_MAPPING, INDEX), sameNameMapping);
    TitanGraphIndex vindex = getExternalIndex(Vertex.class, INDEX);
    TitanGraphIndex eindex = getExternalIndex(Edge.class, INDEX);
    TitanGraphIndex pindex = getExternalIndex(TitanVertexProperty.class, INDEX);
    PropertyKey name = makeKey("name", String.class);

    mgmt.addIndexKey(vindex, name, getStringMapping());
    mgmt.addIndexKey(eindex, name, getStringMapping());
    mgmt.addIndexKey(pindex, name, getStringMapping(), Parameter.of("mapped-name", "xstr"));
    PropertyKey text = makeKey("text", String.class);
    mgmt.addIndexKey(vindex, text, getTextMapping(), Parameter.of("mapped-name", "xtext"));
    mgmt.addIndexKey(eindex, text, getTextMapping());
    mgmt.addIndexKey(pindex, text, getTextMapping());
    mgmt.makeEdgeLabel("knows").signature(name).make();
    mgmt.makePropertyKey("uid").dataType(String.class).signature(text).make();
    finishSchema();
    TitanVertex previous = null;
    for (int i = 0; i < numV; i++) {
        TitanVertex v = graph.addVertex("name", strs[i % strs.length], "text", strs[i % strs.length]);
        Edge e = v.addEdge("knows", previous == null ? v : previous,
                "name", strs[i % strs.length], "text", strs[i % strs.length]);
        VertexProperty p = v.property("uid", "v" + i,
                "name", strs[i % strs.length], "text", strs[i % strs.length]);
        previous = v;
    }
}
 
Example 12
Project: titan1withtp3.1   File: TitanOperationCountingTest.java   View source code 5 votes vote down vote up
@Test
public void checkPropertyLockingAndIndex() {
    PropertyKey uid = makeKey("uid",String.class);
    TitanGraphIndex index = mgmt.buildIndex("uid",Vertex.class).unique().addKey(uid).buildCompositeIndex();
    mgmt.setConsistency(index, ConsistencyModifier.LOCK);
    mgmt.makePropertyKey("name").dataType(String.class).make();
    mgmt.makePropertyKey("age").dataType(Integer.class).make();
    finishSchema();

    metricsPrefix = "checkPropertyLockingAndIndex";

    TitanTransaction tx = graph.buildTransaction().groupName(metricsPrefix).start();
    TitanVertex v = tx.addVertex("uid", "v1", "age", 25, "name", "john");
    assertEquals(25,v.property("age").value());
    tx.commit();
    verifyStoreMetrics(EDGESTORE_NAME);
    verifyLockingOverwrite(INDEXSTORE_NAME, 1);
    verifyStoreMetrics(METRICS_STOREMANAGER_NAME, ImmutableMap.of(M_MUTATE, 1l));

    resetMetrics();

    tx = graph.buildTransaction().groupName(metricsPrefix).start();
    v = Iterables.getOnlyElement(tx.query().has("uid", Cmp.EQUAL, "v1").vertices());
    assertEquals(25,v.property("age").value());
    tx.commit();
    verifyStoreMetrics(EDGESTORE_NAME, ImmutableMap.of(M_GET_SLICE,1l));
    verifyStoreMetrics(INDEXSTORE_NAME, ImmutableMap.of(M_GET_SLICE,1l));
    verifyStoreMetrics(METRICS_STOREMANAGER_NAME);
}
 
Example 13
Project: titan1withtp3.1   File: TitanGraphBaseTest.java   View source code 5 votes vote down vote up
public TitanGraphIndex getExternalIndex(Class<? extends Element> clazz, String backingIndex) {
    String prefix;
    if (Vertex.class.isAssignableFrom(clazz)) prefix = "v";
    else if (Edge.class.isAssignableFrom(clazz)) prefix = "e";
    else if (TitanVertexProperty.class.isAssignableFrom(clazz)) prefix = "p";
    else throw new AssertionError(clazz.toString());

    String indexName = prefix+backingIndex;
    TitanGraphIndex index = mgmt.getGraphIndex(indexName);
    if (index==null) {
        index = mgmt.buildIndex(indexName,clazz).buildMixedIndex(backingIndex);
    }
    return index;
}
 
Example 14
Project: titan1withtp3.1   File: AbstractIndexManagementIT.java   View source code 5 votes vote down vote up
@Test
public void testRemoveGraphIndex() throws InterruptedException, BackendException, ExecutionException {
    tx.commit();
    mgmt.commit();

    // Load the "Graph of the Gods" sample data
    GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true);

    // Disable the "name" composite index
    TitanManagement m = graph.openManagement();
    TitanGraphIndex nameIndex = m.getGraphIndex("name");
    m.updateIndex(nameIndex, SchemaAction.DISABLE_INDEX);
    m.commit();
    graph.tx().commit();

    // Block until the SchemaStatus transitions to DISABLED
    assertTrue(ManagementSystem.awaitGraphIndexStatus(graph, "name")
            .status(SchemaStatus.DISABLED).call().getSucceeded());

    // Remove index
    MapReduceIndexManagement mri = new MapReduceIndexManagement(graph);
    m = graph.openManagement();
    TitanGraphIndex index = m.getGraphIndex("name");
    ScanMetrics metrics = mri.updateIndex(index, SchemaAction.REMOVE_INDEX).get();

    assertEquals(12, metrics.getCustom(IndexRemoveJob.DELETED_RECORDS_COUNT));
}
 
Example 15
Project: titan1withtp3.1   File: ManagementSystem.java   View source code 5 votes vote down vote up
@Override
public void addIndexKey(final TitanGraphIndex index, final PropertyKey key, Parameter... parameters) {
    Preconditions.checkArgument(index != null && key != null && index instanceof TitanGraphIndexWrapper
            && !(key instanceof BaseKey), "Need to provide valid index and key");
    if (parameters == null) parameters = new Parameter[0];
    IndexType indexType = ((TitanGraphIndexWrapper) index).getBaseIndex();
    Preconditions.checkArgument(indexType instanceof MixedIndexType, "Can only add keys to an external index, not %s", index.name());
    Preconditions.checkArgument(indexType instanceof IndexTypeWrapper && key instanceof TitanSchemaVertex
            && ((IndexTypeWrapper) indexType).getSchemaBase() instanceof TitanSchemaVertex);

    TitanSchemaVertex indexVertex = (TitanSchemaVertex) ((IndexTypeWrapper) indexType).getSchemaBase();

    for (IndexField field : indexType.getFieldKeys())
        Preconditions.checkArgument(!field.getFieldKey().equals(key), "Key [%s] has already been added to index %s", key.name(), index.name());

    //Assemble parameters
    boolean addMappingParameter = !ParameterType.MAPPED_NAME.hasParameter(parameters);
    Parameter[] extendedParas = new Parameter[parameters.length + 1 + (addMappingParameter ? 1 : 0)];
    System.arraycopy(parameters, 0, extendedParas, 0, parameters.length);
    int arrPosition = parameters.length;
    if (addMappingParameter) extendedParas[arrPosition++] = ParameterType.MAPPED_NAME.getParameter(
            graph.getIndexSerializer().getDefaultFieldName(key, parameters, indexType.getBackingIndexName()));
    extendedParas[arrPosition++] = ParameterType.STATUS.getParameter(key.isNew() ? SchemaStatus.ENABLED : SchemaStatus.INSTALLED);

    addSchemaEdge(indexVertex, key, TypeDefinitionCategory.INDEX_FIELD, extendedParas);
    updateSchemaVertex(indexVertex);
    indexType.resetCache();
    //Check to see if the index supports this
    if (!graph.getIndexSerializer().supports((MixedIndexType) indexType, ParameterIndexField.of(key, parameters))) {
        throw new TitanException("Could not register new index field '" + key.name() + "' with index backend as the data type, cardinality or parameter combination is not supported.");
    }

    try {
        IndexSerializer.register((MixedIndexType) indexType, key, transaction.getTxHandle());
    } catch (BackendException e) {
        throw new TitanException("Could not register new index field with index backend", e);
    }
    if (!indexVertex.isNew()) updatedTypes.add(indexVertex);
    if (!key.isNew()) updateIndex(index, SchemaAction.REGISTER_INDEX);
}
 
Example 16
Project: titan1withtp3.1   File: ManagementSystem.java   View source code 5 votes vote down vote up
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;
}
 
Example 17
Project: titan1withtp3.1   File: ManagementSystem.java   View source code 5 votes vote down vote up
@Override
public TitanGraphIndex buildCompositeIndex() {
    Preconditions.checkArgument(!keys.isEmpty(), "Need to specify at least one key for the composite index");
    PropertyKey[] keyArr = new PropertyKey[keys.size()];
    int pos = 0;
    for (Map.Entry<PropertyKey, Parameter[]> entry : keys.entrySet()) {
        Preconditions.checkArgument(entry.getValue() == null, "Cannot specify parameters for composite index: %s", entry.getKey());
        keyArr[pos++] = entry.getKey();
    }
    return createCompositeIndex(indexName, elementCategory, unique, constraint, keyArr);
}
 
Example 18
Project: titan1withtp3.1   File: ManagementSystem.java   View source code 5 votes vote down vote up
@Override
public TitanGraphIndex buildMixedIndex(String backingIndex) {
    Preconditions.checkArgument(StringUtils.isNotBlank(backingIndex), "Need to specify backing index name");
    Preconditions.checkArgument(!unique, "An external index cannot be unique");

    TitanGraphIndex index = createMixedIndex(indexName, elementCategory, constraint, backingIndex);
    for (Map.Entry<PropertyKey, Parameter[]> entry : keys.entrySet()) {
        addIndexKey(index, entry.getKey(), entry.getValue());
    }
    return index;
}
 
Example 19
Project: titan1withtp3.1   File: ManagementSystem.java   View source code 5 votes vote down vote up
/**
 * Retrieves the consistency level for a schema element (types and internal indexes)
 *
 * @param element
 * @return
 */
@Override
public ConsistencyModifier getConsistency(TitanSchemaElement element) {
    Preconditions.checkArgument(element != null);
    if (element instanceof RelationType) return ((InternalRelationType) element).getConsistencyModifier();
    else if (element instanceof TitanGraphIndex) {
        IndexType index = ((TitanGraphIndexWrapper) element).getBaseIndex();
        if (index.isMixedIndex()) return ConsistencyModifier.DEFAULT;
        return ((CompositeIndexType) index).getConsistencyModifier();
    } else return ConsistencyModifier.DEFAULT;
}
 
Example 20
Project: titan1withtp3.1   File: ManagementSystem.java   View source code 5 votes vote down vote up
/**
 * Sets the consistency level for those schema elements that support it (types and internal indexes)
 * </p>
 * Note, that it is possible to have a race condition here if two threads simultaneously try to change the
 * consistency level. However, this is resolved when the consistency level is being read by taking the
 * first one and deleting all existing attached consistency levels upon modification.
 *
 * @param element
 * @param consistency
 */
@Override
public void setConsistency(TitanSchemaElement element, ConsistencyModifier consistency) {
    if (element instanceof RelationType) {
        RelationTypeVertex rv = (RelationTypeVertex) element;
        Preconditions.checkArgument(consistency != ConsistencyModifier.FORK || !rv.multiplicity().isConstrained(),
                "Cannot apply FORK consistency mode to constraint relation type: %s", rv.name());
    } else if (element instanceof TitanGraphIndex) {
        IndexType index = ((TitanGraphIndexWrapper) element).getBaseIndex();
        if (index.isMixedIndex())
            throw new IllegalArgumentException("Cannot change consistency on mixed index: " + element);
    } else throw new IllegalArgumentException("Cannot change consistency of schema element: " + element);
    setTypeModifier(element, ModifierType.CONSISTENCY, consistency);
}
 
Example 21
Project: antioch   File: TitanService.java   View source code 5 votes vote down vote up
public IndexInfo(TitanGraphIndex index) {
  name = index.name();
  backingIndex = index.getBackingIndex();
  indexedElement = index.getIndexedElement();
  PropertyKey[] fieldKeys = index.getFieldKeys();
  indexStatus = index.getIndexStatus(fieldKeys[0]);
}
 
Example 22
Project: antioch   File: TitanService.java   View source code 5 votes vote down vote up
private static boolean createIndexWhenAbsent(TitanManagement mgmt, VertexCompositeIndex compositeIndex) {
  String name = compositeIndex.name;
  if (!mgmt.containsGraphIndex(name)) {
    String property = compositeIndex.property;
    String label = compositeIndex.label;
    boolean unique = compositeIndex.unique;
    LOG.info("building {} index '{}' for label '{}' + property '{}'", unique ? "unique" : "non-unique", name, label, property);

    PropertyKey uuidKey = mgmt.containsPropertyKey(property)//
        ? mgmt.getPropertyKey(property)//
        : mgmt.makePropertyKey(property).dataType(String.class).make();

    IndexBuilder indexBuilder = mgmt.buildIndex(name, Vertex.class)//
        .addKey(uuidKey);

    if (label != null) {
      VertexLabel vertexLabel = mgmt.containsVertexLabel(label)//
          ? mgmt.getVertexLabel(label)//
          : mgmt.makeVertexLabel(label).make();
      indexBuilder = indexBuilder.indexOnly(vertexLabel);
    }

    if (unique) {
      indexBuilder = indexBuilder.unique();
    }

    TitanGraphIndex index = indexBuilder.buildCompositeIndex();
    mgmt.setConsistency(index, ConsistencyModifier.LOCK);

    return true;
  }
  return false;
}
 
Example 23
Project: antioch   File: TitanService.java   View source code 5 votes vote down vote up
private static void waitForCompletion(TitanManagement mgmt, VertexCompositeIndex compositeIndex) {
  String name = compositeIndex.name;
  TitanGraphIndex graphIndex = mgmt.getGraphIndex(name);
  PropertyKey propertyKey = graphIndex.getFieldKeys()[0];
  // For composite indexes, the propertyKey is ignored and the status of the index as a whole is returned
  if (!SchemaStatus.ENABLED.equals(graphIndex.getIndexStatus(propertyKey))) {
    try {
      GraphIndexStatusReport report = ManagementSystem.awaitGraphIndexStatus(titanGraph, name).call();
      LOG.info("report={}", report);
    } catch (InterruptedException e) {
      e.printStackTrace();
      throw new RuntimeException(e);
    }
  }
}
 
Example 24
Project: incubator-atlas   File: Titan1Graph.java   View source code 5 votes vote down vote up
private Set<String> getIndexKeys(Class<? extends Element> titanElementClass) {

        TitanManagement mgmt = getGraph().openManagement();
        Iterable<TitanGraphIndex> indices = mgmt.getGraphIndexes(titanElementClass);
        Set<String> result = new HashSet<String>();
        for (TitanGraphIndex index : indices) {
            result.add(index.name());
        }
        mgmt.commit();
        return result;

    }
 
Example 25
Project: incubator-atlas   File: GraphDbObjectFactory.java   View source code 5 votes vote down vote up
/**
 * @param index The gremlin index.
 * @return
 */
public static AtlasGraphIndex createGraphIndex(TitanGraphIndex index) {
    if (index == null) {
        return null;
    }
    return new Titan1GraphIndex(index);
}
 
Example 26
Project: incubator-atlas   File: GraphDbObjectFactory.java   View source code 5 votes vote down vote up
/**
 * @param index The gremlin index.
 * @return
 */
public static AtlasGraphIndex createGraphIndex(TitanGraphIndex index) {
    if (index == null) {
        return null;
    }
    return new Titan0GraphIndex(index);
}
 
Example 27
Project: titan1.0.1.kafka   File: TitanGraphTest.java   View source code 5 votes vote down vote up
@Test
public void testIndexQueryWithLabelsAndContainsIN() {
    // This test is based on the steps to reproduce #882

    String labelName = "labelName";

    VertexLabel label = mgmt.makeVertexLabel(labelName).make();
    PropertyKey uid = mgmt.makePropertyKey("uid").dataType(String.class).make();
    TitanGraphIndex uidCompositeIndex = mgmt.buildIndex("uidIndex", Vertex.class).indexOnly(label).addKey(uid).unique().buildCompositeIndex();
    mgmt.setConsistency(uidCompositeIndex, ConsistencyModifier.LOCK);
    finishSchema();

    TitanVertex foo = graph.addVertex(labelName);
    TitanVertex bar = graph.addVertex(labelName);
    foo.property("uid", "foo");
    bar.property("uid", "bar");
    graph.tx().commit();

    Iterable<TitanVertex> vertexes = graph.query()
            .has("uid", Contain.IN, ImmutableList.of("foo", "bar"))
            .has(LABEL_NAME, labelName)
            .vertices();
    assertEquals(2, Iterables.size(vertexes));
    for (TitanVertex v : vertexes) {
        assertEquals(labelName, v.vertexLabel().name());
    }
}
 
Example 28
Project: titan1.0.1.kafka   File: TitanGraphTest.java   View source code 5 votes vote down vote up
@Test
public void testVertexTTLWithCompositeIndex() throws Exception {
    if (!features.hasCellTTL()) {
        return;
    }

    PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
    PropertyKey time = mgmt.makePropertyKey("time").dataType(Long.class).make();
    TitanGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name).buildCompositeIndex();
    TitanGraphIndex index2 = mgmt.buildIndex("index2", Vertex.class).addKey(name).addKey(time).buildCompositeIndex();
    VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make();
    mgmt.setTTL(label1, Duration.ofSeconds(1));
    assertEquals(Duration.ZERO, mgmt.getTTL(name));
    assertEquals(Duration.ZERO, mgmt.getTTL(time));
    assertEquals(Duration.ofSeconds(1), mgmt.getTTL(label1));
    mgmt.commit();

    TitanVertex v1 = tx.addVertex(T.label, "event", "name", "some event", "time", System.currentTimeMillis());
    tx.commit();
    Object id = v1.id();

    v1 = getV(graph, id);
    assertNotNull(v1);
    assertNotEmpty(graph.query().has("name", "some event").vertices());

    Thread.sleep(1001);
    graph.tx().rollback();

    v1 = getV(graph, id);
    assertNull(v1);
    assertEmpty(graph.query().has("name", "some event").vertices());
}
 
Example 29
Project: titan1.0.1.kafka   File: TitanIndexTest.java   View source code 5 votes vote down vote up
private void setupChainGraph(int numV, String[] strs, boolean sameNameMapping) {
    clopen(option(INDEX_NAME_MAPPING, INDEX), sameNameMapping);
    TitanGraphIndex vindex = getExternalIndex(Vertex.class, INDEX);
    TitanGraphIndex eindex = getExternalIndex(Edge.class, INDEX);
    TitanGraphIndex pindex = getExternalIndex(TitanVertexProperty.class, INDEX);
    PropertyKey name = makeKey("name", String.class);

    mgmt.addIndexKey(vindex, name, getStringMapping());
    mgmt.addIndexKey(eindex, name, getStringMapping());
    mgmt.addIndexKey(pindex, name, getStringMapping(), Parameter.of("mapped-name", "xstr"));
    PropertyKey text = makeKey("text", String.class);
    mgmt.addIndexKey(vindex, text, getTextMapping(), Parameter.of("mapped-name", "xtext"));
    mgmt.addIndexKey(eindex, text, getTextMapping());
    mgmt.addIndexKey(pindex, text, getTextMapping());
    mgmt.makeEdgeLabel("knows").signature(name).make();
    mgmt.makePropertyKey("uid").dataType(String.class).signature(text).make();
    finishSchema();
    TitanVertex previous = null;
    for (int i = 0; i < numV; i++) {
        TitanVertex v = graph.addVertex("name", strs[i % strs.length], "text", strs[i % strs.length]);
        Edge e = v.addEdge("knows", previous == null ? v : previous,
                "name", strs[i % strs.length], "text", strs[i % strs.length]);
        VertexProperty p = v.property("uid", "v" + i,
                "name", strs[i % strs.length], "text", strs[i % strs.length]);
        previous = v;
    }
}
 
Example 30
Project: titan1.0.1.kafka   File: TitanOperationCountingTest.java   View source code 5 votes vote down vote up
@Test
public void checkPropertyLockingAndIndex() {
    PropertyKey uid = makeKey("uid",String.class);
    TitanGraphIndex index = mgmt.buildIndex("uid",Vertex.class).unique().addKey(uid).buildCompositeIndex();
    mgmt.setConsistency(index, ConsistencyModifier.LOCK);
    mgmt.makePropertyKey("name").dataType(String.class).make();
    mgmt.makePropertyKey("age").dataType(Integer.class).make();
    finishSchema();

    metricsPrefix = "checkPropertyLockingAndIndex";

    TitanTransaction tx = graph.buildTransaction().groupName(metricsPrefix).start();
    TitanVertex v = tx.addVertex("uid", "v1", "age", 25, "name", "john");
    assertEquals(25,v.property("age").value());
    tx.commit();
    verifyStoreMetrics(EDGESTORE_NAME);
    verifyLockingOverwrite(INDEXSTORE_NAME, 1);
    verifyStoreMetrics(METRICS_STOREMANAGER_NAME, ImmutableMap.of(M_MUTATE, 1l));

    resetMetrics();

    tx = graph.buildTransaction().groupName(metricsPrefix).start();
    v = Iterables.getOnlyElement(tx.query().has("uid", Cmp.EQUAL, "v1").vertices());
    assertEquals(25,v.property("age").value());
    tx.commit();
    verifyStoreMetrics(EDGESTORE_NAME, ImmutableMap.of(M_GET_SLICE,1l));
    verifyStoreMetrics(INDEXSTORE_NAME, ImmutableMap.of(M_GET_SLICE,1l));
    verifyStoreMetrics(METRICS_STOREMANAGER_NAME);
}
 
Example 31
Project: titan1.0.1.kafka   File: TitanGraphBaseTest.java   View source code 5 votes vote down vote up
public TitanGraphIndex getExternalIndex(Class<? extends Element> clazz, String backingIndex) {
    String prefix;
    if (Vertex.class.isAssignableFrom(clazz)) prefix = "v";
    else if (Edge.class.isAssignableFrom(clazz)) prefix = "e";
    else if (TitanVertexProperty.class.isAssignableFrom(clazz)) prefix = "p";
    else throw new AssertionError(clazz.toString());

    String indexName = prefix+backingIndex;
    TitanGraphIndex index = mgmt.getGraphIndex(indexName);
    if (index==null) {
        index = mgmt.buildIndex(indexName,clazz).buildMixedIndex(backingIndex);
    }
    return index;
}
 
Example 32
Project: titan1.0.1.kafka   File: AbstractIndexManagementIT.java   View source code 5 votes vote down vote up
@Test
public void testRemoveGraphIndex() throws InterruptedException, BackendException, ExecutionException {
    tx.commit();
    mgmt.commit();

    // Load the "Graph of the Gods" sample data
    GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true);

    // Disable the "name" composite index
    TitanManagement m = graph.openManagement();
    TitanGraphIndex nameIndex = m.getGraphIndex("name");
    m.updateIndex(nameIndex, SchemaAction.DISABLE_INDEX);
    m.commit();
    graph.tx().commit();

    // Block until the SchemaStatus transitions to DISABLED
    assertTrue(ManagementSystem.awaitGraphIndexStatus(graph, "name")
            .status(SchemaStatus.DISABLED).call().getSucceeded());

    // Remove index
    MapReduceIndexManagement mri = new MapReduceIndexManagement(graph);
    m = graph.openManagement();
    TitanGraphIndex index = m.getGraphIndex("name");
    ScanMetrics metrics = mri.updateIndex(index, SchemaAction.REMOVE_INDEX).get();

    assertEquals(12, metrics.getCustom(IndexRemoveJob.DELETED_RECORDS_COUNT));
}
 
Example 33
Project: titan1.0.1.kafka   File: ManagementSystem.java   View source code 5 votes vote down vote up
@Override
public void addIndexKey(final TitanGraphIndex index, final PropertyKey key, Parameter... parameters) {
    Preconditions.checkArgument(index != null && key != null && index instanceof TitanGraphIndexWrapper
            && !(key instanceof BaseKey), "Need to provide valid index and key");
    if (parameters == null) parameters = new Parameter[0];
    IndexType indexType = ((TitanGraphIndexWrapper) index).getBaseIndex();
    Preconditions.checkArgument(indexType instanceof MixedIndexType, "Can only add keys to an external index, not %s", index.name());
    Preconditions.checkArgument(indexType instanceof IndexTypeWrapper && key instanceof TitanSchemaVertex
            && ((IndexTypeWrapper) indexType).getSchemaBase() instanceof TitanSchemaVertex);

    TitanSchemaVertex indexVertex = (TitanSchemaVertex) ((IndexTypeWrapper) indexType).getSchemaBase();

    for (IndexField field : indexType.getFieldKeys())
        Preconditions.checkArgument(!field.getFieldKey().equals(key), "Key [%s] has already been added to index %s", key.name(), index.name());

    //Assemble parameters
    boolean addMappingParameter = !ParameterType.MAPPED_NAME.hasParameter(parameters);
    Parameter[] extendedParas = new Parameter[parameters.length + 1 + (addMappingParameter ? 1 : 0)];
    System.arraycopy(parameters, 0, extendedParas, 0, parameters.length);
    int arrPosition = parameters.length;
    if (addMappingParameter) extendedParas[arrPosition++] = ParameterType.MAPPED_NAME.getParameter(
            graph.getIndexSerializer().getDefaultFieldName(key, parameters, indexType.getBackingIndexName()));
    extendedParas[arrPosition++] = ParameterType.STATUS.getParameter(key.isNew() ? SchemaStatus.ENABLED : SchemaStatus.INSTALLED);

    addSchemaEdge(indexVertex, key, TypeDefinitionCategory.INDEX_FIELD, extendedParas);
    updateSchemaVertex(indexVertex);
    indexType.resetCache();
    //Check to see if the index supports this
    if (!graph.getIndexSerializer().supports((MixedIndexType) indexType, ParameterIndexField.of(key, parameters))) {
        throw new TitanException("Could not register new index field '" + key.name() + "' with index backend as the data type, cardinality or parameter combination is not supported.");
    }

    try {
        IndexSerializer.register((MixedIndexType) indexType, key, transaction.getTxHandle());
    } catch (BackendException e) {
        throw new TitanException("Could not register new index field with index backend", e);
    }
    if (!indexVertex.isNew()) updatedTypes.add(indexVertex);
    if (!key.isNew()) updateIndex(index, SchemaAction.REGISTER_INDEX);
}
 
Example 34
Project: titan1.0.1.kafka   File: ManagementSystem.java   View source code 5 votes vote down vote up
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;
}
 
Example 35
Project: titan1.0.1.kafka   File: ManagementSystem.java   View source code 5 votes vote down vote up
@Override
public TitanGraphIndex buildCompositeIndex() {
    Preconditions.checkArgument(!keys.isEmpty(), "Need to specify at least one key for the composite index");
    PropertyKey[] keyArr = new PropertyKey[keys.size()];
    int pos = 0;
    for (Map.Entry<PropertyKey, Parameter[]> entry : keys.entrySet()) {
        Preconditions.checkArgument(entry.getValue() == null, "Cannot specify parameters for composite index: %s", entry.getKey());
        keyArr[pos++] = entry.getKey();
    }
    return createCompositeIndex(indexName, elementCategory, unique, constraint, keyArr);
}
 
Example 36
Project: titan1.0.1.kafka   File: ManagementSystem.java   View source code 5 votes vote down vote up
@Override
public TitanGraphIndex buildMixedIndex(String backingIndex) {
    Preconditions.checkArgument(StringUtils.isNotBlank(backingIndex), "Need to specify backing index name");
    Preconditions.checkArgument(!unique, "An external index cannot be unique");

    TitanGraphIndex index = createMixedIndex(indexName, elementCategory, constraint, backingIndex);
    for (Map.Entry<PropertyKey, Parameter[]> entry : keys.entrySet()) {
        addIndexKey(index, entry.getKey(), entry.getValue());
    }
    return index;
}
 
Example 37
Project: titan1.0.1.kafka   File: ManagementSystem.java   View source code 5 votes vote down vote up
/**
 * Retrieves the consistency level for a schema element (types and internal indexes)
 *
 * @param element
 * @return
 */
@Override
public ConsistencyModifier getConsistency(TitanSchemaElement element) {
    Preconditions.checkArgument(element != null);
    if (element instanceof RelationType) return ((InternalRelationType) element).getConsistencyModifier();
    else if (element instanceof TitanGraphIndex) {
        IndexType index = ((TitanGraphIndexWrapper) element).getBaseIndex();
        if (index.isMixedIndex()) return ConsistencyModifier.DEFAULT;
        return ((CompositeIndexType) index).getConsistencyModifier();
    } else return ConsistencyModifier.DEFAULT;
}
 
Example 38
Project: titan1.0.1.kafka   File: ManagementSystem.java   View source code 5 votes vote down vote up
/**
 * Sets the consistency level for those schema elements that support it (types and internal indexes)
 * </p>
 * Note, that it is possible to have a race condition here if two threads simultaneously try to change the
 * consistency level. However, this is resolved when the consistency level is being read by taking the
 * first one and deleting all existing attached consistency levels upon modification.
 *
 * @param element
 * @param consistency
 */
@Override
public void setConsistency(TitanSchemaElement element, ConsistencyModifier consistency) {
    if (element instanceof RelationType) {
        RelationTypeVertex rv = (RelationTypeVertex) element;
        Preconditions.checkArgument(consistency != ConsistencyModifier.FORK || !rv.multiplicity().isConstrained(),
                "Cannot apply FORK consistency mode to constraint relation type: %s", rv.name());
    } else if (element instanceof TitanGraphIndex) {
        IndexType index = ((TitanGraphIndexWrapper) element).getBaseIndex();
        if (index.isMixedIndex())
            throw new IllegalArgumentException("Cannot change consistency on mixed index: " + element);
    } else throw new IllegalArgumentException("Cannot change consistency of schema element: " + element);
    setTypeModifier(element, ModifierType.CONSISTENCY, consistency);
}
 
Example 39
Project: titan0.5.4-hbase1.1.1-custom   File: TitanIndexTest.java   View source code 5 votes vote down vote up
private void setupChainGraph(int numV, String[] strs, boolean sameNameMapping) {
    clopen(option(INDEX_NAME_MAPPING,INDEX),sameNameMapping);
    TitanGraphIndex vindex = getExternalIndex(Vertex.class,INDEX);
    TitanGraphIndex eindex = getExternalIndex(Edge.class,INDEX);
    TitanGraphIndex pindex = getExternalIndex(TitanProperty.class,INDEX);
    PropertyKey name = makeKey("name",String.class);

    mgmt.addIndexKey(vindex, name, getStringMapping());
    mgmt.addIndexKey(eindex, name, getStringMapping());
    mgmt.addIndexKey(pindex, name, getStringMapping(), Parameter.of("mapped-name", "xstr"));
    PropertyKey text = makeKey("text",String.class);
    mgmt.addIndexKey(vindex, text, getTextMapping(), Parameter.of("mapped-name","xtext"));
    mgmt.addIndexKey(eindex, text, getTextMapping());
    mgmt.addIndexKey(pindex, text, getTextMapping());
    mgmt.makeEdgeLabel("knows").signature(name).make();
    mgmt.makePropertyKey("uid").dataType(String.class).signature(text).make();
    finishSchema();
    TitanVertex previous = null;
    for (int i=0;i<numV;i++) {
        TitanVertex v = graph.addVertex(null);
        v.setProperty("name",strs[i%strs.length]);
        v.setProperty("text",strs[i%strs.length]);
        TitanEdge e = v.addEdge("knows",previous==null?v:previous);
        e.setProperty("name",strs[i%strs.length]);
        e.setProperty("text",strs[i%strs.length]);
        TitanProperty p = v.addProperty("uid","v"+i);
        p.setProperty("name", strs[i % strs.length]);
        p.setProperty("text", strs[i % strs.length]);
        previous=v;
    }
}
 
Example 40
Project: titan0.5.4-hbase1.1.1-custom   File: TitanEventualGraphTest.java   View source code 5 votes vote down vote up
public void testBatchLoadingLocking(boolean batchloading) {
        PropertyKey uid = makeKey("uid",Long.class);
        TitanGraphIndex uidIndex = mgmt.buildIndex("uid",Vertex.class).unique().addKey(uid).buildCompositeIndex();
        mgmt.setConsistency(uid, ConsistencyModifier.LOCK);
        mgmt.setConsistency(uidIndex,ConsistencyModifier.LOCK);
        EdgeLabel knows = mgmt.makeEdgeLabel("knows").multiplicity(Multiplicity.ONE2ONE).make();
        mgmt.setConsistency(knows,ConsistencyModifier.LOCK);
        finishSchema();

        TestLockerManager.ERROR_ON_LOCKING=true;
        clopen(option(GraphDatabaseConfiguration.STORAGE_BATCH),batchloading,
                option(GraphDatabaseConfiguration.LOCK_BACKEND),"test");


        int numV = 10000;
        long start = System.currentTimeMillis();
        for (int i=0;i<numV;i++) {
            TitanVertex v = tx.addVertex();
            v.setProperty("uid",i+1);
            v.addEdge("knows",v);
        }
        clopen();
//        System.out.println("Time: " + (System.currentTimeMillis()-start));

        for (int i=0;i<Math.min(numV,300);i++) {
            assertEquals(1, Iterables.size(graph.query().has("uid", i + 1).vertices()));
            assertEquals(1, Iterables.size(graph.query().has("uid", i + 1).vertices().iterator().next().getEdges(Direction.OUT, "knows")));
        }
    }