h2database源码浅析:事务、两阶段提交
Transaction Isolation
Transaction isolation is provided for all data manipulation language (DML) statements. Most data definition language (DDL) statements commit the current transaction. See the Grammar for details.
This database supports the following transaction isolation levels:
- Read Committed
This is the default level. Read locks are released immediately after executing the statement, but write locks are kept until the transaction commits. Higher concurrency is possible when using this level.
To enable, execute the SQL statementSET LOCK_MODE 3
or append;LOCK_MODE=3to the database URL:jdbc:h2:~/test;LOCK_MODE=3 - Serializable
Both read locks and write locks are kept until the transaction commits. To enable, execute the SQL statementSET LOCK_MODE 1
or append;LOCK_MODE=1to the database URL:jdbc:h2:~/test;LOCK_MODE=1 - Read Uncommitted
This level means that transaction isolation is disabled.
To enable, execute the SQL statementSET LOCK_MODE 0
or append;LOCK_MODE=0to the database URL:jdbc:h2:~/test;LOCK_MODE=0
When using the isolation level 'serializable', dirty reads, non-repeatable reads, and phantom reads are prohibited.
- Dirty Reads
Means a connection can read uncommitted changes made by another connection.
Possible with: read uncommitted - Non-Repeatable Reads
A connection reads a row, another connection changes a row and commits, and the first connection re-reads the same row and gets the new result.
Possible with: read uncommitted, read committed - Phantom Reads
A connection reads a set of rows using a condition, another connection inserts a row that falls in this condition and commits, then the first connection re-reads using the same condition and gets the new row.
Possible with: read uncommitted, read committed
Two Phase Commit
The two phase commit protocol is supported. 2-phase-commit works as follows:
- Autocommit needs to be switched off
- A transaction is started, for example by inserting a row
- The transaction is marked 'prepared' by executing the SQL statement
PREPARE COMMIT transactionName - The transaction can now be committed or rolled back
- If a problem occurs before the transaction was successfully committed or rolled back (for example because a network problem occurred), the transaction is in the state 'in-doubt'
- When re-connecting to the database, the in-doubt transactions can be listed with
SELECT * FROM INFORMATION_SCHEMA.IN_DOUBT - Each transaction in this list must now be committed or rolled back by executing
COMMIT TRANSACTION transactionNameorROLLBACK TRANSACTION transactionName - The database needs to be closed and re-opened to apply the changes
h2database源码浅析:事务、两阶段提交的更多相关文章
- 分布式事务 & 两阶段提交 & 三阶段提交
可以参考这篇文章: http://blog.csdn.net/whycold/article/details/47702133 两阶段提交保证了分布式事务的原子性,这些子事务要么都做,要么都不做. 而 ...
- h2database源码浅析:SQL语句的执行
最近想好好了解一下数据库的原理,下载了h2database的源码,准备好好看看.此过程的一些想法,暂且记下来,权当做读码笔记吧! 为了调试准备的测试用例: @Test public void test ...
- h2database源码浅析:集群
Clustering / High Availability This database supports a simple clustering / high availability mechan ...
- h2database源码浅析:锁与MVCC
Table Level Locking The database allows multiple concurrent connections to the same database. To mak ...
- h2database源码浅析:TransactionMap、MVMap、MVStore
TransactionStore:A store that supports concurrent MVCC read-committed transactions. TransactionStore ...
- h2database源码浅析:MVTable与MVIndex
Database包含一个Store:MVTableEngine.Store getMvStore() MVTableEngine.Store可以获取各tables:java.util.HashMap& ...
- 分布式事务 spring 两阶段提交 tcc
请问分布式事务一致性与raft或paxos协议解决的一致性问题是同一回事吗? - 知乎 https://www.zhihu.com/question/275845393 分布式事务11_TCC 两阶段 ...
- Flink EOS如何防止外部系统乱入--两阶段提交源码
一.前言 根据维基百科的定义,两阶段提交(Two-phase Commit,简称2PC)是巨人们用来解决分布式系统架构下的所有节点在进行事务提交时保持一致性问题而设计的一种算法,也可称之为协议. 在F ...
- MySQL源码之两阶段提交
在双1的情况下,两阶段提交的过程 环境准备:mysql 5.5.18, innodb 1.1 version配置: sync_binlog=1 innodb_flush_log_at_trx_comm ...
随机推荐
- HDU4862-Jump(最大流量最大费用流)
题意:有n*m的格子,每一个格子包含一个数字,0-9.你初始的能量为0,你可以玩k次,每一个你可以选择你现在的格子的正下方或者正右方的任意一个格子跳,但必须是之前没有跳过的格子.每玩一次你都可以跳任意 ...
- [OC Foundation框架 - 12] NSNumber
1.概念 NSArray,NSDictionary只能放OC对象,不能放入基本数据类型 必须使用包装类NSNumber,把基本数据类型包装成OC对象 不支持自动包装解包 void number() ...
- 射频识别技术漫谈(8)——动物标签【worldsing笔记】
动物标签也是工作在TTF模式的ID(Identification)卡.之所以通常称为动物标签,估计是因为一来和识别人的ID卡相区分,二是因为动物不如人听话,人的ID卡可以做成卡片形状拿在手上,而动物不 ...
- Java任务调度
最近项目要用到任务调度的相关知识,昨天信心满满的去官网学习,结果被坑个半死,我用的最新版的quartz,文档里说是兼容所有版本,但是代码连编译都报错,无奈只好从网上找资料,摸着石头过河总算有点眉目,在 ...
- Oracle 监听器无法启动(TNS-12537,TNS-12560,TNS-00507)
Oracle启动监听报错,提示 连接中断 [oracle@localhost ~]$ lsnrctl start LSNRCTL for Linux: Version 11.2.0.1.0 - Pro ...
- 2016 Mac OS 10.11 CocoaPods的安装问题
CocoaPods的安装问题: 1.首先用淘宝的Ruby镜像来访问CocoaPods,打开终端输入以下命令: (1)gem sources --remove https://rubygems.org ...
- 教你50招提升ASP.NET性能(三):使用Microsoft的PDBs调试和分析外部的程序集和库
(3)Use Microsoft’s PDBs to debug or profile external assemblies or libraries 招数3: 使用Microsoft的PDBs调试 ...
- 汽车行业的DMS系统 IT不变应万变
DMS是针对4S店的整车销售.零配件仓库.售后维修服务(含车间管理).客服服务涵盖4S店业务进行完整管理的系统,是对销售.维修.客户关系进行一系列的整合.其中,服务的预约.进店接待都有着跟踪处理,客户 ...
- Python、C和Java对比
先上一个Python小测试: #!/usr/bin/env python #coding=utf-8 ''' 等腰三角形 ''' for i in range(1,6): print ' '*(6-i ...
- 解读BOM与COM
概念: 1.BOM(Browser Object Model): 浏览器对象模型,从名字上就能知道它和浏览器关系密切. 浏览器的非常多行为是通过JavaScript控制的.比如打开新窗体.打开关闭标签 ...