Skip to content

Commit

Permalink
Merge pull request #2 from russelldb/rdb_N_nodes
Browse files Browse the repository at this point in the history
Update for multi-node devrel (as per riak)
  • Loading branch information
neuhausler committed Dec 22, 2012
2 parents cb073f1 + d95ad23 commit 4f755f8
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 58 deletions.
48 changes: 38 additions & 10 deletions README.md
Expand Up @@ -56,13 +56,13 @@ Now shut it down:
devrel
----------

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.
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.

Build the dev-nodes:

make devrel

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

ls dev

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

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

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.
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.

for d in dev/dev{2,3}; do $d/bin/firstapp-admin join firstapp1@127.0.0.1; done
for d in dev/dev{2,3,4}; do $d/bin/firstapp-admin join firstapp1@127.0.0.1; done

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

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

Which returns something like:

TRUE All nodes agree on the ring ['firstapp1@127.0.0.1','firstapp2@127.0.0.1','firstapp3@127.0.0.1']
TRUE All nodes agree on the ring ['firstapp1@127.0.0.1','firstapp2@127.0.0.1','firstapp3@127.0.0.1'],'firstapp4@127.0.0.1']

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

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

Expand All @@ -95,14 +95,42 @@ Which returns:
================================= Membership ==================================
Status Ring Pending Node
-------------------------------------------------------------------------------
valid 34.4% -- 'firstapp1@127.0.0.1'
valid 32.8% -- 'firstapp2@127.0.0.1'
valid 32.8% -- 'firstapp3@127.0.0.1'
valid 25.0% -- 'firstapp1@127.0.0.1'
valid 25.0% -- 'firstapp2@127.0.0.1'
valid 25.0% -- 'firstapp3@127.0.0.1'
valid 25.0% -- 'firstapp4@127.0.0.1'
-------------------------------------------------------------------------------
Valid:3 / Leaving:0 / Exiting:0 / Joining:0 / Down:0
Valid:4 / Leaving:0 / Exiting:0 / Joining:0 / Down:0

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

And in case you want to stop all the nodes:

for d in dev/dev*; do $d/bin/firstapp stop; done

stage and stagedevrel
----------

For rapid, iterative development both `make rel` and `make devrel`
have a `stage` counterpart. Running either:

make stage

or

make stagedevrel

will cause the `deps` and `apps` directories to be symlinked into the
release(s) `lib` directory. This means you can edit your apps source
code, recompile it, and load it on to the running node(s). You can
either start mochiweb reloader

reloader:start().

when attached to the node(s), which will cause any changes to be
automatically reloaded. Or attach to a running node and run

`l(mod_name)`.

to reload a specific module.

