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.
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.
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.