使用熟悉一点的系统来测试TitanDB,HBASE+ES,记录下来一些小tips。

1、首先TitanDB支持的Hadoop只有1.2.1,所以Hbase自然也只能取到0.98,虽然官网上提供了titan-1.0-hadoop2,但是并不好用,向hbase存数据时会报错,原因是因为hadoop1的configure格式和hadoop2的不同,创建的config hbase和hadoop没法用,只能退回到上述版本。(ES包是1.5.1,建议使用1.5.2避免奇怪的错误)

2、使用gremlin按照官方文档上的方法进行添加索引(参照官方文档第8节)

mgmt = graph.openManagement()
name = mgmt.getPropertyKey('name')
age = mgmt.getPropertyKey('age')
mgmt.buildIndex('byNameComposite', Vertex.class).addKey(name).buildCompositeIndex()
mgmt.buildIndex('byNameAndAgeComposite', Vertex.class).addKey(name).addKey(age).buildCompositeIndex()
mgmt.commit()
//Wait for the index to become available
mgmt.awaitGraphIndexStatus(graph, 'byNameComposite').call()
mgmt.awaitGraphIndexStatus(graph, 'byNameAndAgeComposite').call()
//Reindex the existing data
mgmt = graph.openManagement()
mgmt.updateIndex(mgmt.getGraphIndex("byNameComposite"), SchemaAction.REINDEX).get()
mgmt.updateIndex(mgmt.getGraphIndex("byNameAndAgeComposite"), SchemaAction.REINDEX).get()
mgmt.commit()

 在执行完mgmt.commit()之后,第一个事物会关闭,一定要重新开一个management才能使用updateIndex。这和0.5.1版本不同

3、JAVA API在添加索引这里有个问题,titan建索引大致是这样:

  (1)创建一个空索引,将其状态设置为registered(mgmt.buildIndex('byNameComposite', Vertex.class).addKey(name).buildCompositeIndex())

  (2)修改索引状态,将其状态设置为install(mgmt.awaitGraphIndexStatus(graph, 'byNameComposite').call())

  (3)将表中现有数据reindex(mgmt.updateIndex(mgmt.getGraphIndex("byNameComposite"), SchemaAction.REINDEX).get())

  JAVA API中没有找到将索引状态转化为install的方法,还在摸索。但是使用gremlin创建的索引在java使用查询时是可以正确使用的。

  这个titan由于活跃度较低,用eclipse import mvn project的方式导入出了各种各样的错误,最后只能用最原始的办法:下载源码包,然后将所有依赖包加进来,虽然还有编译错误,但是至少不影响代码阅读了,找到了Titanfactory.open方法,发现如下:

    public static TitanGraph open(ReadConfiguration configuration) {
return new StandardTitanGraph(new GraphDatabaseConfiguration(configuration));
}

  找到StandardTitanGraph的openManagement方法

    public TitanManagement openManagement() {
return new ManagementSystem(this,backend.getGlobalSystemConfig(),backend.getSystemMgmtLog(), mgmtLogger, schemaCache);
}

  好吧,原来是TitanManagement的子类,找到ManagementSystem类,查看其源码发现:

    public static GraphIndexStatusWatcher awaitGraphIndexStatus(TitanGraph g, String graphIndexName) {
return new GraphIndexStatusWatcher(g, graphIndexName);
}

  原来还是个静态方法,在gremlin中使用的个mgmt.awaitGraphIndexStatus来更改index状态,而在api中是调用静态方法ManagementSystem.awaitGraphIndexStatus(g, indexname)来更改的。。

  不过感觉有点奇怪,我使用updateindex方法更改其状态,titan竟然是把这个更改放在了触发器里而不是直接更改,按理说在不commit的时候是不会涉及到修改底层数据的,为什么要做成触发而且写在log类里?

  现在一套走下来没什么问题了,Titan+HBASE+ES的代码如下(scala):

    val g = TitanFactory.open(conf)
var mgmt = g.openManagement
val name = mgmt getPropertyKey "movieId"
var index = mgmt.buildIndex("movie2WIndex666", classOf[Vertex]).addKey(name).buildCompositeIndex
mgmt.updateIndex(index, SchemaAction.REGISTER_INDEX)
mgmt.commit
val ms = ManagementSystem.awaitGraphIndexStatus(g, "movie2WIndex666").call
println(ms.getTargetStatus)
mgmt = g.openManagement
index = mgmt.getGraphIndex("movie2WIndex666")
println(index.getIndexStatus(name))
mgmt.updateIndex(index, SchemaAction.REINDEX).get
mgmt.commit
val res = g.traversal().V().has("movieId",12345).out()
println(res)
g.close  

4、这个和HBASE连接使用的时get方法,每次get一条数据,所以在没索引的前提下1秒只能检索100条左右的数据,测试时18万条的数据做一遍g.V().has(XX)需要34分钟左右,建立好索引的话查询一条只需要200ms左右。

  建立索引时也是做一遍scan(这里是逐条get),所以百万级的数据对一个属性做CompositeIndex需要好几个小时- -mix索引和更大规模的数据集总感觉有点不对劲。

5、由于上述原因,hbase的连接超时要设置的很长,目前我设置的为180000秒,配置文件如下。

<property>
<name>hbase.rootdir</name>
<value>hdfs://cloud12:9000/hbase</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.master</name>
<value>cloud12:60000</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/home/Titan/hbase/zookeeperDir</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>192.168.12.148</value>
</property>
<property>
<name>hbase.regionserver.lease.period</name>
<value>180000000</value>
</property>
<property>
<name>hbase.rpc.timeout</name>
<value>180000000</value>
</property>

  

Titan DB的一些问题的更多相关文章

  1. Linux平台 Oracle 10gR2(10.2.0.5)RAC安装 Part3:db安装和升级

    Linux平台 Oracle 10gR2(10.2.0.5)RAC安装 Part3:db安装和升级 环境:OEL 5.7 + Oracle 10.2.0.5 RAC 5.安装Database软件 5. ...

  2. VS15 preview 5打开文件夹自动生成slnx.VC.db SQLite库疑惑?求解答

    用VS15 preview 5打开文件夹(详情查看博客http://www.cnblogs.com/zsy/p/5962242.html中配置),文件夹下多一个slnx.VC.db文件,如下图: 本文 ...

  3. ODBC、OLE DB、 ADO的区别

    转自:http://blog.csdn.net/yinjingjing198808/article/details/7665577 一.ODBC ODBC的由来 1992年Microsoft和Syba ...

  4. Linux平台 Oracle 11gR2 RAC安装Part3:DB安装

    四.DB(Database)安装 4.1 解压DB的安装包 4.2 DB软件安装 4.3 ASMCA创建磁盘组 4.4 DBCA建库 4.5 验证crsctl的状态 Linux平台 Oracle 11 ...

  5. SSRS ----环境配置,没有 ReportServer DB 怎么办?

    今天项目进入报表开发阶段,按照习惯,打开报表管理器,发现提示下面的错误: 错误:报表服务器无法打开与报表服务器数据库的连接.所有请求和处理都要求与数据库建立连接. 这是怎么回事儿呢,经过排查,发现数据 ...

  6. mongo DB for C#

    (1)Download the MongoDB C#驱动. http://www.nuget.org/packages/mongocsharpdriver/. (2) Add Reference to ...

  7. jBPM4.4 no jBPM DB schema: no JBPM4_EXECUTION table. Run the create.jbpm.schema target first in the install tool.

    jBPM4.4 no jBPM DB schema: no JBPM4_EXECUTION table. Run the create.jbpm.schema target first in the ...

  8. oracle db link的查看创建与删除

    1.查看dblink select owner,object_name from dba_objects where object_type='DATABASE LINK'; 或者 select * ...

  9. Gc.Db之循序渐进

    距离上次写Gc.Db框架已经有一段时间了,最近默默对框架代码已经做了不少优化和功能,且已经提交至nuget,大家如果想使用此框架,可以通过nuget搜索:Gc.Db进行下载和安装包. 本篇文章主要是介 ...

随机推荐

  1. batch 数字进制的问题

    when set viable to number type in cmdexample: set /a num=0833echo %num% display: Invalid number.  Nu ...

  2. linux c/c++ IP字符串转换成可比较大小的数字

    由www.169it.com搜集整理 IP字符串转换成可比较大小的数字,具体代码如下所示: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 #include "stdio. ...

  3. 免费主机kilu使用

    我也是看了这篇文章:http://www.cnblogs.com/tenny/archive/2011/03/30/1999957.html 采取申请注册. 主机申请地址:http://www.kil ...

  4. bootstrap 分页样式代码

    bootstrap 分页样式代码,废话不多说,直接上源码 <!DOCTYPE html> <html> <head> <title>Bootstrap ...

  5. IOS 如何选择delegate、notification、KVO?(转)

    前面分别讲了delegate.notification和KVO的实现原理,以及实际使用步骤,我们心中不禁有个疑问,他们的功能比较类似,那么在实际的编程中,如何选择这些方式呢? 在网上看到一个博客上详细 ...

  6. 项目中的那些事---PHP函数

    总结工作中遇到的php函数: 1.查找:strpos("str", "substr"): 查找substr字符串在str字符串中出现的位置 第一个参数是:被查找 ...

  7. javascript原生获取元素的方法对比

    document.getElementsByTagName(li)获取的是数组,要获取指定值,需在后面加[0],[1]等,即document.getElementsByTagName(li)[0] d ...

  8. DDL操作前后都有COMMIT

    引用出处: http://www.itpub.net/thread-1746448-1-1.html 要说明这个问题,首先需要说明什么是DDL语句.DDL语句是数据定义语句,包括各种数据对象的创建.修 ...

  9. Ubuntu、Sql Server卸载心得

    这几天真是搞得亏大了! 首先是卸载Ubuntu,直接在Windows下格式化那个盘了,这就出岔子了……然后越来越糟糕,最后弄得一个系统都没有了……然后重装系统…… 然后装VS和Sql Server,因 ...

  10. FileStream使用小记

    流用于对IO处理 在System.IO名称空间中有以下类 BinaryReader/Writer TextReader/Writer Stream 其中类Stream为抽象类.由此有三个派生类: Me ...