FinnTew opened a new pull request, #986: URL: https://github.com/apache/incubator-seata-go/pull/986
<!-- Thanks for sending a pull request! --> **What this PR does**: Fixed XA mode transaction failed when `query and udpate`. **Which issue(s) this PR fixes**: <!-- *Automatically closes linked issue when PR is merged. Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`. _If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_* --> Fixes #904 **Special notes for your reviewer**: The repair method is as follows: <img width="1145" height="432" alt="截屏2025-11-08 14 53 05" src="https://github.com/user-attachments/assets/616f0f34-0343-4fae-b016-c46e40623810" /> The code for the problem scenario is as follows(See the related issue for details): ```go // testDeduct tests the Query+Update pattern that triggers issue #904 // This is the exact pattern provided by the user, adapted to use order_tbl func testDeduct(ctx context.Context) error { userID := "NO-100001" deductAmount := int64(5) println("Step 1: Querying order with First (SELECT)...") var order OrderTblModel err := gormDB.WithContext(ctx).Table("order_tbl").Where("user_id = ?", userID).First(&order).Error if err != nil { return fmt.Errorf("order not found for user_id: %s, error: %w", userID, err) } println(fmt.Sprintf(" Found order: id=%d, user_id=%s, money=%d", order.Id, order.UserId, order.Money)) if order.Money < deductAmount { return fmt.Errorf("insufficient money: current money %d, required %d", order.Money, deductAmount) } newMoney := order.Money - deductAmount println("Step 2: Updating money with Update (UPDATE)...") err = gormDB.WithContext(ctx).Table("order_tbl"). Where("id = ?", order.Id). Update("money", newMoney).Error if err != nil { return fmt.Errorf("failed to deduct money: %w", err) } println(fmt.Sprintf(" ✅ Money updated successfully: %d -> %d", order.Money, newMoney)) return nil } ``` The following is an excerpt of the test log after the repair: ```plain text 2025-11-08 14:37:22.860 INFO getty/listener.go:58 Open new getty session 2025-11-08 14:37:22.861 INFO getty/getty_remoting.go:82 send async message: {message.RpcMessage{ID:1, Type:0x2, ...Body:message.RegisterTMRequest{...Version:"1.1.0", ApplicationId:"applicationName", TransactionServiceGroup:"default_tx_group"...}}} 2025-11-08 14:37:22.872 INFO getty/getty_remoting.go:82 send async message: {message.RpcMessage{ID:2, Type:0x0, ...Body:message.RegisterRMRequest{...Version:"1.5.2", ApplicationId:"applicationName", TransactionServiceGroup:"default_tx_group", ResourceIds:"root:12345678@tcp(127.0.0.1:3306)/seata_client"}}} 2025-11-08 14:37:22.883 INFO client/client_on_response_processor.go:48 the rm client received clientOnResponse msg ...RegisterTMResponse{...Version:"1.8.1-SNAPSHOT"...Identified:true}}} from tc server. 2025-11-08 14:37:22.886 INFO client/client_on_response_processor.go:48 the rm client received clientOnResponse msg ...RegisterRMResponse{...Version:"1.8.1-SNAPSHOT"...Identified:true}}} from tc server. 2025-11-08 14:37:22.886 INFO rm/rm_remoting.go:169 register RM success. response: message.RegisterRMResponse{...ResultCode:0x0, Msg:""...Identified:true}} Testing issue #904: Deduct with Query+Update pattern in XA mode... 2025-11-08 14:37:22.889 INFO getty/getty_remoting.go:82 send async message: {message.RpcMessage{ID:3, ...Body:message.GlobalBeginRequest{Timeout:30000000000, TransactionName:"XATestIssue904"}}} 2025-11-08 14:37:22.894 INFO client/client_on_response_processor.go:48 the rm client received clientOnResponse msg ...GlobalBeginResponse{...ResultCode:0x1, Msg:""..., Xid:"172.19.0.2:8091:2009318740325138436"...} from tc server. 2025-11-08 14:37:22.894 INFO tm/global_transaction.go:66 GlobalBeginRequest success, res {{{1 } 0} 172.19.0.2:8091:2009318740325138436 []} Step 1: Querying order with First (SELECT)... Found order: id=1, user_id=NO-100001, money=110 Step 2: Updating money with Update (UPDATE)... 2025-11-08 14:37:22.898 INFO getty/getty_remoting.go:82 send async message: {message.RpcMessage{ID:4, ...Body:message.BranchRegisterRequest{Xid:"172.19.0.2:8091:2009318740325138436", BranchType:3, ResourceId:"root:12345678@tcp(127.0.0.1:3306)/seata_client"...}}} 2025-11-08 14:37:22.902 INFO client/client_on_response_processor.go:48 the rm client received clientOnResponse msg ...BranchRegisterResponse{...ResultCode:0x1, Msg:""..., BranchId:2009318740325138437}} from tc server. 2025-11-08 14:37:22.902 INFO xa/mysql_xa_connection.go:184 xa branch start, xid 172.19.0.2:8091:2009318740325138436-2009318740325138437 ✅ Money updated successfully: 110 -> 105 2025-11-08 14:37:22.904 INFO getty/getty_remoting.go:82 send async message: {message.RpcMessage{ID:5, ...Body:message.GlobalCommitRequest{...Xid:"172.19.0.2:8091:2009318740325138436"...}}} ...... 2025-11-08 14:37:43.093 INFO getty/getty_remoting.go:82 send async message: {message.RpcMessage{ID:6, ...Body:message.GlobalCommitRequest{...Xid:"172.19.0.2:8091:2009318740325138436"...}}} 2025-11-08 14:37:43.099 INFO client/client_on_response_processor.go:48 the rm client received clientOnResponse msg ...GlobalCommitResponse{...ResultCode:0x1, Msg:""..., GlobalStatus:0x3}}} from tc server. 2025-11-08 14:37:43.099 INFO tm/global_transaction.go:115 send global commit request success, xid 172.19.0.2:8091:2009318740325138436 ✅ Test PASSED: Query+Update works correctly! ``` **Does this PR introduce a user-facing change?**: <!-- If no, just write "NONE" in the release-note block below. If yes, a release note is required: Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required". --> ```release-note ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
