-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dangling delete record when deletes your own write in a transaction #27564
Comments
@TonsnakeLin |
Currently in tidb the "delete-your-write" tranaction commit is not fully optimized, just the rowkey or unique index keys in the optimistic transaction satisfying the "delete-your-write" condition will be ignored, which also introduces some critical bugs before. If we want to solve it completely we may need to find out a way to distinguish the "newly" inserted and later deleted keys for both optimistic and pessimistic transactions, also this may be a risky change so we need to plan it well before doing things. |
There are serveral things to consider deciding if the key in the memory buffer is "newly" inserted and then deleted. The difficult part is to diffrentiate the following situation:
Here the final generated delete operation could not be ignored though it deletes the new row inserted by previous insert statement. For the pessimistic transaction mode, a simple way to verify if the inserted key is "new" is to verify if the oldest value for this key in For the optimistic transactions with default configurations, the row key or the unique index key would be marked with "presume not exist flag" and they will be skipped in the 2pc phase processing the delete mutations.However the related secondary index key delete opertion is not skipped and they will still be generated and forwarded as part of the transaction mutations.A simple way to solve this is add similar mark on the secondary index keys too so they could be skippped in the For the optimistic transaction with /cc @MyonKeminta @you06 @coocood |
If so, it seems that the case you given will commit success in the optimistic transaction, is this expected? |
I have one more question: when we avoid the delete record on a delete-your-write key, should we still put a |
I think so, though the current implementation is a bit confusing processing For optimistic transactions with
For optimistic transactions with
For pessimistic transactions, the pessimistic lock will be added first doing insert, and then delete will change the record in memdb into a
The resonable way is that the locked keys should be committed using lock type and other keys deleted should be skipped. The difficult part is how to identify the |
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
See https://github.com/pingcap/ticdc/issues/2612. This behavior of TiDB may result in strange event in TiCDC.
2. What did you expect to see? (Required)
No delete record in write CF.
3. What did you see instead (Required)
Only When deletes by the clustered primary key or unique index key in optimistic transactions, the delete record on such keys won't appear.
https://github.com/tikv/client-go/blob/16d902a3c7e5e850c931f0e9515c3dbb4944b6f8/txnkv/transaction/2pc.go#L435-L440
4. What is your TiDB version? (Required)
4.0.x, 5.x
The text was updated successfully, but these errors were encountered: