portunus_batch_keepalive (portunus v0.14.0)

View Source

Renews multiple leases in a single renewal round, for nodes with a lot of processes that use automatic lease renewal.

portunus_keepalive gives every holder its own renewer, so a node with N leases sends N renewal calls every TTL/3, each a leader round trip with a quorum heartbeat.

This module is one registered process per node that holders attach leases to. Leases sharing a {ClusterName, TTL} pair renew together in a single portunus:renew_leases/3 call, so the rate is per node, not per lease.

Resource owner processes monitor it and re-attach if it restarts. A lease survives the restart as long as the owner re-attaches within a TTL of the last renewal.

Summary

Functions

Attach LeaseId for batched renewal, with the caller as its lock owner. Pass the TTL the lease was granted with. The owner process should monitor this server (registered as portunus_batch_keepalive) and re-attach on 'DOWN'.

Stop renewing LeaseId. Idempotent.

The attached leases per {ClusterName, TTL} group. For introspection and tests.

Types

group_key()

-type group_key() :: {portunus:cluster_name(), portunus:ttl()}.

Functions

attach(ClusterName, LeaseId, TtlMs)

Attach LeaseId for batched renewal, with the caller as its lock owner. Pass the TTL the lease was granted with. The owner process should monitor this server (registered as portunus_batch_keepalive) and re-attach on 'DOWN'.

detach(ClusterName, LeaseId)

-spec detach(portunus:cluster_name(), portunus:lease_id()) -> ok.

Stop renewing LeaseId. Idempotent.

handle_call/3

handle_cast(Msg, State)

handle_info/2

init/1

overview()

-spec overview() -> #{group_key() => [portunus:lease_id()]}.

The attached leases per {ClusterName, TTL} group. For introspection and tests.

start_link()

-spec start_link() -> {ok, pid()} | {error, term()}.

terminate(Reason, State)