titan 学习1

titan是一个可扩展的图形数据库,用于存储和查询包含数百亿的顶点和边分布在一个多机集群的图表。titan是事务性数据库,可以支持的并发用户在实时执行复杂的图遍历的千。
此外,titan提供以下功能:
一个不断增长的数据和用户基础的弹性和线性可扩展性。
性能和容错的数据分布和复制。
多数据中心的高可用性和热备份。
acid的支持和最终的一致性。
各种存储后端支持:
Apache Cassandra
Apache HBase
Oracle BerkeleyDB
支持全局图数据分析报告,并通过大数据平台集成的ETL:
Apache Spark

 Apache Giraph

Apache Hadoop


支持地理,数字范围和全文搜索:
Elasticsearch
Solr
Lucene
与tinkerpop图栈原生集成:
Gremlin图查询语言
Gremlin图服务器
Gremlin的应用
在自由开源的Apache 2许可证。
从GitHub下载titan或克隆。阅读titan文档并加入邮件列表。

2章。建筑概要
titan是一个图形数据库引擎。titan本身是专注于紧凑的图形系列化,丰富的图形数据建模,高效的查询执行。此外,titan利用图形分析和批量图形处理的Hadoop。titan实现强大的,模块化的数据持久性,数据索引,和客户端访问接口。titan的模块化结构使它具有广泛的存储、索引进行互操作,以及客户端技术;它还简化了扩展以支持新的titan的过程。
titan和磁盘之间,有一个或多个存储和索引适配器。titan的标准与以下的适配器,但titan的模块化架构,支持第三方适配器。
数据存储:
卡桑德拉
HBase
BerkeleyDB
指数,加快,使更复杂的查询:
Elasticsearch
Lucene
从广义上讲,应用程序可以用2种方式与titan进行交互:
嵌入在应用程序执行查询titan小鬼直接对图在相同的JVM。执行查询,titan的缓存和事务处理都发生在同一个JVM的应用而从后端存储数据检索可能是本地或远程。
与本地或远程实例的titan服务器提交查询交互的小鬼。titan本身支持的tinkerpop堆栈的小鬼服务器组件。

内容表
3.1。下载titan和小鬼壳运行
3.2。将神的图载入titan
3.3。全局图指数
3.3.1。图遍历实例
3.3.2。更复杂的图遍历实例

 

在开始时,存在两个神被称为天王星和盖亚。他们生了titan(一个强大的种族)。土星,titan的时间,在运动中设置现实。最终,时间产生了天空,大海和生命终结的死亡。为了统治这些观念,土星有三个儿子:木星(天空),海王星(海),冥王星(黑社会)。土星的儿子是不是巨人,但一场看似不那么强大的神,被全世界称为神。害怕他的儿子们会推翻他,土星把他们吞下去,把他们囚禁在他的肚子里。这引起了titan神之间的伟大战争。最终,众神赢得了,而木星又把王位作为神的领袖。
在这一节中的例子,使广泛使用的一个玩具图分布与titan称为神的图形。这图是下面的图。抽象的数据模型称为属性图模型和这个特殊的实例描述了人与场所的关系罗马神殿。此外,图中文字和符号的特殊改性剂(如粗体,下划线等)表示不同的原理图/打字在图。

 

 

意义
大胆的钥匙
图索引键
大胆的关键与明星
必须具有唯一值的图形索引键
下划线键
一个以顶点为中心的索引键
空心头边缘
功能/独特优势(无重复)
尾缘
单向边(只能在一个方向移动)

3.1。下载titan和小鬼壳运行
众神都不知道,还住在一个titan。这个titan无法看见,没有名字,只有现实存在的事实。在这失去的titan的肩膀上,所有的现实都是一个起伏的网络中的关系。
titan可以从项目库的下载部分下载。一旦被打开,一个小鬼控制台可以打开。小鬼REPL(即交互式shell)分布与titan和唯一不同于标准的小鬼控制台只要titan是一个预安装和预加载的包。另外,用户可以选择安装和激活titan在现有的小鬼控制台通过从中央存储库下载titan包。在下面的例子中,titan.zip使用,但一定要解压缩zip文件下载。
重要的
titan需要8(标准版)。8是推荐的。titan的shell脚本预计,美元java_home环境变量指向目录JRE或JDK的安装。

 

