incubator-seata icon indicating copy to clipboard operation
incubator-seata copied to clipboard

Why does TC try to rollback branch trsaction infinitely after a dirty write?

Open AL-Liang opened this issue 6 years ago • 6 comments

Sometimes we want to keep the modification that was caused by the dirty write because of business logic. Is it really appropriate to assume that the rollback is retryable?

The only way to stop TC trying rolling back is to modify the data back to the afterImage manually. And this will cause a lost update since we may want to keep the current modification.

Maybe no retrying this type of rollback is better. Let users decide the modification.

Maybe there is a way to prevent dirty writes completely.

AL-Liang avatar Jun 30 '20 13:06 AL-Liang

数据库本地事物加行锁 字段锁 可以防止脏数据

hermitcai avatar Jun 30 '20 13:06 hermitcai

数据库本地事物加行锁 字段锁 可以防止脏数据

@Garlichead 感谢回复。本地事务提交后且全局事务提交前,可能别的应用进程修改了本地事务提交的更新。那即使本地事务加上了行锁,也无法避免更新的记录被别的事务修改,因为本地事务已经提交了,锁会被释放。

AL-Liang avatar Jun 30 '20 14:06 AL-Liang

@Garlichead 感谢回复。本地事务提交后且全局事务提交前,可能别的应用进程修改了本地事务提交的更新。那即使本地事务加上了行锁,也无法避免更新的记录被别的事务修改,因为本地事务已经提交了,锁会被释放。

在全局事物提交前 另外一个事物的线程需要先获取全局锁 才能进行本地事物的提交更新

hermitcai avatar Jul 01 '20 02:07 hermitcai

@Garlichead 感谢回复。本地事务提交后且全局事务提交前,可能别的应用进程修改了本地事务提交的更新。那即使本地事务加上了行锁,也无法避免更新的记录被别的事务修改,因为本地事务已经提交了,锁会被释放。

在全局事物提交前 另外一个事物的线程需要先获取全局锁 才能进行本地事物的提交更新

那其实您说的方案,是不是就是弃用 Spring @Transactional,用 @GlobalTransactional?

AL-Liang avatar Jul 01 '20 02:07 AL-Liang

那其实您说的方案,是不是就是弃用 Spring @transactional,用 @GlobalTransactional? 嗯 使用 @GlobalTransactional spring @transactional 也可以用 不冲突

hermitcai avatar Jul 02 '20 23:07 hermitcai

那其实您说的方案,是不是就是弃用 Spring @transactional,用 @GlobalTransactional? 嗯 使用 @GlobalTransactional spring @transactional 也可以用 不冲突

现在看来(1.2.0 版本),我觉得,使用 AT 模式,只能通过全部走全局事务(即便全局事务里面只有一个本地事务),才能真的避免全局事务的脏写。

AL-Liang avatar Jul 04 '20 04:07 AL-Liang