Playing with Lasp in a 3 Node Cluster
After playing with Lasp in a single node in the previous post: Playing with Lasp and CRDTs
I created a rebar3 template to easily setup a 3 node cluster to play with Lasp where it shines, in a distributed environment.
Install rebar3 if you haven't already.
then install this template:
mkdir -p ~/.config/rebar3/templates git clone https://github.com/marianoguerra/rebar3_template_lasp.git ~/.config/rebar3/templates/rebar3_template_lasp
Use
rebar3 new rebar3_template_lasp name=laspy cd laspy # build the 3 node cluster make devrel # on 3 different shells make dev1-console make dev2-console make dev3-console # join all nodes: make devrel-join # check node members make devrel-status
On one of the nodes' shell run:
Key1 = <<"key1">>. Key2 = <<"key2">>. Timestamp = fun () -> erlang:unique_integer([monotonic, positive]) end. AwMapType = {state_awmap, [state_mvregister]}. AwMapVarName = <<"awmap">>. AwMapVal = #{what => i_am_an_awmap_value}. % declare the variable {ok, {AwMap, _, _, _}} = lasp:declare({AwMapVarName, AwMapType}, AwMapType). % update its content setting Key1 = AwMapVal {ok, {AwMap1, _, _, _}} = lasp:update(AwMap, {apply, Key1, {set, Timestamp(), AwMapVal}}, self()). % timestamp argument is not needed in mvregister, it's only for compatibility % with lwwregister {ok, _} = lasp:update(AwMap, {apply, Key1, {set, nil, AwMapVal}}, self()). % get the value {ok, AwMapRes} = lasp:query(AwMap1). AwMapRes. % {ok,[{<<"key1">>, {set, ...#{what => i_am_an_awmap_value} ... }}]} [{_, AwMapSet}] = AwMapRes. sets:to_list(AwMapSet). % [#{what => i_am_an_awmap_value}]
On another one run:
{ok, AwMapRes} = lasp:query({<<"awmap">>,{state_awmap,[state_mvregister]}}). AwMapRes. [{_, AwMapSet}] = AwMapRes. sets:to_list(AwMapSet).
You should get:
All the examples from the previous post should run.
A termcast (?) of the process:
Happy Lasping!