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. 40个Java集合面试问题和答案

    Java集合框架为Java编程语言的基础,也是Java面试中很重要的一个知识点.这里,我列出了一些关于Java集合的重要问题和答案. 另外,码农网之前也整理过一篇关于Java集合面试题的文章:大公司最 ...

  2. ubuntu完全卸载一个软件

    今天卸载一个软件,老是有配置残留,网上找到了解决方案: 查看已安装的软件: dpkg -l |grep 软件名 找到一大堆相关的包,然后卸载核心的包: sudo apt-get remove --pu ...

  3. [Objective-c 基础 - 2.5] NSString

    1.NSString基本使用 使用%@占位符输出对象 ; ; NSString *str2 = [NSString stringWithFormat:@"My age is %d and n ...

  4. 笔记-iOS 视图控制器转场详解(上)

    这是一篇长文,详细讲解了视图控制器转场的方方面面,配有详细的示意图和代码,为了使得文章在微信公众号中易于阅读,seedante 辛苦将大量长篇代码用截图的方式呈现,另外作者也在 Github 上附上了 ...

  5. C# 产生随机密码

    using System.Web.Security var rawPassword = System.Web.Security.Membership.GeneratePassword(10,1) re ...

  6. sizeof _countof _tcslen的比较

    sizeof ----用于计算数组或其他对象的大小,以字节为单位,含\0结束符. _countof----一个宏,用于计算数组的实际元素个数 ,含\0结束符: _tcslen----c++求数组长度的 ...

  7. HTML5随笔

    1 首先介绍一下html5,以及为什么用html5, HTML5是HTML最新的修订版本,2014年10月由万维网联盟(W3C)完成标准制定. HTML5的设计目的是为了在移动设备上支持多媒体.HTM ...

  8. js避免全局污染

    避免声明全局变量,以免发生冲突

  9. 修改cmd字体为Consolas

    windows下的cmd窗口默认的字体有点难看,长时间使用操作nodejs有点小疲劳,可以修改注册表替换字体为Consolas,并且可以全屏cmd窗口,代码如下: Windows Registry E ...

  10. 基于jquery扩展漂亮的分页控件(ajax)

    分页控件式大家在熟悉不过的控件,很多情况下都需要使用到分页控件来完成列表数据加载操作,在很多分页控件中有的编写麻烦,有的应用扩展比较复杂,有的分页控件样式比较丑陋,有的分页控件用户体验操作比较简单等等 ...