JanusGraph學習筆記-問題與解決(總集)

這是一個JANUSGRAPH v0.4.0學習實踐的填坑排錯集錦,文末持續更新篇,歡迎收藏或一塊兒貢獻!java

遇到新問題的同窗能夠在下方留言討論。shell

E01. gremlin命令行能夠查到,但在IDE中運行java程序查不到結果

問題背景:已實如今後臺使用addV()添加一些頂點數據,後臺控制檯能夠查到,但執行下面代碼輸出爲~0。vim

代碼示例

public static void main(String[] args) throws Exception {
        GraphTraversalSource graph = traversal()
                .withRemote(DriverRemoteConnection.using("my.host.com",8182,"g"));
      
        List<Vertex> ls = graph.V().has("name").toList();
        System.out.println("==="+graph.V().count().next());
        System.out.println("==="+graph.getGraph());
        for(Vertex v :ls){
            System.out.println("========="+v.label()+"=======");
        }
        graph.close();
}
複製代碼

解決方案

在gremlin控制檯添加頂點數據後,在java程序中查不到,結果爲空,緣由是任何的圖操做都會自動開啓一個事務。若是事務沒有提交,那麼操做就不會生效。須要在gremlin控制檯執行事務提交後才能查詢到:bash

for (tx in graph.getOpenTransactions()) tx.commit()
複製代碼

事務提交後便可在Java程序中查詢剛纔添加的數據。簡單來講就須要graph.tx().commit()服務器


E02. 遠程鏈接GremlinServer,報錯源[g]別名未在服務器上配置

錯誤信息:The traversal source [g] for alias [g] is not configured on the server.curl

代碼示例

同上,據稱ES沒有正常運行也會遇到這個錯誤。elasticsearch

解決方案

修改配置文件oop

vim janusgraph-hbase-es.properties
複製代碼

在文件末尾添加以下配置:post

gremlin.graph=org.janusgraph.core.JanusGraphFactory
複製代碼

保存後重啓GremlinServer服務器,命令以下學習

/path_to_janus/janusgraph-0.4.0-hadoop2/bin/gremlin-server.sh  stop  /path_to_janus/conf/janusgraph-hbase-es.properties
/path_to_janus/janusgraph-0.4.0-hadoop2/bin/gremlin-server.sh  start  /path_to_janus/conf/janusgraph-hbase-es.properties
複製代碼

java程序便可遠程鏈接GremlinServer,查詢數據無誤。

E03. java.lang.IllegalArgumentException: Could not instantiate implementation: org.janusgraph.diskstorage.es.ElasticSearchIndex

錯誤信息:Caused by: java.lang.reflect.InvocationTargetException

在Gremlin命令行建立graph時報錯java.lang.IllegalArgumentException: Could not instantiate implementation: org.janusgraph.diskstorage.es.ElasticSearchIndex

注:這在IDEA項目裏用java代碼訪問JanusGraph時也會報一樣的錯,以前解決辦法參考JanusGraph入門第一課:建立IDEA項目,但錯誤的緣由並不同,代碼沒有改動卻報這個錯誤,這和E06很像,是同類型的錯誤。排查以下:

執行的代碼示例

gremlin> graph = JanusGraphFactory.open('/opt/janusgraph/conf/janusgraph-hbase-es.properties')
複製代碼

解決方案

curl http://localhost:9200檢查相應正常。但不管如何修改httpclient依賴包仍是報錯。經排查發現此時elasticsearch服務狀態是red(因昨晚服務器所有掉電的緣故),將es的狀態恢復到green以後,再次執行代碼,直接就行了。隨後用java代碼讀取數據一切正常。

能夠看到:standardjanusgraph巴拉巴拉……

找了很久,總算解決了。【2019-09-15更新】

JanusGraph問題與解決系列目錄:

JanusGraph問題筆記(二)-SchemaViolationException

JanusGraph問題筆記(三):NoNodeException(hbase)

JanusGraph問題筆記(四):ResponseException(ES)


相關專欄:

JanusGraph入門第一課:建立IDEA項目

相關文章
相關標籤/搜索