竞争条件的概念
我知道什么是竞争条件,但我仍然不完全理解:
首先,我知道myisam不支持事务,而innodb支持事务。
我正在构建一个有很多用户的社交网站,我想知道是否需要考虑竞争条件,因为用户将使用“重复密钥更新”更新他们的个人资料,但我想知道是否会发生竞争条件以及如何处理编写代码来防止此问题?
有人可以解释一下具有多个用户的站点上竞争条件的概念,例如使用 COMMIT、ROLLBACK 等。
我在哪里使用这些东西?
I know what a race condition is but I still don't fully understand:
Firstly, I know myisam does not support transactions and innodb does.
I am building a social site with a lot of users in mind and I wonder if I need to think about race conditions, because users will update their profile with ON DUPLICATE KEY UPDATE, but I wonder if a race condition will occur and how do you write code to protect against this issue?
Can someone please explain the concept of race condition on a site with multiple users e.g. use of COMMIT, ROLLBACK etc.
Where do I use these things?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个好的开始。我建议使用InnoDB。事务使数据库的修改具有原子性和一致性。事务还确保隔离,以便数据库的任何用户都不能干扰其他用户的修改。
当存在多线程时,可能会出现竞争条件。是的,数据库使用多个线程,但事务可确保一个用户的数据库更改先于另一用户的数据库更改。 (是的,这是一个简化的逻辑解释。)
编辑添加:您可以询问其他 Stack Overflow 问题中可能遇到的特定 SQL 问题,但一般来说,您希望在 INSERT、UPDATE 或 DELETE SQL 后尽快提交陈述。
That's a good start. I suggest using InnoDB. Transactions are what make the modifications of a database atomic and consistent. Transactions also ensure isolation, so that no user of the database can interfere with the modifications of another user.
Race conditions can occur when there is multithreading. Yes, a database uses more than one thread, but transactions assure that one user's database changes are made before another user's database changes. (Yes, that's a simplified logical explanation.)
Edited to add: You can ask specific SQL question you might have in other Stack Overflow quesitons, but in general, you want to COMMIT as soon as possible after an INSERT, UPDATE, or DELETE SQL statement.