解释dbms中使用的锁定。_DBMS中的锁定协议及其类型

解释dbms中使用的锁定。

DBMS中的锁定协议 (Locking Protocol in DBMS)

The protocol utilizes locks, applied by a transaction to data, which may block (interpreted as signals to stop) other transactions from accessing the same data during the transaction's life.

协议利用事务施加到数据的锁,这可以阻止(解释为停止信号)其他事务在事务生命期内访问同一数据。

锁定协议的类型 (Types of locking protocols)

  1. Simple locking

    简单锁定

  2. 2-Phase Locking

    两相锁定

    1. Simple 2-phase locking
    2. Conservative 2-Phase locking
    3. Strict 2-phase locking
    4. Rigorous 2-phase locking
  3. Graph-based locks

    基于图的锁

1)简单锁定 (1) Simple locking)

  • If the first transaction is a shared lock, then the second transaction is to use a shared lock.

    如果第一个事务是共享锁,则第二个事务将使用共享锁。

  • If the first lock is an exclusive lock, then no lock use in the second transaction.

    如果第一个锁是排他锁,则在第二个事务中不使用任何锁。

Note: Simple locking achieves consistency means infinite waiting and sometimes it creates a problem.

注意:简单锁定实现一致性意味着无限等待,有时会产生问题。

2)两相锁定 (2) 2-Phase lock)

It is used to overcome the disadvantage of the simple lock. In the 2-phase locking, there are two phases are growing phase and shrinking phase. 2-phase ensures serializability.

它用于克服简单锁定的缺点。 在2相锁定中,有两个阶段:生长阶段和收缩阶段。 2相确保可串行化。

Growing phase: A transaction may obtain locks but not release any locks.

生长阶段:事务可以获取锁,但不能释放任何锁。

Shrinking phase: A transaction may release lock but may not obtain new locks.

缩减阶段:事务可能会释放锁,但可能不会获得新的锁。

a) Simple 2-phase locking: Once a transaction releases a lock it enters in shrinking phase and in shrinking phase it cannot issue any more locks.

a)简单的两阶段锁定:一旦事务释放了锁定,它就会进入收缩阶段,而在收缩阶段就无法再发出任何锁定。

Advantage:

优点:

  • Less resource utilization.

    资源利用率较低。

Disadvantage:

坏处:

  • Deadlock present.

    存在死锁。

Note: The final point of lock-in schedule of transaction called lock point of transaction. We denote conversion from shared to an exclusive mode called upgrade and its opposite conversion from exclusive to shared mode is called downgrade.

注意:交易锁定时间表的最终点称为交易锁定点。 我们表示从共享模式到独占模式的转换称为升级,而从独占模式到共享模式的相反转换称为降级。

b) Conservative 2-phase locking: The lock of the entire data item that we need before the transaction starts.

b)保守的两阶段锁定:在事务开始之前,我们需要锁定整个数据项。

Advantage:

优点:

  • No waiting for the data item

    无需等待数据项

  • No deadlock create

    没有死锁

Disadvantage:

坏处:

  • Practically data implementation is difficult

    实际上很难实现数据

c) Strict 2-phase locking: Transaction does not release any of the exclusive locks until after its commit or abort.

c)严格的两阶段锁定:事务在提交或中止之后才释放任何排他锁。

Advantage:

优点:

  • No dirty read problem

    没有脏读问题

  • Proper lock

    正确锁

Disadvantage:

坏处:

  • Deadlock create

    死锁创建

d) Rigorous 2-phase locking: Transaction "t" does not release any of its locks until after it commits or aborts. All lock release at the same time no lock release first or last.

d)严格的两阶段锁定:事务“ t”在提交或中止之后才释放其任何锁定。 所有锁同时释放,没有第一个或最后一个锁释放。

3)基于图的协议 (3) Graph-based protocol)

It follows 6 rules:

它遵循6条规则:

  • It uses the only exclusive lock.

    它使用唯一的排他锁。

  • The first lock can be acquired on any data item.

    可以在任何数据项上获取第一锁。

  • Subsequent locks are allowed only if the parent is locked.

    仅当父级被锁定时,才允许后续锁定。

  • Unlock at any point.

    随时解锁。

  • Each data item can be accessed at most once.

    每个数据项最多可以访问一次。

  • Relocking by the same transaction is not allowed.

    不允许通过同一事务重新锁定。

Advantage:

优点:

  • No rollback

    无回滚

  • No deadlock

    无死锁

  • Less waiting time

    等待时间更少

Disadvantage:

坏处:

  • Prior knowledge of data

    数据先验知识

  • Unnecessary lock

    不必要的锁

Conclusion:

结论:

In this article, we have learned all the types of locking protocols and its advantage and disadvantage. In the next article, we gather more about DBMS. Stay tuned for the next article. Have a nice day! Happy Learning!

在本文中,我们了解了锁定协议的所有类型以及它的优缺点 。 在下一篇文章中,我们将收集有关DBMS的更多信息。 请继续关注下一篇文章。 祝你今天愉快! 学习愉快!

翻译自: https://www.includehelp.com/dbms/locking-protocols-and-its-types-in-dbms.aspx

解释dbms中使用的锁定。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值