Skip to content
Ameen Abozaid
Planned lessonMID-032-L04

Fencing tokens

  • Lesson 4 of 5
  • Mid-level
On This Lesson 4 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

make stale holders harmless.

Planned topics

  • A fencing token is a number that increases every time the lock is granted.
  • The holder sends the token with each write; the resource rejects writes with a token lower than one it has seen.
  • The check must be at the resource (database, storage), not only in the client.
  • In SQL: store last_token and add WHERE last_token <= :token to the update.
  • A version column or a monotonically increasing sequence can provide the token.
Draft outline details

Demonstration

sql
UPDATE recon_state SET last_token = :t, result = :r
WHERE id = 1 AND last_token <= :t;   -- 0 rows updated: you are stale, stop

Check your understanding

Where must the token be checked?

Show answer

At the resource being written, not just in the client.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.