到目前为目在我们的例子中使用的图是包含在阿帕奇TinkerPop中的廷克衅。一旦您对小精的学习更进一步,它相关的技术、面向生产环境的布署,您就需要图存储可以提供这些能力,例如:可靠的持久性,定义数据库模式的能力和对于事务ACID的支持。 杰森图项目开始于2016年,是一个开源的巨型图数据库,它由Linux基金会主导,提供了这些高级的能力。
So far we have been using the TinkerGraph graph that is included with Apache TinkerPop in our
examples. Once you move beyond learning about Gremlin and its related technologies and moving
towards a production deployment, you will need a graph store that provides capabilities such as
reliable persistence, the ability to define schemas and support for ACID transactions. The
JanusGraph project, which began in 2016 as an open source fork of the popular Titan graph
database, is hosted by the Linux Foundation and provides these advanced capabilities.
在本书中笔试尝试提供适量的杰森图的内容介绍,但仍推荐您熟悉杰森图官方的文档,您可以从那找到更多关于高级话题的研究和更多您在使用它满足您的需求时很多配置的解释。
In this book I have attempted to provide a reasonable amount of JanusGraph coverage but it is still
recommended to become familiar with the official JanusGraph documentation where you will find
more in depth discussions of advanced topics and explanations of the many settings that you can
manipulate to suit your needs.
杰森图可以从一台桌面电脑上运行,有利于学习和实验,但它设计出来是为了存储在处理分布式聚簇的大型的图。就如我们将要介绍的,杰森图设计出来可以用来与多种不同的持久化方式如阿帕奇 Cassandra,阿帕奇 HBase交互,也可以和阿帕奇 Solr,ES这样的索引技术一起工作。
JanusGraph can run on a laptop, which is useful for learning and experimenting, but it is designed
to handle very large graphs stored on distributed clusters. It can handle graphs containing billions
of vertices and edges. As we shall discuss, JanusGraph is designed to work with a variety of
persistent storage options including Apache Cassandra and Apache HBase as well as indexing
technology such as Apache Solr and Elasticsearch.
这是一些有用的杰森图的资源。
Here are some useful JanusGraph resources
运行时的下载(Jar文件及更多)
Runtime download (JAR files and more)
http://janusgraph.org/
文档
Documentation
http://docs.janusgraph.org/latest/.
API文档
API Documentation
http://docs.janusgraph.org/latest/javadoc.html http://javadoc.io/doc/org.janusgraph/janusgraph
core/0.2.0
在接下来的小节中我们将深入了解杰森图和其它的技术,在联合起来提供一种方式来构建、布署一个大规模图数据库解决方案时。
In the following sections we will take an in depth look at JanusGraph and other technologies that,
when combined, provide a way to build and deploy a massively scalable graph database solution.
在进行更高级的话题哪呢如何中创建和管理数据库模式,索引,如何使用杰森图提供的事务能力之前,我们会从如何快速地安装和从小精灵控制台访问它开始。也推荐您阅读和熟悉杰森图的官方文档和阅读下来出现的内容。
We will start by quickly looking at how to install JanusGraph and access it from the Gremlin
Console before getting into more advanced topics including how to create and manage both
schemas and indexes and how to use the transactional capabilities provided by JanusGraph.
It is also recommended that you read and get familiar with the official JanusGraph documentation
as well as reading what is presented below.
 
6.3.1. 安装杰森图 Installing JanusGraph
杰森图本身很容易安装。您只需下载ZIP压缩文件,解压它到一个合适的位置。之后,您就可以立即开始实验它,如果您采用的是内存模式。这个模式会在下面的“使用杰森图的内存模式”这一节中详细说明。然而如果是生产环境布署,您可能会使用杰森图和其它的一些持久化方案一起使用,还有索引服务和其它的组件也将被安装。我们稍后会了解。下载页面有杰森图与相应的技术如Apache Cassandra and Apache Solr的兼容的版本信息已测试过了。
JanusGraph itself is very easy to install. You just have to download the ZIP file and unzip it into a
convenient location. Having done that you can immediately begin to experiment with it if you use
the inmemory option which is explained more in the Using JanusGraph with the inmemory option
section below. However, for a production deployment you will probably be using JanusGraph in
conjunction with some sort of persistent storage, an indexing service and other components that
will also have to be installed. We will get into that a bit later on. The download page has
information regarding versions of related technologies like Apache Cassandra and Apache Solr that
JanusGraph has been tested with.
重要的是记住:杰森图没有它自己的进程,它不是做为一个您可以运行的服务发布的,相返它是一系列的Java类,可以从您自己的代码中调用它们,或者是从小精灵控制台,使用类似小精灵服务器这样的服务器来管理它。
It is important to remember that JanusGraph does not have its own process, it is
not a delivered as a service that you run, rather it is a set of Java classes that have
to be invoked either from your own code, the Gremlin Console hosted using
something like Gremlin Server.
杰森图的安装包在http://janusgraph.org/ ,是一个ZIP压缩文件。一旦您下载并解压,您就可以开始使用小精灵控制台做实验啦。和前边提到的一样,在使用杰森图时,您必须使用做为它的下载包的一部分的那个版本的小精灵控制台。
The install package for JanusGraph is located at http://janusgraph.org/ and is a single ZIP file. Once
you have it downloaded and unzipped you are ready to experiment using the Gremlin Console. As
will be discussed below, when working with JanusGraph you must use the version of the Gremlin
Console that is packaged as part of the JanusGraph download.
 
6.3.2.从小精灵控制台中使用杰森图  Using JanusGraph from the Gremlin Console
某个版本的小精灵控制台是做为杰森图的安装包的一部分的。这个版本的控制台和您自己从标准的阿帕奇TinkerPop下载中得到的那个控制台的差别就是:这个版本的控制台有一些预配置可以识别和找到杰森图的类。这样的类的典型的例子就是 JanusGraphFactory,它可用在从控制台创建一个新的杰森图实例中。
A version of the Gremlin Console is included as part of the JanusGraph download. The only major
difference between this version of the console and the one you get as part of the standard Apache
TinkerPop download is that the console has been preconfigured to recognize and find the
JanusGraph specific classes. A good example of one such class is JanusGraphFactory that is used
from the Console to create a new JanusGraph instance.
在使用杰森图时,您必须使用做为安装包的一部分的那个版本的小精灵控制台。
When working with JanusGraph you must use the version of the Gremlin Console
that is packaged as part of the JanusGraph download.
如上所术,杰森图不是一个独产的服务,它是一系列Java类,仍需由一个进程调用来激活。小精灵控制台起了这样的作用。在您解压了安装包之后,您就会发现 在JanusGraph目录的bin 目录下的gremlin.sh 和 gremlin.bat 脚本。启动控制台,您就可以告诉杰森图您将运行的环境,用术语说就是后端存储和索引。
As mentioned above, JanusGraph is not a standalone service, it is a set of Java classes that still need
to be invoked by a calling process. The Gremlin Console can play that role. After you have unzipped
JanusGraph you will find the gremlin.sh and gremlin.bat scripts in the bin directory under the
JanusGraph parent directory. Once you have started the Gremlin Console you can, as we will
explore in the next few sections, tell JanusGraph about the environment you will be operating in in
terms of back end store and index.
6.3.3. 使用内存模式的杰森图 Using JanusGraph with the inmemory option
对于大多数的生产环境。您将会把杰森图和类似Apache Cassandra 或 Apache HBase这样的后端持久化环境一起使用。然而在进行杰森图的实验时,内存模式足够使用了,可以快速启动运行,无需担心配置后端存储组件。这种可能性是由杰森图的内存模式这一选项提供的。这允许我们像使用其它在计算的内存中的图数据库中使用廷克图一样,使用杰森图。然而杰森图与它们最大的差异就是,即使是使用内存模式,它也允许我们实验一些廷克图没有提供的特性,例如数据库模式,事务。我们可以在稍后讨论这些话题。首先让我们通过在小精灵控制台使用内存存储模式创建一个杰森图的实例。
For almost all production use cases, you will be using JanusGraph along with a persistent back end
store such as Apache Cassandra or Apache HBase. However while experimenting with JanusGraph
it is incredibly useful to be able to get up and running quickly without having to worry about
configuring all of the back end storage components. This is made possible by the inmemory option
that JanusGraph provides. This essentially allows us to use JanusGraph in the same way as we have
been using TinkerGraph with all of our graph data stored in the memory of the computer. The one
big difference however is that JanusGraph, even while using the inmemory storage model, allows us
to experiment with features that TinkerGraph does not offer, such as schemas and transactions. We
will get into those topics a bit later on. First, let’s create an instance of JanusGraph from the
Gremlin console that uses the inmemory storage model.
创建一个杰森图实例非常类似于我们在本书前边创建廷克图实例。唯一的区别是我们用到了JanusGraphFactory来创建图,在这个例子中我们指定了一个参数inmemory ,来告诉杰森图我们想要使用内存存储模式。我们和以前一样创建了图遍历对象g.
Creating a JanusGraph instance is very similar to the way we created a TinkerGraph instance
earlier in the book. The only difference is that we use the JanusGraphFactory to create the graph
and in this case we specify inmemory as the only parameter to tell JanusGraph that we want to use
the all in memory storage model. We create our graph traversal object g in just the same way as
before.
 

 

 注意上面的命令是下面的命令的一个缩写形式。