$ unzip titan-1.0.0-hadoop1.zipArchive:  titan-1.0.0-hadoop1.zip  creating: titan-1.0.0-hadoop1/...$ cd titan-1.0.0-hadoop1$ bin/gremlin.sh         \,,,/         (o o)-----oOOo-(3)-oOOo-----09:12:24 INFO  org.apache.tinkerpop.gremlin.hadoop.structure.HadoopGraph  - HADOOP_GREMLIN_LIBS is set to: /usr/local/titan/libplugin activated: tinkerpop.hadoopplugin activated: aurelius.titangremlin>

 

 

注意,本教程假设更为简明的语法的tinkerpop.sugar包激活。请参阅tinkerpop文献在包处理的更多信息。
小鬼终端是一个常规的壳。Groovy是一个Java的超集,有各种各样的速记符号,使编程更容易。同样,小鬼是一个超集各种速记符号,使图遍历的简单常规。下面的基本实例演示处理数字、字符串和地图。本教程的其余部分将讨论图的具体构造。

 

gremlin> 100-10==>90

gremlin> "Titan:" + " The Rise of Big Graph Data"==>Titan: The Rise of Big Graph Data

gremlin> [name:'aurelius', vocation:['philosopher', 'emperor']]==>name=aurelius==>vocation=[philosopher, emperor]

下面的示例将打开一个titan图实例和负载的神图数据集上面的图。titanfactory提供了一组静态开放的方法,其中每个需要配置的参数并返回一个图实例。本教程中调用这些方法在开放配置使用BerkeleyDB存储后端和Elasticsearch指数后端,然后加载使用助手类graphofthegodsfactory神图。这段跳过配置细节,但相关的额外信息的存储后端,后端的配置指标,可在第三部分中,“存储后端”,第四部分,“指数的后台”,和12章,参考配置。

gremlin> graph = TitanFactory.open('conf/titan-berkeleyje-es.properties')==>standardtitangraph[berkeleyje:../db/berkeley]

gremlin> GraphOfTheGodsFactory.load(graph)==>null

gremlin> g = graph.traversal()==>graphtraversalsource[standardtitangraph[berkeleyje:../db/berkeley], standard]

 

他titanfactory。open()和graphofthegodsfactory。()方法做以下新建图返回它之前:
创建全局和顶点为中心的指数图。
将所有的顶点添加到图中,以及它们的属性。
将所有的边添加到图形中,以及它们的属性。

For those using Titan/Cassandra (or Titan/HBase), be sure to make use of conf/titan-cassandra-es.properties (or conf/titan-hbase-es.properties) and GraphOfTheGodsFactory.load().

gremlin> graph = TitanFactory.open('conf/titan-cassandra-es.properties')==>standardtitangraph[cassandrathrift:[127.0.0.1]]

gremlin> GraphOfTheGodsFactory.load(graph)==>null

gremlin> g = graph.traversal()==>graphtraversalsource[standardtitangraph[cassandrathrift:[127.0.0.1]], standard]

 

 

在图形数据库中访问数据的典型模式是首先使用图形索引将输入点定位为图形。这个切入点是一个元素(或元素) - 即顶点或边。从入门的元素,一个小鬼路径描述如何遍历图中的其他元素通过显式图结构。
鉴于有一个独特的名字属性指数,土星的顶点可以检索。属性映射(即关键/值对土星),然后可以检查。研究表明,土星的顶点有“土星的名字,”一个10000岁,一种“titan”。土星的孙子可以遍历表示:“谁是检索到土星的孙子吗?”(“父亲”是“孩子”)。其结果是大力士。

 

gremlin> saturn = g.V().has('name', 'saturn').next()==>v[256]

gremlin> g.V(saturn).valueMap()==>[name:[saturn], age:[10000]]

gremlin> g.V(saturn).in('father').in('father').values('name')==>hercules

 

属性位置也在图形索引中。这个属性是一个边属性。因此,titan可以在图指数中的边。在雅典50公里(纬度:23.72和37.97)的所有事件中,可以查询神的图。然后,给定的信息,哪些顶点被涉及在这些事件。

 

 

 

 

 

gremlin> g.E().has('place', geoWithin(Geoshape.circle(37.97, 23.72, 50)))==>e[a9x-co8-9hx-39s][16424-battled->4240]==>e[9vp-co8-9hx-9ns][16424-battled->12520]

gremlin> 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')==>[god1:hercules, god2:hydra]==>[god1:hercules, god2:nemean]

 

 

图指数是titan上的一类指标结构。图指标是由titan回答所要求的所有顶点选择自动(化)或边缘(G.e),满足一个或多个约束条件(如有或间隔)。在titan的第二个方面是被称为顶点为中心的指数。顶点为中心的指标是用来加快里面的图遍历。顶点为中心的指标进行说明。

 

 

