database 等待死亡和伤口等待有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32794142/
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 07:59:14  来源:igfitidea点击:

What is the difference between wait-die and wound-wait?

databasedeadlockdatabase-deadlocks

提问by Nadeem Bhati

What is the difference between wait-die and wound-wait?

等待死亡和伤口等待有什么区别?

I found that both the techniques of deadlock prevention are doing the same thing (Rollback of Older process).

我发现两种防止死锁的技术都在做同样的事情(旧进程的回滚)。

Can anybody explain me what is the difference between them with suitable example ?

谁能用合适的例子向我解释它们之间的区别?

回答by Parth Patel

Wait-die scheme: It is a non-preemptive technique for deadlock prevention. When transaction Ti requests a data item currently held by Tj, Ti is allowed to wait only if it has a timestamp smaller than that of Tj (That is Ti is older than Tj), otherwise Ti is rolled back (dies).

Wait-die 方案:它是一种防止死锁的非抢占式技术。当事务 Ti 请求 Tj 当前持有的数据项时,只有当它的时间戳小于 Tj 时才允许 Ti 等待(即 Ti 比 Tj 旧),否则 Ti 回滚(死亡)。

In this scheme, if a transaction requests to lock a resource (data item), which is already held with a conflicting lock by another transaction, then one of the two possibilities may occur ?

在这个方案中,如果一个事务请求锁定一个资源(数据项),而该资源(数据项)已经被另一个事务持有一个冲突锁,那么可能会出现两种可能性之一?

(1)If TS(Ti) < TS(Tj) ? that is Ti, which is requesting a conflicting lock, is older than Tj ? then Ti is allowed to wait until the data-item is available.

(1)如果 TS(Ti) < TS(Tj) ?即请求冲突锁的 Ti 比 Tj 更旧?然后允许 Ti 等待直到数据项可用。

(2)If TS(Ti) > TS(tj) ? that is Ti is younger than Tj ? then Ti dies. Ti is restarted later with a random delay but with the same timestamp.

(2)如果 TS(Ti) > TS(tj) ? 那是 Ti 比 Tj 年轻吗?然后Ti死了。Ti 稍后以随机延迟重新启动,但具有相同的时间戳。

This scheme allows the older transaction to wait but kills the younger one.

该方案允许较旧的事务等待但杀死较新的事务。

For example:

例如:

Suppose that transaction T22, T23, T24 have time-stamps 5, 10 and 15 respectively. If T22requests a data item held by T23 then T22 will wait. If T24 requests a data item held by T23, then T24 will be rolled back.

假设事务 T22、T23、T24 分别具有时间戳 5、10 和 15。如果 T22 请求 T23 持有的数据项,则 T22 将等待。如果 T24 请求 T23 持有的数据项,则 T24 将被回滚。

Wound-wait scheme:It is a preemptive technique for deadlock prevention. It is a counterpart to the wait-die scheme. When Transaction Ti requests a data item currently held by Tj, Ti is allowed to wait only if it has a timestamp larger than that of Tj, otherwise Tj is rolled back (Tj is wounded by Ti).

伤口等待方案:这是一种预防死锁的抢占技术。它是等待死亡计划的对应物。当事务 Ti 请求 Tj 当前持有的数据项时,只有当它的时间戳大于 Tj 时才允许 Ti 等待,否则 Tj 回滚(Tj 被 Ti 伤害)。

In this scheme, if a transaction requests to lock a resource (data item), which is already held with conflicting lock by some another transaction, one of the two possibilities may occur ?

在这个方案中,如果一个事务请求锁定一个资源(数据项),该资源已经被另一个事务持有冲突锁,可能会发生两种可能性之一?

(1)If TS(Ti) < TS(Tj), then Ti forces Tj to be rolled back ? that is Ti wounds Tj. Tj is restarted later with a random delay but with the same timestamp.

(1)如果 TS(Ti) < TS(Tj),那么 Ti 迫使 Tj 回滚?即 Ti 伤口 Tj。Tj 稍后以随机延迟重新启动,但具有相同的时间戳。

(2)If TS(Ti) > TS(Tj), then Ti is forced to wait until the resource is available.

(2)如果 TS(Ti) > TS(Tj),则 Ti 被强制等待,直到资源可用。

This scheme, allows the younger transaction to wait; but when an older transaction requests an item held by a younger one, the older transaction forces the younger one to abort and release the item.

这个方案,允许年轻的交易等待;但是当较旧的事务请求较年轻的事务持有的项目时,较旧的事务会强制较年轻的事务中止并释放该项目。

For example:

例如:

Suppose that Transactions T22, T23, T24 have time-stamps 5, 10 and 15 respectively . If T22requests a data item held by T23, then data item will be preempted from T23 and T23 will be rolled back. If T24 requests a data item held by T23, then T24 will wait.

假设事务 T22、T23、T24 分别具有时间戳 5、10 和 15。如果 T22 请求 T23 持有的数据项,则数据项将从 T23 中抢占并且 T23 将回滚。如果 T24 请求 T23 持有的数据项,则 T24 将等待。

In both the cases, the transaction that enters the system at a later stage is aborted.

在这两种情况下,稍后进入系统的事务都会中止。

回答by Jingguo Yao

Parth has given a detailed answer. Here I summarize it in a different way.

帕斯已经给出了详细的答案。这里我换一种方式总结一下。

Assume that Ti requests a lock held by Tj. The following table summarizes the actions taken for wait-die and wound-wait scheme:

假设 Ti 请求 Tj 持有的锁。下表总结了等待死亡和伤口等待方案所采取的行动:

                           wait-die         wound-wait
Ti is younger than Tj      Ti dies          Ti waits
Ti is older than Tj        Ti waits         Tj aborts

Both schemes prefer older transactions with an older timestamp.

两种方案都更喜欢具有较旧时间戳的较旧事务。

回答by Jason Law

wait-die: When an oldertransaction tries to lock a DB element that has been locked by a youngertransaction, it waits. When a youngertransaction tries to lock a DB element that has been locked by an oldertransaction, it dies.

等待模:当旧的事务试图锁定已锁定由一个DB元素年轻的交易,它等待。当较新的事务尝试锁定已被较旧事务锁定的 DB 元素时,它就会死亡

wound-wait: When an oldertransaction tries to lock a DB element that has been locked by a youngertransaction, it woundsthe younger transaction. When a youngertransaction tries to lock a DB element that has been locked by an oldertransaction, it waits.

伤口等待:当较旧的事务尝试锁定已被较年轻事务锁定的数据库元素时,它会伤害较年轻的事务。当较新的事务尝试锁定已被较旧事务锁定的数据库元素时,它会等待



References:

参考:

回答by 18446744073709551615

I'll put the @JingguoYao's summary a bit differently. I just rearranged it because for me (and others like me) it reads easier like this.

我将@JingguoYao 的总结稍有不同。我只是重新排列它,因为对我(和其他像我一样的人)来说,这样读起来更容易。

Assume that Ti requests a lock held by Tj. The following table summarizes the actions taken for wait-die and wound-wait scheme:

假设 Ti 请求 Tj 持有的锁。下表总结了等待死亡和伤口等待方案所采取的行动:

                Ti is older than Tj     Ti is younger than Tj
wait-die        Ti waits                Ti dies
wound-wait      Tj aborts               Ti waits

Both schemes prefer older transactions with an older timestamp.

两种方案都更喜欢具有较旧时间戳的较旧事务。

回答by Vijnana Yogi

In both cases Old is always champ i.e. will survive. Difference is from younger transaction point of view.

在这两种情况下,老总是冠军,即会生存。区别在于年轻的交易角度。

If younger one is requesting a resource held by a old trans. , in wait/die he can wait to give respect as Old trans.If younger one is requesting a resource held by a old trans., in wound/die he will be force to rollback as Old trans.

如果较年轻的人正在请求由旧的 trans 持有的资源。, 在wait/die 中他可以等待作为Old trans 给予尊重。如果年轻的人正在请求旧trans. 持有的资源,在wound/die 中他将被强制回滚为Old trans。

In both scheme old is never in loss.

在这两个计划中,旧的永远不会亏本。

Refer:https://www.tutorialspoint.com/dbms/dbms_deadlock.htm

参考:https: //www.tutorialspoint.com/dbms/dbms_deadlock.htm