Module molly.client

Module with default Molly client.

A client is executed by a thread pool in a number of stages: open a connection, set up the DB, invoke operations, tear down and close. When a runner passes opts.barriers (see molly.thread), threads synchronize at stage boundaries: no thread runs operations until every thread opened a connection and set up the DB, and no thread tears down until every thread finished operations. Only open, setup and invoke boundaries are synchronized; threads tear down and close connections independently after the last barrier.

An operation that crashed a client is recorded as an info operation (an indeterminate state) and the process is restarted, as in Jepsen. A client that is not reusable is reopened before the next operation; see the reusable method below.

See also:

Functions

new () Function that returns a default client implementation.

Local Functions

run_client (thread_id, opts)


Functions

new ()
Function that returns a default client implementation.

Default implementation of a client defines open, setup, teardown and close methods with empty implementation that always returns true.

Client must implement the following methods:

open - function that open a connection to a database instance. Function must raise an error on failure. Two arguments are passed to the function: - address - an 'address' of the remote node - client_data - a table with client's data

setup - function that set up a database instance. Function must raise an error on failure. A single argument is passed to the function: - client_data - a table with client's data

invoke - function that accept an operation and invoke it on database instance, function should process user-defined types of operations and execute intended actions on databases. Function must return an operation after invocation. Two arguments are passed to the function: - op - an operation generated by a test generator - client_data - a table with client's data

An invoke that raises an error crashes the client. The operation is recorded in a history as info (an indeterminate state: it may or may not have taken place) and the process is restarted. See reusable below.

teardown - function that tear down a database instance. Function must raise an error on failure. Single argument is passed to the function: - client_data - a table with client's data

close - function that close connection to a database instance. Function must raise an error on failure. Single argument is passed to the function: - client_data - a table with client's data

reusable - optional function that reports whether a client survives a crashed invocation without a restart. A single argument is passed to the function: - client_data - a table with client's data A client is not reusable by default, as in Jepsen: after a crashed invoke (or an invoke that returned info) the connection is reopened with close and open before the next operation. A failed reconnect is recorded as a fail operation and retried on the next operation.

In general it is recommended to raise an error in case of fatal errors like failed database setup, teardown or connection and set status of operation to 'fail' when key is not found in database table etc. A returned false is not treated as a failure and does not abort a run.

Returns:

    client

See also:

Usage:

    local client = require('molly').client.new()
    client.invoke = function(op)
        return true
    end

Local Functions

run_client (thread_id, opts)

Parameters:

  • thread_id
  • opts
generated by LDoc 1.5.0 Last updated 2026-10-22 11:22:25