33 changes: 28 additions & 5 deletions riak_core.Makefile
Expand Up @@ -24,12 +24,35 @@ stage : rel
$(foreach dep,$(wildcard deps/*), rm -rf rel/{{appid}}/lib/$(shell basename $(dep))-* && ln -sf $(abspath $(dep)) rel/{{appid}}/lib;)
$(foreach app,$(wildcard apps/*), rm -rf rel/{{appid}}/lib/$(shell basename $(app))-* && ln -sf $(abspath $(app)) rel/{{appid}}/lib;)

devrel: all dev1 dev2 dev3

dev1 dev2 dev3:
##
## Developer targets
##
## devN - Make a dev build for node N
## stagedevN - Make a stage dev build for node N (symlink libraries)
## devrel - Make a dev build for 1..$DEVNODES
## stagedevrel Make a stagedev build for 1..$DEVNODES
##
## Example, make a 68 node devrel cluster
## make stagedevrel DEVNODES=68

.PHONY : stagedevrel devrel
DEVNODES ?= 4

# 'seq' is not available on all *BSD, so using an alternate in awk
SEQ = $(shell awk 'BEGIN { for (i = 1; i < '$(DEVNODES)'; i++) printf("%i ", i); print i ;exit(0);}')

$(eval stagedevrel : $(foreach n,$(SEQ),stagedev$(n)))
$(eval devrel : $(foreach n,$(SEQ),dev$(n)))

dev% : all
mkdir -p dev
(cd rel && ../rebar generate target_dir=../dev/$@ overlay_vars=vars/$@.config)
rel/gen_dev $@ rel/vars/dev_vars.config.src rel/vars/$@_vars.config
(cd rel && ../rebar generate target_dir=../dev/$@ overlay_vars=vars/$@_vars.config)

stagedev% : dev%
$(foreach dep,$(wildcard deps/*), rm -rf dev/$^/lib/$(shell basename $(dep))* && ln -sf $(abspath $(dep)) dev/$^/lib;)
$(foreach app,$(wildcard apps/*), rm -rf dev/$^/lib/$(shell basename $(app))* && ln -sf $(abspath $(app)) dev/$^/lib;)

devclean:
devclean: clean
rm -rf dev

13 changes: 0 additions & 13 deletions riak_core.dev1.config

This file was deleted.

13 changes: 0 additions & 13 deletions riak_core.dev2.config

This file was deleted.

13 changes: 0 additions & 13 deletions riak_core.dev3.config

This file was deleted.

17 changes: 17 additions & 0 deletions riak_core.dev_vars.config.src
@@ -0,0 +1,17 @@
%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ft=erlang ts=4 sw=4 et

%%
%% etc/app.config
%%
{ring_state_dir, "data/ring"}.
{web_ip, "127.0.0.1"}.
{web_port, @WEBPORT@}.
{handoff_port, @HANDOFFPORT@}.

%%
%% etc/vm.args
%%
{node, "@NODE@"}.
{cookie, "{{appid}}"}.

24 changes: 24 additions & 0 deletions riak_core.gen_dev
@@ -0,0 +1,24 @@
#! /bin/sh
#
# gen_dev dev4 vars.src vars
#
# Generate an overlay config for devNNN from vars.src and write to vars
#

NAME=$1
TEMPLATE=$2
VARFILE=$3

## Allocate 10 ports per node
## .7 - http

NUMBER=${NAME##dev}
BASE=$((10000 + 10 * $NUMBER))
WEBPORT=$(($BASE + 8))
HANDOFFPORT=$(($BASE + 9))
NODENAME="{{appid}}$NUMBER@127.0.0.1"

echo "Generating $NAME - node='$NODENAME' http=$WEBPORT handoff=$HANDOFFPORT"
sed -e "s/@NODE@/$NODENAME/" \
-e "s/@WEBPORT@/$WEBPORT/" \
-e "s/@HANDOFFPORT@/$HANDOFFPORT/" < $TEMPLATE > $VARFILE
1 change: 1 addition & 0 deletions riak_core.reltool.config
Expand Up @@ -16,6 +16,7 @@
{profile, embedded},
{excl_sys_filters, ["^bin/.*",
"^erts.*/bin/(dialyzer|typer)"]},
{excl_archive_filters, [".*"]},
{app, sasl, [{incl_cond, include}]},
{app, {{appid}}, [{incl_cond, include}]}
]}.
Expand Down
7 changes: 3 additions & 4 deletions riak_core.template
Expand Up @@ -11,6 +11,8 @@
{dir, "rel"}.
{template, "riak_core.reltool.config", "rel/reltool.config"}.
{template, "riak_core.vars.config", "rel/vars.config"}.
{template, "riak_core.gen_dev", "rel/gen_dev"}.
{chmod, 8#744, "rel/gen_dev"}.

{dir, "rel/files"}.
{file, "riak_core.app.config", "rel/files/app.config"}.
Expand All @@ -25,10 +27,7 @@
{file, "riak_core.vm.args", "rel/files/vm.args"}.

{dir, "rel/vars"}.
{template, "riak_core.dev1.config", "rel/vars/dev1.config"}.
{template, "riak_core.dev2.config", "rel/vars/dev2.config"}.
{template, "riak_core.dev3.config", "rel/vars/dev3.config"}.

{template, "riak_core.dev_vars.config.src", "rel/vars/dev_vars.config.src"}.

%% ./src
{dir, "src"}.
Expand Down

0 comments on commit 4f755f8

Please sign in to comment.