Skip to content

Commit

Permalink
Add three nodes example
Browse files Browse the repository at this point in the history
  • Loading branch information
arcusfelis committed Sep 3, 2024
1 parent bc61bd9 commit 4b64dde
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,58 @@ Before making a new pull request run tests:
```
rebar3 all
```

# Three nodes example

Create file with a list of cluster nodes.

echo "node1@localhost\nnode2@localhost\nnode3@localhost" > /tmp/nodes.txt

Open 3 shells in tmux.

```bash
rebar3 shell --sname node1@localhost
rebar3 shell --sname node2@localhost
rebar3 shell --sname node3@localhost
```

On each node run:

```erlang
{ok, Disco} = cets_discovery:start(#{disco_file => "/tmp/nodes.txt"}).
cets:start(test_table, #{}).
cets_discovery:add_table(Disco, test_table).
```

Check the list of nodes:

```erlang
cets_discovery:info(Disco).
[#{memory => 201,size => 3,table => test_table,
nodes => [node1@localhost,node2@localhost,node3@localhost],
opts => #{},
join_ref => #Ref<22882.3930565377.1965031426.177252>,
ack_pid => <0.1066.0>,
other_servers => [<22882.601.0>],
pause_monitors => [],node_down_history => []}]
```

Insert records on one of the nodes (read about keys considerations before):

```erlang
cets:insert(test_table, {1, <<"test_info">>}).
cets:insert(test_table, {{cool_name, self()}, <<"use CETS as a process registry">>}).
```

Check records:

```erlang
ets:tab2list(test_table).
[{1,<<"test_info">>},
{{cool_name,<0.591.0>},
<<"use CETS as a process registry">>}]
```

Use ets API to read records.

Use supervision and `start_link` instead of `start` in the real world code.

0 comments on commit 4b64dde

Please sign in to comment.