zno2

Spring 事务隔离级别

其中 DEFAULT 的解释是:Use the default isolation level of the underlying datastore.

意思是不同数据库有其默认的隔离级别,使用对应数据库的默认隔离级别。

Tips:

数据库 默认隔离级别 参考文档 备注
MySQL REPEATABLE READ https://dev.mysql.com/doc/refman/5.6/en/glossary.html#glos_isolation_level 可修改默认
Oracle Read committed https://docs.oracle.com/cd/B14117_01/server.101/b10743/consist.htm  

 

isolation  [aɪsə'leɪʃ(ə)n] when one group, person, or thing is separate from others

  • Dirty reads

    A transaction reads data that has been written by another transaction that has not been committed yet.

  • Nonrepeatable (fuzzy) reads

    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.

  • Phantom reads

    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.

Table 9-1 Preventable Read Phenomena by Isolation Level

Isolation LevelDirty ReadNonrepeatable ReadPhantom Read

Read uncommitted

Possible

Possible

Possible

Read committed

Not possible

Possible

Possible

Repeatable read

Not possible

Not possible

Possible

Serializable

Not possible

Not possible

Not possible

 

首先需要明确问题是发生在 concurrency ,t1 指某次事务从开始到结束

脏           读:t1 读了 t2 改了但没提交的数据

不可重复读:t1 读了一条数据,t1再次读时发现数据发生了变化(t1执行期间该数据被t2修改)

虚           读:t1 按条件检索了一批数据,t1再次按该条件检索时有了新增数据(t1执行期间t2新增了符合t1检索条件的数据)

 

上述问题的实际场景(首先需要确认是否有并发事务操作有交集的数据):

1. 如何一个用户操作自己的数据

 

备注:读操作也可以加事务,应用场景视情况而定

posted on 2023-07-13 18:00  zno2  阅读(35)  评论(0编辑  收藏  举报

导航