/ THE IDEA
The lock record contains an owner token, a hard-to-guess unique value chosen for that acquisition. Acquiring a lock means creating the record only if it does not already exist, with an expiry time so abandoned ownership can end. Releasing it must compare the stored token with the caller’s token and delete only if they match. The comparison and deletion must be one indivisible action at the lock service. Reading the token first and issuing a separate unconditional delete leaves room for ownership to change between the two steps.
THE FORMAL IDEA
if stored_owner = my_token, delete; otherwise leave unchanged
| stored_owner is the value currently inside the lock record. | | my_token identifies this particular acquisition, not just the computer’s name. A later acquisition by the same computer must receive a different value so old cleanup cannot release new ownership. |
|
RUN THE TINY EXAMPLE
Change one thing. Predict what happens.
Worker A acquires the report lock with token apple-17. A pauses; the record expires. B acquires it with token birch-29. A returns and asks to release apple-17. The comparison fails, so B’s record stays. Change A’s cleanup to unconditional delete: B’s active lock disappears, allowing another worker to enter.
|
Only the release rule changed, yet the replacement went from protected to exposed. Tokens make the service distinguish an old owner’s cleanup from the current owner’s legitimate release request.
/ SO WHAT?
The same ownership check matters when extending a lock’s lifetime. A late renewal from A must not quietly renew or replace B’s record. This is why a lock is more than a shared boolean saying busy. Its current owner and the atomic transitions between owners carry part of the safety argument. Application code should use a tested primitive that performs those transitions together, not assemble them from separate reads and writes.
ONE CAVEAT |
| This token prevents one acquisition from releasing another’s record. It does not stop an expired owner continuing work on the protected resource. A random owner token is not an increasing fencing token, and correctness-sensitive writes may need destination-side authority enforcement as well. |
KEEP THIS
A safe unlock removes only the caller’s own acquisition, because a delayed former owner may be cleaning up after ownership has changed.
|
NEXT: Why every space photograph is an old photograph
|