大力士,儿子朱庇特和阿尔克墨涅,孔超人类的力量。他是一个神,因为他的父亲是一个神,他的母亲是一个人类。朱诺,木星的妻子,对木星的不忠感到愤怒。为了报复,她弄瞎了大力神与暂时性精神错乱,使他杀死自己的妻子和孩子。为了弥补这个杀害,大力士的特尔斐神谕下令俄瑞斯忒斯。俄瑞斯忒斯派大力神12劳动力。
在上一节中,它表明,土星的孙子是大力士。这可以用一个循环来表示。在本质上,他是顶点,两级离土星沿在(父亲的)路径。

gremlin> hercules = g.V(saturn).repeat(__.in('father')).times(2).next()==>v[1536]

 

 

 

他是一个神。为了证明他是半人半神,他父母的起源必须检查。这是可能的遍历从大力神顶点到他的父亲和母亲。最后,可以确定每一种人 - 屈服的“神”和“人”。

 

gremlin> g.V(hercules).out('father', 'mother')==>v[1024]==>v[1792]

gremlin> g.V(hercules).out('father', 'mother').values('name')==>jupiter==>alcmene

gremlin> g.V(hercules).out('father', 'mother').label()==>god==>human

gremlin> hercules.label()==>demigod

 

实例为止一直就在罗马万神殿的各种行为者的遗传线。属性图模型具有足够的表达能力来表示多类型的事情和关系。这样,神的图还确定了赫拉克勒斯的各种英雄事迹,他著名的12劳动力。在上一节中,它被发现,他是参与雅典附近两仗。可以通过探索这些事件与边缘的大力士顶点。

gremlin> g.V(hercules).out('battled')==>v[2304]==>v[2560]==>v[2816]

gremlin> g.V(hercules).out('battled').valueMap()==>[name:[nemean]]==>[name:[hydra]]==>[name:[cerberus]]

gremlin> g.V(hercules).outE('battled').has('time', gt(1)).inV().values('name')==>cerberus==>hydra

 

边缘属性的时间是由顶点为中心的顶点索引的顶点。检索与边缘入射到大力士根据约束/过滤时间比做线性边缘和过滤扫描(通常为O(log n),其中n是多少事件的边缘)。titan是聪明的,可以使用顶点为中心的指标时,可用。一个tostring()一小鬼表达具有分解成各个步骤。

gremlin> g.V(hercules).outE('battled').has('time', gt(1)).inV().values('name').toString()==>[GraphStep([v[24744]],vertex), VertexStep(OUT,[battled],edge), HasStep([time.gt(1)]), EdgeVertexStep(IN), PropertiesStep([name],value)]

 

在地狱深处生活的冥王星。他与大力神赫拉克勒斯的事实与他的宠物狗紧张。然而,他是他的侄子 - 他要如何让他支付他的无礼?
下面的例子在小鬼遍历提供更多的神图。每一个遍历的解释是在前一行作为一个/ /评论。

gremlin> pluto = g.V().has('name', 'pluto').next()==>v[2048]

gremlin> // who are pluto's cohabitants?

gremlin> g.V(pluto).out('lives').in('lives').values('name')==>pluto==>cerberus

gremlin> // pluto can't be his own cohabitant

gremlin> g.V(pluto).out('lives').in('lives').where(is(neq(pluto))).values('name')==>cerberus

gremlin> g.V(pluto).as('x').out('lives').in('lives').where(neq('x')).values('name')==>cerberus

 

 

gremlin> // where do pluto's brothers live?

gremlin> g.V(pluto).out('brother').out('lives').values('name')==>sky==>sea

gremlin> // which brother lives in which place?

gremlin> g.V(pluto).out('brother').as('god').out('lives').as('place').select()==>[god:v[1024], place:v[512]]==>[god:v[1280], place:v[768]]

gremlin> // what is the name of the brother and the name of the place?

gremlin> g.V(pluto).out('brother').as('god').out('lives').as('place').select().by('name')==>[god:jupiter, place:sky]==>[god:neptune, place:sea]

 

 

最后,布鲁托住在地狱因为他不关心死亡。他的兄弟,另一方面,选择了他们的位置,根据他们对这些位置的某些品质的爱。

 

gremlin> g.V(pluto).outE('lives').values('reason')==>no fear of death

gremlin> g.E().has('reason', textContains('loves'))==>e[6xs-sg-m51-e8][1024-lives->512]==>e[70g-zk-m51-lc][1280-lives->768]

