From 97990229c9d89785995be0d8ff7532555bcef96b Mon Sep 17 00:00:00 2001 From: asahi Date: Wed, 27 Aug 2025 10:25:59 +0800 Subject: [PATCH] =?UTF-8?q?doc:=20=E9=98=85=E8=AF=BBseata=20AT=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 分布式事务/seata/seata.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/分布式事务/seata/seata.md b/分布式事务/seata/seata.md index 0993568..cea2ce2 100644 --- a/分布式事务/seata/seata.md +++ b/分布式事务/seata/seata.md @@ -2,6 +2,8 @@ - [Seata Global Exclusive Write Lock](#seata-global-exclusive-write-lock) - [TC - Global Exclusive Write Lock Implementation](#tc---global-exclusive-write-lock-implementation) - [RM - Global Exclusive Write Lock Usage](#rm---global-exclusive-write-lock-usage) + - [Read Committed \&\& Read UnCommitted](#read-committed--read-uncommitted) + - [`select ... for update` to apply global exclusive write lock](#select--for-update-to-apply-global-exclusive-write-lock) # seata @@ -56,4 +58,13 @@ global write lock的释放和RM无关,当全局事务提交时,全局事务 但是,在全局事务提交前,其他事务必须等待global exclusive write lock的释放,这种等待会带来性能损耗。 +## Read Committed && Read UnCommitted +在seata系统中,`local transaction/branch transaction`的事务隔离级别和数据库实例的默认隔离级别一致,例如在mysql中,默认为`repeatable read`;但是,seata系统中,对于`global transaction`,其事务隔离级别为`read uncommitted`,作为全局事务G1中的分支事务L1,其在L1提交但是G1尚未提交的场景下,L1对数据库造成的修改对全局事务G2仍然可见。 + +故而,seata中全局事务的隔离级别为`读未提交`。 + +### `select ... for update` to apply global exclusive write lock +在seata系统中,如果特定场景下`需要将全局事务的隔离级别改为读已提交`,可以使用`select ... for update`来实现。 + +在seata-AT的实现中,对于`select ... for update`语句,其会在`ConnectionProxy`执行时校验是否可获取`global write lock`。如果当时global write lock被其他全局事务持有,那么当前`select ... for update`会进行重试。当重试次数达到上限时,会抛出异常,如此,可以保证全局事务的读已提交,当全局事务尚未提交/回滚时,会持有global write lock,其他全局事务无法获取相同数据的global write lock。