Skip to content

Commit 4f755f8

Browse files
committed
Merge pull request rzezeski#2 from russelldb/rdb_N_nodes
Update for multi-node devrel (as per riak)
2 parents cb073f1 + d95ad23 commit 4f755f8

9 files changed

+111
-58
lines changed

README.md

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ Now shut it down:
5656
devrel
5757
----------
5858

59-
Above we showed how to start a single node, but this isn't typically how other Riak Core based applications like Riak are tested. Instead, there is something called a _devrel_ that allows one to easily set up a local 3-node cluster.
59+
Above we showed how to start a single node, but this isn't typically how other Riak Core based applications like Riak are tested. Instead, there is something called a _devrel_ that allows one to easily set up a local `N`-node cluster. By defauly `N` is 4. You can change this by either editing the `Makefile` and changing `DEVNODES` to your prefered `N`, or by setting the variable `DEVNODES` before running the commands below.
6060

6161
Build the dev-nodes:
6262

6363
make devrel
6464

65-
This did create 3 separate instances under the `dev/` dir; check it out:
65+
This did create 4 separate instances under the `dev/` dir; check it out:
6666

6767
ls dev
6868

@@ -74,19 +74,19 @@ Verify that the nodes are up and running:
7474

7575
for d in dev/dev*; do $d/bin/firstapp ping; done
7676

77-
You should see three `pong` replies. At this point it is worth saying that you have three **INDIVIDUAL** firstapp nodes running. They are **NOT** aware of each other yet. In order to form a cluster you have to _join_ the nodes. That has to be done only once. If a node, or the entire cluster, goes down it will remember the nodes it was connected to.
77+
You should see four `pong` replies. At this point it is worth saying that you have four **INDIVIDUAL** firstapp nodes running. They are **NOT** aware of each other yet. In order to form a cluster you have to _join_ the nodes. That has to be done only once. If a node, or the entire cluster, goes down it will remember the nodes it was connected to.
7878

79-
for d in dev/dev{2,3}; do $d/bin/firstapp-admin join [email protected]; done
79+
for d in dev/dev{2,3,4}; do $d/bin/firstapp-admin join [email protected]; done
8080

8181
Finally, to make sure they really all agree on the shape of the cluster you can ask if the _ring_ is "ready."
8282

8383
./dev/dev1/bin/firstapp-admin ringready
8484

8585
Which returns something like:
8686

87-
TRUE All nodes agree on the ring ['[email protected]','[email protected]','[email protected]']
87+
TRUE All nodes agree on the ring ['[email protected]','[email protected]','[email protected]'],'[email protected]']
8888

89-
To verify you have a 3 node cluster and to see the distribution of the ring, run the `member_status` command:
89+
To verify you have a 4 node cluster and to see the distribution of the ring, run the `member_status` command:
9090

9191
./dev/dev1/bin/firstapp-admin member_status
9292

@@ -95,14 +95,42 @@ Which returns:
9595
================================= Membership ==================================
9696
Status Ring Pending Node
9797
-------------------------------------------------------------------------------
98-
valid 34.4% -- '[email protected]'
99-
valid 32.8% -- '[email protected]'
100-
valid 32.8% -- '[email protected]'
98+
valid 25.0% -- '[email protected]'
99+
valid 25.0% -- '[email protected]'
100+
valid 25.0% -- '[email protected]'
101+
valid 25.0% -- '[email protected]'
101102
-------------------------------------------------------------------------------
102-
Valid:3 / Leaving:0 / Exiting:0 / Joining:0 / Down:0
103+
Valid:4 / Leaving:0 / Exiting:0 / Joining:0 / Down:0
103104

104105
Pretty cool!! Your riak-core cluster is up and running.
105106

106107
And in case you want to stop all the nodes:
107108

108109
for d in dev/dev*; do $d/bin/firstapp stop; done
110+
111+
stage and stagedevrel
112+
----------
113+
114+
For rapid, iterative development both `make rel` and `make devrel`
115+
have a `stage` counterpart. Running either:
116+
117+
make stage
118+
119+
or
120+
121+
make stagedevrel
122+
123+
will cause the `deps` and `apps` directories to be symlinked into the
124+
release(s) `lib` directory. This means you can edit your apps source
125+
code, recompile it, and load it on to the running node(s). You can
126+
either start mochiweb reloader
127+
128+
reloader:start().
129+
130+
when attached to the node(s), which will cause any changes to be
131+
automatically reloaded. Or attach to a running node and run
132+
133+
`l(mod_name)`.
134+
135+
to reload a specific module.
136+

