Vsr

Viewstamped Replication for Elixir

A distributed consensus system implementing the Viewstamped Replication (VSR) protocol, providing fault-tolerant state machine replication with automatic failure recovery.

Features

Core VSR Protocol

Implemented Components

Observability

Current Limitations

⚠️ Client Request Deduplication: Currently only implemented for read-only operations. Write operations may be processed multiple times if clients retry requests due to network timeouts. This does not affect VSR protocol correctness or safety properties, but may impact user experience.

⚠️ No Reconfiguration Support: The implementation assumes a static cluster with fixed membership. Dynamic addition or removal of replicas (reconfiguration protocol from the VSR paper) is not currently supported.

Installation

If available in Hex, the package can be installed by adding vsr to your list of dependencies in mix.exs:

def deps do
  [
    {:vsr, "~> 0.1.0"}
  ]
end

Usage

# Start a VSR replica with a key-value state machine
{:ok, replica} = Vsr.start_link(
  log: [],
  state_machine: VsrKv,
  cluster_size: 3
)

# Perform operations
VsrKv.put(replica, "key", "value")
result = VsrKv.get(replica, "key")  # Returns "value"

Testing

Unit Tests

mix test

Test Status: 106/106 tests passing

Jepsen Maelstrom Testing

VSR includes integration with Jepsen Maelstrom, a workbench for learning distributed systems by writing your own implementations and testing them against fault injection.

Download Maelstrom

  1. Download the latest Maelstrom release:

    wget https://github.com/jepsen-io/maelstrom/releases/download/v0.2.3/maelstrom.tar.bz2
    tar -xjf maelstrom.tar.bz2
  2. Or use the provided script to download and extract:

    curl -L https://github.com/jepsen-io/maelstrom/releases/download/v0.2.3/maelstrom.tar.bz2 | tar -xj

Run Maelstrom Tests

The repository includes a convenience script for running linearizable key-value tests:

./maelstrom-kv

This runs the lin-kv workload which tests:

Manual Maelstrom Testing

You can also run Maelstrom tests manually:

cd maelstrom
java -jar maelstrom.jar test \
  -w lin-kv \
  --bin ../run-vsr-node \
  --node-count 3 \
  --time-limit 10 \
  --concurrency 6

Workload Options:

Interpreting Results

After a test run, check:

  1. Test results: Maelstrom will report if linearizability was maintained
  2. Logs: Found in store/lin-kv/latest/
    • jepsen.log - Test runner logs and errors
    • node-logs/n*.log - Individual node logs

Success criteria:

Architecture

See SPECIFICATION.md for detailed VSR protocol specification.

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/vsr.