Skip to main content

Module writer

Module writer 

Source
Expand description

Singleton write authority: the advisory boot lock and the durable epoch.

Two independent guards, because they fail in different directions.

The advisory lock is held for the process lifetime on its own dedicated connection, taken with the NONBLOCKING variant so a second kernel exits immediately with a clear message instead of hanging on a queue nobody is watching. PostgreSQL releases a session advisory lock when its session ends, so the lock is exactly as alive as that connection — which is why losing the connection and losing the lock are the same event, and why a dead probe is sufficient evidence of both.

The durable epoch covers what the lock cannot. A process that was fenced out may still hold pooled connections with in-flight work; the lock says nothing about those. Bumping a row at boot and comparing it inside every mutating transaction makes such a write fail at COMMIT time rather than land behind its successor’s back.

Structs§

WriterLock
The process-lifetime advisory lock, plus the signal that it is gone.

Constants§

LOCK_PROBE_INTERVAL
How often the holder proves its connection is still alive.
WRITER_LOCK_KEY
The advisory-lock key for “this database’s kernel writer”.

Functions§

claim_epoch
Claim this boot’s writer epoch: bump the durable counter under a row lock and return what this process must present from now on.