httk.store.mongo.leases

Cross-process writer and fsck leases for httk.store.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.mongo.leases.StoreLockedError[source]

Bases: RuntimeError

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

exception httk.store.mongo.leases.LeaseLostError[source]

Bases: StoreLockedError

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

class httk.store.mongo.leases.LeaseTiming[source]

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[source]
stale_multiplier: int = 4[source]
poll_initial: float = 0.02[source]
poll_max: float = 0.25[source]
property stale_after: float[source]

Return the age after which a writer heartbeat is stale.

class httk.store.mongo.leases.Lease[source]

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

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

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

release()[source]

Remove this process’s lease document.

class httk.store.mongo.leases.WriterLease[source]

Bases: Lease

A writer registration plus the generation seen during acquisition.

generation: int = 0[source]
class httk.store.mongo.leases.FsckLease[source]

Bases: Lease

The singleton fsck exclusion lease.

httk.store.mongo.leases.acquire_writer(database, *, timing=DEFAULT_TIMING)[source]

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.mongo.leases.acquire_fsck(database, *, force=False, timing=DEFAULT_TIMING)[source]

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.mongo.leases.clear_stale_lock(database, *, timing=DEFAULT_TIMING)[source]

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.