janusgraph源码分析1-下载编译启动

简介: 转自:janusgraph源码分析1-下载编译启动 date: 2018-04-26title: "janusgraph源码分析1-下载编译启动"author: "邓子明"tags: - 源码 - janusgraph categories: - 源码分析 janusgraph源码分析1-下.

date: 2018-04-26
title: "janusgraph源码分析1-下载编译启动"
author: "邓子明"
tags:

- 源码
- janusgraph

categories:

- 源码分析

janusgraph源码分析1-下载编译启动

研究了好久的 neo4j源码,现在公司要换 janusgraph,只要半途而废开始研究 janusgraph 了
https://github.com/JanusGraph/janusgraph和http://janusgraph.org/

一、下载编译

我直接使用github desktop打开了 janusgraph 的源码,使用IDEA打开,然后编译:

# 编译完整的
mvn -settings ~/opt/soft/apache-maven-3.5.0/conf/settings.xml -Dlicense.skip=true -DskipTests clean install
# 只编译core部分
mvn -pl janusgraph-core -am clean install -Dlicense.skip=true -DskipTests -P prod

-rf :janusgraph-test
mvn -pl janusgraph-test -am clean install -Dlicense.skip=true -DskipTests -P prod

更多阅读:

JanusGraph 技术交流圈

neo4j技术交流圈

JanusGraph中文翻译文档
我们在 janusgraph-test 下面编写一个例子 FirstTest:

public class FirstTest {

    public static void main(String[] args) {

        /*
         * The example below will open a JanusGraph graph instance and load The Graph of the Gods dataset diagrammed above.
         * JanusGraphFactory provides a set of static open methods,
         * each of which takes a configuration as its argument and returns a graph instance.
         * This tutorial calls one of these open methods on a configuration
         * that uses the BerkeleyDB storage backend and the Elasticsearch index backend,
         * then loads The Graph of the Gods using the helper class GraphOfTheGodsFactory.
         * This section skips over the configuration details, but additional information about storage backends,
         * index backends, and their configuration are available in
         * Part III, “Storage Backends”, Part IV, “Index Backends”, and Chapter 13, Configuration Reference.
         */

        // Loading the Graph of the Gods Into JanusGraph
        JanusGraph graph = JanusGraphFactory
                .open("janusgraph-dist/src/assembly/cfilter/conf/janusgraph-berkeleyje-es.properties");

        GraphOfTheGodsFactory.load(graph);
        GraphTraversalSource g = graph.traversal();

        /*
         * The typical pattern for accessing data in a graph database is to first locate the entry point into the graph
         * using a graph index. That entry point is an element (or set of elements) 
         * — i.e. a vertex or edge. From the entry elements,
         * a Gremlin path description describes how to traverse to other elements in the graph via the explicit graph structure.
         * Given that there is a unique index on name property, the Saturn vertex can be retrieved.
         * The property map (i.e. the key/value pairs of Saturn) can then be examined.
         * As demonstrated, the Saturn vertex has a name of "saturn, " an age of 10000, and a type of "titan."
         * The grandchild of Saturn can be retrieved with a traversal that expresses:
         * "Who is Saturn’s grandchild?" (the inverse of "father" is "child"). The result is Hercules.
         */
        // Global Graph Indices
        Vertex saturn = g.V().has("name", "saturn").next();
        GraphTraversal<Vertex, Map<String, Object>> vertexMapGraphTraversal = g.V(saturn).valueMap();

        GraphTraversal<Vertex, Object> values = g.V(saturn).in("father").in("father").values("name");

        /*
         * The property place is also in a graph index. The property place is an edge property.
         * Therefore, JanusGraph can index edges in a graph index.
         * It is possible to query The Graph of the Gods for all events that have happened within 50 kilometers of Athens
          * (latitude:37.97 and long:23.72).
          * Then, given that information, which vertices were involved in those events.
         */
        System.out.println(g.E().has("place", geoWithin(Geoshape.circle(37.97, 23.72, 50))));
        System.out.println(g.E().has("place", geoWithin(Geoshape.circle(37.97, 23.72, 50)))
                .as("source").inV()
                .as("god2")
                .select("source").outV()
                .as("god1").select("god1", "god2")
                .by("name"));
    }

}

然后在"janusgraph-dist/src/assembly/cfilter/conf/janusgraph-berkeleyje-es.properties" 文件中,将注释掉的内容取消注释。

运行发现依赖挺麻烦。
首先运行报错了:

Exception in thread "main" java.lang.IllegalArgumentException: Could not find implementation class: org.janusgraph.diskstorage.berkeleyje.BerkeleyJEStoreManager

