pg_lease

Crates.iopg_lease
lib.rspg_lease
version0.1.3
created_at2025-06-22 16:15:04.798307+00
updated_at2025-06-22 18:51:27.685916+00
descriptionPostgres lease management package for running a single looping function while a lease is held
homepage
repositoryhttps://github.com/danthegoodman1/pg_lease
max_upload_size
id1721730
size89,683
Dan Goodman (danthegoodman1)

documentation

https://docs.rs/pg_lease

README

pg_lease

Go and Rust package for Postgres lease management package for running a single looping function while a lease is held.

This is a great building block for distributed systems that need a simple mechanism to coordinate ownership of partitions via a single process making decisions. This can then be integrated with VerifyLeaseHeld to transactionally verify that the lease is still held when making updates.

Downstream dependencies (e.g. partitions) would asynchornously receive updates and use transactional methods to verify they own the partition when doing some operation (e.g. writing log segment metadata to postgres as the metadata store).

Architecture

With the current design, if a worker dies and then restarts, it can actually recover its lease before the timeout!

Not using LISTEN/NOTIFY

While this could be use to optimize for recovery, I chose not to use it for 2 reasons:

  1. Requires an extra connection
  2. Leases can be lost due to timeouts (crashed lease holder, hangs, etc.), so need polling anyway
Commit count: 0

cargo fmt