Note that the open command above is a shorthand form of the command shown below.
 

 

 现在我们已经创建了一个图实例,就像在廷克图中一样,我们可以查询图支持的特性。在本书最开始“廷克图介绍”这一节中我们查看了廷克衅所提供的特性。如果我们比较这些特性与杰森图提供给我们的特性,就可以说出关键的差异。

Now that we have a graph instance created, just like with TinkerGraph, we can query which
features the graph supports. Earlier in the book in the "Introducing TinkerGraph" section we looked
at the features offered by TinkerGraph. If we compare those features to what JanusGraph offers we
can spot some key differences.
通过调用graph.feature方法我们可以得到特性的集合,如下所示。要说明的第一件事就是各种特征,包括事务现在都设为真,这说明杰森图支持事务。我们将在下一节看到如何去使用这些事务特性。注意持久性仍然显示为false,因为我们使用的是内存模式。另一件要注意的事情是:不像廷克图,UserSuppliedIds的设置是false,这说明杰森图将会创建它自己的ID值,忽略我们提供的。为了帮助阅读列表分两栏显示。
We can get the feature set back by calling the features method as shown below. The first thing that
stands out is that the various features that involve transactions are now set to true indicating that
JanusGraph supports transactions. We will take a look at how to use these transactional capabilities
in the next section. Note that Persistence still shows as false as we are using the inmemory mode.
Another thing to note is that, unlike with TinkerGraph, UserSuppliedIds is set to false, indicating
that JanusGraph will create its own ID values and ignore any that we provide. The list is formatted
in two columns to aid readability.
 

 

 

 现在我们有了一个内存杰森图的空实例,我们可以从小精灵控制台使用它,就像我们在前边的例子中使用廷克图时一样。注意杰森图生成的ID值与我们在廷克图中用的,看起来很不一样(它们不是从0开始的)

Now that we have an empty instance of an inmemory JanusGraph we can use it from the Gremlin
Console just as we did with TinkerGraph in our prior examples. Notice that the ID values that
JanusGraph generates look quite different (as in they don’t start at zero) from what we might
expect from TinkerGraph.
 

 

 在我们使用杰森图进行各种实验前,有三件重要的事要讨论。 第一,事务,另一个是定义数据库模式,为顶点、边和属性定义索引,第三件是杰森图的管理API。我们会在下面的小节中依次讨论这三个关键的话题。

Before we experiment too much more with JanusGraph there are three important subjects we need
to discuss. One is transactions, another is defining a schema and indexes for our vertices, edges and
properties and the third is the JanusGraph management API. We will cover each of these key
subjects in the following sections.
posted on 2022-05-02 11:48  bokeyuannicheng0000  阅读(53)  评论(0)    收藏  举报