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 statement SET LOCK_MODE 3
    or append ;LOCK_MODE=3 to 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 statement SET LOCK_MODE 1
    or append ;LOCK_MODE=1 to the database URL: jdbc:h2:~/test;LOCK_MODE=1
  • Read Uncommitted
    This level means that transaction isolation is disabled.
    To enable, execute the SQL statement SET LOCK_MODE 0
    or append ;LOCK_MODE=0 to 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 transactionName or ROLLBACK TRANSACTION transactionName
  • The database needs to be closed and re-opened to apply the changes

h2database源码浅析:事务、两阶段提交的更多相关文章

  1. 分布式事务 & 两阶段提交 & 三阶段提交

    可以参考这篇文章: http://blog.csdn.net/whycold/article/details/47702133 两阶段提交保证了分布式事务的原子性,这些子事务要么都做,要么都不做. 而 ...

  2. h2database源码浅析:SQL语句的执行

    最近想好好了解一下数据库的原理,下载了h2database的源码,准备好好看看.此过程的一些想法,暂且记下来,权当做读码笔记吧! 为了调试准备的测试用例: @Test public void test ...

  3. h2database源码浅析:集群

    Clustering / High Availability This database supports a simple clustering / high availability mechan ...

  4. h2database源码浅析:锁与MVCC

    Table Level Locking The database allows multiple concurrent connections to the same database. To mak ...

  5. h2database源码浅析:TransactionMap、MVMap、MVStore

    TransactionStore:A store that supports concurrent MVCC read-committed transactions. TransactionStore ...

  6. h2database源码浅析:MVTable与MVIndex

    Database包含一个Store:MVTableEngine.Store getMvStore() MVTableEngine.Store可以获取各tables:java.util.HashMap& ...

  7. 分布式事务 spring 两阶段提交 tcc

    请问分布式事务一致性与raft或paxos协议解决的一致性问题是同一回事吗? - 知乎 https://www.zhihu.com/question/275845393 分布式事务11_TCC 两阶段 ...

  8. Flink EOS如何防止外部系统乱入--两阶段提交源码

    一.前言 根据维基百科的定义,两阶段提交(Two-phase Commit,简称2PC)是巨人们用来解决分布式系统架构下的所有节点在进行事务提交时保持一致性问题而设计的一种算法,也可称之为协议. 在F ...

  9. MySQL源码之两阶段提交

    在双1的情况下,两阶段提交的过程 环境准备:mysql 5.5.18, innodb 1.1 version配置: sync_binlog=1 innodb_flush_log_at_trx_comm ...

随机推荐

  1. SQL中binary 和 varbinary的区别 blob

    binary 和 varbinary固定长度 (binary) 的或可变长度 (varbinary) 的 binary 数据类型. binary [ ( n ) ] 固定长度的 n 个字节二进制数据. ...

  2. jqgrid使用sql row_number进行分页

    背景 系统中使用了jqgrid的展示,现在要处理10w+的数据量 现状 使用了全查询的,查询到了10w+的数据放到了datatable中,每次页面刷新需要9秒多,并且传递给另一个dll来处理一些事情. ...

  3. 问题-关于 in []使用过程中报错" Constant expression violates subrange bounds"

    问题现象:在DELPHI中使用户in [] 时参数大于255后,报错,错误如下:Constant expression violates subrange bounds E1012常量表达式超出子界 ...

  4. Altium Designer导出部分元件过滤不焊接的元件【worldsing笔记】

    在Altium Designer画图过程中难免会多出单元电路,或是测试电路,特别是第一版时,有部分元件不用焊接   这时给采购.或是生产时有必要注明哪些元件不焊接,哪些元件不采购.有两种方法可以过滤: ...

  5. Linux就是这个范儿之第一次亲密接触(3)

    原创作品,允许转载,转载时请务必以超链接形式标明文章原始出处 .作者信息和本声明.否则将追究法律责 1.4 返璞归真的命令行 有一种说法,现代计算机不是靠电力驱动,而是靠“鼠标”.多少应用程序的界面需 ...

  6. android http 通信(httpclient 实现)

    1.httpclient get 方式 HttpGet httpGet = new HttpGet(url); HttpClient client = new DefaultHttpClient(); ...

  7. Android开发中常用的Eclipse快捷键

    关闭所有窗口Ctrl + Shift + W  关闭所有已打开的编辑窗口 重命名Alt + Shift + R    文件或变量重命名(先选中文件或变量再同时按下快捷键) 快速引包Ctrl + Shi ...

  8. Swift 基本语法1

    一.Swift简介 2010年的夏天,苹果公司的开发人员Chris Lattne接到了一个特别的任务,为OS X 和iOS平台开发下一代的编程语言,也就是Swift. 苹果公司于2014年WWDC(苹 ...

  9. (JAVA版)冒泡排序

    核心代码: public void bubbleSort(){ ;i<length-;i++){ ;j<length-i-;j++){ ]) swap(j,j+); } } } publi ...

  10. nonce和timestamp在Http安全协议中的作用

    前段时间给客户网站做新浪微博账号登录功能,对OAuth协议以及相关的一些安全协议做了一些研究,顺便就记录一下学习心得吧.在这里就不打算具体讲OAuth的协议流程了,而是针对OAuth请求头里的nonc ...