简体   繁体   English

是mysql(innodb)行级锁定解决方案吗?

[英]Is Mysql (innodb) row level locking the solution?

Recently ran into a problem after putting my codeiginter application into a clustered environment. 最近在将我的codeiginter应用程序放入集群环境后遇到了问题。 Users are able to get site rewards at point levels, after they click submit to retrieve the reward I have code that grabs the current point level of the reward is at and save that in a table with the user_id and what point level they got the reward at. 用户可以在点级别获得站点奖励,在他们点击提交以获取奖励后,我有代码,用于获取奖励的当前点级别并将其保存在具有user_id的表格中以及他们获得奖励的点级别在。 it is suppose to increment that reward by 1 point level after the user has retrieved the reward. 假设在用户检索到奖励之后将该奖励增加1点级别。 I have ran into a problem where 2 users might click submit at the same time and in the records table it has that both users got the reward at the same point level which shouldn't happen because it is suppose to increment by 1 point after each submit. 我遇到了一个问题,其中2个用户可能同时点击提交,并且在记录表中,两个用户都获得了同一点级别的奖励,这是不应该发生的,因为假设每个用户增加1点提交。 would row level locking on the reward row that is being incrementing stop this issue ? 会对正在递增的奖励行进行行级锁定会阻止此问题吗? and how do i implement it? 我该如何实现呢?

If you need anymore information or clarification let me know. 如果您需要更多信息或澄清,请告诉我。

  • Users Table 用户表
    id ID
    username 用户名
    [...] [...]

  • Rewards Table 奖励表
    id ID
    name 名称
    points

  • Records Table 记录表
    id ID
    users_id users_id
    rewards_id rewards_id
    points

The points in the records table is suppose to be the amount of points the reward was at when the user submitted to retrieve the reward. 记录表中的点数被假定为当用户提交检索奖励时奖励的点数。

No. Row-level vs table-level locking is primarily a performance issue. 否。行级锁定与表级锁定主要是性能问题。

What you're looking for is transactions. 你要找的是交易。 Start the transaction, increase the point level, add the reward, commit. 开始交易,增加积分等级,添加奖励,提交。 Either the whole transaction completes and both the reward and the point-increase are done at once, or it fails and neither happens. 整个交易完成,奖励和积分增加都是立即完成,或者失败并且都没有发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM