neo4j源碼分析1-編譯打包啟動



date: 2018-03-22 title: "neo4j源碼分析1-編譯打包啟動" author: "鄧子明" tags:

- 源碼
- neo4j
- 大數據

categories:

- 源碼分析

1.打包

1.打包community

進入community,neo4j-graphdb-api, 注釋掉common的:

<plugin>
  <groupId>org.revapi</groupId>
  <artifactId>revapi-maven-plugin</artifactId>
</plugin>

里面好像涉及到了版本檢查,如果某個類的最新發布版本已經沒有這個方法,打包會失敗,反正對打包有影響,不刪除可能會失敗。

還可能要在主項目的pom里面注釋掉:maven-checkstyle-plugin,代碼風格檢查可能會通不過。 然后用maven命令:

mvn -settings ~/opt/soft/apache-maven-3.5.0/conf/settings.xml -Dlicense.skip=true -DskipTests package install

2.打包企業版

進入enterprise,ha目錄 進入management,注釋掉 org.revapi 還有其他問題,比如java文件沒有license,這里不一一列舉。

mvn -settings ~/opt/soft/apache-maven-3.5.0/conf/settings.xml -Dlicense.skip=true -DskipTests package install

3. 打包完整的tar包

進入項目路徑

mvn clean install -Dmaven.test.skip=true

要注意兩個參數的異同點:


-DskipTests,不執行測試用例,但編譯測試用例類生成相應的class文件至target/test-classes下。

-Dmaven.test.skip=true,不執行測試用例,也不編譯測試用例類。

打包的輸出文件:packaging/standalone/target/neo4j-community-3.4.0-SNAPSHOT-unix.tar.gz,這個就是我們的neo4j包。解壓后,放到一個目錄。一方面你可以選擇執行 bin/neo4j start 啟動neo4j,我們要分析源碼,自然會是在本地啟動。

二、運行

1.啟動

我們在IDEA中,找到入口類:org.neo4j.server.CommunityEntryPoint,點擊運行,然后會報錯,我們需要添加運行參數:

-server --home-dir=~/neo4j-community-3.2.6 --config-dir=~/neo4j-community-3.2.6/conf

這里的參數是剛剛解壓的neo4j目錄和配置文件。然后運行成功,訪問 http://localhost:7474/browser/,會發現有問題。 通過調試前端的js代碼,我們發現版本有問題,這里我們稍作修改,找到 org.neo4j.kernel.internal.Version。最后的代碼注釋掉,換成我們的版本,也就是將Version.class.getPackage().getImplementationVersion() 換成 3.4,然后就可以運行成功了。 打開7474端口,寫cypher語言,查看。

2.打斷點調試

既然是源碼分析,我們的辦法就是先看,然后打斷點調試,查看調用棧,但是由於是多線程,其實還是很有難度的,容易跟丟,后續我們慢慢來吧。

3.代碼結構查看

看源碼之前我們先大概過一下代碼結構。我們主要看 community 模塊的結構,里面有很多子模塊。

我們可以大概根據名字猜測 :io模塊是用來處理讀寫數據的,kernel模塊是我們需要着重查看的。bolt是處理bolt連接的,server是整個項目啟動的。codegen是動態生成代碼的。我們要從內核部分開始看。

4.架構了解

The node records contain only a pointer to their first property and their first relationship (in what is oftentermed the _relationship chain). From here, we can follow the (doubly) linked-list of relationships until we find the one we’re interested in, the LIKES relationship from Node 1 to Node 2 in this case. Once we’ve found the relationship record of interest, we can simply read its properties if there are any via the same singly-linked list structure as node properties, or we can examine the node records that it relates via its start node and end node IDs. These IDs, multiplied by the node record size, of course give the immediate offset of both nodes in the node store file.

這段話來自 (作者:IanRobinson) 一書。描述了neo4j的存儲方式。詳情可以查閱其他資料。

5.源碼查看

參考下一篇

原文地址:http://www.k6k4.com/blog/show/aaavurkwu1547605733514


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM