博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
h2database源码浅析:事务、两阶段提交
阅读量:5096 次
发布时间:2019-06-13

本文共 2657 字,大约阅读时间需要 8 分钟。

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  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

转载于:https://www.cnblogs.com/bluejoe/p/5115883.html

你可能感兴趣的文章
python学习4 常用内置模块
查看>>
Window7上搭建symfony开发环境(PEAR)
查看>>
ResolveUrl的用法
查看>>
Linux内核态、用户态简介与IntelCPU特权级别--Ring0-3
查看>>
第23月第24天 git命令 .git-credentials git rm --cached git stash clear
查看>>
java SE :标准输入/输出
查看>>
一些方便系统诊断的bash函数
查看>>
【转载】基于vw等viewport视区相对单位的响应式排版和布局
查看>>
<转>关于MFC的多线程类 CSemaphore,CMutex,CCriticalSection,CEvent
查看>>
jquery中ajax返回值无法传递到上层函数
查看>>
css3之transform-origin
查看>>
[转]JavaScript快速检测浏览器对CSS3特性的支持
查看>>
Master选举原理
查看>>
[ JAVA编程 ] double类型计算精度丢失问题及解决方法
查看>>
小别离
查看>>
微信小程序-发起 HTTPS 请求
查看>>
WPF动画设置1(转)
查看>>
backgound-attachment属性学习
查看>>
个人作业——关于K米的产品案例分析
查看>>
基于node/mongo的App Docker化测试环境搭建
查看>>