Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Add swarm mode testdrive example #113

Merged
merged 1 commit into from
Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions testdrive/swarm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Swarm Mode Testdrive

This testdrive example shows how to leverage docker-compose to run Scrolls in "swarm mode".

## How does it work?

The docker compose file will start several Scrolls instances, each instance as a different container. The config for each pipeline instructs Scrolls to crawl a different segment of the chain (by setting the intersect & finalize sections).

> **Note**
> The segments were constructed by hand. Since the chain-sync mini-protocol requires slot & hash to initiate, there's no _easy_ way to define the segments programatically. Automating this step is out of scope for this example.

Each Scrolls instance requires a different config file. To avoid duplicating of common values, we use a feature called 'layered config'. There's a `common.toml` file with the values shared across all instances. The instance-specific values are defined in `daemon-x.toml` files, Scrolls will _overlay_ these values on top of the ones defined in `common.toml`.

> **Warning**
> Swarm mode won't work correctly with reducers that require the 'enrich' stage. For the enrich stage to work correctly, it needs to crawl the chain from origin. Swarm mode relies on crawling the chain from different points. Attempting to run both features simultaneously will yield unknown results.

The data from each Scrolls instance is sent to a single, shared Redis instance. The cursor for each pipeline is kept as a different Redis key to avoid collisions. It should be safe to stop / start the whole swarm, each pipeline will attempt to continue from where it was prior to the restart.

## Getting started

Run the following command from within the directory of this example:

```sh
docker-compose up
```
17 changes: 17 additions & 0 deletions testdrive/swarm/common.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[source]
type = "N2N"
address = "relays-new.cardano-mainnet.iohk.io:3001"

[[reducers]]
type = "AddressByTxo"
key_prefix = "c1"

[storage]
type = "Redis"
connection_params = "redis://redis:6379"

[chain]
type = "Mainnet"

[policy]
missing_data = "Skip"
8 changes: 8 additions & 0 deletions testdrive/swarm/daemon-a.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[intersect]
type = "Origin"

[storage]
cursor_key = "_cursor_a"

[finalize]
until_hash = "d74267944135fad75d90476630d032e7f11e460993a71ae5c024a00864da2b7b"
12 changes: 12 additions & 0 deletions testdrive/swarm/daemon-b.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[intersect]
type = "Point"
value = [
1329363,
"d74267944135fad75d90476630d032e7f11e460993a71ae5c024a00864da2b7b",
]

[storage]
cursor_key = "_cursor_b"

[finalize]
until_hash = "16367ca4c0c6daed1f4c74d7f7af9c71f7e0a88dfb6289b34d33f8a9039eb3a2"
12 changes: 12 additions & 0 deletions testdrive/swarm/daemon-c.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[intersect]
type = "Point"
value = [
2659848,
"16367ca4c0c6daed1f4c74d7f7af9c71f7e0a88dfb6289b34d33f8a9039eb3a2",
]

[storage]
cursor_key = "_cursor_c"

[finalize]
until_hash = "d30b6e06d72d479441d3bb832306926a81cd79c09e275741e9968ab7f1cc9a0a"
12 changes: 12 additions & 0 deletions testdrive/swarm/daemon-d.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[intersect]
type = "Point"
value = [
3989584,
"d30b6e06d72d479441d3bb832306926a81cd79c09e275741e9968ab7f1cc9a0a",
]

[storage]
cursor_key = "_cursor_c"

[finalize]
until_hash = "4100ba6296f8e8437032c308ee24920027d96f00467a46ad36711bed23e10459"
12 changes: 12 additions & 0 deletions testdrive/swarm/daemon-e.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[intersect]
type = "Point"
value = [
21243299,
"4100ba6296f8e8437032c308ee24920027d96f00467a46ad36711bed23e10459",
]

[storage]
cursor_key = "_cursor_c"

[finalize]
until_hash = "5f78088805e8ff56bdd2c11d13944d5d8ce99df041922711789dec346979256f"
12 changes: 12 additions & 0 deletions testdrive/swarm/daemon-f.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[intersect]
type = "Point"
value = [
48312866,
"5f78088805e8ff56bdd2c11d13944d5d8ce99df041922711789dec346979256f",
]

[storage]
cursor_key = "_cursor_c"

[finalize]
until_hash = "8ae85d3f16843e8fbb572de471d5364e03b9a87c9097ce05690452e2e6afea64"
1 change: 1 addition & 0 deletions testdrive/swarm/data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dump.rdb
75 changes: 75 additions & 0 deletions testdrive/swarm/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
version: "3.7"

services:
scrolls-a:
image: ghcr.io/txpipe/scrolls-testdrive:testdrive
command: [ "daemon" ]
environment:
- RUST_LOG=info
working_dir: "/"
volumes:
- ./daemon-a.toml:/scrolls.toml
- ./common.toml:/etc/scrolls/daemon.toml
links:
- redis
scrolls-b:
image: ghcr.io/txpipe/scrolls-testdrive:testdrive
command: [ "daemon" ]
environment:
- RUST_LOG=info
working_dir: "/"
volumes:
- ./daemon-b.toml:/scrolls.toml
- ./common.toml:/etc/scrolls/daemon.toml
links:
- redis
scrolls-c:
image: ghcr.io/txpipe/scrolls-testdrive:testdrive
command: [ "daemon" ]
environment:
- RUST_LOG=info
working_dir: "/"
volumes:
- ./daemon-c.toml:/scrolls.toml
- ./common.toml:/etc/scrolls/daemon.toml
links:
- redis
scrolls-d:
image: ghcr.io/txpipe/scrolls-testdrive:testdrive
command: [ "daemon" ]
environment:
- RUST_LOG=info
working_dir: "/"
volumes:
- ./daemon-d.toml:/scrolls.toml
- ./common.toml:/etc/scrolls/daemon.toml
links:
- redis
scrolls-e:
image: ghcr.io/txpipe/scrolls-testdrive:testdrive
command: [ "daemon" ]
environment:
- RUST_LOG=info
working_dir: "/"
volumes:
- ./daemon-e.toml:/scrolls.toml
- ./common.toml:/etc/scrolls/daemon.toml
links:
- redis
scrolls-f:
image: ghcr.io/txpipe/scrolls-testdrive:testdrive
command: [ "daemon" ]
environment:
- RUST_LOG=info
working_dir: "/"
volumes:
- ./daemon-f.toml:/scrolls.toml
- ./common.toml:/etc/scrolls/daemon.toml
links:
- redis
redis:
image: redis
volumes:
- ./data:/data
ports:
- "6379:6379"