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

【BUG】商品库存超售问题 #40

Open
Exrick opened this issue Apr 8, 2020 · 0 comments
Open

【BUG】商品库存超售问题 #40

Exrick opened this issue Apr 8, 2020 · 0 comments
Labels

Comments

@Exrick
Copy link
Owner

Exrick commented Apr 8, 2020

目前方案存在的问题,为什么

  • 虽然MySQL任意隔离级别都可避免更新丢失,但并发量高的时候仍会存在数据库的丢失更新造成超售问题

如何解决/优化

  • 隔离级别最高SERIALIZABLE,但串行不可取
  • 乐观锁 update x set num = x where id = x and num = 原库存数,单表推荐
  • 若要处理多个表可使用分布式锁,参考xboot项目
  • 秒杀场景:使用Redis事务+watch
@Exrick Exrick added the bug label Apr 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant