简体   繁体   English

并发数据库连接

[英]Concurrent Database Connections

How do SQL databases prevent corruption from occurring when two or three connections to it modify the same table at the same time (or even the same row)? 当两个或三个连接同时修改同一张表(甚至同一行)时,SQL数据库如何防止损坏?

I was thinking of an theoretical possibility that could occur on databases which have multiple server based load balanced front ends: 我正在考虑可能在具有多个基于服务器的负载平衡前端的数据库上发生的理论可能性:

  • Server 1 accesses the central database 服务器1访问中央数据库
  • Server 2 accesses the central database 服务器2访问中央数据库
  • Server 1 gets info for user X in central database 服务器1在中央数据库中获取用户X的信息
  • Server 2 gets info for same user X in central database 服务器2在中央数据库中获取同一用户X的信息
  • Server 1 sets new data for user X in central database after doing some work (could be a do or do not transaction) 服务器1完成某些工作(可以做事务或不做事务)后,在中央数据库中为用户X设置新数据
  • Server 2 sets new data for user X in central database 服务器2在中央数据库中为用户X设置新数据

Which at this point user X would contain invalid entries as it has basically overwritten the work Server 1 just did to that same user. 由于用户X基本上已经覆盖了服务器1刚刚对该用户所做的工作,因此用户X此处将包含无效条目。

I was thinking about constantly checking the same table & row to see if it has been modified lately but still nothing is stopping that same table & row being modified by something else between the time it has checked and the time it will write to the DB after checking. 我一直在考虑不断检查同一张表和行,以查看是否最近对其进行了修改,但是在检查完该表和行之后将其写入数据库之前,仍然没有任何其他方法阻止该同一张表和行被其他东西修改检查。

I'm just trying to get an idea how large databases with millions of users work and how they are distributed over tens or hundreds of separate servers. 我只是想了解一个具有数百万用户的大型数据库如何工作以及如何将它们分布在数十个或数百个单独的服务器上。

Database transactional integrity was what I was looking for. 我一直在寻找数据库事务完整性。

Good links to read: 好的链接阅读:

technet.microsoft.com/en-us/library/ms173763.aspx technet.microsoft.com/en-us/library/ms173763.aspx

http://en.wikipedia.org/wiki/Isolation_%28database_systems%29#Isolation_Levels.2C_Read_Phenomena_and_Locks http://en.wikipedia.org/wiki/Isolation_%28database_systems%29#Isolation_Levels.2C_Read_Phenomena_and_Locks

Thanks 谢谢

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

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