JanusGraph中的事务
Transaction Handling
juno = graph.addVertex() //Automatically opens a new transaction
juno.property("name", "juno")
graph.tx().commit() //Commits transaction
graph = JanusGraphFactory.open("berkeleyje:/tmp/janusgraph")
juno = graph.addVertex() //Automatically opens a new transaction
juno.property("name", "juno")
graph.tx().commit() //Commits transaction
Transaction Scope
juno = graph.addVertex() //Automatically opens a new transaction
graph.tx().commit() //Ends transaction
juno.property("name", "juno") //Vertex is automatically transitioned
graph = JanusGraphFactory.open("berkeleyje:/tmp/janusgraph")
juno = graph.addVertex() //Automatically opens a new transaction
graph.tx().commit() //Ends transaction
juno.property("name", "juno") //Vertex is automatically transitioned
Transaction Failures
try {
if (g.V().has("name", name).iterator().hasNext())
throw new IllegalArgumentException("Username already taken: " + name)
user = graph.addVertex()
user.property("name", name)
graph.tx().commit()
} catch (Exception e) {
//Recover, retry, or return error message
println(e.getMessage())
}
- Potentially temporary failures
- Permanent failures
Multi-Threaded Transactions
threadedGraph = graph.tx().createThreadedTx();
threads = new Thread[10];
for (int i=0; i<threads.length; i++) {
threads[i]=new Thread({
println("Do something with 'threadedGraph''");
});
threads[i].start();
}
for (int i=0; i<threads.length; i++) threads[i].join();
threadedGraph.tx().commit();
Nested Transactions 嵌套事务
v1 = graph.addVertex()
//Do many other things
v2 = graph.addVertex()
v2.property("uniqueName", "foo")
v1.addEdge("related", v2)
//Do many other things
graph.tx().commit() // This long-running tx might fail due to contention on its uniqueName lock
v1 = graph.addVertex()
//Do many other things
tx = graph.tx().createThreadedTx()
v2 = tx.addVertex()
v2.property("uniqueName", "foo")
tx.commit() // Any lock contention will be detected here
v1.addEdge("related", g.V(v2).next()) // Need to load v2 into outer transaction
//Do many other things
graph.tx().commit() // Can't fail due to uniqueName write lock contention involving v2
Common Transaction Handling Problems
v = g.V(4).next() // Retrieve vertex, first action automatically starts transaction
g.V(v).bothE()
>> returns nothing, v has no edges
//thread is idle for a few seconds, another thread adds edges to v
g.V(v).bothE()
>> still returns nothing because the transactional state from the beginning is maintained
从上面的代码中可以看出,由于事务没有结束,对象的状态得意维持,另外线程的更改没有体现出来。这个问题通常出现在客户端-服务器模式部署的场景下,为了解决此问题,用户需要在执行完毕后手工调用commit()方法。
v = g.V(4).next() // Retrieve vertex, first action automatically starts transaction
g.V(v).bothE()
graph.tx().commit()
//thread is idle for a few seconds, another thread adds edges to v
g.V(v).bothE()
>> returns the newly added edge
graph.tx().commit()
在使用multi-threaded事务时,在事务范围内创建的所有的vertices和edges在事务外均不可见,在事务结束后访问这些元素将会导致错误。根据上面展示的,这些element需要在新事务中显示刷新,使用:
g.V(existingVertex)或者g.E(existingEdge)
Transaction Configruation
- readOnly()
- enableBatchLoading()
- setTimestamp()
- setVertexCacheSize(long)
- checkExternalVertexExistence(boolean)
- checkInternalVertexExistence(boolean)
- consistencyChecks(boolean)
JanusGraph中的事务的更多相关文章
- Microsoft SQL Server中的事务与并发详解
本篇索引: 1.事务 2.锁定和阻塞 3.隔离级别 4.死锁 一.事务 1.1 事务的概念 事务是作为单个工作单元而执行的一系列操作,比如查询和修改数据等. 事务是数据库并发控制的基本单位,一条或者一 ...
- Redis系列之key操作命令与Redis中的事务详解(六)
序言 本篇主要目的有二: 1.展示所有数据类型中key的所有操作命令,以供大家学习,查阅,更深入的挖掘redis潜力. 2.掌握redis中的事务,让你的数据完整性一致性拥有更优的保障. redis命 ...
- SQL Server 中的事务与事务隔离级别以及如何理解脏读, 未提交读,不可重复读和幻读产生的过程和原因
原本打算写有关 SSIS Package 中的事务控制过程的,但是发现很多基本的概念还是需要有 SQL Server 事务和事务的隔离级别做基础铺垫.所以花了点时间,把 SQL Server 数据库中 ...
- 【转】SQL Server中的事务与锁
SQL Server中的事务与锁 了解事务和锁 事务:保持逻辑数据一致性与可恢复性,必不可少的利器. 锁:多用户访问同一数据库资源时,对访问的先后次序权限管理的一种机制,没有他事务或许将会一塌糊涂 ...
- 存储过程中使用事务,sql server 事务,sql事务
一.存储过程中使用事务的简单语法 在存储过程中使用事务时非常重要的,使用数据可以保持数据的关联完整性,在Sql server存储过程中使用事务也很简单,用一个例子来说明它的语法格式: 代码 ...
- 【MySQL】漫谈MySQL中的事务及其实现
最近一直在做订单类的项目,使用了事务.我们的数据库选用的是MySQL,存储引擎选用innoDB,innoDB对事务有着良好的支持.这篇文章我们一起来扒一扒事务相关的知识. 为什么要有事务? 事务广泛的 ...
- SQL Server中的事务日志管理(9/9):监控事务日志
当一切正常时,没有必要特别留意什么是事务日志,它是如何工作的.你只要确保每个数据库都有正确的备份.当出现问题时,事务日志的理解对于采取修正操作是重要的,尤其在需要紧急恢复数据库到指定点时.这系列文章会 ...
- Spring中的事务
Spring配置文件中关于事务配置总是由三个组成部分,分别是DataSource.TransactionManager和代理机制这三部分,无论哪种配置方式,一般变化的只是代理机制这部分. DataSo ...
- SQL2005中的事务与锁定(八)- 转载
------------------------------------------------------------------------ -- Author : happyflystone - ...
随机推荐
- Unity中Invoke 和 InvokeRepeating的区别
Invoke() 方法是 Unity3D 的一种委托机制 如: Invoke("Test", 5); 它的意思是:5 秒之后调用 Test() 方法: 使用 Invoke() ...
- OpenVPN官方资源下载和官方教程入口
官方资源: https://openvpn.net/index.php/open-source/downloads.html 2.4.4版本下载:(链接: https://pan.baidu.com/ ...
- iOS-Runtime、对象模型、消息转发
Objective-C只是在C语言层面上加了些关键字和语法.真正让Objective-C如此强大的是它的运行时.它很小但却很强大.它的核心是消息分发. Message 执行一个方法,有些语言.编译器会 ...
- iOS:KVC和KVO
来源: 对月流 链接:http://www.jianshu.com/p/f1393d10109d 写在前面: 关于KVC和KVO各种博客多了去了,重新整理下,就当是温习一下吧,也还算是个新手,不对的 ...
- delphi 查看编译版本
对照表: http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Compiler_Versions procedure TForm1.Button1Cli ...
- java 实现poi方式读取word文件内容
1.下载poi的jar包 下载地址:https://www.apache.org/dyn/closer.lua/poi/release/bin/poi-bin-3.17-20170915.tar.gz ...
- 如何使用 awk 的 ‘next’ 命令
导读 在 awk 系列文章中,我们来看一下next 命令 ,它告诉 awk 跳过你所提供的所有剩下的模式和表达式,直接处理下一个输入行.next 命令帮助你阻止运行命令执行过程中多余的步骤. 要明白它 ...
- automake连载--Linux下使用autoconfig automake进阶
http://blog.csdn.net/shanzhizi/article/details/30247325 前言: 这次task,我大概用了4天的时间去完成.四天的时间内,我不停地去查 ...
- PHP上传文件类 代码练习
类文件: <?php class upload{ protected $fileName; protected $uploadPath; protected $maxSize; protecte ...
- sip
INVITE sip:10010101402@10.7.36.70:5060 SIP/2.0 Via: SIP/2.0/UDP 10.7.36.250:5060;rport;branch=z9hG4b ...