apache / apache/incubator-seata

About preventing users from missing write @GlobalLock

Open
#1,653 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
26k
Forks
8.8k
Avg merge
1d 8h
Merged PRs (30d)
4

Description

## Why you need it?
If a database table is updated in a global transaction API, and also updated in lots of local transaction APIs. To prevent seata from rollback failure, we need to add @GlobalLock annotation in all local transaction APIs. But if developer miss a little APIs, rollback failure will happen in time. And once it happen, developer maybe need lots of time to fix the dirty data.

So i am thinking, is there a solution to prevent users from missing write @GlobalLock. In another word, could seata provides a mechanism to find out missing wirte of @GlobalLock, and automatically add it in runtime.

## How it could be?
I think description of how important @GlobalLock in local transaction APIs is necessary, in future document and sample.

Besides, maybe we could provide a mechanism in seata to add @GlobalLock annotation automatically in runtime, once find the missing write problem.

I have a idea, it will decrease little performance of RM sql invocation, but could find almost missing write problem, and automatically add global lock.
1. TC maintains a resource table set(TableSet) for each RM, once RM register a branch transaction to TC, TC will add the table name to the TableSet. Once the TableSet do updated(size change) or a new RM connected, TC will push the newest TableSet to target RM.
2. Use a special interceptor(AutoGlobalLockInterceptor) to handle all normal local transaction(No GlobalTransaction & GlobalLock), it will analyze sql and check table for CUD(insert,update,delete) operations, if this table in TableSet, use GlobalLockTemplate to execute target method, and notify developer this auto upgrade event. Maybe we could also cache each method's ayalysis result to help performance, and refresh that cache when TableSet updated.
3. If developer clearly know dirty write will not happen, we could provide a annotation like
@IgnoreAutoGlobalLock to skip this mechanism for performance.
## Other related information

Contributor guide

Open the contributing guide

Research direction

Start by reading the @GlobalLock and GlobalLockTemplate entry points, then trace RM branch registration with the TC and the proposed AutoGlobalLockInterceptor flow. The issue is done only when the project agrees on a runtime mechanism, its performance and opt-out behavior, and how the missing-write notification or automatic lock upgrade should work.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, sql
Domain
distributed-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.