Skip to main content

Module owner_lock_record

Module owner_lock_record 

Source
Expand description

The owner record inside every owner-lock directory. What: The owner record inside every owner-lock directory (owner.json, schema version 1): its strict parser, its exact encoding, and the owner-liveness rule. Why: The landing, reservation, hook, capture and push locks are directories holding this record. The incumbent and its hook dispatcher write and read the same record (src/owner-lock/owner-lock-record.ts), so both wrappers contend on one lock and each retires the other’s dead lock.

In TS you’d write (pseudocode):

const record = parseOwnerLockRecord(text); const alive = await ownerLockHolderIsAlive(record);

Structs§

OwnerLockRecord
What: The durable owner of one published lock. A struct groups named fields; Option<String> is “text or nothing”. Why: The token distinguishes this acquisition from every other; the PID and birth identity prove liveness; the reservation lock also names its transaction.

Enums§

OwnerRecordError
What: Why a lock’s record could not be judged. Why: A malformed or unreadable record must stop the acquirer: it might belong to a live owner, and the wrapper never deletes a lock it cannot prove dead.
PublishedOwner
What: What reading a published lock found. Busy means the lock vanished while it was read, so the caller must look again. Why: A release or retirement renames the directory away at any moment; that is a race to retry, not corruption.

Constants§

OWNER_LOCK_RECORD_FILENAME
Owner record filename inside a published lock directory.
OWNER_LOCK_RECORD_LIMIT
Largest owner record read; a record is about 150 bytes, so anything near this is corrupt.
OWNER_LOCK_SCHEMA_VERSION
Owner-lock record schema version.

Functions§

encode_owner_lock_record
What: Encode an owner record exactly as the incumbent’s writeCandidate does: compact JSON in field order, with a trailing newline. Why: Records written by either wrapper are byte-identical for the same values.
owner_lock_holder_is_alive
What: Whether a recorded owner still runs with the same process birth. Why: A PID that names no process, a zombie, or a younger process reusing the PID is a dead owner. The incumbent’s ownerLockHolderIsAlive compares identities only.
parse_owner_lock_record
What: Parse an owner record’s text, or nothing when it is malformed. Why: The incumbent’s parseOwnerLockRecord accepts exactly: schema version 1, a non-empty token, a safe-integer PID of at least 1, a non-empty birth identity, and an optional non-empty transaction ID. Anything else is malformed.
read_owner_lock_record
What: Read the owner of a published lock directory. Why: A missing record or directory means the lock vanished (ENOENT, ENOTDIR), which the incumbent reports as busy so the caller retries.