在Titan / Janus中启用力指数的索引失败

时间:2017-07-28 11:30:18

标签: titan tinkerpop3 janusgraph

如果存在marko,我已经编写了一个JUnit测试来检查generate-modern.groovy图 我的gremlin查询

  

“g.V()具有( '姓名', '马尔科')。”;

正如您在generate-modern.groovy文件中所看到的,索引已经应用于此人的name属性。 我后来发了以下几个

  
    

query.force-index = true

  

属性在dynamodb.properties文件中为true,阻止整个图扫描,从而使索引成为必需。 然而,它引发了以下异常

org.janusgraph.core.JanusGraphException: Could not find a suitable index to answer graph query and graph scans are disabled: [(name = marko)]:VERTEX

以下StandardJanusGraphTx类的方法

引发了上述异常
    @Override
    public Iterator<JanusGraphElement> execute(final GraphCentricQuery query, final JointIndexQuery indexQuery, final Object exeInfo, final QueryProfiler profiler) {
        Iterator<JanusGraphElement> iter;
        if (!indexQuery.isEmpty()) {
            List<QueryUtil.IndexCall<Object>> retrievals = new ArrayList<QueryUtil.IndexCall<Object>>();
            for (int i = 0; i < indexQuery.size(); i++) {
                final JointIndexQuery.Subquery subquery = indexQuery.getQuery(i);

                retrievals.add(new QueryUtil.IndexCall<Object>() {
                    @Override
                    public Collection<Object> call(int limit) {
                        final JointIndexQuery.Subquery adjustedQuery = subquery.updateLimit(limit);
                        try {
                            return indexCache.get(adjustedQuery, new Callable<List<Object>>() {
                                @Override
                                public List<Object> call() throws Exception {
                                    return QueryProfiler.profile(subquery.getProfiler(), adjustedQuery, q -> indexSerializer.query(q, txHandle));
                                }
                            });
                        } catch (Exception e) {
                            throw new JanusGraphException("Could not call index", e.getCause());
                        }
                    }
                });
            }


            List<Object> resultSet = QueryUtil.processIntersectingRetrievals(retrievals, indexQuery.getLimit());
            iter = com.google.common.collect.Iterators.transform(resultSet.iterator(), getConversionFunction(query.getResultType()));
        } else {
            if (config.hasForceIndexUsage()) throw new JanusGraphException("Could not find a suitable index to answer graph query and graph scans are disabled: " + query);
            log.warn("Query requires iterating over all vertices [{}]. For better performance, use indexes", query.getCondition());

            QueryProfiler sub = profiler.addNested("scan");
            sub.setAnnotation(QueryProfiler.QUERY_ANNOTATION,indexQuery);
            sub.setAnnotation(QueryProfiler.FULLSCAN_ANNOTATION,true);
            sub.setAnnotation(QueryProfiler.CONDITION_ANNOTATION,query.getResultType());

            switch (query.getResultType()) {
                case VERTEX:
                    return (Iterator) getVertices().iterator();

                case EDGE:
                    return (Iterator) getEdges().iterator();

                case PROPERTY:
                    return new VertexCentricEdgeIterable(getInternalVertices(),RelationCategory.PROPERTY).iterator();

                default:
                    throw new IllegalArgumentException("Unexpected type: " + query.getResultType());
            }
        }

        return iter;
    }

};

正如您可以从方法中看到,当JointIndexQuery对象为空(arrayList为空)且force index为true时引发异常。
问题是列表为空的原因?当我们从JUnit Test查询时,我们在generate-modern.groovy中为name属性指定了索引查询。这很正常意味着当相同的数据被预加载到具有相同文件的gremlin服务器时,列表不为空。

1 个答案:

答案 0 :(得分:1)

personByName index definition使用标签约束。

def personByName = mgmt.buildIndex("personByName", Vertex.class).addKey(name).indexOnly(person).buildCompositeIndex()

为了利用该索引,您必须使用标签和属性。例如:

g.V().has('person', 'name', 'marko')

您可以在JanusGraph文档http://docs.janusgraph.org/latest/indexes.html#_label_constraint

中阅读更多相关信息