如果存在marko,我已經編寫了一個JUnit測試來檢查generate-modern.groovy圖。
我的小鬼查詢是在Titan/Janus中啓用強制索引時索引失敗
「g.V()有( '名', '馬爾科')。」;
正如您在generate-modern.groovy文件中看到的那樣,索引已經應用於人員的name屬性。 我後來提出了以下
query.force指數=真
屬性真在dynamodb.properties文件哪些塊整個圖形掃描從而使分度強制性的。 但是它拋出我下面的例外
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爲空)並且強制索引爲真。
問題是爲什麼列表爲空?當我們在從JUnit Test中查詢時針對generate-modern.groovy中的name屬性指定索引查詢。這很好地工作,這意味着當相同的數據被預加載到具有相同文件的gremlin服務器時,列表不是空的。
你能提供你的整個失敗的JUnit測試?這裏可能會發生很多事情。如果您只是簡單地使用'generate-modern.groovy'腳本並嘗試在服務器啓動之外加載該腳本,則會遇到問題,因爲它設置爲在服務器生命週期中作爲鉤子運行,並且不會實際運行生成任何東西如果情況並非如此,如果您在測試中使用的圖表上創建了任何頂點標籤,則該腳本不會創建索引。 – pantalohnes
不,我在創建服務器時加載腳本。我已經驗證了這一事實,因爲當我切換強制索引屬性爲false時,我的測試用例通過成功。 –
將'force-index'設置爲false後成功表明簡單索引沒有被創建。 您是否已經在圖表中添加了數據,您正在嘗試加載該數據? https://github.com/pluradj/titan-tp3-driver-example/blob/master/scripts/generate-modern.groovy#L13假設您使用的是沒有預先存在的頂點標籤的空圖。 – pantalohnes