httk.store.backend.mongo.leases

Cross-process writer and fsck leases for httk.store.backend.mongo.

The lease protocol deliberately uses MongoDB’s server clock. A writer first inserts itself and only then looks for the fsck singleton; fsck does the opposite half of that handshake by installing the singleton before draining fresh writers.

Exceptions

StoreLockedError

An fsck lease or a live writer prevents the requested operation.

LeaseLostError

A lease owner tried to refresh after its lease was displaced.

Classes

LeaseTiming

Server-clock lease timings.

Lease

Shared lease state and heartbeat operations for writer and fsck leases.

WriterLease

A writer registration plus the generation seen during acquisition.

FsckLease

The singleton fsck exclusion lease.

Functions

acquire_writer(database, *[, timing])

Insert a writer lease, then check fsck and observe the layout generation.

acquire_fsck(database, *[, force, timing])

Install the fsck singleton and drain fresh writer registrations.

clear_stale_lock(database, *[, timing])

Clear a stale fsck lock after an administrator verified its owner died.

Module Contents

exception httk.store.backend.mongo.leases.StoreLockedError

Bases: RuntimeError

An fsck lease or a live writer prevents the requested operation.

exception httk.store.backend.mongo.leases.LeaseLostError

Bases: StoreLockedError

A lease owner tried to refresh after its lease was displaced.

class httk.store.backend.mongo.leases.LeaseTiming

Server-clock lease timings.

Parameters:
  • refresh_interval – Maximum normal interval between heartbeats.

  • stale_multiplier – Number of refresh intervals before a writer is stale.

  • poll_initial – Initial fsck writer-drain sleep.

  • poll_max – Maximum fsck writer-drain sleep.

refresh_interval: float = 2.0
stale_multiplier: int = 4
poll_initial: float = 0.02
poll_max: float = 0.25
property stale_after: float

Return the age after which a writer heartbeat is stale.

class httk.store.backend.mongo.leases.Lease

Shared lease state and heartbeat operations for writer and fsck leases.

database: Any
identifier: str
owner: str
timing: LeaseTiming
refresh_heartbeat(*, force=False)

Refresh this lease using MongoDB’s $$NOW server timestamp.

release()

Remove this process’s lease document.

class httk.store.backend.mongo.leases.WriterLease

Bases: Lease

A writer registration plus the generation seen during acquisition.

generation: int = 0
class httk.store.backend.mongo.leases.FsckLease

Bases: Lease

The singleton fsck exclusion lease.

httk.store.backend.mongo.leases.acquire_writer(database, *, timing=DEFAULT_TIMING)

Insert a writer lease, then check fsck and observe the layout generation.

The ordering is the writer half of the insert-then-check handshake. A stale fsck lease intentionally still blocks writers: clearing it is an explicit administrative assertion that its owner is dead.

httk.store.backend.mongo.leases.acquire_fsck(database, *, force=False, timing=DEFAULT_TIMING)

Install the fsck singleton and drain fresh writer registrations.

force may replace a pre-existing fsck lease and may proceed past stale writer residue. It is an administrative assertion that those owners are dead; using it against a still-running owner can corrupt the store.

httk.store.backend.mongo.leases.clear_stale_lock(database, *, timing=DEFAULT_TIMING)

Clear a stale fsck lock after an administrator verified its owner died.

This has no fencing: clearing a merely slow fsck can corrupt the store.