Skip to content
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

在at/basic下运行 go run .出错 #32

Open
123kangning opened this issue May 4, 2023 · 0 comments
Open

在at/basic下运行 go run .出错 #32

123kangning opened this issue May 4, 2023 · 0 comments

Comments

@123kangning
Copy link

What happened:
在at/basic下运行 go run .时,在sql相关文件中出现异常,经过本地测试,发现并不是sql配置的问题,同样的环境配置本机可以成功执行对应sql。具体输出如下:

2023-05-04 09:18:58.111         INFO    getty/getty_remoting.go:79                      send async message: {message.RpcMessage{ID:6, Type:0x0, Codec:0x1, Compressor:0x0, HeadMap:map[string]string(nil), Body:message.GlobalBeginRequest{Timeout:30000000000, TransactionName:"ATSampleLocalGlobalTx_InsertOnUpdate"}}}
2023-05-04 09:18:58.112         INFO    client/client_on_response_processor.go:48       the rm client received  clientOnResponse msg message.RpcMessage{ID:6, Type:0x1, Codec:0x1, Compressor:0x0, HeadMap:map[string]string{}, Body:message.GlobalBeginResponse{AbstractTransactionResponse:message.AbstractTransactionResponse{AbstractResultMessage:message.AbstractResultMessage{ResultCode:0x1, Msg:""}, TransactionErrorCode:0}, Xid:"172.23.0.3:8091:27409587150266392", ExtraData:[]uint8{}}} from tc server.
2023-05-04 09:18:58.112         INFO    tm/global_transaction.go:66                     GlobalBeginRequest success, res {{{1 } 0} 172.23.0.3:8091:27409587150266392 []}
2023-05-04 09:18:58.113         INFO    at/insert_on_update_executor.go:199             build select sql by insert on update sourceQuery, sql SELECT * FROM order_tbl  WHERE (id = ? ) 
2023-05-04 09:18:58.114         INFO    at/insert_on_update_executor.go:312             build after select sql by insert on duplicate sourceQuery, sql {}%!(EXTRA string=SELECT * FROM order_tbl  WHERE (id = ? ) )
2023-05-04 09:18:58.161         INFO    getty/getty_remoting.go:79                      send async message: {message.RpcMessage{ID:7, Type:0x0, Codec:0x1, Compressor:0x0, HeadMap:map[string]string(nil), Body:message.BranchRegisterRequest{Xid:"172.23.0.3:8091:27409587150266392", BranchType:0, ResourceId:"", LockKey:"order_tbl:1;", ApplicationData:[]uint8{}}}}
2023-05-04 09:18:58.163         INFO    client/client_on_response_processor.go:48       the rm client received  clientOnResponse msg message.RpcMessage{ID:7, Type:0x1, Codec:0x1, Compressor:0x0, HeadMap:map[string]string{}, Body:message.BranchRegisterResponse{AbstractTransactionResponse:message.AbstractTransactionResponse{AbstractResultMessage:message.AbstractResultMessage{ResultCode:0x0, Msg:"RuntimeException[null]"}, TransactionErrorCode:0}, BranchId:0}} from tc server.
2023-05-04 09:18:58.163         ERROR   sql/tx.go:176                                   Failed to register branch: Response RuntimeException[null]
github.com/seata/seata-go/pkg/datasource/sql.(*Tx).register
        /home/kangning/clone/seata/seata-go/pkg/datasource/sql/tx.go:176
github.com/seata/seata-go/pkg/datasource/sql.(*ATTx).commitOnAT
        /home/kangning/clone/seata/seata-go/pkg/datasource/sql/tx_at.go:57
github.com/seata/seata-go/pkg/datasource/sql.(*ATTx).Commit
        /home/kangning/clone/seata/seata-go/pkg/datasource/sql/tx_at.go:37
github.com/seata/seata-go/pkg/datasource/sql.(*ATConn).createNewTxOnExecIfNeed
        /home/kangning/clone/seata/seata-go/pkg/datasource/sql/conn_at.go:193
github.com/seata/seata-go/pkg/datasource/sql.(*ATConn).ExecContext
        /home/kangning/clone/seata/seata-go/pkg/datasource/sql/conn_at.go:92
database/sql.ctxDriverExec
        /usr/lib/go/src/database/sql/ctxutil.go:31
database/sql.(*DB).execDC.func2
        /usr/lib/go/src/database/sql/sql.go:1675
database/sql.withLock
        /usr/lib/go/src/database/sql/sql.go:3405
database/sql.(*DB).execDC
        /usr/lib/go/src/database/sql/sql.go:1670
database/sql.(*DB).exec
        /usr/lib/go/src/database/sql/sql.go:1655
database/sql.(*DB).ExecContext.func1
        /usr/lib/go/src/database/sql/sql.go:1634
database/sql.(*DB).retry
        /usr/lib/go/src/database/sql/sql.go:1538
database/sql.(*DB).ExecContext
        /usr/lib/go/src/database/sql/sql.go:1633
main.insertOnUpdateData
        /home/kangning/clone/seata/seata-go-samples/at/basic/insert_on_update.go:31
github.com/seata/seata-go/pkg/tm.WithGlobalTx
        /home/kangning/clone/seata/seata-go/pkg/tm/transaction_executor.go:80
main.sampleInsertOnUpdate
        /home/kangning/clone/seata/seata-go-samples/at/basic/insert_on_update.go:46
main.main
        /home/kangning/clone/seata/seata-go-samples/at/basic/main.go:44
runtime.main
        /usr/lib/go/src/runtime/proc.go:250
insert on update failed, err:Response RuntimeException[null]

What you expected to happen:
我期望没有异常出现

How to reproduce it (as minimally and precisely as possible):
在at/basic下运行 go run .
Anything else we need to know?:
我对at/basic/main.go做了一些修改,如下:

func main() {
	os.Chdir("/home/kangning/clone/seata/seata-go-samples")
	client.InitPath("./conf/seatago.yml")
	db = util.GetAtMySqlDb()
	ctx := context.Background()
	fmt.Printf("\n0\n")
	// sample: insert
	sampleInsert(ctx)
	fmt.Printf("\n1\n")

	// sample: insert on update
	sampleInsertOnUpdate(ctx)
	fmt.Printf("\n2\n")

	// sample: select for udpate
	sampleSelectForUpdate(ctx)
	fmt.Printf("\n3\n")
	<-make(chan struct{})
}

对util/db.go做了一些修改,如下:

func defaultEnv() {
	if os.Getenv("MYSQL_HOST") == "" {
		os.Setenv("MYSQL_HOST", "127.0.0.1")
	}
	if os.Getenv("MYSQL_PORT") == "" {
 //本机3305映射到docker中3306
		os.Setenv("MYSQL_PORT", "3305")
	}
	if os.Getenv("MYSQL_USERNAME") == "" {
		os.Setenv("MYSQL_USERNAME", "root")
	}
	if os.Getenv("MYSQL_PASSWORD") == "" {
		os.Setenv("MYSQL_PASSWORD", "root")
	}
	if os.Getenv("MYSQL_DB") == "" {
		os.Setenv("MYSQL_DB", "seata_client")
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant