1

我正在尝试构建一个数据库,用于存储某些测试的结果。问题是这些测试在并行和单独的进程中运行,并且在它们中的每一个完成后,它会将结果提交到数据库。现在我知道 MySQL 旨在处理这种情况,并且像 InnoDB 这样的一些引擎可以实现行级锁定。

  1. 如果一个进程要访问一个锁定的表或条目,这个进程会被阻塞并轮询,直到表或条目被解锁,还是会缓存查询并且进程可以正常终止?
  2. 当一个进程在它关闭时尝试连接到服务器时,会发生什么或者由我来处理它?

非常感谢任何帮助。

4

1 回答 1

2

The number 2 is up to you, what will you do when mysql_connect() or whatever you use to connect to database will throw an exception. The number 1 issue will be resolved at MySQL level, depending on what does your process require to do with locked table or row. Usually this results in a temporary delay for query to access the data in locked areas, but can return an out-of-time error, should the other process lock the table/row for an extended period of time. Also a mutual lock is possible, say process A locks row 1, and process B locks row 2, and A wants data from row 2 and B wants data from row 1. This is named "deadlocking", and one of the processes is chosen as a deadlock victim and its query returns a failure.

于 2013-07-25T09:55:21.830 回答