事务笔记
本地事务管理器。
无法管理多个事务性资源。
倾向于入侵式编程。
全局事务管理器。
事务的属性:
1 timeout
2 read-only
3 隔离级别
read_uncommitted
read_committed
repeatable_read
isolation_serializable
4 事务的传播
问题的分类
脏读
A transaction reads data that has been written by another transaction that has not been committed yet.
不可重复读
A transaction rereads data it has previously read and finds that another committed transaction has modified or deleted the data. For example, a user queries a row and then later queries the same row, only to discover that the data has changed.
幻读
A transaction reruns a query returning a set of rows that satisfies a search condition and finds that another committed transaction has inserted additional rows that satisfy the condition.
For example, a transaction queries the number of employees. Five minutes later it performs the same query, but now the number has increased by one because another user inserted a record for a new hire. More data satisfies the query criteria than before, but unlike in a fuzzy read the previously read data is unchanged.
更新丢失
悲观锁 乐观锁
ACID BASE
Local Transcation Model
限制比较多,无法管理多个资源。
code太杂,调用时要注意的事情多。
dev管理Connection 资源本身管理transaction。
简单的场景下使用。
Programming transaction model
直接管理transaction
注意UT
Exception Handling
事务和线程一般有紧密的关系
Declarative transaction model
事务传播级别的设置,大的范围用严格的,小的范围内再微调。
setRollbackOnly和exception handling
事务和异常处理应该分开考虑
事务的开始回滚结束应该在同一个method里面。(职责单一 集中化)
各种db支持的隔离级别不一样。
2PC提交
小心SP,尤其是里面如果有DDL。
避免嵌套事务,或者小心考察。
Client based transaction management
怎么看都不好使。
server端不能rollback,因为rollback是一种管理。
Domain Service Owner Model