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

用tcc-and-fescar这个demo并发测试同一个请求,锁表fescar_lock主键冲突。 #143

Open
lvchongyi opened this issue Jan 15, 2020 · 3 comments

Comments

@lvchongyi
Copy link

错误描述:
用tcc-and-fescar这个demo并发测试同一个请求:
http://172.32.147.38:9990/buySth?userId=1&money=10
会出现fescar_lock这个加锁表的主键冲突。

请教下同时多次对同一条记录做修改操作时,通常是不是应该排队等待上一个请求的锁释放了,
才能继续添加另外一次请求的锁。而不是对同一条记录同时加锁,不然会导致这个锁表的主键冲突。
请问下这边我应该怎么处理? 谢谢!!

错误日志如下:
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'coupon-1' for key 'PRIMARY'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_161]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_161]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_161]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_161]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) ~[mysql-connector-java-5.1.46.jar:5.1.46]
at com.mysql.jdbc.Util.getInstance(Util.java:408) ~[mysql-connector-java-5.1.46.jar:5.1.46]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936) ~[mysql-connector-java-5.1.46.jar:5.1.46]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3976) ~[mysql-connector-java-5.1.46.jar:5.1.46]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3912) ~[mysql-connector-java-5.1.46.jar:5.1.46]
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2530) ~[mysql-connector-java-5.1.46.jar:5.1.46]
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2683) ~[mysql-connector-java-5.1.46.jar:5.1.46]
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2486) ~[mysql-connector-java-5.1.46.jar:5.1.46]
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858) ~[mysql-connector-java-5.1.46.jar:5.1.46]
at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2079) ~[mysql-connector-java-5.1.46.jar:5.1.46]
at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2013) ~[mysql-connector-java-5.1.46.jar:5.1.46]
at com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5104) ~[mysql-connector-java-5.1.46.jar:5.1.46]
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1998) ~[mysql-connector-java-5.1.46.jar:5.1.46]
at com.alibaba.druid.pool.DruidPooledPreparedStatement.executeUpdate(DruidPooledPreparedStatement.java:256) ~[druid-1.1.13.jar:1.1.13]
at com.yiqiniu.easytrans.protocol.autocps.EtDataSourceManager.doLockKeys(EtDataSourceManager.java:304) ~[classes/:na]
at com.yiqiniu.easytrans.protocol.autocps.EtDataSourceManager.branchRegister(EtDataSourceManager.java:91) ~[classes/:na]

@skyesx
Copy link
Contributor

skyesx commented Jan 18, 2020

目前就是通过这个冲突来控制数据正确性,要实现等待的话,会对没有冲突的情况增加消耗

@lvchongyi
Copy link
Author

按现有情况来看,同一时间只有一个事务可以执行成功,其他事务会因为行锁冲突,倒是事务失败。
在实际使用中肯定会有并发同时请求的情况,请问有没有什么这方面的建议?

@skyesx
Copy link
Contributor

skyesx commented Feb 9, 2020

并发请求让其中一个失败回滚,跟乐观锁机制一样

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

2 participants