Computer Science An Overview _J. Glenn Brookshear _11th Edition

To solve such problems, a DBMS could force transactions to execute in
their entirety on a one-at-a-time basis by holding each new transaction in a
queue until those preceding it have completed. But a transaction often spends
a lot of time waiting for mass storage operations to be performed. By inter-
weaving the execution of transactions, the time during which one transaction
is waiting can be used by another transaction to process data it has already
retrieved. Most large database management systems therefore contain a
scheduler to coordinate time-sharing among transactions in much the same
way that a multiprogramming operating system coordinates interweaving of
processes (Section 3.3).

To guard against such anomalies as the incorrect summary problem and the
lost update problem, these schedulers incorporate a locking protocol in which
the items within a database that are currently being used by some transaction

are marked as such. These marks are called locks; marked items are said to be
locked. Two types of locks are common—shared locks and exclusive locks.
They correspond to the two types of access to data that a transaction might
require—shared access and exclusive access. If a transaction is not going to alter
a data item, then it requires shared access, meaning that other transactions are
also allowed to view the data. However, if the transaction is going to alter the
item, it must have exclusive access, meaning that it must be the only transaction
with access to that data.

In a locking protocol, each time a transaction requests access to a data
item, it must also tell the DBMS the type of access it requires. If a transaction
requests shared access to an item that is either unlocked or locked with a
shared lock, that access is granted and the item is marked with a shared lock.
If, however, the requested item is already marked with an exclusive lock, the
additional access is denied. If a transaction requests exclusive access to an
item, that request is granted only if the item has no lock associated with it. In
this manner, a transaction that is going to alter data protects that data from
other transactions by obtaining exclusive access, whereas several transactions
can share access to an item if none of them are going to change it. Of course,
once a transaction is finished with an item, it notifies the DBMS, and the asso-
ciated lock is removed.

Various algorithms are used to handle the case in which a transaction’s
access request is rejected. One algorithm is that the transaction is merely
forced to wait until the requested item becomes available. This approach, how-
ever, can lead to deadlock, since two transactions that require exclusive access
to the same two data items could block each other’s progress if each obtains
exclusive access to one of the items and then insists on waiting for the other. To
avoid such deadlocks, some database management systems give priority to
older transactions. That is, if an older transaction requires access to an item
that is locked by a younger transaction, the younger transaction is forced to
release all of its data items, and its activities are rolled back (based on the log).
Then, the older transaction is given access to the item it required, and the
younger transaction is forced to start again. If a younger transaction is repeat-
edly preempted, it will grow older in the process and ultimately become one
of the older transactions with high priority. This protocol, known as the
wound-wait protocol (old transactions wound young transactions, young
transactions wait for old ones), ensures that every transaction will ultimately
be allowed to complete its task.

Locking的更多相关文章

  1. MySQL 之 Metadata Locking 研究

    MySQL5.5 中引入了 metadata lock. 顾名思义,metadata lock 不是为了保护表中的数据的,而是保护 database objects(元数据)的.包括表结构.schem ...

  2. 数据库中的two phase locking

    数据库中的two phase locking 两段锁协议是指每个事务的执行可以分为两个阶段:生长阶段(加锁阶段)和衰退阶段(解锁阶段). 加锁阶段:在该阶段可以进行加锁操作.在对任何数据进行读操作之前 ...

  3. Double Checked Locking 模式

    转自:http://blog.csdn.net/wwsoon/article/details/1485886 之前在使用Double Check Locking 模式时,发现自己还是不太理解.于是写个 ...

  4. [zt]Singleton和Double-Checked Locking设计模式—UML图及代码实现

    Singleton和Double-Checked Locking设计模式,分别指的是单例模式和双重检查锁模式,它们都可以用于确保某个类只有一个对象实例化. 两个模式的区别在于:Singleton模式用 ...

  5. ConcurrentDictionary 对决 Dictionary+Locking

    在 .NET 4.0 之前,如果我们需要在多线程环境下使用 Dictionary 类,除了自己实现线程同步来保证线程安全之外,我们没有其他选择. 很多开发人员肯定都实现过类似的线程安全方案,可能是通过 ...

  6. SDK Manager failed to install 'java.exe' locking directory

    转自:http://stackoverflow.com/questions/13587478/sdk-manager-failed-to-install-java-exe-locking-direct ...

  7. 无锁编程(一) - Double-checked Locking

      Double-checked Locking,严格意义上来讲不属于无锁范畴,无论什么时候当临界区中的代码仅仅需要加锁一次,同时当其获取锁的时候必须是线程安全的,此时就可以利用 Double-che ...

  8. 锁之“轻量级锁”原理详解(Lightweight Locking)

    大家知道,Java的多线程安全是基于Lock机制实现的,而Lock的性能往往不如人意. 原因是,monitorenter与monitorexit这两个控制多线程同步的bytecode原语,是JVM依赖 ...

  9. 乐观锁(optimistic locking)与悲观锁(pessimistic locking)

    首先,乐观锁(optimistic locking)与悲观锁(pessimistic locking)基本是针对数据处理来说,也就是跟数据库有关的术语,目的是为了解决并发处理时所遇到的相关性能问题,以 ...

随机推荐

  1. 基于superagent 与 cheerio 的node简单爬虫

    最近重新玩起了node,便总结下基本的东西,在本文中通过node的superagent与cheerio来抓取分析网页的数据. 目的  superagent 抓取网页 cheerio 分析网页 准备 N ...

  2. android 文字写在图片上

    在linearlayout中直接设置背景图片,背景图片会被拉伸.. 我们来试一下imagebutton 但是imagebutton无法添加文字.. button能同时添加文字和图片但是图片比例没法控制 ...

  3. 向table添加水平滚动条

    转自:http://www.cnblogs.com/linjiqin/p/3148225.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4. ...

  4. Xamarin.Android编译CPU类型选择方式

    Xamarin.Android编译CPU类型选择方式 在Xamarin.Android编译的时候,默认提供了5种CPU类型供大家选择.它们分别为armeabi.armeabi-v7a.arm64-v8 ...

  5. 前端JSON使用总结

    JSON: JavaScript Object Notation(JavaScript 对象表示法)的简称. 1. 什么是 JSON ? JSON 指的是 JavaScript 对象表示法(JavaS ...

  6. POJ2823 Sliding Window(单调队列)

    题目要输出一个序列各个长度k的连续子序列的最大值最小值. 多次RMQ的算法也是能过的,不过单调队列O(n). 这题,队列存元素值以及元素下标,队尾出队维护单调性然后入队,队首出队保持新元素下标与队首元 ...

  7. Codeforces Round #213 (Div. 2) B. The Fibonacci Segment

    #include <iostream> #include <algorithm> #include <vector> using namespace std; in ...

  8. TYVJ P1031 热浪 Label:dijkstra 最短路

    背景 USACO OCT09 9TH 描述 德克萨斯纯朴的民眾们这个夏天正在遭受巨大的热浪!!!他们的德克萨斯长角牛吃起来不错,可是他们并不是很擅长生產富含奶油的乳製品.Farmer John此时以先 ...

  9. POJ 3335 Rotating Scoreboard(多边形的核)

    题目链接 我看的这里:http://www.cnblogs.com/ka200812/archive/2012/01/20/2328316.html 然后整理一下当做模版.0换成eps,会wa,应该要 ...

  10. POJ 2486 Apple Tree(树形DP)

    题目链接 树形DP很弱啊,开始看题,觉得貌似挺简单的,然后发现貌似还可以往回走...然后就不知道怎么做了... 看看了题解http://www.cnblogs.com/wuyiqi/archive/2 ...