jepsen.reconnect

Stateful wrappers for automatically reconnecting network clients.

A wrapper is a map with a connection atom conn and a pair of functions: (open), which opens a new connection, and (close conn), which closes a connection. We use these to provide a with-conn macro that acquires the current connection from a wrapper, evaluates body, and automatically closes/reopens the connection when errors occur.

Connect/close/reconnect lock the wrapper, but multiple threads may acquire the current connection at once.

close!

(close! wrapper)

Closes a wrapper.

conn

(conn wrapper)

Active connection for a wrapper, if one exists.

open!

(open! wrapper)

Given a wrapper, opens a connection. Noop if conn is already open.

reopen!

(reopen! wrapper)

Reopens a wrapper’s connection.

with-conn

macro

(with-conn [c wrapper] & body)

Acquires a read lock, takes a connection from the wrapper, and evaluates body with that connection bound to c. If any Exception is thrown, closes the connection and opens a new one.

with-lock

macro

(with-lock wrapper lock-method & body)

with-read-lock

macro

(with-read-lock wrapper & body)

with-write-lock

macro

(with-write-lock wrapper & body)

wrapper

(wrapper options)

A wrapper is a stateful construct for talking to a database. Options:

:name An optional name for this wrapper (for debugging logs) :open A function which generates a new conn :close A function which closes a conn :log? Whether to log reconnect messages. A special value, minimal logs only a single line rather than a full stacktrace.