找到报错处的代码,我们发现 janusgraph-core 中通过反射创建一个类,但是这个类在 janusgraph-berkeleyje 中,而前者不依赖后者,所以找不到这个类,我们可以将后者加到前者的依赖,
但是我们发现后者依赖前者,如果加了依赖两个就相互依赖了,这是 Janus 官方设计的问题。我们只好在 FirstTest 所在的module中把两个依赖都加进来试试。
(注意,如果我们将所有的都打进一个包,这个问题就不存在了,但是在本地运行是不一样的,各自模块的编译输出文件在不同的地方。)在 janusgraph-test 中添加:

        <dependency>
            <groupId>org.janusgraph</groupId>
            <artifactId>janusgraph-berkeleyje</artifactId>
            <version>0.3.0-SNAPSHOT</version>
        </dependency>

发现 janusgraph-berkeleyje也依赖了 janusgraph-test,又相互依赖了,好麻烦。我们写写代码一定要注意这个问题。这里我的解决方法是直接把 代码放到 janusgraph-berkeleyje 中运行。

Exception in thread "main" java.lang.IllegalArgumentException: Could not find implementation class: org.janusgraph.diskstorage.es.ElasticSearchIndex

和上面一样,还依赖了 janusgraph-es,我只好吧代码复制到 janusgraph-es 的test代码块中运行(注意一点是test代码中),顺便在 janusgraph-es 中 添加上janusgraph-berkeleyje的依赖。
运行成功了,但是报了连接失败,是因为我本地没有启动es,我启动一下es:elasticsearch
然后在运行:

