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中文翻译文档
我们在 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中使用反射,所以编译通过了,打包到了一起就没问题了。但是本地运行没法成功。
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Javascript基础之-this
this应该算是前期比较容易混淆的一个关键字了,在这里,我就打算按照我的理解来说一下 首先呢,this的值是跟运行时被调用的位置相关的,而不是词法作用域。 也就是说,他的绑定的值很可能是动态的,不同的调用位置,很可能值就不一样,比如说: function foo() { console.log(this.a); } var a = 2; var obj = { a: 3, foo, } foo(); //2 obj.foo(); //3 var c = obj.foo; c(); //2 然后你会惊讶的发现,foo()通过不同的形式调用,他最终的值是不一样的,咱们这一节主要就来讲一讲他们里面的这些绑定的规则 默认绑定 独立的函数调用,它的作用域是作用在全局的,这种绑定规则最常见并且是优先级最低的一种绑定规则。来一个例子 function foo() { console.log(this.a); //2 console.log(this === window); //true } var a = 2; foo(); 在浏览器中执行,会发现,如果foo()作为一个函数单独调用,那么this...
- 下一篇
python 数据类型 、运算符
基本的(字面量)值 类型 描述 语法示例 整型 无小数部分的数 42 长整型 大整数 42L 浮点型 有小数部分的数 42.5, 42.5e-2 复合型 实数(整数或浮点数)和虚数的和 38+4j, 42j 字符串 不可变的字符序列 "foo", 'bar', """baz""", r'n' Unicode 不可变的Unicode字符序列 u'foo', u"bar", u"""baz""" 运算符 运算符 描述 优先级 lambda lambda表达式 1 or 逻辑或 2 and 逻辑与 3 not 逻辑非 4 in 成员资格测试 5 not in 非成员资格测试 5 is 一致性测试 6 is not 非一致性测试 6 < 小于 7 > 大于 7 <= 小于或等于 7 >= 大于或等于 7 == 等于 7 != 不等于 7 \ 按位或 8 ^ 按位异或 9 & 按位与 10 << 左移 11 >> 右移 11 + 加法 12 - 减法 12 * 乘法 13 / 除法 13 % 求余 13 + 一元一致性 14 - 一元不一致...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
-
Docker使用Oracle官方镜像安装(12C,18C,19C)
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- CentOS8编译安装MySQL8.0.19
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- MySQL8.0.19开启GTID主从同步CentOS8
- CentOS7,8上快速安装Gitea,搭建Git服务器
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果
推荐阅读
最新文章
- CentOS6,CentOS7官方镜像安装Oracle11G
- Windows10,CentOS7,CentOS8安装Nodejs环境
- CentOS8编译安装MySQL8.0.19
- SpringBoot2整合Thymeleaf,官方推荐html解决方案
- 设置Eclipse缩进为4个空格,增强代码规范
- CentOS7,8上快速安装Gitea,搭建Git服务器
- Windows10,CentOS7,CentOS8安装MongoDB4.0.16
- CentOS7安装Docker,走上虚拟化容器引擎之路
- CentOS6,7,8上安装Nginx,支持https2.0的开启
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题