gremlin> g.E().has('reason', textContains('loves')).as('source').values('reason').as('reason').select('source').outV().values('name').as('god').select('source').inV().values('name').as('thing').select('god', 'reason', 'thing')==>[god:neptune, reason:loves waves, thing:sea]==>[god:jupiter, reason:loves fresh breezes, thing:sky]

 

 

 

内容表
4.1。实例配置
4.1.1。卡桑德拉Elasticsearch
4.1.2。HBase的缓存
4.1.3。BerkeleyDB
4.1.4。进一步的例子
4.2。使用配置
4.2.1。titanfactory
4.2.2。titan服务器
4.3。全球配置
4.3.1。改变离线选

titan图数据库集群由一个或多个titan实例。要打开一个titan的实例,必须提供一个配置,它指定了titan应该如何设置。
titan的配置指定titan应该使用的组件,控制titan部署的所有操作方面,并提供了一些调整选项,以获得最大的性能从titan集群。
在最低限度,titan配置必须定义的持久性引擎,titan应该使用作为存储后端。第三部分,“存储后端”列出所有支持的持久引擎和如何配置它们分别。如果高级图形查询支持(如全文检索、地理搜索、或范围查询),则需要一个额外的索引后端来配置。看到第四部分”的细节指标的后台”。如果查询性能是一个问题,则应该启用缓存。高速缓存配置和调整是在第10章中描述的,titan高速缓存。
4.1。实例配置
下面是一些示例配置文件说明了如何配置最常用的存储后端,索引系统,和性能的组件。这只涵盖了可用的配置选项的一小部分。参考12章,对所有选项的完整列表进行配置引用。

建立了titan使用Cassandra持久引擎运行在本地和远程弹性搜索索引系统:

storage.backend=cassandras

torage.hostname=localhost

index.search.backend=elasticsearch

index.search.hostname=100.100.101.1, 100.100.101.2

index.search.elasticsearch.client-only=true

 

 

建立了titan使用HBase的持久引擎运行远程使用titan的缓存组件提供更好的性能。

 

storage.backend=hbase

storage.hostname=100.100.101.1

storage.port=2181

cache.db-cache = true

cache.db-cache-clean-wait = 20

cache.db-cache-time = 180000

cache.db-cache-size = 0.5

 

建立了titan使用BerkeleyDB作为嵌入式持久引擎Elasticsearch作为一个嵌入式的索引系统。

storage.backend=berkeleyje

storage.directory=/tmp/graph

index.search.backend=elasticsearch

index.search.directory=/tmp/searchindex

index.search.elasticsearch.client-only=false

index.search.elasticsearch.local-mode=true

 

 

有几个例子配置文件在conf/目录可以用来开始titan快。这些文件的路径可以通过titanfactory。开放(…)如下图所示:

// Connect to Cassandra on localhost using a default configuration

graph = TitanFactory.open("conf/titan-cassandra.properties")// Connect to HBase on localhost using a default configuration

graph = TitanFactory.open("conf/titan-hbase.properties")

 

titan分布包含一个命令行控制台,这使得它很容易上手,并与titan互动。调用斌/ gremlin.sh(Unix / Linux)或仓/ gremlin.bat(Windows)启动控制台,然后打开一个titan图使用工厂和存储在一个可访问的属性配置文件的配置:

graph = TitanFactory.open('path/to/configuration.properties')

titanfactory也可以用来打开一个嵌入式titan图实例从一个基于JVM的用户应用。在这种情况下,titan是用户应用程序的一部分,应用程序可以通过它的公共接口文档直接调用titan

 

如果titan图论聚类已预先配置和/或只有后端存储需要被定义,titanfactory接受一个冒号分隔的字符串表示形式存储后端的名称和主机名或目录。

graph = TitanFactory.open('cassandra:localhost')

graph = TitanFactory.open('berkeleyje:/tmp/graph')

通过客户端远程或另一个进程进行交互,titan“服务器”需要配置和启动。在内部,titan使用的tinkerpop堆小鬼服务器服务客户端的请求,因此,配置titan服务器通过服务器配置文件完成的小鬼。
与titangraph审小鬼服务器配置文件需要以下设置服务器配置的小鬼:

...

graphs: {

  graph: conf/titan-berkeleyje.properties

}

plugins:

  - aurelius.titan

...

