database 在多用户系统中并发执行数据库事务是什么意思?为什么需要并发控制?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5722469/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 08:09:49  来源:igfitidea点击:

what is meant by the concurrent execution of database transactions in a multiuser system? why concurrency control is needed?

databaseconcurrency

提问by Stephanie Dente

what is meant by the concurrent execution of database transactions in a multiuser system? why concurrency control is needed?

在多用户系统中并发执行数据库事务是什么意思?为什么需要并发控制?

I'm having trouble with this. and what are some informal examples for concurrency control. any help would be greatly appreciated.

我遇到了这个问题。以及并发控制的一些非正式示例。任何帮助将不胜感激。

回答by Justin

Concurrent execution of database transactions in a multi-user system means that any number of users can use the same database at the same time. Concurrency control is needed in order to avoid inconsistencies in the database.

在多用户系统中并发执行数据库事务意味着任意数量的用户可以同时使用同一个数据库。需要并发控制以避免数据库中的不一致。

Here is an example of how this scenario can lead to an inconsistency:

以下是此场景如何导致不一致的示例:

Assume we have two users, Alice and Bob, who both have access to the same bank account. Alice wants to deposit $100 and Bob wants to withdraw $200. Assuming there is $500 in the account, here is how the execution mighttake place if they perform their actions at the same time:

假设我们有两个用户 Alice 和 Bob,他们都可以访问同一个银行账户。爱丽丝想存入 100 美元,鲍勃想提取 200 美元。假设账户中有 500 美元,如果他们同时执行他们的操作,执行可能会发生以下情况:

  1. Alice gets initial amount (x = $500)
  2. Bob gets initial amount (x = $500)
  3. Alice deposits $100 (x + 100) = $600
  4. Bob withdraws $200 (x - 200) = $300
  5. Alice saves the new balance ($600)
  6. Bob saves the new balance ($300)
  1. Alice 获得初始金额 (x = $500)
  2. Bob 获得初始金额 (x = $500)
  3. Alice 存入 $100 (x + 100) = $600
  4. Bob 提取 200 美元 (x - 200) = 300 美元
  5. 爱丽丝保存新余额(600 美元)
  6. 鲍勃保存新余额(300 美元)

New balance after both actions should be $400. Now the database is in an inconsistent state.

两次操作后的新余额应为 400 美元。现在数据库处于不一致状态。

Concurrency control can prevent inconsistencies by providing Alice with a temporary "lock" on the database until she is done with her action.

并发控制可以通过为 Alice 提供数据库上的临时“锁定”来防止不一致,直到她完成她的操作。

回答by Johan Kotlinski

Well, it is as simple as this... Say you have a bank, and simultaneously two persons try to withdraw 100 from an account with 100 on it. These are concurrent operations.

嗯,就是这么简单……假设你有一家银行,同时两个人试图从一个有 100 的账户中提取 100。这些是并发操作。

You need to make sure that only one of them manage to withdraw 100. This is concurrency handling.

您需要确保只有其中一个能够提取 100。这是并发处理。

回答by Diwas Poudel

My english is not so good but I am trying my best to answer the term mentioned.

我的英语不是很好,但我正在尽力回答提到的术语。

In my view, the action will be too fast that it seems doing the work by the number of users at the same time. Doing the work at the same time means doing the work parallelly but this doesn't happen in the case of concurrent.

在我看来,动作会太快,以至于它似乎在同时按用户数量进行工作。同时做工作意味着并行做工作,但在并发的情况下不会发生这种情况。

Concurrencyis when two tasks can start, run, and complete in overlapping time periods. It doesn't necessarily mean they'll ever both be running at the same instant.

Concurrency是指两个任务可以在重叠的时间段内启动、运行和完成。这并不一定意味着它们会同时运行。

Eg.multitasking on a single-core machine.

例如。在单核机器上进行多任务处理。

回答by Sachin De Silva

Concurrent execution of database transactions in a multi-user system is where any number of users can use the same database at the same time. Concurrency control is needed in order to avoid inconsistencies in the database. Examples Assume that there are two administrators oliver and gorge who have access to the same users' database record in an organization. Oliver is trying to update one of the records of a particular user at the same time Ross is trying to update a record of the same user. If there are no proper ways of dealing with the simultaneous access of this data, possibly the final result of the updated data of that user might be inaccurate

在多用户系统中并发执行数据库事务是指任意数量的用户可以同时使用同一个数据库。需要并发控制以避免数据库中的不一致。示例 假设有两个管理员 Oliver 和 Gorge,他们有权访问组织中相同用户的数据库记录。Oliver 正在尝试更新特定用户的记录之一,而 Ross 正在尝试更新同一用户的记录。如果没有适当的方法来处理这些数据的同时访问,则可能该用户更新数据的最终结果可能不准确