ContentsThe library

What a Transaction Promises

Take Them All Before You Give Any Back

Last timeThe Levels and What They Buy

Two kinds of lock, one rule about when you may release them, and that rule alone is enough to guarantee the serial order. It also makes a new failure possible.

Two mechanisms produce the guarantees in the previous lesson, and every

database uses one, the other, or both. This lesson is the first: locking. It is

the older idea, the easier one to prove correct, and the one whose failure mode

you have probably already seen in a log.

Two kinds and the table

A lock is taken on a thing, usually a row, in one of two modes. Shared means I

am reading this and I need it not to change. Exclusive means I am writing this

and nobody else may touch it.

FIG 1Which request can be granted while a lock is already held
a shared requestan exclusive request
nothing held11
shared held10
exclusive held00
One is grant, zero is wait. The marked cell is the only interesting entry and the reason the two modes exist at all: several readers can hold a shared lock on the same row at the same time, so reading does not serialise. Every other conflict is total. Note the asymmetry in the second row, which is the upgrade problem: a transaction holding a shared lock and wanting an exclusive one must wait for every other reader to finish, and two transactions doing that at once are already deadlocked.

That is the whole mechanism. What makes it a correctness argument rather than a

collection of waits is the rule about when locks may be given back.

The lesson stops here

5 more paragraphs to go

You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.

The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.

See the planThe contents

This is the reading half

Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.

The contents

The rest of this course

  1. 01The Power Can Fail Between Your Two Statements
  2. 02Both of Them Read 10 and Both of Them Wrote 11opening only
  3. 03Reading Something That Was Never True, and Three Relativesopening only
  4. 04Your Database Is Not Using the Level You Think It Isopening only
  5. 05Take Them All Before You Give Any Backyou are here
  6. 06Keep the Old Row and Nobody Has to Waitopening only
  7. 07Both Doctors Checked That Someone Else Was on Callopening only
  8. 08Name the Rule First, Then Pick the Weakest Level That Holds Itopening only

Read alongside