riak_core.Makefile

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,35 @@ stage : rel
2424
$(foreach dep,$(wildcard deps/*), rm -rf rel/{{appid}}/lib/$(shell basename $(dep))-* && ln -sf $(abspath $(dep)) rel/{{appid}}/lib;)
2525
$(foreach app,$(wildcard apps/*), rm -rf rel/{{appid}}/lib/$(shell basename $(app))-* && ln -sf $(abspath $(app)) rel/{{appid}}/lib;)
2626

27-
devrel: all dev1 dev2 dev3
2827

29-
dev1 dev2 dev3:
28+
##
29+
## Developer targets
30+
##
31+
## devN - Make a dev build for node N
32+
## stagedevN - Make a stage dev build for node N (symlink libraries)
33+
## devrel - Make a dev build for 1..$DEVNODES
34+
## stagedevrel Make a stagedev build for 1..$DEVNODES
35+
##
36+
## Example, make a 68 node devrel cluster
37+
## make stagedevrel DEVNODES=68
38+
39+
.PHONY : stagedevrel devrel
40+
DEVNODES ?= 4
41+
42+
# 'seq' is not available on all *BSD, so using an alternate in awk
43+
SEQ = $(shell awk 'BEGIN { for (i = 1; i < '$(DEVNODES)'; i++) printf("%i ", i); print i ;exit(0);}')
44+
45+
$(eval stagedevrel : $(foreach n,$(SEQ),stagedev$(n)))
46+
$(eval devrel : $(foreach n,$(SEQ),dev$(n)))
47+
48+
dev% : all
3049
mkdir -p dev
31-
(cd rel && ../rebar generate target_dir=../dev/$@ overlay_vars=vars/$@.config)
50+
rel/gen_dev $@ rel/vars/dev_vars.config.src rel/vars/$@_vars.config
51+
(cd rel && ../rebar generate target_dir=../dev/$@ overlay_vars=vars/$@_vars.config)
52+
53+
stagedev% : dev%
54+
$(foreach dep,$(wildcard deps/*), rm -rf dev/$^/lib/$(shell basename $(dep))* && ln -sf $(abspath $(dep)) dev/$^/lib;)
55+
$(foreach app,$(wildcard apps/*), rm -rf dev/$^/lib/$(shell basename $(app))* && ln -sf $(abspath $(app)) dev/$^/lib;)
3256

33-
devclean:
57+
devclean: clean
3458
rm -rf dev
35-

riak_core.dev1.config

Lines changed: 0 additions & 13 deletions
This file was deleted.

riak_core.dev2.config

Lines changed: 0 additions & 13 deletions
This file was deleted.

riak_core.dev3.config

Lines changed: 0 additions & 13 deletions
This file was deleted.

riak_core.dev_vars.config.src

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
2+
%% ex: ft=erlang ts=4 sw=4 et
3+
4+
%%
5+
%% etc/app.config
6+
%%
7+
{ring_state_dir, "data/ring"}.
8+
{web_ip, "127.0.0.1"}.
9+
{web_port, @WEBPORT@}.
10+
{handoff_port, @HANDOFFPORT@}.
11+
12+
%%
13+
%% etc/vm.args
14+
%%
15+
{node, "@NODE@"}.
16+
{cookie, "{{appid}}"}.
17+

riak_core.gen_dev

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#! /bin/sh
2+
#
3+
# gen_dev dev4 vars.src vars
4+
#
5+
# Generate an overlay config for devNNN from vars.src and write to vars
6+
#
7+
8+
NAME=$1
9+
TEMPLATE=$2
10+
VARFILE=$3
11+
12+
## Allocate 10 ports per node
13+
## .7 - http
14+
15+
NUMBER=${NAME##dev}
16+
BASE=$((10000 + 10 * $NUMBER))
17+
WEBPORT=$(($BASE + 8))
18+
HANDOFFPORT=$(($BASE + 9))
19+
NODENAME="{{appid}}$NUMBER@127.0.0.1"
20+
21+
echo "Generating $NAME - node='$NODENAME' http=$WEBPORT handoff=$HANDOFFPORT"
22+
sed -e "s/@NODE@/$NODENAME/" \
23+
-e "s/@WEBPORT@/$WEBPORT/" \
24+
-e "s/@HANDOFFPORT@/$HANDOFFPORT/" < $TEMPLATE > $VARFILE

riak_core.reltool.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
{profile, embedded},
1717
{excl_sys_filters, ["^bin/.*",
1818
"^erts.*/bin/(dialyzer|typer)"]},
19+
{excl_archive_filters, [".*"]},
1920
{app, sasl, [{incl_cond, include}]},
2021
{app, {{appid}}, [{incl_cond, include}]}
2122
]}.

riak_core.template

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
{dir, "rel"}.
1212
{template, "riak_core.reltool.config", "rel/reltool.config"}.
1313
{template, "riak_core.vars.config", "rel/vars.config"}.
14+
{template, "riak_core.gen_dev", "rel/gen_dev"}.
15+
{chmod, 8#744, "rel/gen_dev"}.
1416

1517
{dir, "rel/files"}.
1618
{file, "riak_core.app.config", "rel/files/app.config"}.
@@ -25,10 +27,7 @@
2527
{file, "riak_core.vm.args", "rel/files/vm.args"}.
2628

2729
{dir, "rel/vars"}.
28-
{template, "riak_core.dev1.config", "rel/vars/dev1.config"}.
29-
{template, "riak_core.dev2.config", "rel/vars/dev2.config"}.
30-
{template, "riak_core.dev3.config", "rel/vars/dev3.config"}.
31-
30+
{template, "riak_core.dev_vars.config.src", "rel/vars/dev_vars.config.src"}.
3231

3332
%% ./src
3433
{dir, "src"}.

0 commit comments

Comments
 (0)