Exception in thread "main" org.janusgraph.core.SchemaViolationException: Adding this property for key [~T$SchemaName] and value [rtname] violates a uniqueness constraint [SystemIndex#~T$SchemaName]

经过google查到原因: https://groups.google.com/forum/#!topic/aureliusgraphs/vZ_nTXlXj4k

This exception is thrown only when you already have added property key to index. So "name" is already added and next time when you run your program somewhere it is again adding "name" property key. So check if that particular code is running twice

然后我们可以在我们传入的配置文件找到:storage.directory=../db/berkeley ,直接删除这个目录,再重新运行,就成功了:

11:20:17,051  INFO GraphDatabaseConfiguration:1285 - Set default timestamp provider MICRO
11:20:17,296  INFO GraphDatabaseConfiguration:1492 - Generated unique-instance-id=c0a815a789637-dengzimings-MacBook-Pro-local1
11:20:17,547  INFO Backend:462 - Configuring index [search]
11:20:19,279  INFO Backend:177 - Initiated backend operations thread pool of size 8
11:20:19,461  INFO KCVSLog:753 - Loaded unidentified ReadMarker start time 2018-04-26T03:20:19.408Z into org.janusgraph.diskstorage.log.kcvs.KCVSLog$MessagePuller@73cd37c0
[GraphStep(edge,[]), HasStep([place.geoWithin(BUFFER (POINT (23.72 37.97), 0.44966))])]
[GraphStep(edge,[]), HasStep([place.geoWithin(BUFFER (POINT (23.72 37.97), 0.44966))])@[source], EdgeVertexStep(IN)@[god2], SelectOneStep(last,source), EdgeVertexStep(OUT)@[god1], SelectStep(last,[god1, god2],[value(name)])]
11:20:29,578  INFO ManagementLogger:192 - Received all acknowledgements for eviction [1]

然后我们可以去 ../db/berkeley 目录查看,多了一些文件,这些文件的作用我们后续再分析。
然后我们取es查看:curl -XGET 'localhost:9200/_cat/indices?v&pretty' ,发现多了两个index:

yellow open   janusgraph_edges    QT-E7AV6SMWr8Cu_ywKsXg   5   1          6            0     13.7kb         13.7kb
yellow open   janusgraph_vertices gE4TSXFATnSZUWYdAf46Xg   5   1          6            0     10.9kb         10.9kb

还可以具体查看内容。例如名字是titan的内容:curl -XGET 'localhost:9200/janusgraph_vertices/_search?q=name:titan&pretty'

到现在我们第一个案例就结束了。

g.E().has("place", geoWithin(Geoshape.circle(37.97, 23.72, 50)))
                .as("source").inV()
                .as("god2")
                .select("source").outV()
                .as("god1").select("god1", "god2")
                .by("name")

这种风格的代码实际上是groovy语言的代码,大家可以研究一下groovy语言。

注意事项:
上述第一次运行问题的原因是 janusgraph-core需要用到 janusgraph-berkeleyje的类,
但是janusgraph-berkeleyje是依赖 janusgraph-core的,所以两个相互依赖了。
janus的做法是在core中使用反射,所以编译通过了,打包到了一起就没问题了。但是本地运行没法成功。

目录
相关文章
|
3月前
|
数据采集 JSON 小程序
多市场黄金价格查询API:覆盖上金所、上期所、品牌金店、国际金银数据
本文介绍探数API黄金价格查询接口,帮助开发者快速获取多源贵金属行情,适配黄金回收、珠宝零售、财经工具等业务开发。
|
5月前
|
SQL 人工智能 安全
2026六款Vibe Coding工具实测:PHP副业开发核心技巧全景解析
本文实测TRAE、Cursor等六款Vibe Coding工具在PHP Laravel副业开发中的表现,聚焦无损长上下文、本地代码隔离、跨文件同步重构与自动文档生成四大维度,提炼三段式需求输入、上下文管控、缺陷前置约束等五大落地技巧,助力独立开发者提效降险、安全交付。(239字)
2026六款Vibe Coding工具实测:PHP副业开发核心技巧全景解析
|
8月前
|
缓存 网络协议 定位技术
游戏服务器选择,为何绕不开IP地址查询?
游戏版本更新后,华东玩家延迟飙升,根源在于调度系统缺乏IP定位能力,导致用户被错误分配至华南服务器。通过集成高精度IP归属地查询(如城市/街道级),可实现就近接入、智能调度,实测降低延迟30%–50%,提升稳定性与体验。
|
8月前
|
弹性计算 应用服务中间件 网络安全
企业网站建设实战:PageAdmin定制开发 + 阿里云服务器部署
分享PageAdmin+阿里云ECS的企业建站实战经验,从选型到部署全流程解析,99元/年低成本方案,适合中小企业快速搭建高性价比官网。
513 4
|
人工智能 安全 自动驾驶
通义灵码入职蔚来汽车,AI生成代码30%以上
通义灵码已正式应用于蔚来汽车智能座舱部门,近400名成员使用该工具,AI生成代码占比达30%以上,“天探”项目中甚至高达70%-80%。它通过提升代码开发效率、降低维护成本、智能生成单元测试及问题排查等功能助力研发。蔚来选择通义灵码看重其企业专属版的安全能力和知识管理功能。未来,期望AI编程将研发流程规范化,成为类似自动驾驶的高效指引工具。
1131 5
|
存储 人工智能 缓存
AI变革药物研发:深势科技的云原生实践之路
阿里云助力深势科技推出创新的玻尔Bohrium®科研云平台和Hermite®药物计算设计平台,并持续完善。这两项先进的工业设计与仿真基础设施成果通过AI技术赋能科学研究和工业研发,不仅大幅缩短了药物研发周期,降低了成本,还显著提高了研发成功率,为生物医药行业带来了前所未有的变革,这是AI for Science领域的重大突破。
1314 38
|
算法 数据安全/隐私保护 异构计算
基于FPGA的16QAM调制+软解调系统,包含testbench,高斯信道模块,误码率统计模块,可以设置不同SNR
本项目基于FPGA实现了16QAM基带通信系统,包括调制、信道仿真、解调及误码率统计模块。通过Vivado2019.2仿真,设置不同SNR(如8dB、12dB),验证了软解调相较于传统16QAM系统的优越性,误码率显著降低。系统采用Verilog语言编写,详细介绍了16QAM软解调的原理及实现步骤,适用于高性能数据传输场景。
952 69
|
Python
解决Python报错:DataFrame对象没有concat属性的多种方法(解决方案汇总)
总的来说,解决“DataFrame对象没有concat属性”的错误的关键是理解concat函数应该如何正确使用,以及Pandas库提供了哪些其他的数据连接方法。希望这些方法能帮助你解决问题。记住,编程就像是解谜游戏,每一个错误都是一个谜题,解决它们需要耐心和细心。
782 15
|
机器学习/深度学习 存储 大数据
在大数据时代,高维数据处理成为难题,主成分分析(PCA)作为一种有效的数据降维技术,通过线性变换将数据投影到新的坐标系
在大数据时代,高维数据处理成为难题,主成分分析(PCA)作为一种有效的数据降维技术,通过线性变换将数据投影到新的坐标系,保留最大方差信息,实现数据压缩、去噪及可视化。本文详解PCA原理、步骤及其Python实现,探讨其在图像压缩、特征提取等领域的应用,并指出使用时的注意事项,旨在帮助读者掌握这一强大工具。
1261 4
|
SQL 安全 JavaScript
0x00.基础漏洞篇
0x00.基础漏洞篇
851 3