图的输入定义特定titangraph配置绑定。在上述情况下结合图titan配置在conf/ titan-berkeleyje.properties。这意味着,当引用titangraph远程上下文,这个图可以简单地被称为G的脚本发送到服务器。插件入口只是使titan小鬼插件,使得土卫六类进口汽车使他们可以在脚本中引用远程提交。
关于使用和连接到titan服务器在第7章,titan服务器。

 

titan的zip文件包含一个快速启动的服务器组件,使它更容易上手的小鬼服务器和titan。调用斌/ gremlin-server.sh可选使用后续包含配置文件的路径参数。默认情况下,没有这样的说法,包装小鬼服务器将指向下gremlin-server.yaml是预配置一个titan伯克利实例如上面的示例配置显示。

titan区分本地和全局配置选项。本地配置选项适用于单个titan实例。全局配置选项适用于集群中的所有实例。更具体地说,titan区分下列五个配置选项的范围:
当地人:这些选项只适用于个别titan实例和在配置初始化实例时指定的titan
屏蔽:这些配置选项可以覆盖一个人的titan实例的本地配置文件。如果本地配置文件没有指定选项,它的值是从“全局”titan群集配置中读取的。
全球:这些选项总是从群集配置和无法读取被覆盖在一个实例的基础上。
global_offline:全球,但更改这些选项需要一个集群重新启动以确保值相同的整个集群。
固定:如全球,但价值是不能改变的,一旦titan集群被初始化。
当一个集群中的第一个“titan”实例开始时,将从所提供的本地配置文件中初始化全局配置选项。随后改变全球配置选项是通过titan的管理。访问管理API,叫G getmanagementsystem()开放titan实例句柄:例如,更改默认的缓存行为对titan集群:

mgmt = graph.openManagement()mgmt.get('cache.db-cache')// Prints the current config settingmgmt.set('cache.db-cache', true)// Changes optionmgmt.get('cache.db-cache')// Prints 'true'mgmt.commit()// Changes take effect

更改配置选项不影响运行实例,只适用于新启动的。改变global_offline配置选项需要重新启动群集以便更改立即生效的所有实例。改变global_offline选择遵循这些步骤:
关闭所有但在集群中的一个titan实例
连接到一个实例
确保所有正在运行的事务都被关闭
确保没有启动新的交易(即集群必须处于离线状态)
开放管理
改变配置选项(的)
调用将自动关闭图形实例的提交
重新启动所有实例
在12章中,参考了配置选项的全部列表,包括每个选项的配置范围在内的更多信息的配置参考。


转载于:https://my.oschina.net/u/269325/blog/552580

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
About This Book Explore the integration of Apache Spark with third party applications such as H20, Databricks and Titan Evaluate how Cassandra and Hbase can be used for storage An advanced guide with a combination of instructions and practical examples to extend the most up-to date Spark functionalities Who This Book Is For If you are a developer with some experience with Spark and want to strengthen your knowledge of how to get around in the world of Spark, then this book is ideal for you. Basic knowledge of Linux, Hadoop and Spark is assumed. Reasonable knowledge of Scala is expected. What You Will Learn Extend the tools available for processing and storage Examine clustering and classification using MLlib Discover Spark stream processing via Flume, HDFS Create a schema in Spark SQL, and learn how a Spark schema can be populated with data Study Spark based graph processing using Spark GraphX Combine Spark with H20 and deep learning and learn why it is useful Evaluate how graph storage works with Apache Spark, Titan, HBase and Cassandra Use Apache Spark in the cloud with Databricks and AWS In Detail Apache Spark is an in-memory cluster based parallel processing system that provides a wide range of functionality like graph processing, machine learning, stream processing and SQL. It operates at unprecedented speeds, is easy to use and offers a rich set of data transformations. This book aims to take your limited knowledge of Spark to the next level by teaching you how to expand Spark functionality. The book commences with an overview of the Spark eco-system. You will learn how to use MLlib to create a fully working neural net for handwriting recognition. You will then discover how stream processing can be tuned for optimal performance and to ensure parallel processing. The book extends to show how to incorporate H20 for machine learning, Titan for graph based storage, Databricks for cloud-based Spark. Intermediate Scala based code examples are provided for Apache Spark module processing in a CentOS Linux and Databricks cloud environment. Table of Contents Chapter 1: Apache Spark Chapter 2: Apache Spark Mllib Chapter 3: Apache Spark Streaming Chapter 4: Apache Spark Sql Chapter 5: Apache Spark Graphx Chapter 6: Graph-Based Storage Chapter 7: Extending Spark With H2O Chapter 8: Spark Databricks Chapter 9: Databricks Visualization

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值