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.
| a shared request | an exclusive request | |
|---|---|---|
| nothing held | 1 | 1 |
| shared held | 1 | 0 |
| exclusive held | 0 | 0 |
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 contentsThis 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